2020年3月25日 星期三

時間


( 1 )
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/

or google: jsyeh.org.3dcg10  copy from the first web.

( 2 )

download:
glut32.dll
data.zip
windows.

( 3 )
data and glut32.dll -- windows

open Transformation.


( 4 )
右手大拇指定則






用滑鼠旋轉



float myAngle=0;
void motion(int x,int y)
{
    myAngle=x;
    glutPostRedisplay();
}



int main()
{
    glutMotionFunc(motion);// 加進main函式中
}



teapot rotate.



#include <GL/glut.h>

float myAngle=0;
void motion(int x,int y)
{
    myAngle=x;
    glutPostRedisplay();
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(myAngle,0,0,1);
        glutWireTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}

int main(int argc,char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week 02 CCE");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMainLoop();
}



讓他轉順一點


#include <GL/glut.h>

float myAngle=0,oldx=0;
void motion(int x,int y)
{
    myAngle+=(x-oldx);
    oldx=x;
    glutPostRedisplay();
}

void mouse(int button,int state,int x,int y)
{
    oldx=x;
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glRotatef(myAngle,0,0,1);
        glutWireTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}

int main(int argc,char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week 02 CCE");
    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutMainLoop();
}

沒有留言:

張貼留言