2020年3月25日 星期三

4444444

國中右手定則與xy軸,以大姆指指向方向為軸,其餘4根手指所指方向轉動

如圖比讚之後,紅箭頭為大拇指,其餘四根手指指項方向為藍箭頭,模型往藍箭頭方向轉動。

改為滑鼠移動控制轉動

#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);
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc,char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");

    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);
        glutSolidTeapot( 0.3 );
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc,char ** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");

    glutDisplayFunc(display);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);
    glutMainLoop();
}
每一次都取代新的座標

沒有留言:

張貼留言