W04-01---移動 縮放
開啟3D圖學網址
對X軸旋轉
對Y軸旋轉
對Z軸旋轉
W04-02---對x軸旋轉,用滑鼠轉動
打開CodeBlocks 新project.glut
像DJ一樣,用mouse的rotate轉動~~
橘色是旋轉軸
W04-03---讓茶壺像MAYA一樣旋轉
#include <GL/glut.h>
float myAngle=0;///TODO:宣告角度的變數
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///TODO:清畫面
glColor3f(0.5,0.1,0.2);
glPushMatrix();
glRotatef(myAngle,0,0,1); ///TODO:對Z軸,做旋轉
glutSolidTeapot( 0.3 );
glPopMatrix();
glutSwapBuffers();
}
int oldx=0; ///(0)宣告變數
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN) oldx = x;
///(1)按下去時,要記憶在哪裏!
}
void motion(int x,int y)
{
myAngle += (x-oldx);///(2)加了多少度?
oldx = x ;///我的角度,等下要拿來用
display();///每次做動作,清畫面
}
int main(int argc, char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week04 rotate");
glutMotionFunc(motion);///TODO:加Motion函式
glutMouseFunc(mouse);
glutDisplayFunc(display);
glutMainLoop();
}
讓茶壺對Z軸旋轉
像在Maya裡,把3D模型轉動
(1)mouse按下去 (2)mouse移動 (3)放開
移動運算:新x減掉舊x值









沒有留言:
張貼留言