Skip to content

🎥 Issue 8 — Add Camera Distance Printout #27

@dhruv0154

Description

@dhruv0154

Goal

To help developers understand how camera movement affects the scene, print the camera’s position and direction every few seconds. This is useful for debugging and tuning camera movement, FPS controls, and scene composition.


Overview

  • Add a timer in the scene’s update() method.
  • Every n seconds, print camera information to the console.
  • Use the camera's Position and Front vectors to display its current location and orientation.
  • Make it easy to adjust the print interval.

Implementation Steps

1️⃣ Add Timer in Scene

File: scenes/test.cpp

#include <iostream>
#include "scenes/test.h"
#include "core/Camera.h"

class TestScene {
    float printInterval = 2.0f; // seconds
    float timeSinceLastPrint = 0.0f;
    Camera* camera;
public:
    TestScene(Camera* cam) : camera(cam) {}

    void update(float deltaTime) {
        timeSinceLastPrint += deltaTime;

        if (timeSinceLastPrint >= printInterval) {
            PrintCameraInfo();
            timeSinceLastPrint = 0.0f;
        }

        // Existing scene update logic...
    }

    void PrintCameraInfo() {
        glm::vec3 pos = camera->Position;
        glm::vec3 dir = camera->Front;
        std::cout << "Camera Position: (" << pos.x << ", " << pos.y << ", " << pos.z << ")" << std::endl;
        std::cout << "Camera Direction: (" << dir.x << ", " << dir.y << ", " << dir.z << ")" << std::endl;
        std::cout << "----------------------------" << std::endl;
    }
};
  • printInterval controls how often the print occurs.
  • timeSinceLastPrint accumulates delta time between updates.
  • PrintCameraInfo() prints the camera’s Position and Front vectors.

2️⃣ Update Scene Loop

Make sure your main update loop passes deltaTime:

float currentFrame = static_cast<float>(glfwGetTime());
float deltaTime = currentFrame - lastFrame;
lastFrame = currentFrame;

scene->update(deltaTime);

This ensures timeSinceLastPrint increments correctly.


3️⃣ Optional: Toggle Printing On/Off

You can add a key to enable or disable the printout:

bool printCameraEnabled = true;
input->BindKeyEvent(GLFW_KEY_P, GLFW_RELEASE, [&]() {
    printCameraEnabled = !printCameraEnabled;
});

// In update()
if (printCameraEnabled && timeSinceLastPrint >= printInterval) {
    PrintCameraInfo();
    timeSinceLastPrint = 0.0f;
}

4️⃣ Output Example

Camera Position: (0.0, 0.0, 3.0)
Camera Direction: (0.0, 0.0, -1.0)
----------------------------
Camera Position: (0.1, 0.0, 2.95)
Camera Direction: (0.0, 0.1, -0.99)
----------------------------
  • Shows how the camera moves and rotates in the scene.
  • Helps debug FPS-style camera movement or automated camera paths.

📂 Files to Modify

  • scenes/test.cpp
  • includes/helpers/camera.h (if you want to add helper getters for Position and Front)

🎯 Outcome

  • Camera position and direction are logged every few seconds.
  • Developers can track how camera movement affects rendering.
  • Easy to toggle printing for debugging or performance.

Metadata

Metadata

Labels

enhancementNew feature or requestgood first issueGood for newcomershacktoberfestthis issue is listed under hacktoberfest and is up for grabs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions