Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I offset an openGL object while still keeping the projection like I'm looking straight at it?

My brain has melted as I've spent forever on this problem.

I need to offset a cube from the origin by two in both the x and y direction however keep the one point perspective like I'm looking straight at it.

Everytime I translate the cube it is acting as if the projection is coming from the origin.

I cant figure out how to do it.

//this is here to draw a graph  
glMatrixMode (GL_PROJECTION);  
glLoadIdentity();  
glOrtho(-10,10,-10,10,-10,10);  
glBegin(GL_LINES);  
glVertex3f(-10, 0,0);  
glVertex3f(10, 0 ,0);  
glVertex3f(0, -10,0);  
glVertex3f(0, 10 ,0);  
glEnd();  



glPushMatrix();  
glLoadIdentity();  
glFrustum(-2.0, 2.0, -2.0, 2.0, 5, 100);

gluLookAt( 0,0,-6,
       0, 0, 0,
       0.0, 1.0, 0.0);
glutWireCube (.5);

glPopMatrix();

glFlush();
like image 885
Nick Avatar asked Dec 08 '25 23:12

Nick


1 Answers

You're using gluLookAt on the projection matrix. This is wrong, gluLookAt is to be applied on the modelview matrix.

like image 131
datenwolf Avatar answered Dec 11 '25 21:12

datenwolf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!