2
\$\begingroup\$

First of all, sorry if my question sounds too basic or even makes no sense. I'm new with game development

I'm working with HPL1Engine, specifically, the lights parts. I need to know the direction in which a spot light emits its light. But the class that represents a spot light, doesn't have any direction vector.

So, I've been reading about lights in 3D engines, and I've detected in the class some other properties that I consider important. Like a projection matrix and angles (FOV and aspect). I'm trying to focus on the projection matrix (here, how the engine calculates it), but I'm not sure if I'm wasting my time.

Again, my goal is to know the direction in which a spot light emits its light (a vector), but I just have this matrix, and many other properties I don't relate with the spot direction calculation.

How could I know this direction from which I have (what the class provides me)?

Many thanks in advance.

\$\endgroup\$
1
\$\begingroup\$

You need the view matrix of the class (looks like you can retrieve it via GetViewMatrix()). Take a vec4 that points in the "default direction" (0 0 -1 most likely), e.g. (0 0 -1 0) and multiply it by the view matrix. This should give you the direction of the spot light in the x y and z components of the vec4.

This is assuming, though, that the view matrix here actually does what I assume it does, which is to shift the coordinate system such that its new z axis through the origin lines up with the "middle ray" of the projection cone.

\$\endgroup\$
1
\$\begingroup\$

You should be able to get the direction from the view matrix. The view matrix contains the axes of the spot light: the first collumn contains the x-axis ("side" vector), the second collumn contains the y-axis ("up" vector), and the third collumn contains the z-axis ("forward" vector). So grab the x, y and z values from the third collumn, and there you go. Depending on the coordinate system, you may need to negate the value, as per TravisG's answer.

\$\endgroup\$
  • \$\begingroup\$ Seems to work. As you both sent the same message, I mark the first one as response. But many thanks! \$\endgroup\$ – Jorge Arévalo Mar 14 '14 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.