本文介绍了真正的等距投影与opengl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用C ++的OpenGL编程的新手,而不是很好的数学。有一个简单的方法来等距投影吗?



我的意思是

  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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 05:44