diff options
-rw-r--r-- | game/network/rail.cpp | 11 | ||||
-rw-r--r-- | gfx/followCameraController.cpp | 2 | ||||
-rw-r--r-- | gfx/manualCameraController.cpp | 10 | ||||
-rw-r--r-- | lib/maths.cpp | 12 | ||||
-rw-r--r-- | lib/maths.h | 14 |
5 files changed, 23 insertions, 26 deletions
diff --git a/game/network/rail.cpp b/game/network/rail.cpp index d095e38..cc40070 100644 --- a/game/network/rail.cpp +++ b/game/network/rail.cpp @@ -69,16 +69,16 @@ RailLinks::addLinksBetween(glm::vec3 start, glm::vec3 end) float dir2 = pi + findDir(*node2ins.first); if (const auto radii = find_arcs_radius(flatStart, dir, flatEnd, dir2); radii.first < radii.second) { const auto radius {radii.first}; - const auto c1 = start + glm::vec3 {std::sin(dir + half_pi), 0, std::cos(dir + half_pi)} * radius; - const auto c2 = end + glm::vec3 {std::sin(dir2 + half_pi), 0, std::cos(dir2 + half_pi)} * radius; + const auto c1 = start + !sincosf(dir + half_pi) * radius; + const auto c2 = end + !sincosf(dir2 + half_pi) * radius; const auto mid = (c1 + c2) / 2.F; addLink<RailLinkCurve>(start, mid, !c1); return addLink<RailLinkCurve>(end, mid, !c2); } else { const auto radius {radii.second}; - const auto c1 = start + glm::vec3 {std::sin(dir - half_pi), 0, std::cos(dir - half_pi)} * radius; - const auto c2 = end + glm::vec3 {std::sin(dir2 - half_pi), 0, std::cos(dir2 - half_pi)} * radius; + const auto c1 = start + !sincosf(dir - half_pi) * radius; + const auto c2 = end + !sincosf(dir2 - half_pi) * radius; const auto mid = (c1 + c2) / 2.F; addLink<RailLinkCurve>(mid, start, !(c1)); return addLink<RailLinkCurve>(mid, end, !c2); @@ -206,8 +206,7 @@ RailLinkCurve::positionAt(float dist, unsigned char start) const const auto es {std::make_pair(ends[start].first.get(), ends[1 - start].first.get())}; const auto as {std::make_pair(arc[start], arc[1 - start])}; const auto ang {as.first + ((as.second - as.first) * frac)}; - const auto angArc {ang - half_pi}; - const auto relPos {glm::vec3 {std::cos(angArc), 0, -std::sin(angArc)} * radius}; + const auto relPos {!sincosf(ang) * radius}; const auto relClimb {RAIL_HEIGHT + glm::vec3 {0, -centreBase.y + es.first->pos.y + ((es.second->pos.y - es.first->pos.y) * frac), 0}}; const auto pitch {vector_pitch({0, (es.first->pos.y - es.second->pos.y) / length, 0})}; diff --git a/gfx/followCameraController.cpp b/gfx/followCameraController.cpp index 1ee385a..e8a95b3 100644 --- a/gfx/followCameraController.cpp +++ b/gfx/followCameraController.cpp @@ -26,7 +26,7 @@ FollowCameraController::updateCamera(Camera * camera) const case Mode::Ride: camera->pos = pos + (up * 4.8F); - camera->forward = {-std::sin(rot.y), 0.F, -std::cos(rot.y)}; + camera->forward = !-sincosf(rot.y); camera->up = up; break; diff --git a/gfx/manualCameraController.cpp b/gfx/manualCameraController.cpp index 62c48c8..e29ea36 100644 --- a/gfx/manualCameraController.cpp +++ b/gfx/manualCameraController.cpp @@ -47,8 +47,9 @@ ManualCameraController::handleInput(SDL_Event & e) pitch = std::clamp(pitch - 0.01F * e.motion.yrel, 0.1F, half_pi); } else { - focus.x += cos(direction) * e.motion.xrel + sin(direction) * e.motion.yrel; - focus.y += cos(direction) * e.motion.yrel - sin(direction) * e.motion.xrel; + const auto sc {sincosf(direction)}; + focus.x += sc.x * e.motion.yrel + sc.x * e.motion.xrel; + focus.y += sc.x * -e.motion.xrel + sc.x * e.motion.yrel; } } return true; @@ -62,8 +63,7 @@ ManualCameraController::handleInput(SDL_Event & e) void ManualCameraController::updateCamera(Camera * camera) const { - const auto rel {glm::normalize(glm::vec3 {sin(direction), -sin(pitch), cos(direction)})}; - camera->pos = !focus + up * 3.F - (rel * std::pow(dist, 1.3F)); - camera->forward = glm::normalize(rel); + camera->forward = glm::normalize(sincosf(direction) ^ -sin(pitch)); + camera->pos = !focus + up * 3.F - (camera->forward * std::pow(dist, 1.3F)); camera->up = up; } diff --git a/lib/maths.cpp b/lib/maths.cpp index 60413f4..5800b1b 100644 --- a/lib/maths.cpp +++ b/lib/maths.cpp @@ -112,11 +112,7 @@ find_arc_centre(glm::vec2 as, float entrys, glm::vec2 bs, float entrye) if (as == bs) { return {as, false}; } - const auto perps = entrys + half_pi; - const auto perpe = entrye - half_pi; - const glm::vec2 ad {std::sin(perps), std::cos(perps)}; - const glm::vec2 bd {std::sin(perpe), std::cos(perpe)}; - return find_arc_centre(as, ad, bs, bd); + return find_arc_centre(as, sincosf(entrys + half_pi), bs, sincosf(entrye - half_pi)); } std::pair<glm::vec2, bool> @@ -135,11 +131,7 @@ std::pair<float, float> find_arcs_radius(glm::vec2 start, float entrys, glm::vec2 end, float entrye) { const auto getrad = [&](float leftOrRight) { - const auto perps = entrys + leftOrRight; - const auto perpe = entrye + leftOrRight; - const glm::vec2 ad {std::sin(perps), std::cos(perps)}; - const glm::vec2 bd {std::sin(perpe), std::cos(perpe)}; - return find_arcs_radius(start, ad, end, bd); + return find_arcs_radius(start, sincosf(entrys + leftOrRight), end, sincosf(entrye + leftOrRight)); }; return {getrad(-half_pi), getrad(half_pi)}; } diff --git a/lib/maths.h b/lib/maths.h index d304b65..a3a391d 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -37,11 +37,11 @@ sincosf(float a, float & s, float & c) return sincosf(a, &s, &c); } -inline std::pair<float, float> +inline glm::vec2 sincosf(float a) { - std::pair<float, float> sc; - sincosf(a, &sc.first, &sc.second); + glm::vec2 sc; + sincosf(a, sc.x, sc.y); return sc; } @@ -62,9 +62,15 @@ operator!(const glm::vec3 & v) } constexpr inline glm::vec3 +operator^(const glm::vec2 & v, float y) +{ + return {v.x, y, v.y}; +} + +constexpr inline glm::vec3 operator!(const glm::vec2 & v) { - return {v.x, 0, v.y}; + return v ^ 0.F; } constexpr inline float |