]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/world.cpp
add ray/box intersect test
[blobs.git] / src / world / world.cpp
index 49380ac8afdbee816cc6fc6658b2e2b6f78161f4..ef9311fbb79022e1f826593dcd3d791c15704f55 100644 (file)
@@ -26,9 +26,6 @@
 #include <glm/gtx/io.hpp>
 #include <glm/gtx/transform.hpp>
 
-using blobs::G;
-using blobs::PI_2p0;
-
 using std::sin;
 using std::cos;
 using std::pow;
@@ -104,7 +101,7 @@ double Body::GravitationalParameter() const noexcept {
 
 double Body::OrbitalPeriod() const noexcept {
        if (parent) {
-               return PI_2p0 * sqrt(pow(orbit.SemiMajorAxis(), 3) / (G * (parent->Mass() + Mass())));
+               return PI * 2.0 * sqrt(pow(orbit.SemiMajorAxis(), 3) / (G * (parent->Mass() + Mass())));
        } else {
                return 0.0;
        }
@@ -114,7 +111,7 @@ double Body::RotationalPeriod() const noexcept {
        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;
        }
 }
 
@@ -165,11 +162,11 @@ void Body::Tick(double dt) {
 void Body::Cache() noexcept {
        if (parent) {
                orbital =
-                       orbit.Matrix(PI_2p0 * (GetSimulation().Time() / OrbitalPeriod()))
+                       orbit.Matrix(PI * 2.0 * (GetSimulation().Time() / OrbitalPeriod()))
                        * glm::eulerAngleXY(axis_tilt.x, axis_tilt.y);
                inverse_orbital =
                        glm::eulerAngleYX(-axis_tilt.y, -axis_tilt.x)
-                       * orbit.InverseMatrix(PI_2p0 * (GetSimulation().Time() / OrbitalPeriod()));
+                       * orbit.InverseMatrix(PI * 2.0 * (GetSimulation().Time() / OrbitalPeriod()));
        } else {
                orbital = glm::eulerAngleXY(axis_tilt.x, axis_tilt.y);
                inverse_orbital = glm::eulerAngleYX(-axis_tilt.y, -axis_tilt.x);
@@ -482,40 +479,40 @@ void Planet::BuildVAO(const Set<TileType> &ts) {
                                        glm::vec3 pos[5];
                                        pos[0][(surface + 0) % 3] = x + 0 - offset;
                                        pos[0][(surface + 1) % 3] = y + 0 - offset;
-                                       pos[0][(surface + 2) % 3] = surface < 3 ? offset : -offset;
+                                       pos[0][(surface + 2) % 3] = offset;
                                        pos[1][(surface + 0) % 3] = x + 0 - offset;
                                        pos[1][(surface + 1) % 3] = y + 1 - offset;
-                                       pos[1][(surface + 2) % 3] = surface < 3 ? offset : -offset;
+                                       pos[1][(surface + 2) % 3] = offset;
                                        pos[2][(surface + 0) % 3] = x + 1 - offset;
                                        pos[2][(surface + 1) % 3] = y + 0 - offset;
-                                       pos[2][(surface + 2) % 3] = surface < 3 ? offset : -offset;
+                                       pos[2][(surface + 2) % 3] = offset;
                                        pos[3][(surface + 0) % 3] = x + 1 - offset;
                                        pos[3][(surface + 1) % 3] = y + 1 - offset;
-                                       pos[3][(surface + 2) % 3] = surface < 3 ? offset : -offset;
+                                       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].position = normalize(pos[0]) * offset;
+                                       attrib[4 * index + 0].position = normalize(pos[0]) * (surface < 3 ? offset : -offset);
                                        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].position = normalize(pos[1]) * offset;
+                                       attrib[4 * index + 1].position = normalize(pos[1]) * (surface < 3 ? offset : -offset);
                                        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].position = normalize(pos[2]) * offset;
+                                       attrib[4 * index + 2].position = normalize(pos[2]) * (surface < 3 ? offset : -offset);
                                        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].position = normalize(pos[3]) * offset;
+                                       attrib[4 * index + 3].position = normalize(pos[3]) * (surface < 3 ? offset : -offset);
                                        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;