1.下載[data][win32]glut32.dll
2.將[win32]解壓縮
3.將glut32.dll [data] 放入window資料夾
2.使用 ||||安培右手定則||||
說明第二條::glRotatef(旋轉角度,x軸,y軸,z軸)
EX: Y軸
旋轉角度 紅紅的是老師安培右手
負方向 安培右手向下
3.考試重點
-1 week02的圖
glTranslated(x,y,z);
glRotated(angle,x,y,z);
glScalef(x,y,z);
glBegin(GL_POLYGON);
glColor3f(r,g,b);
glVertex3f(x,y,z);
glEnd();
glPopMatrix();
4.老師的自動轉動茶壺
4.老師的自動轉動茶壺
我的轉動茶壺
#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();
printf("%.1f\n",angle);
angle++;
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("05160133_week04 transformation");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
5.老師的手動轉動茶壺
5.老師的手動轉動茶壺

我的手動茶壺
#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();
///printf("%.1f\n",angle);
///angle++;
}
void mouse(int button,int state,int x,int y)
{
}
void motion(int x,int y)
{
angle=x;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("05160133_week04 transformation");
glutMouseFunc(mouse);
glutMotionFunc(motion);
///glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
6.老師的手動轉動茶壺 完整版
我的手動茶壺 完整版
#include <stdio.h>
#include <GL/glut.h>
float angle=0,teapotX=0,teapotY=0;
int oldX=0,oldY=0,nowRotate=0;///
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();
///printf("%.1f\n",angle);
///angle++;
}
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);
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("05160133_week04 transformation");
glutMouseFunc(mouse);
glutMotionFunc(motion);
///glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}







沒有留言:
張貼留言