下載[data]、[windows]、[glut32.dll]檔案
解壓縮後將glut32.dll及data拉到windows裡面,再開啟Transformation
2.
(1) glTranslatef(x,y,z) 移動位置
(2) glRotate(旋轉角度,x,y,z) 旋轉(3) glScale(x,y,z) 大小縮放
3.使用上次茶壺檔案來做增加程式碼
#include <stdio.h>
#include <GL/glut.h>
float teapotX=0,teapotY=0,angle=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();
}
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("Week05 Mouse_Rotate");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言