From 0e061ce526fe46dd3e894223e5d646eb2e30f826 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 8 Dec 2017 13:22:01 +0100 Subject: [PATCH] =?utf8?q?hooray=20for=20k=C3=B6nig=20lookup?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/app/states.cpp | 4 +-- src/creature/creature.cpp | 48 ++++++++++++------------- src/creature/goal.cpp | 20 +++++------ src/graphics/viewport.cpp | 16 ++++----- src/math/geometry.cpp | 24 ++++++------- src/world/CreatureCreatureCollision.hpp | 2 +- src/world/Planet.hpp | 6 ++-- src/world/world.cpp | 26 +++++++------- tst/math/IntersectTest.cpp | 8 ++--- 9 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/app/states.cpp b/src/app/states.cpp index 92879b4..cbb2309 100644 --- a/src/app/states.cpp +++ b/src/app/states.cpp @@ -188,8 +188,8 @@ void MasterState::OnRender(graphics::Viewport &viewport) { // TODO: extend to nearby bodies as well for (auto c : cam.Reference().Creatures()) { assets.shaders.creature_skin.SetM(cam.Model(cam.Reference()) * glm::mat4(c->LocalTransform())); - assets.shaders.creature_skin.SetBaseColor(c->BaseColor()); - assets.shaders.creature_skin.SetHighlightColor(c->HighlightColor()); + assets.shaders.creature_skin.SetBaseColor(glm::vec3(c->BaseColor())); + assets.shaders.creature_skin.SetHighlightColor(glm::vec4(c->HighlightColor())); c->Draw(viewport); } diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index 4689678..7333fdc 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -342,10 +342,10 @@ double Creature::PerceptionField() const noexcept { bool Creature::PerceptionTest(const glm::dvec3 &p) const noexcept { const glm::dvec3 diff(p - situation.Position()); double omni_range = PerceptionOmniRange(); - if (length2(diff) < omni_range * omni_range) return true; + if (glm::length2(diff) < omni_range * omni_range) return true; double range = PerceptionRange(); - if (length2(diff) > range * range) return false; - return dot(normalize(diff), situation.Heading()) > PerceptionField(); + if (glm::length2(diff) > range * range) return false; + return glm::dot(glm::normalize(diff), situation.Heading()) > PerceptionField(); } double Creature::OffspringChance() const noexcept { @@ -397,21 +397,21 @@ void Creature::TickState(double dt) { state.pos += f.vel * dt; state.vel += f.acc * dt; situation.EnforceConstraints(state); - if (length2(state.vel) > 0.000001) { - glm::dvec3 nvel(normalize(state.vel)); - double ang = angle(nvel, state.dir); + if (glm::length2(state.vel) > 0.000001) { + glm::dvec3 nvel(glm::normalize(state.vel)); + double ang = glm::angle(nvel, state.dir); double turn_rate = PI * 0.75 * dt; if (ang < turn_rate) { - state.dir = normalize(state.vel); + state.dir = glm::normalize(state.vel); } else if (std::abs(ang - PI) < 0.001) { - state.dir = rotate(state.dir, turn_rate, situation.GetPlanet().NormalAt(state.pos)); + state.dir = glm::rotate(state.dir, turn_rate, situation.GetPlanet().NormalAt(state.pos)); } else { - state.dir = rotate(state.dir, turn_rate, normalize(cross(state.dir, nvel))); + state.dir = glm::rotate(state.dir, turn_rate, glm::normalize(glm::cross(state.dir, nvel))); } } situation.SetState(state); // work is force times distance - DoWork(length(f.acc) * Mass() * length(f.vel) * dt); + DoWork(glm::length(f.acc) * Mass() * glm::length(f.vel) * dt); } Situation::Derivative Creature::Step(const Situation::Derivative &ds, double dt) const noexcept { @@ -429,10 +429,10 @@ Situation::Derivative Creature::Step(const Situation::Derivative &ds, double dt) // if net force is applied and in contact with surface if (!allzero(force) && std::abs(std::abs(elevation) - situation.GetPlanet().Radius()) < 0.001) { // apply friction = -|normal force| * tangential force * coefficient - glm::dvec3 fn(normal * dot(force, normal)); + glm::dvec3 fn(normal * glm::dot(force, normal)); glm::dvec3 ft(force - fn); double u = 0.4; - glm::dvec3 friction(-length(fn) * ft * u); + glm::dvec3 friction(-glm::length(fn) * ft * u); force += friction; } return { @@ -508,11 +508,11 @@ glm::dmat4 Creature::CollisionTransform() const noexcept { glm::dmat3 orient; orient[1] = situation.GetPlanet().NormalAt(pos); orient[2] = situation.Heading(); - if (std::abs(dot(orient[1], orient[2])) > 0.999) { + if (std::abs(glm::dot(orient[1], orient[2])) > 0.999) { orient[2] = glm::dvec3(orient[1].z, orient[1].x, orient[1].y); } - orient[0] = normalize(cross(orient[1], orient[2])); - orient[2] = normalize(cross(orient[0], orient[1])); + orient[0] = glm::normalize(glm::cross(orient[1], orient[2])); + orient[2] = glm::normalize(glm::cross(orient[0], orient[1])); return glm::translate(glm::dvec3(pos.x, pos.y, pos.z)) * glm::dmat4(orient) * glm::translate(glm::dvec3(0.0, half_size, 0.0)); @@ -864,8 +864,8 @@ void Situation::Accelerate(const glm::dvec3 &dv) noexcept { void Situation::EnforceConstraints(State &s) noexcept { if (OnSurface()) { double r = GetPlanet().Radius(); - if (length2(s.pos) < r * r) { - s.pos = normalize(s.pos) * r; + if (glm::length2(s.pos) < r * r) { + s.pos = glm::normalize(s.pos) * r; } } } @@ -947,10 +947,10 @@ glm::dvec3 Steering::Force(const Situation::State &s) const noexcept { for (auto &other : s.GetPlanet().Creatures()) { if (&*other == &c) continue; glm::dvec3 diff = s.Position() - other->GetSituation().Position(); - if (length2(diff) > max_look * max_look) continue; + if (glm::length2(diff) > max_look * max_look) continue; if (!c.PerceptionTest(other->GetSituation().Position())) continue; - double sep = glm::clamp(length(diff) - other->Size() * 0.707 - c.Size() * 0.707, 0.0, min_dist); - repulse += normalize(diff) * (1.0 - sep / min_dist) * force; + double sep = glm::clamp(glm::length(diff) - other->Size() * 0.707 - c.Size() * 0.707, 0.0, min_dist); + repulse += glm::normalize(diff) * (1.0 - sep / min_dist) * force; } result += repulse; } @@ -961,18 +961,18 @@ glm::dvec3 Steering::Force(const Situation::State &s) const noexcept { if (seeking) { glm::dvec3 diff = target - s.pos; if (!allzero(diff)) { - result += TargetVelocity(s, (normalize(diff) * speed), force); + result += TargetVelocity(s, (glm::normalize(diff) * speed), force); } } if (arriving) { glm::dvec3 diff = target - s.pos; - double dist = length(diff); + double dist = glm::length(diff); if (!allzero(diff) && dist > std::numeric_limits::epsilon()) { result += TargetVelocity(s, diff * std::min(dist * force, speed) / dist, force); } } - if (length2(result) > max_force * max_force) { - result = normalize(result) * max_force; + if (glm::length2(result) > max_force * max_force) { + result = glm::normalize(result) * max_force; } return result; } diff --git a/src/creature/goal.cpp b/src/creature/goal.cpp index 021e32d..c3200a6 100644 --- a/src/creature/goal.cpp +++ b/src/creature/goal.cpp @@ -424,8 +424,8 @@ void LocateResourceGoal::SearchVicinity() { const world::Planet &planet = GetSituation().GetPlanet(); const glm::dvec3 &pos = GetSituation().Position(); const glm::dvec3 normal(planet.NormalAt(pos)); - const glm::dvec3 step_x(normalize(cross(normal, glm::dvec3(normal.z, normal.x, normal.y)))); - const glm::dvec3 step_y(normalize(cross(step_x, normal))); + const glm::dvec3 step_x(glm::normalize(glm::cross(normal, glm::dvec3(normal.z, normal.x, normal.y)))); + const glm::dvec3 step_y(glm::normalize(glm::cross(step_x, normal))); constexpr int search_radius = 2; double rating[2 * search_radius + 1][2 * search_radius + 1] = {0}; @@ -453,7 +453,7 @@ void LocateResourceGoal::SearchVicinity() { for (int y = -search_radius; y < search_radius + 1; ++y) { for (int x = -search_radius; x < search_radius + 1; ++x) { const glm::dvec3 tpos(pos + (double(x) * step_x) + (double(y) * step_y)); - if (length2(tpos - c->GetSituation().Position()) < 1.0) { + if (glm::length2(tpos - c->GetSituation().Position()) < 1.0) { rating[y + search_radius][x + search_radius] *= 0.8; } } @@ -475,7 +475,7 @@ void LocateResourceGoal::SearchVicinity() { if (best_rating > 0.0) { found = true; searching = false; - target_pos = normalize(pos + (double(best_pos.x) * step_x) + (double(best_pos.y) * step_y)) * planet.Radius(); + target_pos = glm::normalize(pos + (double(best_pos.x) * step_x) + (double(best_pos.y) * step_y)) * planet.Radius(); GetSteering().GoTo(target_pos); } else if (!searching) { found = false; @@ -485,14 +485,14 @@ void LocateResourceGoal::SearchVicinity() { target_pos += Random().SNorm() * step_y; // bias towards current heading target_pos += GetSituation().Heading() * 1.5; - target_pos = normalize(target_pos) * planet.Radius(); + target_pos = glm::normalize(target_pos) * planet.Radius(); GetSteering().GoTo(target_pos); } } bool LocateResourceGoal::NearTarget() const noexcept { const Situation &s = GetSituation(); - return s.OnSurface() && length2(s.Position() - target_pos) < 0.5; + return s.OnSurface() && glm::length2(s.Position() - target_pos) < 0.5; } @@ -516,7 +516,7 @@ void StrollGoal::Enable() { } void StrollGoal::Action() { - if (length2(next - GetSituation().Position()) < 0.0001) { + if (glm::length2(next - GetSituation().Position()) < 0.0001) { PickTarget(); } } @@ -530,12 +530,12 @@ void StrollGoal::PickTarget() noexcept { next += GetSituation().Heading() * 1.5; const glm::dvec3 normal(GetSituation().GetPlanet().NormalAt(GetSituation().Position())); glm::dvec3 rand_x(GetSituation().Heading()); - if (std::abs(dot(normal, rand_x)) > 0.999) { + if (std::abs(glm::dot(normal, rand_x)) > 0.999) { rand_x = glm::dvec3(normal.z, normal.x, normal.y); } - glm::dvec3 rand_y = cross(normal, rand_x); + glm::dvec3 rand_y = glm::cross(normal, rand_x); next += ((rand_x * Random().SNorm()) + (rand_y * Random().SNorm())) * 1.5; - next = normalize(next) * GetSituation().GetPlanet().Radius(); + next = glm::normalize(next) * GetSituation().GetPlanet().Radius(); GetSteering().GoTo(next); } diff --git a/src/graphics/viewport.cpp b/src/graphics/viewport.cpp index ff19021..51e8cdd 100644 --- a/src/graphics/viewport.cpp +++ b/src/graphics/viewport.cpp @@ -75,9 +75,9 @@ Camera &Camera::Radial(const creature::Creature &c, double distance, const glm:: Reference(s.GetPlanet()); track_orient = true; up = s.GetPlanet().NormalAt(s.Position()); - glm::dvec3 ref(normalize(cross(up, glm::dvec3(up.z, up.x, up.y)))); + glm::dvec3 ref(glm::normalize(glm::cross(up, glm::dvec3(up.z, up.x, up.y)))); dir = - glm::dmat3(ref, up, cross(ref, up)) + glm::dmat3(ref, up, glm::cross(ref, up)) * glm::dmat3(glm::eulerAngleYX(-angle.y, -angle.x)) * dir; } else { @@ -94,17 +94,17 @@ glm::mat4 Camera::Model(const world::Body &b) const noexcept { if (&b == ref) { return track_orient ? glm::mat4(1.0f) : glm::mat4(ref->LocalTransform()); } else if (b.HasParent() && &b.Parent() == ref) { - return track_orient + return glm::mat4(track_orient ? ref->InverseTransform() * b.FromParent() * b.LocalTransform() - : b.FromParent() * b.LocalTransform(); + : b.FromParent() * b.LocalTransform()); } else if (ref->HasParent() && &ref->Parent() == &b) { - return track_orient + return glm::mat4(track_orient ? ref->InverseTransform() * ref->ToParent() * b.LocalTransform() - : ref->ToParent() * b.LocalTransform(); + : ref->ToParent() * b.LocalTransform()); } else { - return track_orient + return glm::mat4(track_orient ? ref->InverseTransform() * ref->ToUniverse() * b.FromUniverse() * b.LocalTransform() - : ref->ToUniverse() * b.FromUniverse() * b.LocalTransform(); + : ref->ToUniverse() * b.FromUniverse() * b.LocalTransform()); } } diff --git a/src/math/geometry.cpp b/src/math/geometry.cpp index f822ad6..58c97ae 100644 --- a/src/math/geometry.cpp +++ b/src/math/geometry.cpp @@ -41,15 +41,15 @@ bool Intersect( glm::dvec3(b_m[0]), glm::dvec3(b_m[1]), glm::dvec3(b_m[2]), - normalize(cross(glm::dvec3(a_m[0]), glm::dvec3(b_m[0]))), - normalize(cross(glm::dvec3(a_m[0]), glm::dvec3(b_m[1]))), - normalize(cross(glm::dvec3(a_m[0]), glm::dvec3(b_m[2]))), - normalize(cross(glm::dvec3(a_m[1]), glm::dvec3(b_m[0]))), - normalize(cross(glm::dvec3(a_m[1]), glm::dvec3(b_m[1]))), - normalize(cross(glm::dvec3(a_m[1]), glm::dvec3(b_m[2]))), - normalize(cross(glm::dvec3(a_m[2]), glm::dvec3(b_m[0]))), - normalize(cross(glm::dvec3(a_m[2]), glm::dvec3(b_m[1]))), - normalize(cross(glm::dvec3(a_m[2]), glm::dvec3(b_m[2]))), + glm::normalize(glm::cross(glm::dvec3(a_m[0]), glm::dvec3(b_m[0]))), + glm::normalize(glm::cross(glm::dvec3(a_m[0]), glm::dvec3(b_m[1]))), + glm::normalize(glm::cross(glm::dvec3(a_m[0]), glm::dvec3(b_m[2]))), + glm::normalize(glm::cross(glm::dvec3(a_m[1]), glm::dvec3(b_m[0]))), + glm::normalize(glm::cross(glm::dvec3(a_m[1]), glm::dvec3(b_m[1]))), + glm::normalize(glm::cross(glm::dvec3(a_m[1]), glm::dvec3(b_m[2]))), + glm::normalize(glm::cross(glm::dvec3(a_m[2]), glm::dvec3(b_m[0]))), + glm::normalize(glm::cross(glm::dvec3(a_m[2]), glm::dvec3(b_m[1]))), + glm::normalize(glm::cross(glm::dvec3(a_m[2]), glm::dvec3(b_m[2]))), }; depth = std::numeric_limits::infinity(); @@ -57,7 +57,7 @@ bool Intersect( int cur_axis = 0; for (const glm::dvec3 &axis : axes) { - if (any(isnan(axis))) { + if (glm::any(glm::isnan(axis))) { // can result from the cross products if A and B have parallel axes ++cur_axis; continue; @@ -65,7 +65,7 @@ bool Intersect( double a_min = std::numeric_limits::infinity(); double a_max = -std::numeric_limits::infinity(); for (const glm::dvec3 &corner : a_corners) { - double val = dot(corner, axis); + double val = glm::dot(corner, axis); a_min = std::min(a_min, val); a_max = std::max(a_max, val); } @@ -73,7 +73,7 @@ bool Intersect( double b_min = std::numeric_limits::infinity(); double b_max = -std::numeric_limits::infinity(); for (const glm::dvec3 &corner : b_corners) { - double val = dot(corner, axis); + double val = glm::dot(corner, axis); b_min = std::min(b_min, val); b_max = std::max(b_max, val); } diff --git a/src/world/CreatureCreatureCollision.hpp b/src/world/CreatureCreatureCollision.hpp index a26b050..0a90795 100644 --- a/src/world/CreatureCreatureCollision.hpp +++ b/src/world/CreatureCreatureCollision.hpp @@ -19,7 +19,7 @@ public: const glm::dvec3 &n, double depth ) : a(&a), b(&b), normal(n), depth(depth) { - if (dot(normal, BPos() - APos()) < 0.0) { + if (glm::dot(normal, BPos() - APos()) < 0.0) { // make sure normal always is in direction from A to B normal *= -1.0; } diff --git a/src/world/Planet.hpp b/src/world/Planet.hpp index 2371599..2034b8d 100644 --- a/src/world/Planet.hpp +++ b/src/world/Planet.hpp @@ -36,11 +36,11 @@ public: public: /// surface normal - glm::dvec3 NormalAt(const glm::dvec3 &p) const noexcept { return normalize(p); } + glm::dvec3 NormalAt(const glm::dvec3 &p) const noexcept { return glm::normalize(p); } /// height over surface - double ElevationAt(const glm::dvec3 &p) const noexcept { return length(p) - Radius(); } + double ElevationAt(const glm::dvec3 &p) const noexcept { return glm::length(p) - Radius(); } /// distance to planet center - double DistanceAt(const glm::dvec3 &p) const noexcept { return length(p); } + double DistanceAt(const glm::dvec3 &p) const noexcept { return glm::length(p); } /// get ground tile Tile &TileAt(const glm::dvec3 &) noexcept; diff --git a/src/world/world.cpp b/src/world/world.cpp index ef9311f..682eb9b 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -189,7 +189,7 @@ void Body::CheckCollision() noexcept { 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; - if (length2(diff) > max_dist * max_dist) continue; + if (glm::length2(diff) > max_dist * max_dist) continue; math::AABB j_box((*j)->CollisionBox()); glm::dmat4 j_mat((*j)->CollisionTransform()); glm::dvec3 normal; @@ -202,8 +202,8 @@ void Body::CheckCollision() noexcept { 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())); // TODO: notify participants so they can be annoyed } } @@ -314,7 +314,7 @@ double mean2eccentric(double M, double e) { for (int i = 0; i < 100; ++i) { double dE = (E - e * sin(E) - M) / (1 - e * cos(E)); E -= dE; - if (abs(dE) < 1.0e-6) break; + if (std::abs(dE) < 1.0e-6) break; } return E; } @@ -355,8 +355,8 @@ Planet::~Planet() { 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))); double max_axis = 0.0; if (p_pos.x && p_abs.x >= p_abs.y && p_abs.x >= p_abs.z) { @@ -452,7 +452,7 @@ const TileType &Planet::TypeAt(int srf, int x, int y) const noexcept { 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(); - return normalize(cubeunmap(srf, u, v)) * (Radius() + e); + return glm::normalize(cubeunmap(srf, u, v)) * (Radius() + e); } void Planet::BuildVAO(const Set &ts) { @@ -494,25 +494,25 @@ void Planet::BuildVAO(const Set &ts) { 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]) * (surface < 3 ? offset : -offset); + attrib[4 * index + 0].position = glm::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]) * (surface < 3 ? offset : -offset); + attrib[4 * index + 1].position = glm::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]) * (surface < 3 ? offset : -offset); + attrib[4 * index + 2].position = glm::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]) * (surface < 3 ? offset : -offset); + attrib[4 * index + 3].position = glm::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; @@ -604,7 +604,7 @@ void GenerateEarthlike(const Set &tiles, Planet &p) noexcept { } float elevation = math::OctaveNoise( elevation_gen, - to_tile / p.Radius(), + glm::vec3(to_tile / p.Radius()), 3, // octaves 0.5, // persistence 5 / p.Radius(), // frequency @@ -613,7 +613,7 @@ void GenerateEarthlike(const Set &tiles, Planet &p) noexcept { ); float variation = math::OctaveNoise( variation_gen, - to_tile / p.Radius(), + glm::vec3(to_tile / p.Radius()), 3, // octaves 0.5, // persistence 16 / p.Radius(), // frequency diff --git a/tst/math/IntersectTest.cpp b/tst/math/IntersectTest.cpp index dc6667a..2ed07fb 100644 --- a/tst/math/IntersectTest.cpp +++ b/tst/math/IntersectTest.cpp @@ -177,8 +177,8 @@ void IntersectTest::testBoxBoxIntersection() { glm::dvec3 normal(0); AABB box{ { -1, -1, -1 }, { 1, 1, 1 } }; // 2x2x2 cube centered around origin - glm::mat4 Ma(1); // identity - glm::mat4 Mb(1); // identity + glm::dmat4 Ma(1); // identity + glm::dmat4 Mb(1); // identity // they're identical, so should probably intersect ^^ CPPUNIT_ASSERT_MESSAGE( @@ -209,11 +209,11 @@ void IntersectTest::testBoxBoxIntersection() { ); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "bad penetration depth (with rotation)", - 0.0142134428024292, depth, delta + 0.014213562373095, depth, delta ); AssertEqual( "bad intersection normal (with rotation)", - glm::dvec3(1, 0, 0), abs(normal) // normal can be in + or - x, therefore abs() + glm::dvec3(1, 0, 0), glm::abs(normal) // normal can be in + or - x, therefore abs() ); Mb = glm::translate(glm::dvec3(3, 0, 0)); // 3 to the right -- 2.39.2