今日天氣晴3/15WEEK04
主題:Rotate 旋轉
1.至https://jsyeh.org/3dcg10
下載data.zip windows.zip
2.windows.zip =解壓=> 下載\windows\Transformation.exe
data.zip =解壓=>下載\windows\data\模型.org
Rotate 第一個值為轉多少,第二個值為X軸,第三個值為Y軸,第四個值為Z軸
旋轉動作1:
旋轉動作2:
旋轉動作3
4.去CodeBlocks開一個新專案,可以看到旋轉的茶壺
void motion(int x,int y)
{
angle = x;
display();
}
glutMotionFunc(motion);
可以透過滑鼠來操控茶壺的角度,如下圖:
6.讓圖案透過滑鼠的拖曳上下來轉動角度~
#include <GL/glut.h>
float angle=0,oldx=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void motion(int x,int y)
{
angle += (x-oldx);
oldx=x;
display();
}
void mouse(int button,int state,int x,int y)
{
oldx=x;
}
int main(int argc, char *argv[])//main()主函式 進階版
{
glutInit(&argc,argv);//把參數送給glutInit初始化
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//雙緩衝區+3D深度功能
glutCreateWindow("第04週的程式喔!!");//開GLUT視窗
glutDisplayFunc(display);//顯示用的函式
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言