From 1488d7d918080fd4c2acf2b1457cae35175070fd Mon Sep 17 00:00:00 2001 From: Sergey Lapin Date: Tue, 21 Apr 2026 03:04:47 +0300 Subject: [PATCH] Camera change... --- .../systems/PlayerControllerSystem.cpp | 84 +++++++++---------- 1 file changed, 40 insertions(+), 44 deletions(-) diff --git a/src/features/editScene/systems/PlayerControllerSystem.cpp b/src/features/editScene/systems/PlayerControllerSystem.cpp index 20e895d..5746db0 100644 --- a/src/features/editScene/systems/PlayerControllerSystem.cpp +++ b/src/features/editScene/systems/PlayerControllerSystem.cpp @@ -15,8 +15,8 @@ #include PlayerControllerSystem::PlayerControllerSystem(flecs::world &world, - Ogre::SceneManager *sceneMgr, - EditorApp *editorApp) + Ogre::SceneManager *sceneMgr, + EditorApp *editorApp) : m_world(world) , m_sceneMgr(sceneMgr) , m_editorApp(editorApp) @@ -78,6 +78,10 @@ void PlayerControllerSystem::initController(flecs::entity controllerEntity, m_sceneMgr->getRootSceneNode()->createChildSceneNode(); } + // Initialize camera to start behind character (180 degrees yaw) + state.yaw = 180.0f; + state.pitch = 0.0f; + state.initialized = true; state.faceHidden = false; } @@ -86,7 +90,8 @@ void PlayerControllerSystem::update(float deltaTime) { if (!m_editorApp || m_editorApp->getGameMode() != EditorApp::GameMode::Game || - m_editorApp->getGamePlayState() != EditorApp::GamePlayState::Playing) + m_editorApp->getGamePlayState() != + EditorApp::GamePlayState::Playing) return; m_world.query().each( @@ -153,8 +158,7 @@ void PlayerControllerSystem::updateTPSCamera(PlayerControllerComponent &pc, CharacterSlotSystem *css = m_editorApp->getCharacterSlotSystem(); if (css) { - css->setSlotVisible(state.targetEntity, "face", - true); + css->setSlotVisible(state.targetEntity, "face", true); } state.faceHidden = false; } @@ -176,20 +180,19 @@ void PlayerControllerSystem::updateTPSCamera(PlayerControllerComponent &pc, state.pivotNode->setPosition(pivotPos); // Compute goal position based on yaw/pitch/distance - Ogre::Quaternion yawRot(Ogre::Degree(state.yaw), - Ogre::Vector3::UNIT_Y); + Ogre::Quaternion yawRot(Ogre::Degree(state.yaw), Ogre::Vector3::UNIT_Y); Ogre::Quaternion pitchRot(Ogre::Degree(state.pitch), Ogre::Vector3::UNIT_X); - Ogre::Vector3 offset = yawRot * pitchRot * - Ogre::Vector3(0, 0, pc.tpsDistance); + Ogre::Vector3 offset = + yawRot * pitchRot * Ogre::Vector3(0, 0, pc.tpsDistance); Ogre::Vector3 goalPos = pivotPos + offset; state.goalNode->setPosition(goalPos); // Smoothly interpolate camera to goal Ogre::Vector3 currentPos = camNode->getPosition(); - Ogre::Vector3 newPos = Ogre::Math::lerp(currentPos, goalPos, - deltaTime * 9.0f); + Ogre::Vector3 newPos = + Ogre::Math::lerp(currentPos, goalPos, deltaTime * 9.0f); camNode->setPosition(newPos); camNode->lookAt(pivotPos, Ogre::Node::TS_WORLD); } @@ -211,8 +214,7 @@ void PlayerControllerSystem::updateFPSCamera(PlayerControllerComponent &pc, return; // Find animated entity for bone access - AnimationTreeSystem *ats = - m_editorApp->getAnimationTreeSystem(); + AnimationTreeSystem *ats = m_editorApp->getAnimationTreeSystem(); if (!ats) return; @@ -229,8 +231,8 @@ void PlayerControllerSystem::updateFPSCamera(PlayerControllerComponent &pc, bone = skel->getBone(pc.fpsBoneName); } catch (...) { // Try common alternatives - const char *alternatives[] = { "Head", "head", "Neck", "neck", - "Camera", "camera" }; + const char *alternatives[] = { "Head", "head", "Neck", + "neck", "Camera", "camera" }; for (const char *name : alternatives) { try { bone = skel->getBone(name); @@ -253,25 +255,21 @@ void PlayerControllerSystem::updateFPSCamera(PlayerControllerComponent &pc, CharacterSlotSystem *css = m_editorApp->getCharacterSlotSystem(); if (css) { - css->setSlotVisible(state.targetEntity, "face", - false); + css->setSlotVisible(state.targetEntity, "face", false); } state.faceHidden = true; } // Get character scene node - auto &transform = - state.targetEntity.get(); + auto &transform = state.targetEntity.get(); Ogre::SceneNode *charNode = transform.node; // Compute bone world transform - Ogre::Vector3 boneWorldPos = - charNode->_getDerivedOrientation() * - bone->_getDerivedPosition() + - charNode->_getDerivedPosition(); - Ogre::Quaternion boneWorldRot = - charNode->_getDerivedOrientation() * - bone->_getDerivedOrientation(); + Ogre::Vector3 boneWorldPos = charNode->_getDerivedOrientation() * + bone->_getDerivedPosition() + + charNode->_getDerivedPosition(); + Ogre::Quaternion boneWorldRot = charNode->_getDerivedOrientation() * + bone->_getDerivedOrientation(); // Offset slightly forward Ogre::Vector3 offset = boneWorldRot * Ogre::Vector3(0, 0, 0.15f); @@ -289,16 +287,15 @@ void PlayerControllerSystem::updateFPSCamera(PlayerControllerComponent &pc, state.pitch = -89.0f; } - Ogre::Quaternion yawRot(Ogre::Degree(state.yaw), - Ogre::Vector3::UNIT_Y); + Ogre::Quaternion yawRot(Ogre::Degree(state.yaw), Ogre::Vector3::UNIT_Y); Ogre::Quaternion pitchRot(Ogre::Degree(state.pitch), Ogre::Vector3::UNIT_X); camNode->setOrientation(yawRot * pitchRot); } void PlayerControllerSystem::updateLocomotion(PlayerControllerComponent &pc, - ControllerState &state, - float deltaTime) + ControllerState &state, + float deltaTime) { (void)deltaTime; if (!state.targetEntity.has()) @@ -308,8 +305,7 @@ void PlayerControllerSystem::updateLocomotion(PlayerControllerComponent &pc, auto &cc = state.targetEntity.get_mut(); // Get camera yaw for relative movement - Ogre::Quaternion yawRot(Ogre::Degree(state.yaw), - Ogre::Vector3::UNIT_Y); + Ogre::Quaternion yawRot(Ogre::Degree(state.yaw), Ogre::Vector3::UNIT_Y); Ogre::Vector3 forward = yawRot * Ogre::Vector3::NEGATIVE_UNIT_Z; Ogre::Vector3 right = yawRot * Ogre::Vector3::UNIT_X; @@ -346,14 +342,15 @@ void PlayerControllerSystem::updateLocomotion(PlayerControllerComponent &pc, flatForward.y = 0; if (flatForward.squaredLength() > 0.0001f) { flatForward.normalise(); - Ogre::Quaternion targetRot = Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo( - flatForward); - Ogre::Quaternion currentRot = transform.node->getOrientation(); + Ogre::Quaternion targetRot = + Ogre::Vector3::NEGATIVE_UNIT_Z + .getRotationTo(flatForward); + Ogre::Quaternion currentRot = + transform.node->getOrientation(); transform.node->setOrientation( - Ogre::Quaternion::Slerp(deltaTime * 10.0f, - currentRot, - targetRot, - true)); + Ogre::Quaternion::Slerp( + deltaTime * 10.0f, currentRot, + targetRot, true)); } } } else { @@ -361,8 +358,7 @@ void PlayerControllerSystem::updateLocomotion(PlayerControllerComponent &pc, } // Update animation state - AnimationTreeSystem *ats = - m_editorApp->getAnimationTreeSystem(); + AnimationTreeSystem *ats = m_editorApp->getAnimationTreeSystem(); if (!ats) return; @@ -376,7 +372,7 @@ void PlayerControllerSystem::updateLocomotion(PlayerControllerComponent &pc, } if (!animState.empty()) { - ats->setState(state.targetEntity, - pc.locomotionStateMachine, animState); + ats->setState(state.targetEntity, pc.locomotionStateMachine, + animState); } -} +} \ No newline at end of file