Jump to content
  • Advertisement
Sign in to follow this  
Colossus_1

Positioning the model into the scene with mouse

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

Hi, I'm developing a program who allows me to position the models into the scene with the mouse. The problem is the values gluUnproject gives me back.The scene initially is empty, then I start positioning a model with mouse but the model doesn't follow mouse cursor and gluUnproject gives me back some values; as soon as I succeed in having the mouse cursor on the model this one follows the mouse as it would do and the values of gluUnproject are different from those I got when the model is not under the mouse cursor. If I move the mouse cursor too fast and this one is not on the model anymore I find myself into the situation described above. What is wrong ?

Share this post


Link to post
Share on other sites
Advertisement
Colossus_1,it seems to me that you're randomly using gluUnproject,without really know what it does.Can you explain in detail,what are you trying to do and why you use gluUnProject?

Share this post


Link to post
Share on other sites
Quote:
Original post by mikeman
Colossus_1,it seems to me that you're randomly using gluUnproject,without really know what it does.


It seems to me that you speak without thinking my friend, how can I use an API function without knowing what it does ?

Quote:
Original post by mikeman
Can you explain in detail,what are you trying to do and why you use gluUnProject?


Just what I wrote in my thread Mr, I need to position the models with mouse and to do this I need OpenGl coordinates of the mouse that I get with gluUnproject. That's all.

Share this post


Link to post
Share on other sites
gluUnProject translates window coordinates to object coordinates.Window coordinates are (winx,winy,winz).Let's say winx=mousex,winy=mousey.winz=?
And don't try to play smart here.You really don't know what you're doing,and so far I'm the only one here willing to help you.

Share this post


Link to post
Share on other sites
Quote:
Original post by mikeman
gluUnProject translates window coordinates to object coordinates.Window coordinates are (winx,winy,winz).Let's say winx=mousex,winy=mousey.winz=?
And don't try to play smart here.You really don't know what you're doing,and so far I'm the only one here willing to help you.


You know what I'm doing right ? So why don't you help me to understand instead of being polemic mikeman ? I just asked help with politeness but you are repling harshly. If you know what is causing the problem (if you understood what the problem is) please reply otherwise please don't. Playing smart ? Bah !

Share this post


Link to post
Share on other sites
I am helping you understand.Just think about it.How do you obtain the winz value?What does that value mean?I just checked your profile and saw that other thread where you say you get it from the depth buffer,something you don't mention in this thread.That's utterly wrong,it has no meaning,because you are trying to get the position on where to draw a model,not the position of an object already drawn.

Share this post


Link to post
Share on other sites
Quote:
Original post by mikeman
That's utterly wrong,it has no meaning,because you are trying to get the position on where to draw a model,not the position of an object already drawn.


Thank you, I thought at the beginning this would have caused the problem so I put 0.0 in the glTranslate who moves the model:


void GLWidget::paintGL()
{
switch (mode)
{
case Normal:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
CameraLook();
//DrawBasement();
for ( std::map< string , unsigned int >::iterator i= MainWindow->DisplayList.begin(); i != MainWindow->DisplayList.end(); i++)
{
unsigned int index = i->second;
printf ("%f\t%f\n" , Model[ index-1 ].x , Model[ index-1 ].y );//, Model[ ChoosedModel ].z);
glPushMatrix();
glTranslatef ( Model[ index-1 ].x , Model[ index-1 ].y , 0.0 );
glCallList ( index );
glPopMatrix();
}
break;

case Select:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
CameraLook();
break;
}
}




The problem, since I use 0.0 as the z axis should lie elsewhere. What do you think the problem could be mikeman ?

Share this post


Link to post
Share on other sites
Ok,I'm not sure about this,but give it a try:(I assume we're talking about perspective projection).
Basically,the object needs to move in 3 axis:X,Y,Z.
The way to do it is:
The camera pos is in (eyex,eyey,eyez)

1)When the left mouse button is down,it moves in the x and y axis
2)When the right mouse button is down,it moves in the z-axis:Moving the mouse "up" causes the object to go further,and down bring the object closer.

When created,just place the object in a default position,say (0,0,-5).In the object class of course,you will store the current 3D position(ox,oy,oz) of the object at all times.
Now,fot the 2 different types of movement:

1)X&Y axis:
Pass the 3D coordinates of the object to gluProject.That way,we can obtain the winz value.Use that value,along with mousex,mousey in gluUnProject,and you can move the object in XY axis,while the Z position remains fixed.

2)Z axis:
We want the object to go further or closer,but we also want it to stay in the same screen coordinates,right?Well,if we just move it along the Z-axis,that won't happen,because the further it goes,it will approaches the center of the screen.So,we need to move it along a ray from the eyepoint to the object pos.

V=(ox-eyex,oy-eyey,oz-eyez) and normalize it.

Finally,move the object as follows:
ox=ox+V.x*delta*sensitivity;
oy=oy+V.y*delta*sensitivity;
oz=oz+V.z*delta*sensitivity;

delta is a value that shows how many pixels has the mouse moved since the last time the function was called(it can take negative values).Sensitivity is just a constant,the bigger it is,the fastest the object moves.

[Edited by - mikeman on September 8, 2004 3:02:39 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by mikeman

1)X&Y axis:
Pass the 3D coordinates of the object to gluProject.That way,we can obtain the winz value.Use that value,along with mousex,mousey in gluUnProject,and you can move the object in XY axis,while the Z position remains fixed.


Do I have to pass ox , oy , oz as the last three arguments to gluUnproject to move it along the X and Y axis ?

Thanks for replying,

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by mikeman

1)X&Y axis:
Pass the 3D coordinates of the object to gluProject.That way,we can obtain the winz value.Use that value,along with mousex,mousey in gluUnProject,and you can move the object in XY axis,while the Z position remains fixed.


Do I have to pass ox , oy , oz as the last three arguments to gluUnproject to move it along the X and Y axis ?

Thanks for replying,


Yes.As I said,I'm not entirely sure this approach is correct,but I think it is.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!