咕嚕靈波(●´∀`)ノ♡
現在開始↓
http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
windows、data、glut32.dll
下載完後載入變型檔,將data與glut32.dll放入windows,開啟translate執行檔,可以進行位置變換跟視角變換,也能進行大小更改,學到了glTranslatef(0,0,0);能夠改變位置。
加入
glTranslatef(0,0,0);
以變更xyz軸的位置。
加入
glPushMatrix();
glPopMatrix();
以將茶壺固定,不會像變魔術一樣再新增或改變。
glTranslatef((x-150)/150.0,(y-150)/150.0,0);
利用滑鼠小畫家功能查看座標。
((x-150)/150.0,(y-150)/150.0);
放到中心點後再除以實際像素大小(一半,這個例子是300*300
#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);//以視窗內座標決定移動位置
//glColor3f(0.8,0.6,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);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03 translate 06160095");
glutDisplayFunc(display);
glutMotionFunc(motion);//執行
glutMainLoop();
}
回家作業3:
(用三角形或四邊行蓋凸多邊形凹的地方)
glTranslatef((x-150)/150.0,(y-150)/150.0,0);
利用滑鼠小畫家功能查看座標。
((x-150)/150.0,(y-150)/150.0);
放到中心點後再除以實際像素大小(一半,這個例子是300*300
#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);//以視窗內座標決定移動位置
//glColor3f(0.8,0.6,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);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03 translate 06160095");
glutDisplayFunc(display);
glutMotionFunc(motion);//執行
glutMainLoop();
}
回家作業3:
(用三角形或四邊行蓋凸多邊形凹的地方)
結束↑
歐文是誰
回覆刪除