Debug options: Stop moving light, camera and cubes.
F1 to have free camera
This commit is contained in:
@@ -38,6 +38,18 @@
|
||||
#endif
|
||||
|
||||
static bool ShowMemoryDebugger = false;
|
||||
static bool animateCubes = true;
|
||||
static bool animateLights = true;
|
||||
static bool animateCamera = true;
|
||||
|
||||
static bool freeCameraMode = false;
|
||||
static float camYaw = 0.0f;
|
||||
static float camPitch = 0.0f;
|
||||
static Juliet::Vector3 camPos = { 25.0f, 0.0f, 12.5f };
|
||||
|
||||
static float animateCubesTime = 0.0f;
|
||||
static float animateLightsTime = 0.0f;
|
||||
static float animateCameraTime = 0.0f;
|
||||
|
||||
// TODO : Replace with message box from framework + call main and not winmain + subsystem
|
||||
// TODO : Think how to do the draw pipeline.
|
||||
@@ -226,6 +238,7 @@ void JulietApplication::Update()
|
||||
|
||||
bool reloadShaders = false;
|
||||
static bool reloadShadersDebounce = false;
|
||||
static bool f1Debounce = false;
|
||||
|
||||
SystemEvent evt;
|
||||
while (GetEvent(evt))
|
||||
@@ -249,18 +262,112 @@ void JulietApplication::Update()
|
||||
{
|
||||
reloadShadersDebounce = false;
|
||||
}
|
||||
|
||||
if (evt.Type == EventType::Mouse_Move && freeCameraMode)
|
||||
{
|
||||
float sensitivity = 0.005f;
|
||||
camYaw += evt.Data.MouseMovement.X_Displacement * sensitivity;
|
||||
camPitch -= evt.Data.MouseMovement.Y_Displacement * sensitivity;
|
||||
|
||||
// Limit pitch to avoid flipping
|
||||
if (camPitch > 1.5f) camPitch = 1.5f;
|
||||
if (camPitch < -1.5f) camPitch = -1.5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsKeyDown(ScanCode::F1))
|
||||
{
|
||||
if (!f1Debounce)
|
||||
{
|
||||
freeCameraMode = !freeCameraMode;
|
||||
f1Debounce = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
f1Debounce = false;
|
||||
}
|
||||
|
||||
if (freeCameraMode)
|
||||
{
|
||||
float speed = 10.0f * deltaTime;
|
||||
if ((GetKeyModState() & KeyMod::Shift) != KeyMod::None)
|
||||
{
|
||||
speed *= 3.0f;
|
||||
}
|
||||
|
||||
Vector3 forward = { cosf(camYaw) * cosf(camPitch), sinf(camYaw) * cosf(camPitch), sinf(camPitch) };
|
||||
Vector3 right = { cosf(camYaw + 1.5708f), sinf(camYaw + 1.5708f), 0.0f };
|
||||
Vector3 up = { 0.0f, 0.0f, 1.0f };
|
||||
|
||||
if (IsKeyDown(ScanCode::W)) camPos = camPos + forward * speed;
|
||||
if (IsKeyDown(ScanCode::S)) camPos = camPos - forward * speed;
|
||||
if (IsKeyDown(ScanCode::D)) camPos = camPos + right * speed;
|
||||
if (IsKeyDown(ScanCode::A)) camPos = camPos - right * speed;
|
||||
if (IsKeyDown(ScanCode::E)) camPos = camPos + up * speed;
|
||||
if (IsKeyDown(ScanCode::Q)) camPos = camPos - up * speed;
|
||||
}
|
||||
|
||||
if (animateCubes) animateCubesTime += deltaTime;
|
||||
if (animateLights) animateLightsTime += deltaTime;
|
||||
if (animateCamera) animateCameraTime += deltaTime;
|
||||
|
||||
#ifdef JULIET_ENABLE_IMGUI
|
||||
ImGui::Begin("Debug Controls");
|
||||
ImGui::Checkbox("Animate Cubes", &animateCubes);
|
||||
ImGui::Checkbox("Animate Lights", &animateLights);
|
||||
ImGui::Checkbox("Animate Camera", &animateCamera);
|
||||
ImGui::End();
|
||||
#endif
|
||||
|
||||
ArenaClear(GameScratchArena);
|
||||
|
||||
Vector3 redLightPos{ cosf(CameraTime * 2.0f) * 5.0f, sinf(CameraTime * 2.0f) * 5.0f, 2.0f };
|
||||
Vector3 redLightPos = { 5.0f, 5.0f, 2.0f };
|
||||
Vector3 blueLightPos = { -5.0f, 0.0f, 2.0f };
|
||||
|
||||
if (animateLights || animateLightsTime > 0.0f)
|
||||
{
|
||||
redLightPos = { cosf(animateLightsTime * 2.0f) * 5.0f, sinf(animateLightsTime * 2.0f) * 5.0f, 2.0f };
|
||||
blueLightPos = { -5.0f, cosf(animateLightsTime) * 3.0f, 2.0f };
|
||||
}
|
||||
|
||||
SetPointLightPosition(RedLightID, redLightPos);
|
||||
Vector3 blueLightPos{ -5.0f, cosf(CameraTime) * 3.0f, 2.0f };
|
||||
SetPointLightPosition(BlueLightID, blueLightPos);
|
||||
|
||||
#ifdef JULIET_ENABLE_IMGUI
|
||||
ImGui::ShowDemoWindow();
|
||||
#endif
|
||||
// Animate the 100 cubes (10x10 grid)
|
||||
constexpr int kGridSize = 10;
|
||||
constexpr float kSpacing = 2.5f;
|
||||
constexpr float kOffset = (kGridSize - 1) * kSpacing * 0.5f;
|
||||
|
||||
for (int row = 0; row < kGridSize; ++row)
|
||||
{
|
||||
for (int col = 0; col < kGridSize; ++col)
|
||||
{
|
||||
MeshID cube = static_cast<MeshID>(row * kGridSize + col); // Assuming they were added first
|
||||
float x = static_cast<float>(col) * kSpacing - kOffset;
|
||||
float y = static_cast<float>(row) * kSpacing - kOffset;
|
||||
|
||||
float seed = static_cast<float>(cube);
|
||||
float timeZ = animateCubesTime * 2.0f + seed * 0.5f;
|
||||
float z = 0.0f;
|
||||
|
||||
float scaleF = 1.0f;
|
||||
Matrix rotation = MatrixIdentity();
|
||||
|
||||
if (animateCubes || animateCubesTime > 0.0f)
|
||||
{
|
||||
z = sinf(timeZ) * 1.5f; // Oscillate up and down
|
||||
scaleF = 1.0f + sinf(animateCubesTime * 1.5f + seed) * 0.3f; // Pulse scale
|
||||
rotation = MatrixRotation(animateCubesTime * 1.2f + seed * 0.73f, animateCubesTime * 0.8f + seed * 1.17f,
|
||||
animateCubesTime * 0.5f + seed * 0.53f);
|
||||
}
|
||||
Matrix scale = MatrixScale(scaleF, scaleF, scaleF);
|
||||
|
||||
SetMeshTransform(cube, MatrixTranslation(x, y, z) * rotation * scale);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f, 1.0f }, false);
|
||||
DebugDisplay_DrawLine({ 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f, 1.0f }, true);
|
||||
@@ -358,24 +465,51 @@ DepthStencilTargetInfo* JulietApplication::GetDepthTargetInfo()
|
||||
|
||||
Camera JulietApplication::GetDebugCamera()
|
||||
{
|
||||
float time = CameraTime;
|
||||
|
||||
float orbitSpeed = 0.5f;
|
||||
float currentOrbitTime = time * orbitSpeed;
|
||||
if (freeCameraMode)
|
||||
{
|
||||
Camera cam = {};
|
||||
cam.Position = camPos;
|
||||
cam.Target = camPos + Vector3{ cosf(camYaw) * cosf(camPitch), sinf(camYaw) * cosf(camPitch), sinf(camPitch) };
|
||||
cam.Up = { 0.0f, 0.0f, 1.0f };
|
||||
cam.FOV = 1.047f;
|
||||
cam.AspectRatio = 1200.0f / 800.0f;
|
||||
cam.NearPlane = 0.1f;
|
||||
cam.FarPlane = 1000.0f;
|
||||
return cam;
|
||||
}
|
||||
|
||||
// --- Adjusted for 1-Meter Scale ---
|
||||
float baseRadius = 25.0f; // Increased to see 10x10 cube grid
|
||||
|
||||
float radius = baseRadius;
|
||||
//* Uncomment for active zoom
|
||||
float zoomAmplitude = 15.0f;
|
||||
float zoomSpeed = 0.5f;
|
||||
radius = baseRadius + (sinf(time * zoomSpeed) * zoomAmplitude);
|
||||
//*/
|
||||
|
||||
if (animateCamera || animateCameraTime > 0.0f)
|
||||
{
|
||||
float orbitSpeed = 0.5f;
|
||||
float currentOrbitTime = animateCameraTime * orbitSpeed;
|
||||
|
||||
float zoomAmplitude = 15.0f;
|
||||
float zoomSpeed = 0.5f;
|
||||
radius = baseRadius + (sinf(animateCameraTime * zoomSpeed) * zoomAmplitude);
|
||||
|
||||
float zHeight = radius * 0.5f; // Keep a nice downward viewing angle
|
||||
|
||||
Camera cam = {};
|
||||
cam.Position = { cosf(currentOrbitTime) * radius, sinf(currentOrbitTime) * radius, zHeight };
|
||||
cam.Target = { 0.0f, 0.0f, 0.0f };
|
||||
cam.Up = { 0.0f, 0.0f, 1.0f };
|
||||
cam.FOV = 1.047f;
|
||||
cam.AspectRatio = 1200.0f / 800.0f;
|
||||
cam.NearPlane = 0.1f;
|
||||
cam.FarPlane = 1000.0f;
|
||||
|
||||
return cam;
|
||||
}
|
||||
|
||||
float zHeight = radius * 0.5f; // Keep a nice downward viewing angle
|
||||
|
||||
Camera cam = {};
|
||||
cam.Position = { cosf(currentOrbitTime) * radius, sinf(currentOrbitTime) * radius, zHeight };
|
||||
cam.Position = { radius, 0.0f, zHeight };
|
||||
cam.Target = { 0.0f, 0.0f, 0.0f };
|
||||
cam.Up = { 0.0f, 0.0f, 1.0f };
|
||||
cam.FOV = 1.047f;
|
||||
|
||||
Reference in New Issue
Block a user