2016年3月15日 星期二

WEEK 04 顏士傑

W04
Class 1
作業互評

選出五個自己覺得中意的作品
 
 


TIPS à(1)7-zip解壓縮

--------------------------------------------------------------------------------------------------
Class2


STEP 1
請先下載課堂教材(jsyeh/3dcg10/  ) data.zip , windows.zip , glut32.dll
à  (1)理解上方右鍵可換Model
        (2)下方綠字可drag
        (3)下方右鍵可reset

<關於介面選項>
glTranslatef(x,y,z);
glRotatef(角度,x,y,z);
glScalef(x,y,z);


Class3
(1)程式設計實作


#include <GL/glut.h>

void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);

    glTranslatef(0, -0.1, 0); >>>>>>>>這是未定位狀態,會隨著移動CMD發生位置Y軸往下移動0.1
    glColor3f(1,0,0);
    glutSolidTeapot(0.3);


    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hello");

    glutDisplayFunc(display);


    glutMainLoop();
}




(2)程式展示 : 用滑鼠在視窗內點擊,可移動茶壺


#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,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(nowX, nowY, 0);
        glColor3f(1,0,0);
        glutSolidTeapot(0.3);
    glPopMatrix()

    glutSwapBuffers();
}
int main(int argc, char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("Hello");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);

    glutMainLoop();
}


glPushMatrixà備份Matrix

glPopMatrixà還原Matrix



Class4





如何畫出圓形?

>>利用三角函數建立座標


#include <GL/glut.h>
#include <stdio.h>
#include <math.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;
    printf("glTranslatef(%f,%f, 0);\n", nowX, nowY);
}

void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glTranslatef(nowX,nowY,0);
    glColor3f(1,0,0);
    ///glutSolidTeapot(0.3);
    glBegin(GL_POLYGON);
        for(float angle=0; angle<3.14159235358979*2; angle+=0.1){
            glVertex2f(0.2*cos(angle), 0.2*sin(angle));
        }
    glEnd();
    glPopMatrix();
    glutSwapBuffers();
}

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








EXTRA


可隨鼠標移動的黑圓與倒數警示



沒有留言:

張貼留言