考虑一个圆 ( − 40) 2 + ( − 40) 2 = 400。将它沿 X 轴逆时针旋转 30 度并沿 Z 轴平移 +20 个单位
Consider a circle ( − 40) 2 + ( − 40) 2 = 400. Rotate it along X- axis counter clockwise 30 degree and translate it along Z- axis for +20 units
在@Rabbid76 的帮助下,我能够绘制圆并平移和旋转它来自堆栈溢出。
但需要帮助解决问题的这两部分:
Q1 - 对该圆在 xy 平面上进行正投影。
Q2- 考虑 3 个轴 (100, 0, 0), (0, 100, 0), (0, 0, 100),向上向量作为 Z 轴(原圆),相机位置在
起源。查看点位于旋转平移圆的中心。对平移的圆点进行感知投影
这些轴构成的平面。如果相机沿 Z 轴旋转,还编写代码以获得感知投影。
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from math import *
def circle():
posx, posy = 40,40
sides = 80
radius = 20
glBegin(GL_POLYGON)
for i in range(100):
cosine= radius * cos(i*2*pi/sides) + posx
sine = radius * sin(i*2*pi/sides) + posy
glVertex2f(cosine,sine)
glEnd()
def iterate():
glViewport(0, 0, 3000, 3000)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 500, 0.0, 500, -100, 100)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
glTranslatef(0, 0, 20)
glRotatef(30, 1, 0, 0)
def showScreen():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
iterate()
glColor3f(1.0, 0.0, 3.0)
circle()
glutSwapBuffers()
glutInit()
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(400, 400)
glutInitWindowPosition(200, 200)
wind = glutCreateWindow("OpenGL Coding Practice")
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen)
glutMainLoop()
使用gluLookAt
to define the view matrix and gluPerspective
To define the Perspective projection矩阵。
透视投影定义了一个Viewing frustum。几何被平截头体的近平面和远平面裁剪。
确保几何体位于近平面和远平面之间。圆心位于 (0, 0, 0)。使用 (0, 100, 0) 的相机位置,查看圆心。你的向量是 (0, 0, 1):
def circle():
posx, posy = 0, 0
sides = 80
radius = 20
glBegin(GL_POLYGON)
for i in range(100):
cosine= radius * cos(i*2*pi/sides) + posx
sine = radius * sin(i*2*pi/sides) + posy
glVertex3f(cosine,0, sine)
glEnd()
angle = 30
def iterate():
global angle
glViewport(0, 0, 400, 400)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
#glOrtho(0.0, 500, 0.0, 500, -100, 100)
gluPerspective(60, 1, 0.1, 500)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
gluLookAt(0, 100, 0, 0, 0, 0, 0, 0, 1)
glRotatef(angle, 0, 0, 1)
angle += 0.1
在@Rabbid76 的帮助下,我能够绘制圆并平移和旋转它来自堆栈溢出。
但需要帮助解决问题的这两部分:
Q1 - 对该圆在 xy 平面上进行正投影。
Q2- 考虑 3 个轴 (100, 0, 0), (0, 100, 0), (0, 0, 100),向上向量作为 Z 轴(原圆),相机位置在 起源。查看点位于旋转平移圆的中心。对平移的圆点进行感知投影 这些轴构成的平面。如果相机沿 Z 轴旋转,还编写代码以获得感知投影。
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from math import *
def circle():
posx, posy = 40,40
sides = 80
radius = 20
glBegin(GL_POLYGON)
for i in range(100):
cosine= radius * cos(i*2*pi/sides) + posx
sine = radius * sin(i*2*pi/sides) + posy
glVertex2f(cosine,sine)
glEnd()
def iterate():
glViewport(0, 0, 3000, 3000)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 500, 0.0, 500, -100, 100)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
glTranslatef(0, 0, 20)
glRotatef(30, 1, 0, 0)
def showScreen():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
iterate()
glColor3f(1.0, 0.0, 3.0)
circle()
glutSwapBuffers()
glutInit()
glutInitDisplayMode(GLUT_RGBA)
glutInitWindowSize(400, 400)
glutInitWindowPosition(200, 200)
wind = glutCreateWindow("OpenGL Coding Practice")
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen)
glutMainLoop()
使用gluLookAt
to define the view matrix and gluPerspective
To define the Perspective projection矩阵。
透视投影定义了一个Viewing frustum。几何被平截头体的近平面和远平面裁剪。
确保几何体位于近平面和远平面之间。圆心位于 (0, 0, 0)。使用 (0, 100, 0) 的相机位置,查看圆心。你的向量是 (0, 0, 1):
def circle():
posx, posy = 0, 0
sides = 80
radius = 20
glBegin(GL_POLYGON)
for i in range(100):
cosine= radius * cos(i*2*pi/sides) + posx
sine = radius * sin(i*2*pi/sides) + posy
glVertex3f(cosine,0, sine)
glEnd()
angle = 30
def iterate():
global angle
glViewport(0, 0, 400, 400)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
#glOrtho(0.0, 500, 0.0, 500, -100, 100)
gluPerspective(60, 1, 0.1, 500)
glMatrixMode (GL_MODELVIEW)
glLoadIdentity()
gluLookAt(0, 100, 0, 0, 0, 0, 0, 0, 1)
glRotatef(angle, 0, 0, 1)
angle += 0.1