2020年3月25日 星期三

wendy_week04

電腦圖學 學習日誌

week4



1. 主題: Transformation
2. 主題: 旋轉


(一) Transformation





下載 → data 、 win32、glut32.dll




(二) 旋轉

基本概念 →

以安培定理作為概念
定 model頭 Y = 大拇指方向
其餘手指方向指向為旋轉方向

若要改變旋轉方向
改變大拇指的軸座標
若改為 Z
代表以Z軸做旋轉





程式(一)   用內建程式做修改做出旋轉效果


float myAngle = 0;

void Motion(int x,int y)
{
    myAngle = x;
    glutPostRedisplay();
}

⇒ 程式(二)

#include <GL/glut.h>

static int slices = 16;
static int stacks = 16;

/* GLUT callback Handlers */


float myAngle = 0;

void Motion(int x,int y)
{
    myAngle = x;
    glutPostRedisplay();
}


static void display(void)
{
    const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
    const double a = myAngle;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);

    glPushMatrix();
        glRotatef(myAngle , 0, 0, 1);
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}

⇒ 程式(三)


float myAngle = 0,oldx = 0;

void Motion(int x,int y)
{
    myAngle += (x-oldx);
    oldx =x;
    glutPostRedisplay();
}

void Mouse(int button, int state, int x, int y)
{
    oldx = x;

}


static void display(void)
{


    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);

    glPushMatrix();
        glRotatef(myAngle , 0, 0, 1);
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}

沒有留言:

張貼留言