我有一个圆柱体,我想用Y=Y*cos(t+Y)定律来制作坐标Y的动画。我怎样才能使它只与OpenGL?我应该使用什么功能?也许有一些例子?你知道吗
def init():
global xrot
global yrot
global ambient
global cylcolor
global lightpos
xrot = 0.0
yrot = 0.0
ambient = (1.0, 1.0, 1.0, 1)
cylcolor = (0, 0, 1, 0.8)
lightpos = (2.0, 2.0, 0)
glClearColor(0.5, 0.5, 0.5, 1.0)
gluOrtho2D(-1.0, 1.0, -1.0, 1.0)
glRotatef(-90, 1.0, 0.0, 0.0)
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glLightfv(GL_LIGHT0, GL_POSITION, lightpos)
def draw():
global xrot
global yrot
global lightpos
global greencolor
global cylcolor
glClear(GL_COLOR_BUFFER_BIT)
glPushMatrix()
glRotatef(xrot, 1.0, 0.0, 0.0)
glRotatef(yrot, 0.0, 1.0, 0.0)
glLightfv(GL_LIGHT0, GL_POSITION, lightpos)
glMaterialfv(GL_FRONT, GL_DIFFUSE, cylcolor)
glTranslatef(0.0, 0.0, -0.7)
glutSolidCylinder(0.5, 1, 20, 20)
glPopMatrix()
glutSwapBuffers()
然后是程序的主要部分
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
glutInitWindowSize(300, 300)
glutInitWindowPosition(50, 50)
glutInit(sys.argv)
glutDisplayFunc(draw)
init()
glutMainLoop()
注意,由
glBegin
/glEnd
序列和固定函数管道矩阵堆栈绘制的方法几十年来一直被弃用。 阅读Fixed Function Pipeline,并查看Vertex Specification和Shader,了解最先进的渲染方式。你知道吗无论如何,您必须调用^{} ,才能连续重新显示窗口。} 获取调用} 执行。你知道吗
使用^{
glutInit
后的毫秒数。翻译可以由^{
此外,我建议设置一个深度缓冲区(关注
GLUT_DEPTH
):并启用depth test。也不要忘记清除深度缓冲区:
将以下行添加到代码中,以便沿视口的y轴执行上下移动:
我使用应用于原始代码的更改创建了以下动画,并更改了以下参数:
相关问题 更多 >
编程相关推荐