真正的等距投影与opengl

编程入门 行业动态 更新时间:2024-10-10 04:27:33
本文介绍了真正的等距投影与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

本文发布于:2023-05-28 00:48:55,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:opengl

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!