Worldspace to eyespace

Hi, maybe this is an easy question, but if I have a lightposition in worldspace, how do I convert it to eyespace?

Regards, Ninja

Multiply it by your worldspace->eyespace transformation matrix.

Note that GL doesn’t by itself have a notion of worldspace, because it bakes model-to-world and world-to-view into the composite model-to-view matrix.

Anyway, if you create your modelview by using one modelworld matrix and one worldview matrix, then just use the latter to go from world to view.

It goes like this:

object_space->[MODEL_MATRIX]->world_space->[VIEW_MATRIX]->eye_space->[PROJ_MATRIX]-> etc…

Do you have some kind of camera class so you can orient where the “camera” is looking and where it is located? If so, all of those translations and rotations combined in a matrix makes your view_matrix. So just take that matrix and multiply with your light and presto, eye-space light!

-SirKnight

Originally posted by SirKnight:
[b]It goes like this:

object_space->[MODEL_MATRIX]->world_space->[VIEW_MATRIX]->eye_space->[PROJ_MATRIX]-> etc…

Do you have some kind of camera class so you can orient where the “camera” is looking and where it is located? If so, all of those translations and rotations combined in a matrix makes your view_matrix. So just take that matrix and multiply with your light and presto, eye-space light! :smiley:

-SirKnight[/b]

If you talking from the point of view of OpenGL’s transformation pipe, that’s not quite right… As John said:

object_space->[MODEL_VIEW_MATRIX]->eye_space->[PROJ_MATRIX]-> etc…

However, for a light in worldspace, you can back transform the light to model space with a translation, set the actual location to the model’s origin and then transform by the MODELVIEW matrix…

Leathal.

I never said that is exactly how opengl does it. OpenGL ovbiously combines the model and view matrcies together to save an extra matrix multiply or something. But requardless of that, the same math is still taking place, the end result will still be the same. What I said applys to 3d graphics no matter what API is used. I wrote it like that to better see where world space is.

Here is a method that may help:

matrix4x4 mat = object[objIndex].InverseTransform() * light.GetTransform();
mat.Multiply( light_pos, objSpaceLight );

So what we are doing there is taking the inverse of the transformations done to your model and multiplying that with the tranformations that was applied to your light (any translations or rotations if any, otherwise that will just return an identity matrix). Then this matrix is used to take the light position and transform it to object space. That code right there is based on the code in Cass’s inf shadow volume demo, incase that looks familiar to anyone.

-SirKnight