Urgent.News

What's breaking now, across thousands of outlets.

Tech

You don't need look-at matrices for an FPS camera

If you have ever written an FPS camera, you have probably seen something like this: vec3 forward = get_forward_vector ( yaw , pitch ); vec3 target = position + forward ; mat4 view = look_at ( position , target , world_up ); It works, but it's really redundant and there's a way simpler way of doing an FPS camera properly. Constructing a target just to pass it to look_at is unnecessary. The camera…

Writing an FPS camera often involves using look_at matrices, but this approach can be redundant. Instead of constructing a target and passing it to look_at, the camera's position and orientation can be used directly. A more straightforward method involves defining the basis vectors using the camera's position and orientation.

To create the forward direction, use the camera's pitch and yaw angles. Calculate the x, y, and z components of the forward vector using cosine and sine functions, then normalize it.

Next, determine the camera's basis by finding the right and up vectors. The right vector is obtained by taking the cross product of the forward vector and the world up vector, then normalizing it. The up vector is the cross product of the right and forward vectors, also normalized.

With these directions, you can move and orient the camera. Move it along the forward and right vectors based on player input. To create a view matrix, use these axes, or alternatively, construct a camera transform and invert it. This simplified method eliminates the need for look_at matrices in FPS camera implementations.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Breaking Down the Door

In 2022, I was 26 and working for a major grocery store chain. I had been there for more than five years, two of them as a manager.

  • Reporter was 26, worked 5+ years at grocery chain
  • Earned $23/hour, felt overworked, underpaid
  • Transitioned to software developer via coding bootcamp

Two tools disagreed 67 times, and the checker was wrong in all 67

A verifier and the thing it verifies disagreed on 67 rows. My first instinct was that 67 is too many to be the checker's fault. It was the checker's fault, in all 67.

  • Two tools disagreed on 67 rows, with checker found wrong in all 67 cases
  • Checker's private parser had two defects causing row lookup errors
  • Fix involved single reader for configuration, eliminating private parser

More from Saturday 12 September →