Jump to content
  • Advertisement
Sign in to follow this  
clayasaurus

help: gluUnproject ray picking...

This topic is 5171 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. Ok, I'm trying to do ray picking with gluUnproject. It's working on the x and z axis, but the y axis is off. If I look *just right*, the y axis is accurate. If I look up and point the mouse down, the ray is cast up even farther. If I look up and point the mouse up, the ray is cast down more. If I look down and point down, it causes the ray to be cast up more. If I look down and point up, the ray is cast down more. If I look somewhere in the middle *just right*, the y axis becomes fairly accurate. I've tried to invert the Y axis, but it does the same thing in the other direction. I'm not sure what to do. Here's the code.
void project(int x, int y) // mouse coords
{
	// Declarations //////////////////////////////////////////
	Vector near, far;

	GLdouble proj[16]; // view matrix
	GLdouble model[16];
	GLint view[4];

	GLdouble nearx,neary,nearz; // glu coords
	GLdouble farx,fary,farz;

	// Codes /////////////////////////////////////////////////
	glGetDoublev(GL_PROJECTION_MATRIX,proj); // get matrix
	glGetDoublev(GL_MODELVIEW_MATRIX,model);
	glGetIntegerv(GL_VIEWPORT,view);

	gluUnProject(x,y,0,model,proj,view,&nearx,&neary,&nearz); // get coords
	gluUnProject(x,y,1,model,proj,view,&farx,&fary,&farz);

	direction.x = (farx - nearx); 
	direction.y = (fary - neary);
	direction.z = (farz - nearz); 
	
	direction.normalize(); // set length to 1

	end = start + (direction*length);
}


Share this post


Link to post
Share on other sites
Advertisement
Try that

gluUnProject(x,view[3]-y,0,model,proj,view,&nearx,&neary,&nearz);
gluUnProject(x,view[3]-y,1,model,proj,view,&farx,&fary,&farz);

Share this post


Link to post
Share on other sites
Quote:
Original post by Vampyre_Dark
Try that

gluUnProject(x,view[3]-y,0,model,proj,view,&nearx,&neary,&nearz);
gluUnProject(x,view[3]-y,1,model,proj,view,&farx,&fary,&farz);


Thank you Vampyre_Dark! You are my savior! :) :) :)

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!