2023年3月15日 星期三

binhun-week05

  https://jsyeh.org/3dcg10/下載

將data放進window中,打開transformation出現可以轉動的汽車

分別是移動,旋轉,大小

朝著中心點轉
glRotatef(0.0,0.00,1.00,1.00)
glTranslatef(0.00,0.00,0.00)


車子本體旋轉
glTranslatef(0.00,0.00,0.00)
glRotatef(0.0,0.00,1.00,1.00)

#include <GL/glut.h>
float angle = 0; ///宣告global全域變數angle
void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); ///清背景

    glColor3f(0,1,0); ///綠色的
    glPushMatrix(); 
        glTranslatef(0.8,0,0); ///最後是綠色的移動
        glRotatef(angle,0,0,1); ///改對Z軸轉
        glutSolidTeapot(0.3);
    glPopMatrix(); ///還原矩陣

    glColor3f(1,0,0);///紅色的
    glPushMatrix();
        glRotatef(angle,0,0,1);  ///改對Z軸轉
        glTranslatef(0.8,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix(); ///還原矩陣
glutSwapBuffers();
angle++; ///把角度++
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");

glutDisplayFunc(display);
    glutIdleFunc(display); ///有空idle時,就重畫畫面
glutMainLoop();
}

開啟範例製作出手會轉的假人
用CodeBlocks畫出來

#include <GL/glut.h>
float angle =0;
void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glColor3f(0,1,0);
    glPushMatrix();
    glutSolidCube(0.5);

    glPushMatrix();
    glTranslatef(0.25,0.25,0); 
    glRotatef(angle,0,0,1);
    glTranslatef(0.25,0.25,0)
     ///glTranslatef(0.5,0.5,0);
    glColor3f(1,0,0);
    glutSolidCube(0.5);
    glPopMatrix();
    glPopMatrix();

    glutSwapBuffers();
    angle++;
}
int main(int argc, char* argv[] )
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week03");

    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutMainLoop();
}


沒有留言:

張貼留言