I have a camera that follows the position and direction of the player. TheseThese are updated using spin and velocity. TheThe velocity is updated like so:
auto velocity = get_velocity();
velocity += get_acceleration().x * get_right();
velocity += get_acceleration().y * get_up();
velocity -= get_acceleration().z * get_forward();
set_velocity(velocity);
... where acceleration is relative to the object, not the world. ThisThis is the first time I have used OpenGL and I am not sure if this is the best solution, butt tbut it does what I want. II was woundingwondering if there is a better way to do this using OpenGL Mathematics (GLM).
Additionally, this method works like a rocket, which is good for what I am trying to do, but if I want something more like a human, I have to change it to:
auto velocity = get_velocity();
auto const y = velocity.y + get_acceleration().y;
velocity += get_acceleration().x * get_right();
velocity -= get_acceleration().z * get_forward();
velocity.y = y;
set_velocity(velocity);
... to prevent the player from being able to fly by looking up. IsIs there a way of simplifying this case, too?
Acceleration is defined as:
switch (dir) {
case left: return glm::vec3(-1, 0, 0);
case right: return glm::vec3( 1, 0, 0);
case front: return glm::vec3( 0, 0, -1);
case back: return glm::vec3( 0, 0, 1);
case up: return glm::vec3( 0, 1, 0);
case down: return glm::vec3( 0, -1, 0);
default: assert(false);
}