Week03
課堂作業
1-1進到https://jsyeh.org/3dcg10,下載data、win32
1-2將data放到windows裡面,執行Transformation.exe,試試
看換模型及調整glTranslatef
2-1 下載glut檔案,並開啟新Project
2-2 執行上星期的茶壺程式碼,並試著改變茶壺位置
2-3 變出四個茶壺
#include <GL/glut.h>
void myTeapot(float x,float y)
{
glPushMatrix();///備份矩陣(備份舊的位置)
glTranslatef(x,y,0);
glColor3f(1,1,0);///黃色
glutSolidTeapot(0.3);///茶壺
glPopMatrix();///還原矩陣(還原舊的位置)
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
myTeapot(0.5,0.5);
myTeapot(0.5,-0.5);
myTeapot(-0.5,-0.5);
myTeapot(-0.5,0.5);
glutSwapBuffers();
}
int main (int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03_移動");
glutDisplayFunc(display);
glutMainLoop();
}
3-1 建立一個新專案,讓茶壺能跟著滑鼠移動
#include <GL/glut.h>
float mouseX=0,mouseY=0;
void myTeapot(float x,float y)
{
glPushMatrix();///備份矩陣(備份舊的位置)
glTranslatef(x,y,0);
glColor3f(1,1,0);///黃色
glutSolidTeapot(0.3);///茶壺
glPopMatrix();///還原矩陣(還原舊的位置)
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
myTeapot((mouseX-150)/150.0,-(mouseY-150)/150.0);
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
mouseX=x; mouseY=y;
}
int main (int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03_移動");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
3-2 在建立一個新專案(week03_mouse_help_hw2)
#include <GL/glut.h>
#include <stdio.h>
float mouseX=0,mouseY=0;
void myTeapot(float x,float y)
{
glPushMatrix();///備份矩陣(備份舊的位置)
glTranslatef(x,y,0);
glColor3f(1,1,0);///黃色
glutSolidTeapot(0.1);///茶壺
glPopMatrix();///還原矩陣(還原舊的位置)
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
myTeapot((mouseX-150)/150.0,-(mouseY-150)/150.0);
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
printf("%d %d %d %d\n",button,state,x,y);
mouseX=x; mouseY=y;
}
int main (int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week03_移動");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
沒有留言:
張貼留言