開啟blogger寫今天的課堂作業
1.範例 jsyeh.org/3dcg10
1.1下載 data,win32 解壓縮
windows.zip > 下載\windows\Transformation.exe
data.zip > 下載\windows\data\模型.obj
1.2 執行 Transformation.exe
(右上角)右鍵換模型
2
glPushMatrix();///備份矩陣
glTranslated(x,y,0);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();///還原矩陣
#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("第02週的程式喔!");
glutDisplayFunc(display);
glutMainLoop();
}
3
mouse
#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("第02週的程式喔!");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
沒有留言:
張貼留言