mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-06 09:03:52 +00:00
feat(editor): middle mouse orbit camera around terrain point
- Middle mouse drag orbits camera around the terrain point under cursor (or 100 units ahead if no terrain hit) - Maintains distance from pivot while rotating yaw/pitch - Much more intuitive for inspecting terrain features, placed objects, and NPC positions from different angles - Works alongside right-drag (free look) and WASD (fly)
This commit is contained in:
parent
62cfb92c38
commit
496f97f9db
3 changed files with 26 additions and 1 deletions
|
|
@ -71,6 +71,24 @@ void EditorCamera::processKeyEvent(const SDL_KeyboardEvent& event) {
|
|||
void EditorCamera::processMouseButton(const SDL_MouseButtonEvent& event) {
|
||||
if (event.button == SDL_BUTTON_RIGHT)
|
||||
rightMouseDown_ = (event.type == SDL_MOUSEBUTTONDOWN);
|
||||
if (event.button == SDL_BUTTON_MIDDLE)
|
||||
middleMouseDown_ = (event.type == SDL_MOUSEBUTTONDOWN);
|
||||
}
|
||||
|
||||
void EditorCamera::processMiddleMouseMotion(int dx, int dy, const glm::vec3& pivotPoint) {
|
||||
if (!middleMouseDown_) return;
|
||||
|
||||
constexpr float sensitivity = 0.3f;
|
||||
yaw_ += static_cast<float>(dx) * sensitivity;
|
||||
pitch_ -= static_cast<float>(dy) * sensitivity;
|
||||
pitch_ = std::clamp(pitch_, -89.0f, 89.0f);
|
||||
camera_.setRotation(yaw_, pitch_);
|
||||
|
||||
// Orbit: maintain distance from pivot
|
||||
glm::vec3 toPivot = pivotPoint - camera_.getPosition();
|
||||
float dist = glm::length(toPivot);
|
||||
glm::vec3 newPos = pivotPoint - camera_.getForward() * dist;
|
||||
camera_.setPosition(newPos);
|
||||
}
|
||||
|
||||
void EditorCamera::setPosition(const glm::vec3& pos) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue