week04
作業一
1.到下面這個網站 jsyeh/3dcg10 下載[data] [win32] [gult32.dll] 壓縮檔並解壓縮到桌面。
將windows的zip檔解壓縮,再將data壓縮檔裡的資料夾和glut32.dll拉到windows資料夾裡,即可開啟Transformation
作業二
1.開啟上週(Week03)所學到的OpenGL程式及GLUT程式碼之執行檔。
#include <GL/glut.h>
#include <math.h>
float mouth=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0,0);
for(float angle=0+mouth; angle <= 3.1415926 *2-mouth; angle+=0.01)
{
glVertex2f( cos(angle), sin(angle));
}
glEnd();
glutSwapBuffers();
}
void motion(int x, int y)
{
mouth = x/300.0;
glutPostRedisplay();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160250 Translat Rotate Scale");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
#include <math.h>
float mouth=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0,0);
for(float angle=0+mouth; angle <= 3.1415926 *2-mouth; angle+=0.01)
{
glVertex2f( cos(angle), sin(angle));
}
glEnd();
glutSwapBuffers();
}
void motion(int x, int y)
{
mouth = x/300.0;
glutPostRedisplay();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160250 Translat Rotate Scale");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
作業三
#include <GL/glut.h>
float mouseX=0, mouseY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(mouseX, mouseY, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
mouseX = (x-150)/150.0;
mouseY= -(y-150)/150.0;
glutPostRedisplay();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160250 Translat Rotate Scale");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
此段程式碼是為了讓茶壺能夠透過滑鼠移動
#include <GL/glut.h>
float mouseX=0, mouseY=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glScale(mouseX, mouseY, 0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x, int y)
{
mouseX = (x-150)/150.0;
mouseY= -(y-150)/150.0;
glutPostRedisplay();
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("04160250 Translat Rotate Scale");
glutDisplayFunc(display);
///glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
此段程式碼是為了讓茶壺能夠變形
沒有留言:
張貼留言