2019年3月14日 星期四

uh-oh~可恩的上課筆記 Week04


(ó﹏ò。)

第一部分:                                                                                                   觀察 glTranslate

Week3.一樣載 1.windows.zip  2. data.zip 3.glut32.dll
windows.zip解壓縮

然後開啟Transformation



看看glTranslatef原本的座標跟車子的位置


改變X軸


改變Y軸


改變Z軸




第二部分:                                                                                           
            glTranslatef(x,y,z)
                                                   

                                                            跟week1.一樣開啟GLUT




  • 示範:glTranslatef(x,y,z)改變位置



改變X.Y.Z軸↓
#include <GL/glut.h>
void display()
{
    glPushMatrix();
        glTranslated(0.3,0.3,0.3);
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("06161110_Week03!!");
    glutDisplayFunc(display);
    glutMainLoop();
}


  • 示範:glTranslatef(x,y,z)跟著滑鼠移動



#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT  |GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslated((x-150)/150.0,-(y-150)/150.0,0);
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}
void motion(int nowX,int nowY)
{
    x=nowX;y=nowY;
    display();
}

int main(int argc, char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("06161110_Week04!!");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();

}

沒有留言:

張貼留言