0
\$\begingroup\$

I was wondering if it was possible to calculate a lookat position from the translation and rotation matrices (aka the building blocks of my view matrix). I need the lookAt position to implement a special type of frustum culling, but my program does not use the lookat position, so I was looking for a simple solution to calculate it.

\$\endgroup\$
6
  • \$\begingroup\$ Any point along the camera's forward axis can be used as a look-at position. What have you tried so far? \$\endgroup\$
    – DMGregory
    Jan 26, 2023 at 21:41
  • \$\begingroup\$ Okay, thanks so much for the tip \$\endgroup\$
    – oli2
    Jan 26, 2023 at 22:12
  • \$\begingroup\$ Actually, how would I go about calculating the forward vector of the camera? \$\endgroup\$
    – oli2
    Jan 26, 2023 at 23:06
  • \$\begingroup\$ Depends on your framework/tech stack. Sometimes it's the camera's local +z, sometimes -z, though more exotic choices are conceivable. What can you tell us about how you've coded this camera? \$\endgroup\$
    – DMGregory
    Jan 27, 2023 at 0:27
  • \$\begingroup\$ I made my own framework using metal (Apple Graphics API) I have access to the camera position, worldup, view matrix, rotation (in both degrees and radians) and the translation data \$\endgroup\$
    – oli2
    Jan 27, 2023 at 1:41

1 Answer 1

0
\$\begingroup\$

Your view matrix is the inverse of the object's camera transformation, and the inverse of a rotation matrix is just its transpose, so the 3rd row is your camera's local forward vector.

Add some multiple d of the third row of your view matrix to your camera position to get a point d units in front of your camera along its forward axis.

(This is equivalent to multiplying the vector (0, 0, d, 1) by the camera's transformation matrix, or the inverse of the view matrix, just skipping redundant ops for the zero terms)

Using that as a look-at point will give the same result as your current camera orientation, since your camera is already looking at it.

Some APIs treat negative d values as "in front" of the camera, while others say that's behind and positive is in front, so flip the sign on d if you initially get the wrong answer.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .