1.1 先到 https://jsyeh.org/3dcg10/ 網站下載data、win32兩個壓縮檔
1.2 將兩者解壓縮後,把data丟入window資料夾裡
1.3 接著執行Transformation.exe檔案
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///備份矩陣
glRotatef(angle,0,0,1); ///轉180度
glColor3f(1,1,0);
glutSolidTeapot(0.3);
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("week05 Rotate");///建視窗
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
#include <GL/glut.h>
float angle=0,oldx=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///備份矩陣
glRotatef(angle,0,0,1); ///轉180度
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣
glutSwapBuffers();
}
void mouse(int buttom,int state,int x,int y)
{
oldx=x;
}
void motion(int x,int y)
{
angle+=(x-oldx);
angle=x;
display();
}
int main(int argc,char**argv)
{///進階的內函式
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 Rotate");///建視窗
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMouseFunc(mouse);
glutMainLoop();
}
2.1 複習上次的通過點擊畫面得到座標的程式,
#include <GL/glut.h>
#include <stdio.h>
int N=0;///一開始無頂點
int x[1000],y[1000];///最多可以有1000個頂點
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
for(int i=0;i<N;i++) ///用迴圈,畫N個頂點
{
glVertex2f((x[i]-150)/150.0,-(y[i]-150)/150.0);
} ///減一半,除一半,Y加上負號
glEnd();
glutSwapBuffers();
}
void mouse(int button,int state,int mouseX,int mouseY)
{
if(state==GLUT_DOWN) ///如果按下MOUSE
{
N++; ///就多一個頂點
x[N-1]=mouseX; ///最後一個新增的X座標
y[N-1]=mouseY; ///最後一個新增的Y座標
printf("現在按下滑鼠,得到新座標 %d %d\n",x[N-1],y[N-1]);
}
display();
}
int main(int argc,char**argv)
{///進階的內函式
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 複習");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
int N=0;///一開始無頂點
int x[1000],y[1000];///最多可以有1000個頂點
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
for(int i=0;i<N;i++)
{
glVertex2f((x[i]-150)/150.0,-(y[i]-150)/150.0);
}
glEnd();
glutSwapBuffers();
}
void motion(int mouseX,int mouseY)
{
N++;
x[N-1]=mouseX;
y[N-1]=mouseY;
printf("現在按下滑鼠,得到新座標 %d %d\n",x[N-1],y[N-1]);
display();
}
int main(int argc,char**argv)
{///進階的內函式
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05 複習");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言