2018年3月25日 星期日

Week04 來福的汪汪圖學週記

開模型觀察旋轉方向
(滑鼠要按照他的軸向拉才能調整)
轉旋轉軸
 
 
glRotatef(轉幾度, X軸,Y軸,Z軸)
旋轉方向看右手定則 ( 拇指是軸向  四指轉向 )

 
 


旋轉茶壺的程式
 
 
 
#include <stdio.h>
#include <GL/glut.h>
float angle=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glRotatef(angle,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
    printf("%.1f\n",angle);
    angle++;///角度增加
}

int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week04 旋轉");

    glutIdleFunc(display);///重新畫
    glutDisplayFunc(display);
    glutMainLoop();///重複反覆
} 
 
 
手拉旋轉茶壺>>4-1
 
 
新增mouse跟motion函式
(轉更順)
 
void mouse(int but,int state,int x,int y)
{
    if(but==GLUT_LEFT_BUTTON&&state==GLUT_DOWN)
        nowRotate=1;
    if(but==GLUT_RIGHT_BUTTON&&state==GLUT_DOWN)n
        oldRotate=0;
    oldX=x;
  oldY=y;
}



void motion(int x,int y)

{
    if(nowRotate==1)
    angle+=(x-oldX);
    else
    {
        teapotX += (x-oldX)/150.0;
        teapotY += (oldY-y)/150.0;
    }
    oldX=x;
  oldY=y;
    glutPostRedisplay();
}
 

沒有留言:

張貼留言