Currently I'm using gluUnProject to try to draw a line when the use clicks on my subclased openGL Custom view. A line directly along the current line of sight where the use clicks. purely for calibration purposes of gluUnProject. This is my code for the mouse down event where gluUnProject is called.
The line is drawn but never in the right place. I figure the likely fault is in
I've tried several variations of this but none seem to work. any suggestions?
Code:
- (void)mouseDown:(NSEvent *)theEvent
{
GLdouble winX, winY, winZ;
GLdouble modelview[16],projection[16],posX1, posY1, posZ1,posX2, posY2, posZ2,posW;
GLint viewport[4];
NSPoint location = [self convertPoint:[theEvent locationInWindow] fromView:nil];
NSRect rectView = [self bounds];
location.y = rectView.size.height - location.y;
location.y=location.y*2/rectView.size.height-1;
location.x=location.x*2/rectView.size.width-1;
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glGetIntegerv( GL_VIEWPORT, viewport );
winX=location.x;
winY=location.y;
gluUnProject( winX, winY, 0.01, modelview, projection, viewport, &posX1, &posY1, &posZ1);
gluUnProject( winX, winY, 0.99, modelview, projection, viewport, &posX2, &posY2, &posZ2);
myLine[0]=posX1;
myLine[1]=posY1;
myLine[2]=posZ1;
myLine[3]=posX2;
myLine[4]=posY2;
myLine[5]=posZ2;
}
The line is drawn but never in the right place. I figure the likely fault is in
Code:
location.y = rectView.size.height - location.y;
location.y=location.y*2/rectView.size.height-1;
location.x=location.x*2/rectView.size.width-1;
I've tried several variations of this but none seem to work. any suggestions?