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

## 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 on other sites
Try the inverse of the modelview matrix :)

##### Share on other sites
Quote:
 Original post by s3mt3xTry 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 on other sites
the easiest way (+ prolly the quickest)

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

}

##### Share on other sites
Quote:
 Original post by zedzeekthe 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 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 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 on other sites
Quote:
 Original post by godmodderBut 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.

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631776
• Total Posts
3002299
×