
下載glut32.dll

下載data.zip

下載windows.zip


glRotatef(角度,x軸,y軸,z軸)


期 中 考

#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣
glRotatef(angle, 0, 0, 1);///旋轉
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣
glutSwapBuffers();
angle++;///角度+1度
}
int main(int argc, char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week04 transformation");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}

#include <stdio.h>
#include <GL/glut.h>
float angle=0, teapotX=0, teapotY=0;///加上移動的座標
int oldX=0, oldY=0, nowRotate=0; ///0: translate, 1:rotate
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();///備份矩陣
glTranslatef(teapotX, teapotY, 0);///把茶壺再移動
glRotatef(angle, 0, 0, 1);///旋轉
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
if(button==GLUT_LEFT_BUTTON && state==GLUT_DOWN) nowRotate=1;///是左鍵就旋轉
if(button==GLUT_RIGHT_BUTTON&& state==GLUT_DOWN) nowRotate=0;///是右鍵就移動
oldX=x; oldY=y;
}
void motion(int x, int y)
{
if(nowRotate==1) angle += (x-oldX);///改變angle值
else{
teapotX += (x-oldX)/150.0;
teapotY += (oldY-y)/150.0;
}
oldX=x; oldY=y;
glutPostRedisplay();
}
int main(int argc, char*argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Week04 transformation");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言