2016年3月15日 星期二

Week 04 柯君翰

1.課堂作業--互評





2.課堂作業
網址:http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/
載win32 & data & glut32.dII
解壓縮
data & glut32.dII 放入 win32


3.課堂作業(3)
mouse移動(單一方向)
開GULT檔

#include <GL/glut.h>
void display()
{
    glClearColor(1,1,0,1);
    glClear(GL_COLOR_BUFFER_BIT);

    glTranslatef(0.1,0,0);
    glColor3b(1,0,0);
    glutSolidTeapot(0.3);

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

    glutDisplayFunc(display);

    glutMainLoop();
}

4.課堂作業
mouse點哪移動倒哪


#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);
    glColor3b(1,0,0);
    glutSolidTeapot(0.3);
    glPopMatrix();
    glutSwapBuffers();
}
int main(int argc,char**argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Hello3D");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);

    glutMainLoop();
}

5.課堂作業
做"圓"
滑鼠點到哪 圓就移到哪


#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);
    glColor3b(0,0,0);

    glBegin(GL_POLYGON);
        for(float angle=0;angle<3.14159265358979*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("Hello3D");

    glutDisplayFunc(display);
    glutMouseFunc(mouse);

    glutMainLoop();
}





沒有留言:

張貼留言