Jump to content
  • Advertisement
Sign in to follow this  
liuyang2010sjtu

Eye space coordinate problem in glsl

This topic is 2666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I‘am rather confused with the eye space coordinates recently.

In glsl vs shader, there is :
vec4 eyePos = gl_ModelViewMatrix * gl_Vertex;
when I print all value of eyePos.z to one file, I found that all the value is negative.
I think when I set my camera with gluLookAt(0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0,1.0,0.0),
the positive z axis of the camera's space coordinates should go into the screen.
So why all value of eyePos.z be negative rather than positive?

Another problem,
In glsl vs shader, there is :
vec4 eyePos = gl_ModelViewMatrix * gl_Vertex;
vec3 eyeDir = eyePos.xyz;
so the eyeDir point from eye to the point on the object or reverse?

Share this post


Link to post
Share on other sites
Advertisement
In glsl vs shader, there is :
vec4 eyePos = gl_ModelViewMatrix * gl_Vertex;
when I print all value of eyePos.z to one file, I found that all the value is negative.
I think when I set my camera with gluLookAt(0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0,1.0,0.0),
the positive z axis of the camera's space coordinates should go into the screen.
So why all value of eyePos.z be negative rather than positive?
I'm wondering how you printed all values to a file . . .

In any case, I don't think you understand eye coordinates. The View matrix transforms all points such that they are relative to a camera at the origin that is looking directly down the minus-z axis.

If all your points in eye space are negative, then that means that all objects in the scene are in front of the camera; it doesn't mean that these points' world space coordinates were necessarily negative (or that the camera's direction was anything in particular). This should answer your other question as well.

-G

Share this post


Link to post
Share on other sites
thanks for your reply?
Just as what you said, I put all objects in the scene in front of the camera.
In fact , all the points' z values are negative even in world space.
But why all values of eyePos.z be negative rather than positive ?
I think these should be positive because the eyespace coordinates' z axis goes into the screen.

I got all the values by FBO and then printed them to a file.


[quote name='BeyondBorders' timestamp='1299514806' post='4782864']In glsl vs shader, there is :
vec4 eyePos = gl_ModelViewMatrix * gl_Vertex;
when I print all value of eyePos.z to one file, I found that all the value is negative.
I think when I set my camera with gluLookAt(0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0,1.0,0.0),

So why all value of eyePos.z be negative rather than positive?
I'm wondering how you printed all values to a file . . .

In any case, I don't think you understand eye coordinates. The View matrix transforms all points such that they are relative to a camera at the origin that is looking directly down the minus-z axis.

If all your points in eye space are negative, then that means that all objects in the scene are in front of the camera; it doesn't mean that these points' world space coordinates were necessarily negative (or that the camera's direction was anything in particular). This should answer your other question as well.

-G
[/quote]

Share this post


Link to post
Share on other sites
I think these should be positive because the eyespace coordinates' z axis goes into the screen.[/quote]Close, but no. The eyespace's negative z axis goes into the screen.

It can be confusing because OpenGL treats depth values as unsigned (for example, we speak of depths being "less", when they're actually larger (e.g., -0.8 is "less" (closer) than -0.9)). Adding to the confusion, it's the other way in DirectX.
I got all the values by FBO and then printed them to a file.[/quote]Ah, very good.

-G

Share this post


Link to post
Share on other sites
Thank for your help! ^_^
Maybe I am wrong in some concepts.


I think these should be positive because the eyespace coordinates' z axis goes into the screen.
Close, but no. The eyespace's negative z axis goes into the screen.

It can be confusing because OpenGL treats depth values as unsigned (for example, we speak of depths being "less", when they're actually larger (e.g., -0.8 is "less" (closer) than -0.9)). Adding to the confusion, it's the other way in DirectX.
I got all the values by FBO and then printed them to a file.[/quote]Ah, very good.

-G
[/quote]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!