進入http://jsyeh.org/3dcg10
下載 win32 , data , glut32.dll
解壓縮 windows → 開啟 data , 拖曳 data資料夾和 glut32.dll 到 windows 資料夾
→開啟 Transformation.exe
2.
#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion (int x, int y)///mouse motion 拖著移動時,會叫 motion()
{
angle = x;///老師用上周較差的方法,直接把 mouse 座標,變轉動角度
glutPostRedisplay();///請畫面重畫
}
void display()///畫面要 display 時呼叫這個函式
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///先清畫面
glPushMatrix();///備份矩陣(乾淨的矩陣)
glRotatef(angle, 0,0,1);///rotate/translate/scale都會把矩陣改變
glTranslatef(0.45, -0.08, 0);///移動,讓茶壺的柄,放到畫面的中心
glutSolidTeapot(0.3);///TODO: 請試著把茶壺的柄,放到畫面的中心
glPopMatrix();///還原矩陣(乾淨的矩陣)
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion (int x, int y)///mouse motion 拖著移動時,會叫 motion()
{
angle = x;///老師用上周較差的方法,直接把 mouse 座標,變轉動角度
glutPostRedisplay();///請畫面重畫
}
void display()///畫面要 display 時呼叫這個函式
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///先清畫面
glPushMatrix();///備份矩陣(乾淨的矩陣)
glutSolidTeapot(0.3);///放在中間
glTranslatef(0.5, 0.15, 0);///把會旋轉的茶壺柄,放到右上角
glRotatef(angle, 0,0,1);///把整個對畫面中心做旋轉
glTranslatef(0.45, -0.08, 0);///移動,讓茶壺的柄,放到畫面的中心
glutSolidTeapot(0.3);///TODO: 請試著把茶壺的柄,放到畫面的中心
glPopMatrix();///還原矩陣(乾淨的矩陣)
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
#include <GL/glut.h>
float angle=0;///旋轉的角度
void motion (int x, int y)///mouse motion 拖著移動時,會叫 motion()
{
angle = x;///老師用上周較差的方法,直接把 mouse 座標,變轉動角度
glutPostRedisplay();///請畫面重畫
}
void display()///畫面要 display 時呼叫這個函式
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///先清畫面
glPushMatrix();///備份矩陣(乾淨的矩陣)
glutSolidTeapot(0.3);///放在中間
glPushMatrix();
glTranslatef(0.5, 0.15, 0);///把會旋轉的茶壺柄,放到右上角
glRotatef(angle, 0,0,1);///把整個對畫面中心做旋轉
glTranslatef(0.45, -0.08, 0);///移動,讓茶壺的柄,放到畫面的中心
glutSolidTeapot(0.3);///TODO: 請試著把茶壺的柄,放到畫面的中心
glPushMatrix();///備份矩陣(乾淨的矩陣)
glutSolidTeapot(0.3);///放在中間
glTranslatef(0.5, 0.15, 0);///把會旋轉的茶壺柄,放到右上角
glRotatef(angle, 0,0,1);///把整個對畫面中心做旋轉
glTranslatef(0.45, -0.08, 0);///移動,讓茶壺的柄,放到畫面的中心
glutSolidTeapot(0.3);///TODO: 請試著把茶壺的柄,放到畫面的中心
glPopMatrix();
glPopMatrix();
glPopMatrix();///還原矩陣(乾淨的矩陣)
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 TRT");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}






沒有留言:
張貼留言