2019年3月15日 星期五

喬巴的失控道具日 Weekfour

旋轉

























茶壺跟著滑鼠
















#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);///啟動GLUT
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04");
    glutDisplayFunc(display);

    glutMotionFunc(motion);///現在重點在滑鼠
    glutMainLoop();
}

移動變旋轉















在void display(){}中加
glRotatef( y, 1,0,0);

這是在 中四個點任意選一個點作變異數
就可以用滑鼠控制旋轉

void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣,保護好
        glRotatef( y, 1,0,0);
        ///glTranslatef( (x-150)/150.0 , -(y-150)/150.0 , 0 );
        glutSolidTeapot( 0.3 );
    glPopMatrix();///還原復原,恢復

    glutSwapBuffers();
}

沒有留言:

張貼留言