Advertisement

gluUnProject

Started by July 14, 2003 03:41 PM
13 comments, last by AyaKoshigaya 21 years, 7 months ago
Hi, I''m getting insane because of gluUnProject... can anyone tell me how I can get the WinZ Koordinate??? I want to drag an Object in the Scene.. I know the Coordinates of the Camera and the Coordinates of the Object... Please, could anyone help me??? *looks hopefully* Au''revoir, Aya~
I aim for my endless Dreams and I know they will come true!
use glReadPixels with depthcomponent as the format:

glReadPixels( mouse.x, mouse.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &WinZ )

this will return the zdepth at the current mouse coordinates.
don''t piss on an electrical fence
Advertisement
I would like to thank both of you for asking and answering this question - I needed this information too . It was very helpful.

Love means nothing to a tennis player

My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)

Hi,

mh... I''t doesn''t work very good...

I''m using this code:

function GetMousePos(WinX, WinY: Integer): TVertex;
var
ModelView, Projection: TMatrix4d;
Viewport: TVector4i;
ObjX, ObjY, ObjZ: GLDouble;
WinZ: GLFloat;
begin
glReadPixels(WinX,WinY,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,@WinZ);
glGetDoublev(GL_MODELVIEW_MATRIX,@ModelView);
glGetDoublev(GL_PROJECTION_MATRIX,@Projection);
glGetIntegerv(GL_VIEWPORT,@Viewport);
gluUnProject(WinX,Viewport[3] - WinY - 1,WinZ,ModelView,Projection,Viewport,@ObjX,@ObjY,@ObjZ);
Result.X:=ObjX;
Result.Y:=ObjY;
Result.Z:=ObjZ;
end;

But if I move the Object, the Object moves much faster then the Mouse... did you have an small Example code for me???

(My Code is in Delphi, but I have no problems with C/C++)

Au''revoir,
Aya~
I aim for my endless Dreams and I know they will come true!
If you don''t mind my asking, what is the logic you''re using for dragging, in pseudocode?

What I''m trying to accomplish is allowing the user to click and drag to draw objects on the screen, but naturally when the user clicks a point, that point could represent anywhere on a ray from the front of the frustum to the back, and then when he starts dragging, heaven only knows where he''s going. I''ve only just begun thinking about what could be done, I have a couple ideas but nothing that sounds easy for sure.

That''s why I''m asking, what is your "thought process" as you drag the object in 3D, i.e. are you generating a sprite and dragging it in Ortho mode, just dragging the object itself etc?

Love means nothing to a tennis player

My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)

Hi,

for example:
I''ve an Object (DisplayList or VertexArray.. for example a Sphere). In the middle of the Object are 3 Arrows.. one for X, Y, and Z to Translate the Object.

So, if you''re klicking on the Y-Arrow and moving the Mouse up/down the Object should change the Y Position like the Mouse is doing.

There''s no problem changing the Y-Position or something, the only Problem is: The Object is moving much faster then the Object...

Does anyone have an Idea???

Au''revoir,
Aya~
I aim for my endless Dreams and I know they will come true!
Advertisement
Hmm, could you maybe post your code?

Love means nothing to a tennis player

My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)

GLint view[4];
GLdouble model[16], proj[16];
GLfloat winX, winY, winZ;

glGetDoublev( GL_MODELVIEW_MATRIX, model );
glGetDoublev( GL_PROJECTION_MATRIX, proj );
glGetIntegerv( GL_VIEWPORT, view );

mouse.y = view[3] - mouse.y;
winX = (float)mouse.x;
winY = (float)mouse.y;
glReadPixels( mouse.x, mouse.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

gluUnProject( winX, winY, winZ,
model, proj, view,
&pos.x, &pos.y, &pos.z );


...or something like that, it should do the job.
[edit]crap i misread the post...just ignore me[/edit]

[edited by - _Corrupt_ on July 17, 2003 9:24:27 AM]

[edited by - _Corrupt_ on July 17, 2003 9:28:06 AM]
don''t piss on an electrical fence
quote:
Original post by AyaKoshigaya
So, if you''re klicking on the Y-Arrow and moving the Mouse up/down the Object should change the Y Position like the Mouse is doing.

There''s no problem changing the Y-Position or something, the only Problem is: The Object is moving much faster then the Object...



the problem would be the perspective, you are probably moving the object based on the change in the y-coord of the mouse position?

try this, use gluUnproject again but with the same WinZ as when you just clicked the object, when you drag the mouse calculate your new position in 3dspace(unproject) and position the object accordingly.

(hope this made some sense )
don''t piss on an electrical fence
That''s what I was thinking too corrupt.

Aya - one more question - are you just dragging objects to be able to move them, or are you also trying to drag an object from one object to another, like dragging a book from one table to another?

That''s another problem I''m trying to tackle in OpenGL - it''s easy to know the source object from just object picking, but I don''t think that when you drag over to the next item that the glSelect thing gives you another message. I have a lot of work to do today but I''ll see if I can look into it more this weekend.

Love means nothing to a tennis player

My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)

This topic is closed to new replies.

Advertisement