Sign in to follow this  

help: gluUnproject ray picking...

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

This topic is 4833 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this