2016年3月15日 星期二

WEEK04

WEEK04

Homework 2 
網址:jsyeh/3dcg10/
下載[data][win32][glut32.dill]
開啟Transformation
#include <GL/glut.h>
void display()
{
    glClearColor(1,1,0,0); //改背景顏色
    glClear(GL_COLOR_BUFFER_BIT); //清背景
    glTranslatef(0.01,0,0);//移動茶壺
    glColor3f(0,0,1);//改變顏色,3 指有3個數字,f 是符點數
    glutSolidTeapot(0.3);
    glutSwapBuffers();

}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello 3D");
    glutDisplayFunc(display);
    glutMainLoop();

}
滑鼠點擊使茶壺移動
#include <GL/glut.h>
float nowX=0, nowY=0;
void mouse(int button, int state, int x, int y)
{
    nowX = (x-150)/150.0; nowY = -(y-150)/150.0;
}

void display()
{
    glClearColor(1,1,0,0); ///改背景顏色
    glClear(GL_COLOR_BUFFER_BIT); ///清背景

    glPushMatrix();///備份Matrix
        glTranslatef(nowX, nowY, 0);///移動
        glColor3f(0,0,1);///改變顏色,3 指有3個數字,f 是符點數
        glutSolidTeapot(0.3);
    glPopMatrix();///還原Matrix

    glutSwapBuffers();

}
int main(int argc,char**argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("hello 3D");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();

}

沒有留言:

張貼留言