2020年3月24日 星期二

Week04

Transformation












  1. http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
  2. 下載1. data 2. win32 3. glut.dll
  3. Rotate 控制旋轉,根據安培右手方向
Rotate











1. main函式加入glutMotionFunc(motion)//加了mouse motion函式,可捕捉mouse動態
2. 新增motion函式void motion(int x,int y)//mouse motion現在動到哪了
                               {
                                         myAngle=x;//我的角度,就是x的值
                                }
3.float myAngle=0;//宣告變數
4.在display函式更改const double a = myAngle//把角度塞進去//*t*90.0;

Roate Teapot
程式碼:
#include <GL/glut.h>
float myAngle=0;//宣告我的角度變數
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);//清畫面
    glPushMatrix();
        glRotatef(myAngle,0,0,1);//對Z軸做旋轉
        glutWireTeapot(0.5);
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    myAngle = x;//我的角度,等下要拿來用
    display();//每次做動作,就重畫畫面
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week 04 Rotate");

    glutMotionFunc(motion);//加Motion函式
    glutDisplayFunc(display);
    glutMainLoop();
}

Rotate Teapot_MAYA

程式碼:
#include <GL/glut.h>
float myAngle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(myAngle,0,0,1);
        glutWireTeapot(0.5);
    glPopMatrix();
    glutSwapBuffers();
}
int oldx=0;//宣告變數
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN) oldx = x;//按下去時,要記一下你在哪裡!!!
}
void motion(int x,int y)
{
    myAngle += (x-oldx);//加了多少度
    oldx = x;
    display();
}
//Q:如何在MAYA轉動3D模型 (1) 按下Mouse (2) Mouse動 (3)把Mouse放開
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week 04 Rotate");

    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutDisplayFunc(display);
    glutMainLoop();
}

沒有留言:

張貼留言