電腦圖學
(1)期中考:OpenGL必背10函式
(2)複習:移動、旋轉、縮放
準備動作:
TODO:首先先到http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 這個網站
下載:windows.zip解壓縮並下載\windows\Texture.exe
data.zip 解壓縮並下載\windows\data\圖檔
glut32.dll 下載\windows\glut32.dll(3)主題:T-R-T旋轉(改變旋轉軸)
Transformation.exe 自轉vs.公轉
讓三角形能隨著滑鼠動
程式碼如下:
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,0.5,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPushMatrix();
glPopMatrix();
///glutSolidSphere(0.3,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(0.5,0.625,0);
glRotatef(angle,0,0,1);
glTranslatef(0.6,0,0);
glRotatef(-90,0,1,0);
glutSolidCone(0.2,0.6,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(-90,0.1,0);
glutSolidCone(0.2,0.6,30,30);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
angle=x;
display();
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week10");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
程式碼如下:
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,0.5,0);
glutSolidTeapot(0.3);
glPopMatrix();
glPushMatrix();
glPopMatrix();
///glutSolidSphere(0.3,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(0.5,0.625,0);
glRotatef(angle,0,0,1);
glTranslatef(0.6,0,0);
glRotatef(-90,0,1,0);
glutSolidCone(0.2,0.6,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(-90,0.1,0);
glutSolidCone(0.2,0.6,30,30);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
angle=x;
display();
}
int main(int argc,char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week10");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
圖片如下
沒有留言:
張貼留言