if (std::abs(angular) < std::numeric_limits<double>::epsilon()) {
return std::numeric_limits<double>::infinity();
} else {
if (std::abs(angular) < std::numeric_limits<double>::epsilon()) {
return std::numeric_limits<double>::infinity();
} else {
- return PI_2p0 * Inertia() / angular;
+ return PI * 2.0 * Inertia() / angular;
+ }
+}
+
+double Body::SphereOfInfluence() const noexcept {
+ if (HasParent()) {
+ return orbit.SemiMajorAxis() * std::pow(Mass() / Parent().Mass(), 2.0 / 5.0);
+ } else {
+ return std::numeric_limits<double>::infinity();
* glm::eulerAngleXY(axis_tilt.x, axis_tilt.y);
inverse_orbital =
glm::eulerAngleYX(-axis_tilt.y, -axis_tilt.x)
* glm::eulerAngleXY(axis_tilt.x, axis_tilt.y);
inverse_orbital =
glm::eulerAngleYX(-axis_tilt.y, -axis_tilt.x)
} else {
orbital = glm::eulerAngleXY(axis_tilt.x, axis_tilt.y);
inverse_orbital = glm::eulerAngleYX(-axis_tilt.y, -axis_tilt.x);
} else {
orbital = glm::eulerAngleXY(axis_tilt.x, axis_tilt.y);
inverse_orbital = glm::eulerAngleYX(-axis_tilt.y, -axis_tilt.x);
glm::dmat4 i_mat((*i)->CollisionTransform());
for (auto j = (i + 1); j != end; ++j) {
glm::dvec3 diff((*i)->GetSituation().Position() - (*j)->GetSituation().Position());
double max_dist = ((*i)->Size() + (*j)->Size()) * 1.74;
glm::dmat4 i_mat((*i)->CollisionTransform());
for (auto j = (i + 1); j != end; ++j) {
glm::dvec3 diff((*i)->GetSituation().Position() - (*j)->GetSituation().Position());
double max_dist = ((*i)->Size() + (*j)->Size()) * 1.74;
for (auto &c : collisions) {
c.A().GetSituation().Move(c.Normal() * (c.Depth() * -0.5));
c.B().GetSituation().Move(c.Normal() * (c.Depth() * 0.5));
for (auto &c : collisions) {
c.A().GetSituation().Move(c.Normal() * (c.Depth() * -0.5));
c.B().GetSituation().Move(c.Normal() * (c.Depth() * 0.5));
- c.A().GetSituation().Accelerate(c.Normal() * -dot(c.Normal(), c.AVel()));
- c.B().GetSituation().Accelerate(c.Normal() * -dot(c.Normal(), c.BVel()));
+ c.A().GetSituation().Accelerate(c.Normal() * -glm::dot(c.Normal(), c.AVel()));
+ c.B().GetSituation().Accelerate(c.Normal() * -glm::dot(c.Normal(), c.BVel()));
namespace {
/// map p onto cube, s gives the surface, u and v the position in [-1,1]
void cubemap(const glm::dvec3 &p, int &s, double &u, double &v) noexcept {
namespace {
/// map p onto cube, s gives the surface, u and v the position in [-1,1]
void cubemap(const glm::dvec3 &p, int &s, double &u, double &v) noexcept {
- const glm::dvec3 p_abs(abs(p));
- const glm::bvec3 p_pos(greaterThan(p, glm::dvec3(0.0)));
+ const glm::dvec3 p_abs(glm::abs(p));
+ const glm::bvec3 p_pos(glm::greaterThan(p, glm::dvec3(0.0)));
glm::dvec3 Planet::TileCenter(int srf, int x, int y, double e) const noexcept {
double u = (double(x) - Radius() + 0.5) / Radius();
double v = (double(y) - Radius() + 0.5) / Radius();
glm::dvec3 Planet::TileCenter(int srf, int x, int y, double e) const noexcept {
double u = (double(x) - Radius() + 0.5) / Radius();
double v = (double(y) - Radius() + 0.5) / Radius();
for (int index = 0, surface = 0; surface < 6; ++surface) {
for (int y = 0; y < sidelength; ++y) {
for (int x = 0; x < sidelength; ++x, ++index) {
for (int index = 0, surface = 0; surface < 6; ++surface) {
for (int y = 0; y < sidelength; ++y) {
for (int x = 0; x < sidelength; ++x, ++index) {
pos[3][(surface + 2) % 3] = offset;
float tex = ts[TileAt(surface, x, y).type].texture;
const float tex_v_begin = surface < 3 ? 1.0f : 0.0f;
const float tex_v_end = surface < 3 ? 0.0f : 1.0f;
pos[3][(surface + 2) % 3] = offset;
float tex = ts[TileAt(surface, x, y).type].texture;
const float tex_v_begin = surface < 3 ? 1.0f : 0.0f;
const float tex_v_end = surface < 3 ? 0.0f : 1.0f;
attrib[4 * index + 0].normal = pos[0];
attrib[4 * index + 0].tex_coord[0] = 0.0f;
attrib[4 * index + 0].tex_coord[1] = tex_v_begin;
attrib[4 * index + 0].tex_coord[2] = tex;
attrib[4 * index + 0].normal = pos[0];
attrib[4 * index + 0].tex_coord[0] = 0.0f;
attrib[4 * index + 0].tex_coord[1] = tex_v_begin;
attrib[4 * index + 0].tex_coord[2] = tex;
attrib[4 * index + 1].normal = pos[1];
attrib[4 * index + 1].tex_coord[0] = 0.0f;
attrib[4 * index + 1].tex_coord[1] = tex_v_end;
attrib[4 * index + 1].tex_coord[2] = tex;
attrib[4 * index + 1].normal = pos[1];
attrib[4 * index + 1].tex_coord[0] = 0.0f;
attrib[4 * index + 1].tex_coord[1] = tex_v_end;
attrib[4 * index + 1].tex_coord[2] = tex;
attrib[4 * index + 2].normal = pos[2];
attrib[4 * index + 2].tex_coord[0] = 1.0f;
attrib[4 * index + 2].tex_coord[1] = tex_v_begin;
attrib[4 * index + 2].tex_coord[2] = tex;
attrib[4 * index + 2].normal = pos[2];
attrib[4 * index + 2].tex_coord[0] = 1.0f;
attrib[4 * index + 2].tex_coord[1] = tex_v_begin;
attrib[4 * index + 2].tex_coord[2] = tex;
attrib[4 * index + 3].normal = pos[3];
attrib[4 * index + 3].tex_coord[0] = 1.0f;
attrib[4 * index + 3].tex_coord[1] = tex_v_end;
attrib[4 * index + 3].normal = pos[3];
attrib[4 * index + 3].tex_coord[0] = 1.0f;
attrib[4 * index + 3].tex_coord[1] = tex_v_end;