Results 1 to 4 of 4

Thread: Problem when moving object in Z coord...

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    2

    Problem when moving object in Z coord...

    Hello!
    I'm starting to play around with OpenGL ES 2 and when trying to move an object in the Z coord it just either disappears or doesn't do anything.
    It moves well in X and Y but not Z.
    To move in Z I use the gl_Position.z in the shader.

    The source of the project is in: http://cl.ly/24240x2D1t2A3I0c1l1P
    It's a XCode project for iOS, the setup code can be found in EAGLView.m @ createFramebuffer, and the draw code can be found in TranslateSinZ.m @ drawView.

    I believe the problem should be in the setup code but I can't figure out what's wrong...

    Anyone can help me out?
    Thank you!

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Problem when moving object in Z coord...

    gl_Position is the position of the vertex in homogeneous clip space. Its Z component is only used for clipping against the near and far planes as well as for the depth test. It does not affect the position of the vertex in X and Y on screen.

    I suspect that what you actually want is to translate the vertices in view space Z, before applying a projection transformation.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    2

    Re: Problem when moving object in Z coord...

    I thought just changing the value in "gl_Position.z" would work since it works for "gl_Position.x" and "gl_Position.y".
    So to translate the rectangle in Z, how can I achieve that?
    "Translate the vertices in view space Z" can you explain in another fashion?
    Thank you for your time.

  4. #4
    Junior Member
    Join Date
    Apr 2011
    Posts
    4

    Re: Problem when moving object in Z coord...

    Indeed, changing the value of gl_Position.z wont work because the rendered image is on a 2d plane with no depth

    What you need to do is add back in the model, view and projection matrices that got deprecated in the move to programmable shaders, so my vertex shader looks a little something like:

    Code :
    attribute lowp vec4 v_position;
    attribute lowp vec2 v_texture;
     
    uniform mat4 m_model;
    uniform mat4 m_view;
    uniform mat4 m_projection;
     
    varying vec2 textureVarying;
     
    void main()
    {					
    	textureVarying = v_texture;
    	gl_Position = m_projection * m_view * m_model * v_position;
    }

    Here, translations and rotations for a given model are loaded into the model matrix, m_model , the camera setup is loaded into the view matrix, m_view and the projection (ortho or perspective) is loaded into the projection matrix m_projection .

Similar Threads

  1. Moving object allong its own axes
    By freddy50 in forum Developers Coding:Beginner
    Replies: 4
    Last Post: 04-02-2011, 08:58 PM
  2. Moving object with mouse
    By xrew in forum WebGL - General
    Replies: 3
    Last Post: 03-31-2011, 05:25 AM

Posting Permissions

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