• Advertisement


This topic is now archived and is closed to further replies.

Making a Ray for Object Selecting

This topic is 6259 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 Guys, i have try to make a ray for object selecting ( Ray intersecting ) so now my little code:
// For LineStart we use the Camera Pos:

CVector LineStart;
LineStart.fX = cam.fX;
LineStart.fY = cam.fY;
LineStart.fZ = cam.fZ;

// New the LineEnd:

CVector LineEnd;
	GLint viewport[4];
	GLdouble mvmatrix[16], projmatrix[16];	
	GLint realy;			//  OpenGL y coordinate position

	GLint realx;

	glGetIntegerv (GL_VIEWPORT, viewport);    
	glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix);    
	glGetDoublev (GL_PROJECTION_MATRIX, projmatrix);//  note viewport[3] is height of window in pixels  	

	realx = MouseX;
	realy = viewport[3] - MouseY - 1;

	gluUnProject( (GLdouble)realx, (GLdouble)realy, 1.0f, mvmatrix, projmatrix, viewport, &unpX, &unpY, &unpZ); 	

	LineEnd.x = (float)unpX;	
	LineEnd.y = (float)unpY;	
	LineEnd.z = (float)unpZ;
So my question is is this right? If not how i must do it ? Thanks for your help Punika [ Power Productions ]

Share this post

Link to post
Share on other sites

  • Advertisement