开发者

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);

g开发者_运维问答lPopMatrix();

glFlush();


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


You're leaving GL_PROJECTION mode active while you do this. At least if I understand what you're asking for, you want to use GL_PROJECTION while you set up your viewport (e.g., with glOrtho), but for the actual drawing, you want to work in GL_MODELVIEW mode.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜