2022年3月8日 星期二

電腦圖學課堂筆記week03

1.連結http://jsyeh.org/3dcg10/

2.下載data.zip和win32.zip

3.windows.zip ->Transformation.exe

4.data.zip->模型.obj

5.執行Transformation.exe

右鍵更換模型

拖曳滑鼠改變數值

移動

#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("week03");

    glutDisplayFunc(display);

    glutMainLoop();

}



Mouse1

#include<GL/glut.h>
float mouseX=0, mouseY=0;
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((mouseX-150)/150.0, -(mouseY-150)/150.0);
    glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
    mouseX=x;
    mouseY=y;
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week03");
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMainLoop();
}

Mouse2

#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("week03");

    glutDisplayFunc(display);

    glutMouseFunc(mouse);

    glutMainLoop();

}

沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...