Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/1.getting_started/7.5.camera_exercise1/camera_exercise1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
// processes input received from any keyboard-like input system. Accepts input parameter in the form of camera defined ENUM (to abstract it from windowing systems)
void ProcessKeyboard(Camera_Movement direction, float deltaTime)
{
// Make sure the user stays at the ground level by setting the y axis to 0
// The x and z axis should not include pitch as you will only move horizontally
glm::vec3 forward = glm::vec3(cos(glm::radians(Yaw)), 0.0f, sin(glm::radians(Yaw)));

float velocity = MovementSpeed * deltaTime;
if (direction == FORWARD)
Position += Front * velocity;
Position += forward * velocity; // Add the forward vector to position
if (direction == BACKWARD)
Position -= Front * velocity;
Position -= forward * velocity; // Subtract the forward vector from position
if (direction == LEFT)
Position -= Right * velocity;
if (direction == RIGHT)
Position += Right * velocity;
// make sure the user stays at the ground level
Position.y = 0.0f; // <-- this one-liner keeps the user at the ground level (xz plane)
}
[...]