Jump to content
  • Advertisement
Sign in to follow this  
godmodder

OpenGL My eyes hurt in eye-space

This topic is 4292 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

Hello, I want to do something incredibly easy, but apparently I'm missing something and I was hoping you guys could help me out. I have some vertices and I want to know which one is the furthest from the camera. So I thought the easiest way to do it is to multiply the vertices with opengl's modelview matrix, so that they are in eye-space, and then find out which coord has the greatest Z value. Now a vertex is indeed found, but for some reason it's allways around 119.0f Am I missing something and could you explain what I did wrong please? Jeroen

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by s3mt3x
Try the inverse of the modelview matrix :)
No, that's not right - the modelview matrix itself transforms geometry directly from local object space to view/camera space, so multiplying by the modelview matrix should give the correct results.

@The OP: Perhaps there's a problem with your matrix-vector multiplication code, or how you're querying the matrix from OpenGL. If you're not sure, you might post these particular code excerpts.

Share this post


Link to post
Share on other sites
the easiest way (+ prolly the quickest)

loop_all_verts
{
dist = SQUAREDLENGTHOFVECTOR( vertpos - campos );
if ( dist > furtherest )
...

}

Share this post


Link to post
Share on other sites
Quote:
Original post by zedzeek
the easiest way (+ prolly the quickest)

loop_all_verts
{
dist = SQUAREDLENGTHOFVECTOR( vertpos - campos );
if ( dist > furtherest )
...

}
By 'distance from the camera' I think the OP means the distance from the plane defined by the camera's side and up vectors, not the Euclidean distance.

Share this post


Link to post
Share on other sites
Hello,

I'm implementing parallel split shadow maps and I want to adjust the camera's farplane to the furthest vertex of the scene's bounding box so the frustum would fit tightly around my geometry, so using Euclidian distance isn't an option here I'm afraid. I 'm gonna take a good look again through my vector-matrix multiplication code as soon as possible, but I don't think they're the problem because I've used them in a couple of other projects.
I query my modelview matrix in my rendering loop, right before I use it like this:

CMatrix4x4 modelview;
glGetFloatv(GL_MODELVIEW, modelview);

// ... use the matrix here

Jeroen

Share this post


Link to post
Share on other sites
I found the solution. It turns out I had to query the matrix with GL_MODELVIEW_MATRIX instead of with GL_MODELVIEW.
What a stupid error after all...

But what's strange is that I have to multiply my vertex with the modelview matrix AND the projection matrix (modelviewproj) to get it to work. Any idea why this is?

Thanx guys,
Jeroen

Share this post


Link to post
Share on other sites
Quote:
Original post by godmodder
But what's strange is that I have to multiply my vertex with the modelview matrix AND the projection matrix (modelviewproj) to get it to work. Any idea why this is?
Perhaps you have the wrong matrix modes set when you set up your initial matrices (e.g. loading the view matrix while in PROJECTION_MATRIX mode).

In any case you should only need to transform by the modelview matrix, so I suspect something may still be off somewhere in your code.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!