1.下載jsyeh.org/3dcg10
執行Transformation.exe並測試函式的功能
2.移動Translate
開codeblock跟freeglut
測試茶壺
執行translate函式
將拖曳函式(功能)加入Translate
滑鼠拖曳座標的換算
3.縮放 Scale
4.旋轉Rotate
#include <GL/glut.h>
float mouseX=0, mouseY=0, rotX=0;///宣告
void display()
{
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);///清畫面
glPushMatrix();///備份
glRotatef(rotX, 0,1,1);///旋轉
///glScalef(mouseX,mouseY,0);///改縮放
///glTranslatef(mouseX,mouseY,0);///改位置
glutSolidTeapot(0.3);
glPopMatrix();///還原
glutSwapBuffers();
}
void motion(int x, int y)
{
mouseX = (x-150)/150.0;
mouseY = -(y-150)/150.0;
rotX = x;
glutPostRedisplay();///告訴電腦重畫畫面
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04163074 translate rotate scale");
glutDisplayFunc(display);
glutMotionFunc(motion);///drag
glutMainLoop();
}
沒有留言:
張貼留言