mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-24 06:27:24 +00:00
A few minor changes and fixing in game camera
This commit is contained in:
parent
fc0961ed76
commit
e4adba09b4
@ -17,6 +17,10 @@
|
|||||||
#include "dZoneManager.h"
|
#include "dZoneManager.h"
|
||||||
|
|
||||||
inline Vector3 NiPointToVector3(NiPoint3 pos) { return { pos.x, pos.y, pos.z }; };
|
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) {
|
dVisualDebugger::dVisualDebugger(std::string zoneName) {
|
||||||
SetTraceLogLevel(LOG_FATAL);
|
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.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.rot = NiQuaternion::LookAt(info.pos, { m_Camera->target.x, m_Camera->target.y, m_Camera->target.z });
|
||||||
info.spawner = nullptr;
|
info.spawner = nullptr;
|
||||||
info.spawnerID = 0;
|
info.spawnerID = dZoneManager::Instance()->GetZoneControlObject()->GetObjectID();
|
||||||
info.spawnerNodeID = 0;
|
info.spawnerNodeID = 0;
|
||||||
|
|
||||||
Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr);
|
Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr);
|
||||||
@ -77,9 +81,11 @@ void dVisualDebugger::Step(float delta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UpdateCamera(m_Camera);
|
UpdateCamera(m_Camera);
|
||||||
this->AttachToCharacter();
|
|
||||||
|
|
||||||
if (IsKeyDown(KEY_SPACE)) m_BindToGM = !m_BindToGM;
|
this->UpdateCameraPosition();
|
||||||
|
this->UpdateInGameCameraPosition();
|
||||||
|
|
||||||
|
this->HandleInputs();
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
@ -89,27 +95,38 @@ void dVisualDebugger::Step(float delta) {
|
|||||||
this->RenderTerrainMesh();
|
this->RenderTerrainMesh();
|
||||||
EndMode3D();
|
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);
|
DrawFPS(10, 10);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dVisualDebugger::AttachToCharacter() {
|
void dVisualDebugger::HandleInputs() {
|
||||||
|
if (IsKeyDown(KEY_SPACE)) m_BindToGM = !m_BindToGM;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dVisualDebugger::UpdateCameraPosition() {
|
||||||
if (!m_BindToGM) return;
|
if (!m_BindToGM) return;
|
||||||
|
|
||||||
auto characters = EntityManager::Instance()->GetEntitiesByLOT(1);
|
auto characters = EntityManager::Instance()->GetEntitiesByLOT(1);
|
||||||
if (characters.size() != 1) return;
|
if (characters.size() != 1) return;
|
||||||
|
|
||||||
m_Camera->position = NiPointToVector3(characters[0]->GetPosition());
|
m_Camera->position = NiPointToVector3(characters[0]->GetPosition());
|
||||||
m_Camera->target = NiPointToVector3(characters[0]->GetRotation().GetForwardVector());
|
m_Camera->target = NiPointToVector3();
|
||||||
|
}
|
||||||
// Reposition our camera
|
|
||||||
|
|
||||||
|
void dVisualDebugger::UpdateInGameCameraPosition() {
|
||||||
auto* camera = EntityManager::Instance()->GetEntity(m_CameraObjid);
|
auto* camera = EntityManager::Instance()->GetEntity(m_CameraObjid);
|
||||||
|
|
||||||
if (!camera) return;
|
if (!camera) return;
|
||||||
|
|
||||||
auto* physComp = camera->GetComponent<SimplePhysicsComponent>();
|
auto* physComp = camera->GetComponent<SimplePhysicsComponent>();
|
||||||
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);
|
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 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 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]];
|
auto v3 = m_Terrain->GetMesh()->m_Vertices[m_Terrain->GetMesh()->m_Triangles[i + 2]];
|
||||||
|
|
||||||
DrawTriangle3D(NiPointToVector3(v1), NiPointToVector3(v2), NiPointToVector3(v3), GRAY);
|
DrawTriangle3D(NiPointToVector3(v1), NiPointToVector3(v2), NiPointToVector3(v3), GRAY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,10 +14,6 @@ public:
|
|||||||
~dVisualDebugger();
|
~dVisualDebugger();
|
||||||
|
|
||||||
void Step(float delta);
|
void Step(float delta);
|
||||||
|
|
||||||
void RenderEntities(std::vector<dpEntity*>* entities, bool dynamic);
|
|
||||||
void RenderTerrainMesh();
|
|
||||||
void AttachToCharacter();
|
|
||||||
private:
|
private:
|
||||||
Camera3D* m_Camera;
|
Camera3D* m_Camera;
|
||||||
RawFile* m_Terrain;
|
RawFile* m_Terrain;
|
||||||
@ -27,7 +23,15 @@ private:
|
|||||||
void CreateCamera();
|
void CreateCamera();
|
||||||
void CreateInGameCamera();
|
void CreateInGameCamera();
|
||||||
|
|
||||||
|
void UpdateCameraPosition();
|
||||||
|
void UpdateInGameCameraPosition();
|
||||||
|
|
||||||
|
void HandleInputs();
|
||||||
|
|
||||||
|
void RenderEntities(std::vector<dpEntity*>* entities, bool dynamic);
|
||||||
|
void RenderTerrainMesh();
|
||||||
|
|
||||||
const int32_t m_Width = 800;
|
const int32_t m_Width = 800;
|
||||||
const int32_t m_Height = 450;
|
const int32_t m_Height = 450;
|
||||||
const int32_t m_CameraID = 2181;
|
const int32_t m_CameraID = 5204;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user