# Thread: world coordinates to object space

1. ## world coordinates to object space

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..

2. ## Re: world coordinates to object space

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.

3. ## Re: world coordinates to object space

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..

4. ## Re: world coordinates to object space

Well, that all depends on what coordinate system you specified the light position in, doesn't it?

N.

5. ## Re: world coordinates to object space

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.

6. ## Re: world coordinates to object space

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.

7. ## Re: world coordinates to object space

Thanks for your fast replies .
I will try to keep in mind what you wrote and get the program to work hopefully..

8. ## Re: world coordinates to object space

Originally Posted by grayfoxrk
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...

Code :
```+--------------+                             +--------------+
| 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.