2016年3月21日 星期一

Week05 曾容嫻3/21課堂作業

(1)
 到 jsyeh.org/3dcg10
下載data win32 glut32.dll
開啟Transformation
案右鍵Swap Translate/Rotate

以車子為中心點旋轉

車子以一個中心點繞著它旋轉

(2)
#include <GL/glut.h>
float rotX=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();//備份Matrix (Matrix裡有 translate,rotate,scale的量值)
    glRotatef(rotX,0,1,0);
    glColor3f(1,0,0);
    glutSolidTeapot(0.3);
    glPopMatrix();//還原Matrix (回到剛剛push時的樣子)
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x;
    display();//glutPostRedisplay();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//double buffers兩倍記憶體
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

(3)
#include <GL/glut.h>
float rotX=0, rotY=0;
void display()
{
    glClearColor(1,1,1,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();//備份Matrix (Matrix裡有 translate,rotate,scale的量值)
    glRotatef(rotY,1,0,0);//Y的移動量,讓它對x軸轉
    glRotatef(rotX,0,1,0);//X的移動量,讓它對Y軸轉
    glColor3f(1,0,0);
    glutSolidTeapot(0.3);
    glPopMatrix();//還原Matrix (回到剛剛push時的樣子)
    glutSwapBuffers();
}
void motion(int x,int y)
{
    rotX=x; rotY=y;//同時拿來用
    display();//glutPostRedisplay();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);//double buffers兩倍記憶體
    glutInitWindowSize(300,300);glutInitWindowPosition(600,0);
    glutCreateWindow("hello3D");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}








沒有留言:

張貼留言