2023年3月2日 星期四

Toto Week03

 week03

step01-1

到https://jsyeh.org/3dcg10,下載windows.zip and data.zip

        -windows.zip 解壓縮 下載 \windows\Transformation.exe

        -data.zip         解壓縮 下載\windows\data\有3D模型



開始執行

step02-1
CodeBlocks-File_New_Project,GLUT專案,檔名為week03-1_translate
打開上禮拜的Blog利用上次寫的(茶壺)程式,把它複製上去

#include <GL/glut.h>
void display()
{
    glutSolidTeapot(0.3);
    glutSwapBuffers();
}

int main(int argc,char* argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week03");

    glutDisplayFunc(display);

    glutMainLoop();
}
step02-2

用GitHub Gist功能,新增程式,會照著副檔名來變色。使用Embedded JaveScript的方式,便可把那一橫程式,用HTML模式,插入Blog裡
‵‵‵‵html
<script
src="https://gist.github.com/zhierchen0621/3dd3a4f201a5fb72ca52854e0f5c9390"></script>

step02-3

新增程式碼
#include <GL/glut.h>
void display()
{
    glPushMatrix();
        glTranslatef(0.5,0.5,0);
        glutSolidTeapot(0.3);
    glPopMatrix();

    glutSwapBuffers();
}

int main(int argc,char* argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week03");

    glutDisplayFunc(display);

    glutMainLoop();
}

CodeBlocks新增新的專案New-Project-week03-2_translate_mouse
撰寫程式,利用滑鼠可以移動茶壺
#include <GL/glut.h>
float X=0,Y=0,Z=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(X,Y,Z);
        glutSolidTeapot(0.3);
    glPopMatrix();

    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
    X = (x-150)/150.0;
    Y = (y-150)/150.0;
}
int main(int argc,char* argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week03");

    glutMouseFunc(mouse);
    glutDisplayFunc(display);

    glutMainLoop();
}
step03-1CodeBlocks新增專案New-Profect-week03-3_mouse_homework
利用滑鼠寫程式
#include <GL/glut.h>
#include <stdio.h>
float X=0,Y=0,Z=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
    X = (x-150)/150.0;
    Y = (y-150)/150.0;
    if(state==GLUT_DOWN)printf("    glVertex2f(%.2f,%.2f);\n",X,Y);
}
int main(int argc,char* argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week03");

    glutMouseFunc(mouse);
    glutDisplayFunc(display);

    glutMainLoop();
}




















沒有留言:

張貼留言