Jump to content
  • Advertisement
Sign in to follow this  
SulphurTenM

Mouse select 3D object

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

Can someone direct me to an example of code that uses the mouse to select a 3D object. What I mean is if you use the mouse (which is in 2D) to click on a 3D box you've created, you get a cout or something. I see this all the time in games like guild wars... Thank for any help.

Share this post


Link to post
Share on other sites
Advertisement
void Selection::GetOGLPos()
{
GLint viewport[4];
GLdouble projection[16];
GLdouble modelview[16];
GLfloat winX, winY, winZ;
glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); //Get modelMatrix
glGetDoublev( GL_PROJECTION_MATRIX, projection ); //Get projectionMatrix
glGetIntegerv( GL_VIEWPORT, viewport ); //Get windowsMatrix
winX = (float)m_iX; //MousePosX
winY = (float)viewport[3] - (float)m_iY; //MousePosY (opengl from buttom to top ,so Sub...)
glReadPixels( m_iX, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
//Get Select pixle Z-Buffer
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &m_CoordInWorld[0], &m_CoordInWorld[1], &m_CoordInWorld[2]); //m_CoordInWorld[] hold x,y,z in world
}
//---------------
If you get the point's coord[] which you select , you can test this point if it's in the
Object's Culling Box
those code work well on my computer ..so , I think it can help you


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!