Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: world coordinates to object space

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2008
    Posts
    4

    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. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    999

    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. #3
    Junior Member Newbie
    Join Date
    Jan 2008
    Posts
    4

    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. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    999

    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. #5
    Junior Member Newbie
    Join Date
    Jan 2008
    Posts
    4

    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. #6
    Advanced Member Frequent Contributor
    Join Date
    Apr 2004
    Posts
    999

    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. #7
    Junior Member Newbie
    Join Date
    Jan 2008
    Posts
    4

    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. #8
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,894

    Re: world coordinates to object space

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

    You're probably going to find it simpler to pre-transform your light to eye space in your app and pass that into your shader, so you don't have to think about world space in your shader.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •