View Full Version : gluUnProject problem with rotation

infingy

02-24-2010, 09:27 AM

Hey there,

I have a mesh

if i don't rotate it, everything is fine with the coordinates generatet by gluUnProject

But if i rotate the mesh, then gluUnProject gives me different coordinates for the same point

Do i have to do something before calling gluUnProject or glReadPixels ?

Anything i have to consider?

I've searched through many postings and havend found a hint yet.

Any Idear?

strattonbrazil

02-24-2010, 11:12 AM

Are you including your matrix changes into gluUnProject? If you pass gluUnproject the modelview matrix that goes from world to camera space, you're fine if you don't rotate the object. However, if you do rotate the object via the modelview matrix, gluUnproject has to use that new matrix.

Imagine this was the matrix setup:

ViewportMatrix * ProjectionMatrix * ModelViewMatrix * Vertex = VertexOnScreen

Going in modelview details:

ViewportMatrix * ProjectionMatrix * (gluLookAt matrix) * Vertex = VertexOnScreen

If you're rotating the mesh,

ViewportMatrix * ProjectionMatrix * (gluLookAt matrix * someRotationMatrix) * Vertex = VertexOnScreen

To go the other way around, gluLookAt obviously needs to know about the rotation. Are you sure it is getting the new modelview matrix from the rotation?

infingy

02-25-2010, 02:35 AM

thanks for your quick reply

actually i'm not the one who made the code, i just have to implement the picking

i try to find out what you have mentioned

my understanding for opengl becomes clearer and clearer ;-)

thanks for now

infingy

02-25-2010, 05:21 AM

the z-coordinate which i get from glReadPixels still changes when i rotate the model

strattonbrazil

02-25-2010, 03:30 PM

Can you give me a little more info? What's the model look like? Unless you're rotating a sphere and it isn't moving around in screen space, you should get a different value in z. Are you talking about the same (x,y) pixel giving a different z?

Imagine I draw a rectangle across my screen in 3D. Two-thirds across I measure the z-coordinate from glReadPixels. I then rotate the thing around its center. That same (x,y) should be a little closer or further away for most objects.

infingy

02-28-2010, 05:13 AM

the model is very complex.

but there is a part which is planar. There for different (x,y) i have the same z.

if i rotate the model i get almost the right (x,y) coordinates.

But the z coordinates vary for diffrent (x,y) on the planar area, after calling glReadPixels and gluUnProject

strattonbrazil

03-01-2010, 03:07 PM

And this planar area is perfectly aligned with the image plane? Can you post some of your relevant code?

infingy

03-08-2010, 02:10 AM

Hey, im sorry, but i was ill and not in the office

Unfortunatelly i can't post any code

Do you know how much the precision from this method is?

My Model is given in meters and the coordinates are correct till the third decimal place.

Is this the best result i can get?

ZbuffeR

03-08-2010, 04:18 AM

A single float can not hold more than 7 digits (in decimal base) of precision. So with metres, anything around 1000 metres size can not have more than 3 decimal digits of precision (1 millimeter).

If further computations are done on floats (instead of double), it becomes even worse.

Not sure if gluUnProject is all doubles inside, or not...

infingy

03-08-2010, 04:44 AM

Ok, that sounds logical

But my test-coordinates are smaler

for example in initial state i have 0.0015 m for the z-coordinate

after rotation i get values like 0.000912 or 0.001153

Can i get better precision if i choose other (closer) z-near and z-far?

ZbuffeR

03-08-2010, 05:16 AM

Then it sounds more is a z-depth issue.

There are 2 bitdepth possible : 16 and 24. And it is normalized integer, so precision can be very low.

1) make sure you request and get a 24 bits depth buffer

2) read http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

then push znear as far as possible, and zfar as near as possible to get the most depth precision from this depth range.

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.