2019年3月14日 星期四

瞎78打-3

( 1 ) 主題: 移動
( 2 ) 示範: glTranslatef ( x , y , z )
 到網址:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

             下載: windows.zip
                             data.zip
                             glut32.dll

網址:https://www.transmissionzero.co.uk/software/freeglut-devel/

下載:Download freeglut 3.0.0 for MinGW 

  用座標移動水壺的程式碼:

出來的效果:












 #include <GL/glut.h>                 
 void display()
{
    glPushMatrix();
        glTranslatef(0.1,0.1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);
    glutMainLoop();
}

滑鼠脫意移動水壺:


#include <GL/glut.h>
float x=0,y=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef((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("week04");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}

沒有留言:

張貼留言