2022年3月8日 星期二

電腦圖學筆記_week03

 Transformation

  1. 至https://jsyeh.org/3dcg10 下載data , win32
  2. windows.zip解壓縮 >> windows / transformation.exe
  3. data.zip解壓縮 >> windows / data / 模型obj
  4. 把data檔案放進windows >> 執行transformation.exe
=========================================================================

茶壺

moodle下載freeglut.zip >> 解壓縮至桌面 >> freeglut資料夾 >> lib >> 將libfreeglut.a複製貼上 >> 重新命名libglut32.a (此步驟才能讓codeblocks跑) 

codeblocks 17.12 >> file >> new >> project >>選GLUT >> 存桌面 >> next >> 設定GULT目錄(如圖) >> 跑程式
將程式碼都刪掉 >> 
#include <GL/glut.h>
void display()
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glColor3f(1,1,0);
        glutSolidTeapot(0.3);
        glutSwapBuffers();

}
int main(int argc,char** argv){
    glutInit( &argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("第2週的程式");
    glutDisplayFunc(display);
    glutMainLoop();
}

拿上面的程式碼改
#include <GL/glut.h>
void display()
{
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glPushMatrix();
        glTranslatef(0.5,0.5,0);
        glColor3f(1,1,0);
        glutSolidTeapot(0.3);
        glPushMatrix();
        glutSwapBuffers();

}
int main(int argc,char** argv){
    glutInit( &argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week03 移動");
    glutDisplayFunc(display);
    glutMainLoop();
}

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

=======================================================================
用滑鼠動茶壺
#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();
}

=======================================================================
有顯示數據的用滑鼠動茶壺
#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...