From e4adba09b4b7cd31a2e1107b077c035f15f83504 Mon Sep 17 00:00:00 2001 From: Jett <55758076+Jettford@users.noreply.github.com> Date: Tue, 6 Sep 2022 12:45:15 +0100 Subject: [PATCH] A few minor changes and fixing in game camera --- dVisualDebugger/dVisualDebugger.cpp | 38 +++++++++++++++++++++-------- dVisualDebugger/dVisualDebugger.h | 14 +++++++---- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/dVisualDebugger/dVisualDebugger.cpp b/dVisualDebugger/dVisualDebugger.cpp index d0c671fc..ebace162 100644 --- a/dVisualDebugger/dVisualDebugger.cpp +++ b/dVisualDebugger/dVisualDebugger.cpp @@ -17,6 +17,10 @@ #include "dZoneManager.h" inline Vector3 NiPointToVector3(NiPoint3 pos) { return { pos.x, pos.y, pos.z }; }; +inline NiPoint3 Vector3ToNiPoint(Vector3 pos) { return { pos.x, pos.y, pos.z }; }; + +inline Quaternion NiQuaternionToQuaternion(NiQuaternion rot) { return { rot.x, rot.y, rot.z, rot.w }; }; +inline NiQuaternion QuaternionToNiQuaternion(Quaternion rot) { return { rot.x, rot.y, rot.z, rot.w }; }; dVisualDebugger::dVisualDebugger(std::string zoneName) { SetTraceLogLevel(LOG_FATAL); @@ -44,7 +48,7 @@ void dVisualDebugger::CreateInGameCamera() { info.pos = { m_Camera->position.x, m_Camera->position.y, m_Camera->position.z }; info.rot = NiQuaternion::LookAt(info.pos, { m_Camera->target.x, m_Camera->target.y, m_Camera->target.z }); info.spawner = nullptr; - info.spawnerID = 0; + info.spawnerID = dZoneManager::Instance()->GetZoneControlObject()->GetObjectID(); info.spawnerNodeID = 0; Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr); @@ -77,9 +81,11 @@ void dVisualDebugger::Step(float delta) { } UpdateCamera(m_Camera); - this->AttachToCharacter(); - if (IsKeyDown(KEY_SPACE)) m_BindToGM = !m_BindToGM; + this->UpdateCameraPosition(); + this->UpdateInGameCameraPosition(); + + this->HandleInputs(); BeginDrawing(); ClearBackground(RAYWHITE); @@ -89,27 +95,38 @@ void dVisualDebugger::Step(float delta) { this->RenderTerrainMesh(); EndMode3D(); - DrawText((std::to_string(m_Camera->position.x) + " " + std::to_string(m_Camera->position.y) + " " + std::to_string(m_Camera->position.z)).c_str(), 20, 20, 10, BLACK); + DrawText((std::to_string(m_Camera->position.x) + " " + std::to_string(m_Camera->position.y) + " " + std::to_string(m_Camera->position.z)).c_str(), 10, 0, 10, BLACK); DrawFPS(10, 10); EndDrawing(); } -void dVisualDebugger::AttachToCharacter() { +void dVisualDebugger::HandleInputs() { + if (IsKeyDown(KEY_SPACE)) m_BindToGM = !m_BindToGM; +} + +void dVisualDebugger::UpdateCameraPosition() { if (!m_BindToGM) return; auto characters = EntityManager::Instance()->GetEntitiesByLOT(1); if (characters.size() != 1) return; m_Camera->position = NiPointToVector3(characters[0]->GetPosition()); - m_Camera->target = NiPointToVector3(characters[0]->GetRotation().GetForwardVector()); - - // Reposition our camera + m_Camera->target = NiPointToVector3(); +} +void dVisualDebugger::UpdateInGameCameraPosition() { auto* camera = EntityManager::Instance()->GetEntity(m_CameraObjid); + if (!camera) return; + auto* physComp = camera->GetComponent(); - physComp->SetPosition(characters[0]->GetPosition()); - physComp->SetRotation(characters[0]->GetRotation()); + + auto cameraPos = Vector3ToNiPoint(m_Camera->position); + + cameraPos.SetY(cameraPos.GetY() + 10); + physComp->SetPosition(cameraPos); + physComp->SetRotation(NiQuaternion::LookAt(Vector3ToNiPoint(m_Camera->position), Vector3ToNiPoint(m_Camera->target))); + EntityManager::Instance()->SerializeEntity(camera); } @@ -120,6 +137,7 @@ void dVisualDebugger::RenderTerrainMesh() { auto v1 = m_Terrain->GetMesh()->m_Vertices[m_Terrain->GetMesh()->m_Triangles[i]]; auto v2 = m_Terrain->GetMesh()->m_Vertices[m_Terrain->GetMesh()->m_Triangles[i + 1]]; auto v3 = m_Terrain->GetMesh()->m_Vertices[m_Terrain->GetMesh()->m_Triangles[i + 2]]; + DrawTriangle3D(NiPointToVector3(v1), NiPointToVector3(v2), NiPointToVector3(v3), GRAY); } } diff --git a/dVisualDebugger/dVisualDebugger.h b/dVisualDebugger/dVisualDebugger.h index 6f860da5..fe11c7ab 100644 --- a/dVisualDebugger/dVisualDebugger.h +++ b/dVisualDebugger/dVisualDebugger.h @@ -14,10 +14,6 @@ public: ~dVisualDebugger(); void Step(float delta); - - void RenderEntities(std::vector* entities, bool dynamic); - void RenderTerrainMesh(); - void AttachToCharacter(); private: Camera3D* m_Camera; RawFile* m_Terrain; @@ -27,7 +23,15 @@ private: void CreateCamera(); void CreateInGameCamera(); + void UpdateCameraPosition(); + void UpdateInGameCameraPosition(); + + void HandleInputs(); + + void RenderEntities(std::vector* entities, bool dynamic); + void RenderTerrainMesh(); + const int32_t m_Width = 800; const int32_t m_Height = 450; - const int32_t m_CameraID = 2181; + const int32_t m_CameraID = 5204; };