PDA

View Full Version : world coordinates to object space

grayfoxrk
01-24-2008, 08:51 AM
Hi everyone,

how can i calculate the position of a point from world coordinates to object space over the modelviewmatrix? I need the position in a vertex shader.
I tried several hours now, but i just dont get it. :(

I thought it would be the the inverse modelviewmatrix multiplicated by the position, but it doesnt work.

i hope you can help me..

-NiCo-
01-24-2008, 08:54 AM
I don't get it... within a vertex shader you usually start with the object space coordinates. Multiplying these object space coordinates gives you the eye space coordinates and multiplying the eye space coordinates with the projection matrix gives you the window space coordinates.

N.

grayfoxrk
01-24-2008, 09:04 AM
i have set the light position in the main program and hand it over to the shader. and in the shader i need to calculate the lightposition relative to the vertex position. its a lighting vertex shader written in cg..

-NiCo-
01-24-2008, 09:10 AM
Well, that all depends on what coordinate system you specified the light position in, doesn't it?

N.

grayfoxrk
01-24-2008, 09:17 AM
The light position is specified in an array in world space coordinates. I dont use opengl itself to calculate the light. i want to add phong lighting via the vertex shader to the objects.

-NiCo-
01-24-2008, 09:23 AM
It depends on your definition of world space. If it's the same as eye space you need to multiply the vertex position with the modelview matrix (not the inverse one) to get it in the same coordinate system as the light position.

N.

grayfoxrk
01-24-2008, 11:33 AM
Thanks for your fast replies :).
I will try to keep in mind what you wrote and get the program to work hopefully..

Dark Photon
01-30-2008, 04:59 AM
how can i calculate the position of a point from world coordinates to object space over the modelviewmatrix?
-NiCo- may have answered your question, but just in case you're still a little fuzzy on this...

+--------------+ +--------------+
| Object Space | -> Modeling Transform -> | World Space |
+--------------+ +--------------+
+--------------+ +--------------+
| World Space | -> Viewing Transform -> | Eye Space |
+--------------+ +--------------+
+--------------+ +--------------+
| Object Space | -> Modelview Transform -> | Eye Space |
+--------------+ +--------------+

The modelview matrix gets you from object space to eye space (use the inverse to get back). It doesn't know about world space.

The only way you can use modelview to get back to world space is if your object space and world space are the same (i.e. your modeling transform is the identity matrix -- i.e. a no-op). in other words, if the position vertex data for all objects in your scene are specified in a common coordinate system.