2019年4月25日 星期四

RenFu--06160034--week10

(1)期中考:OpenGL必背10函式
(2)複習:移動、旋轉、縮放
(3)主題: T-R-T旋轉(改變旋轉軸)
(4)主題:glut
首先我們要先到網站小葉的網站去下載三個東西
[data][win32][glut32.dll]










把data和win32解壓縮放到windows資料夾
glut32.dll也放進去
之後開啟Transformation.exe














glTranslatef   >>>(控制X,Y,Z方位 )
glRotatef  >>>(控制車的角度 )
glScalef   >>>(控制車子的長扁寬 )


對程式按右鍵可以更改物品哦!




























範例:



讓三角形轉轉轉
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(0,0.5,0);///往上移動的茶壺
        glutSolidTeapot(0.3);
    glPopMatrix();

    glPushMatrix();
        glTranslatef(0.5,0.625,0);///(3)把它掛在你要的地方
        glRotatef(angle,0,0,1);///(1)先有個轉動,但怪怪的
        glTranslatef(0.6,0,0);///(2)要更早去移動旋轉中心

        glRotatef(-90,0,1,0);///轉動90度的cone
        glutSolidCone(0.2,0.6,30,30);///直直的cone
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int x,int y)
{
    angle = x;
    display();///滑鼠motion馬上更新
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("renrenweek10");

    glutDisplayFunc(display);
    glutMotionFunc(motion);///滑鼠motion

    glutMainLoop();
}














沒有留言:

張貼留言