diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-03-03 01:25:15 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-03-03 01:25:15 +0000 |
commit | 253a0b73f0975d8f14c3a3f2a06675b53c736071 (patch) | |
tree | 71cd0bf5604f7dfb07ed7022c1358a8e2aa91f6a /gfx/manualCameraController.cpp | |
parent | Create and use a shader program for things with absolute position (diff) | |
download | ilt-253a0b73f0975d8f14c3a3f2a06675b53c736071.tar.bz2 ilt-253a0b73f0975d8f14c3a3f2a06675b53c736071.tar.xz ilt-253a0b73f0975d8f14c3a3f2a06675b53c736071.zip |
Simplify a lot of code with sincosf
Diffstat (limited to 'gfx/manualCameraController.cpp')
-rw-r--r-- | gfx/manualCameraController.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
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; } |