mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 01:23:52 +00:00
fix(editor): flyToSelected uses atan2(to.y, to.x) for correct camera yaw
Camera::getForward = (cos(yaw), sin(yaw), sin(pitch)) — to make it parallel to a direction vector we need atan2(y, x). The implementation had x and y swapped, causing Fly To to point the camera 90deg off from the target so the user often saw nothing.
This commit is contained in:
parent
fa631a45d6
commit
6610d950cb
1 changed files with 4 additions and 2 deletions
|
|
@ -1514,9 +1514,11 @@ void EditorApp::flyToSelected() {
|
|||
glm::vec3 cam = target + back * 25.0f + glm::vec3(0, 0, 15);
|
||||
camera_.setPosition(cam);
|
||||
|
||||
// Aim at target — yaw is atan2(toX, toY) in editor convention; pitch from height delta.
|
||||
// Aim at target. Camera::getForward = (cos(yaw), sin(yaw), sin(pitch)),
|
||||
// so to make it parallel to `to` we use atan2(to.y, to.x), not (x, y).
|
||||
// The previous swap pointed the camera 90deg off from the target.
|
||||
glm::vec3 to = target - cam;
|
||||
float yaw = glm::degrees(std::atan2(to.x, to.y));
|
||||
float yaw = glm::degrees(std::atan2(to.y, to.x));
|
||||
float horiz = std::sqrt(to.x * to.x + to.y * to.y);
|
||||
float pitch = glm::degrees(std::atan2(to.z, horiz));
|
||||
camera_.setYawPitch(yaw, pitch);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue