本文介绍了真正的等距投影与opengl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是使用C ++的OpenGL编程的新手,而不是很好的数学。有一个简单的方法来等距投影吗?
我的意思是真正的等距投影
(等距投影仅在单位X,Y和Z向量的投影长度相等且它们之间的角度为
解决方案
尝试使用 gluLookAt
glClearColor(0.0,0.0,0.0,1.0); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); / *使用这个长度,以便摄像机离原点1个单位* / double dist = sqrt(1 / 3.0); gluLookAt(dist,dist,dist,/ * camera的相对位置* / 0.0,0.0,0.0,/ *相机指向* / 0.0,1.0, 0.0); / *哪个方向向上* / glMatrixMode(GL_MODELVIEW); glBegin(GL_LINES); glColor3d(1.0,0.0,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(1.0,0.0,0.0); glColor3d(0.0,1.0,0.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,1.0,0.0); glColor3d(0.0,0.0,1.0); glVertex3d(0.0,0.0,0.0); glVertex3d(0.0,0.0,1.0); glEnd(); glFlush();结果
我们可以绘制一个立方体来检查并行线确实是并行
glPushMatrix glTranslated(0.5,0.5,0.5); glColor3d(0.5,0.5,0.5); glutWireCube(1); glPopMatrix(); 202.pngalt =alt text>I am a newbie in OpenGL programming with C++ and not very good at mathematics. Is there a simple way to have isometric projection?
I mean the true isometric projection, not the general orthogonal projection.
(Isometric projection happens only when projections of unit X, Y and Z vectors are equally long and angles between them are exactly 120 degrees.)
Code snippets are highly appreciated..
解决方案Try using gluLookAt
glClearColor(0.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* use this length so that camera is 1 unit away from origin */ double dist = sqrt(1 / 3.0); gluLookAt(dist, dist, dist, /* position of camera */ 0.0, 0.0, 0.0, /* where camera is pointing at */ 0.0, 1.0, 0.0); /* which direction is up */ glMatrixMode(GL_MODELVIEW); glBegin(GL_LINES); glColor3d(1.0, 0.0, 0.0); glVertex3d(0.0, 0.0, 0.0); glVertex3d(1.0, 0.0, 0.0); glColor3d(0.0, 1.0, 0.0); glVertex3d(0.0, 0.0, 0.0); glVertex3d(0.0, 1.0, 0.0); glColor3d(0.0, 0.0, 1.0); glVertex3d(0.0, 0.0, 0.0); glVertex3d(0.0, 0.0, 1.0); glEnd(); glFlush();Results in
We can draw a cube to check that parallel lines are indeed parallel
glPushMatrix(); glTranslated(0.5, 0.5, 0.5); glColor3d(0.5, 0.5, 0.5); glutWireCube(1); glPopMatrix();更多推荐
真正的等距投影与opengl
发布评论