顯示具有 09160854_倪大為 標籤的文章。 顯示所有文章
顯示具有 09160854_倪大為 標籤的文章。 顯示所有文章

2022年6月7日 星期二

為哥的圖學筆記week16

 step01-1

alpha內插公式: alpha: 0.0~1.0

angle = alpha*新 + (1-alpha)*舊

ex:

    alpha:  0 =>  舊

    alpha:  0.5 =>  半新半舊

    alpha:  1 =>  新

可以使用 Excel or Google Spreadsheet 來做練習


step01-2

用程式試試看

step02-2

利用課本的範例講解glutLookAt

step03-1

創一個新專案week16_camera_projection_glutLookAt

2022年5月31日 星期二

為哥的圖學筆記week15

 Step01-1

要播出聲音要先設定
Setting=>Compiler=>Linker settings=>winmm


Step02-1





Step02-2

copy上週程式碼week14_angles_fprintf_fscanf



修改存檔方式

Step03-1

機器人擺動做

改file.txt的工作執行目錄:
用notepad++打開專案裡最長的檔案,更改working_dir


2022年5月24日 星期二

為哥的圖學筆記week14

 step01-1

寫檔 File Output
1.fopen ( )  開啟
2.printf ( )   =>  fprintf ( )  File output
3.fclose ( ) 關閉

step01-2

讀檔 File Input
1.把剛剛 week14-1_fprintf.cpp 拿來用
2.另外一組 FILE * fin = fopen("檔名","r");
3.scanf ()   =>   fscanf()



step02-1

做動畫:


2022年5月17日 星期二

為哥的圖學筆記week13

step01-1

新加的一行程式碼劃出四邊形:glRectf(0.3,0.5,-0.3,-0.5);///四邊形


step01-2

把手加上去讓他可以轉動:加方塊和色彩


移動旋轉中心到身體中心:


旋轉45度:

step02-1

結果:可以透過滑鼠控制轉動

step02-2

畫下手肘:


手肘轉動:

鏡射另一隻手臂:將X值正負相反



step03-1

透過按鍵0,1,2,3控制哪個關節要動:




程式碼:


2022年5月10日 星期二

為哥的圖學筆記week12

step01-1


課本範例 Transformation.exe 看變化
重點在: T移動,R轉動,按右鍵SWAP可以交會程式碼


##在右邊轉動的車子
glTranslatef( 0.9 , 0.0 , 0.0 );移動在右邊 glrotatef(角度,0,1,0);旋轉
## 繞著中間轉彎的車子
glrotatef(角度,0,1,0);旋轉 glTranslatef( 0.9 , 0.0 , 0.0 );移動在右邊

打開120.125.80.50/GL練習程式
先按ToDraw畫身體和手臂
可以按 angle= 再按空白鍵 會自動改變成動畫


Step02-1

glPushMatrix();

        myDrawObject(0);畫身體

        glRotatef(angle,0,0,0);//這個旋轉會轉下面所有的東西

        glTranslatef(0.02,-0.06);往左下方移動(讓軸心在正中央)

        myDrawObject(1);畫手臂(右上方)

glPopMatrix();



myDrawObject(0);畫身體

glPushMatrix()

        glTranslatef(0.15,0.20,0);往右上方移

        glRotatef(angle,0,0,0);//這個旋轉會轉下面所有的東西

        glTranslatef(0.02,-0.06,0);往左下方移動(讓軸心在正中央)

        myDrawObject(1);畫手臂(右上方)

glPopMatrix();


Step02-2

1.File-new project-GLUT專案,week12_TRT
2.把10行程式碼放上去
3.TRT的6行放上去

4.茶壺超人

5.茶壺超人 兩隻手



2022年5月3日 星期二

為哥的圖學筆記week11

step01:

持續實作 glm 模型相關練習: 把茶壺貼上Gundam的貼圖

程式碼:


step02:

持續實作glm模型相關練習:   把模型整個讀進來

1.在https://jsyeh.org/3dcg10/下載三個檔案

2.把glm.c改成glm.cpp,把glm.h glm.cpp放到week11_gundam專案目錄裡

3.在week11_gundam專案中 add files 加入glm.cpp

利用maya切割模型 youtube關鍵字搜尋 maya匯出obj檔案

2022年4月26日 星期二

為哥的圖學筆記week10

Step01-1:開啟一個GLUT專案

Step01-2:複製上週貼圖座標的程式碼

```

#include <opencv/highgui.h>

#include <opencv/cv.h>

#include <GL/glut.h>

int myTexture(char * filename)

{

    IplImage * img = cvLoadImage(filename); ///OpenCV讀圖


    cvCvtColor(img,img, CV_BGR2RGB);


    glEnable(GL_TEXTURE_2D);


    GLuint id;


    glGenTextures(1, &id);


    glBindTexture(GL_TEXTURE_2D, id);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);


    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);


    return id;

}

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glutSolidTeapot( 0.3 );

    glutSwapBuffers();

}

int main(int argc, char**argv)

{

    glutInit( &argc, argv );

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week09 texture");

    glutDisplayFunc(display);

    myTexture("earth.jpg");

    glutMainLoop();

}

```

OpenCV設定: setting-compiler , search directories , compiler include: C:\opencv2.1\include

OpenCV設定: setting-compiler , search directories , Linker lib目錄: C:\opencv2.1\lib

OpenCV設定: setting-compiler , Linker設定: 咒語 cv210 cxcore210 highgui210

XXX.jpg 圖檔要放哪: 工作目錄working_dir   (in C:\Users\...\Desktop\freeglut\bin)


Step02-1:


Step02-2:第二個主題: 上週貼圖+貼到圓球=會轉的地球 

1.新專案week10_texture_earth

最上面要加這行


display();




程式碼:

#include <opencv/highgui.h>

#include <opencv/cv.h>

#include <GL/glut.h>

GLUquadric * sphere = NULL;///指標指到二次曲面

int myTexture(char * filename)

{

    IplImage * img = cvLoadImage(filename); ///OpenCV讀圖


    cvCvtColor(img,img, CV_BGR2RGB);


    glEnable(GL_TEXTURE_2D);


    GLuint id;


    glGenTextures(1, &id);


    glBindTexture(GL_TEXTURE_2D, id);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);


    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);


    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->imageData);


    return id;

}

void display()

{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    gluQuadricTexture(sphere,1);///設好貼圖

    gluSphere(sphere,1,30,30);///畫圓球

    glutSwapBuffers();

}

int main(int argc, char**argv)

{

    glutInit( &argc, argv );

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("week10 texture");

    glutDisplayFunc(display);

    myTexture("earth.jpg");///地球的地圖

    sphere = gluNewQuadric();///準備好二次曲面

    glutMainLoop();


}


地球旋轉:



程式碼:







2022年4月19日 星期二

2022年4月12日 星期二

為哥的圖學筆記week08

 step 1-3

了解GLUT範例 sample.cpp 177行 做什麼事

```C++

#include <GL/glut.h>

```

GLUT  callback?會被GLUT呼叫的函式

我們寫的那些display() keyboard() mouse() motion()函式

2022年3月29日 星期二

為哥的圖學筆記Week06

 1. 下載範例 https://jsyeh.org/3dcg10

   data.zip , windows.zip

2. windows.zip =解壓=> 下載\windows\Transformation.exe

   data.zip =解壓=> 下載\windows\data\模型.obj

Light Material.exe

(左上)左鍵拖移可選轉

(左上)右鍵換模型

(左下)右鍵換Material

下面的程式碼都不用打:

GLfloat light_pos[] = {-2.0,2.0,2.0,1.0};陣列

glLightfv(GL_LIGHT0,GL_POSITION,陣列)

                第幾盞燈            位置



打光後的Teapot:




打光後的Teapot + mouse motion rotate:












2022年3月22日 星期二

為哥的圖學筆記Week05

1. 下載範例 https://jsyeh.org/3dcg10

   data.zip , windows.zip

2. windows.zip =解壓=> 下載\windows\Transformation.exe

   data.zip =解壓=> 下載\windows\data\模型.obj


Keyboard Function:


motion移動:



motion移動修改後:


放大縮小:

完整程式碼:


2022年3月15日 星期二

為哥的圖學筆記Week04

 step01:

選轉方向依照右手定則


0,1,0選轉方向




0,0,1選轉方向




1,0,0選轉方向


旋轉茶壺程式碼:
#include <GL/glut.h>

static void display(void)

{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glRotated(90,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    glutSwapBuffers();
}
int main(int argc, char *argv[])
{

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04_Rotate");
    glutDisplayFunc(display);
    glutMainLoop();
}




用滑鼠調整茶壺角度

程式碼:
#include <GL/glut.h>
float angle = 0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();///備份矩陣
        glRotated(angle,0,0,1);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣
    glutSwapBuffers();
}
void motion(int x, int y)
{
    angle = x;
    display();///重畫畫面
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("Week04_Rotate");
    glutDisplayFunc(display);
    glutMotionFunc(motion);///mouse motion動
    glutMainLoop();
}




2022年3月8日 星期二

為哥的圖學筆記 Week03

 1. 下載範例 https://jsyeh.org/3dcg10

   data.zip , windows.zip

2. windows.zip =解壓=> 下載\windows\Transformation.exe

   data.zip =解壓=> 下載\windows\data\模型.obj

3. 執行 Transformation 看範例, 試試看




4.

    glPushMatrix();///備份矩陣
        glTranslated(x,y,0);
        glColor3f(1,1,0);
        glutSolidTeapot(0.3);
    glPopMatrix();///還原矩陣





2022年3月1日 星期二

為哥圖學筆記 Week02

1. 下載範例 https://jsyeh.org/3dcg10

   data.zip windows.zip glut32.dll

2. windows.zip =解壓=> 下載\windows\Shapes.exe

   data.zip =解壓=> 下載\windows\data\模型

   glut32.dll =複製=> 下載\windows\glut32.dll

3. 跑 Shapes.exe 看範例, 試試看

   左可按右鍵選單: 大頂點、很多顏色

   右可按右鍵選單: POINT....POLYGON 



1. 上週的安裝 Git for Windows
2. 上週的 Git Bash: cd desktop, git clone 你的網址 cd 2022graphics



3. 上週的安裝 freeglut, 記得改檔名 lib\libglut32.a


4. 在 CodeBlocks File-Open week01_GLUT專案,跑!




Teapot程式碼

#include <GL/glut.h>

static void display(void)

{

    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("第02週的程式喔!");

    glutDisplayFunc(display);

    glutMainLoop();


}



三角形程式碼

#include <GL/glut.h>

static void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1,1,0);
    glBegin(GL_POLYGON);

    glColor3f(1,0,0);
    glVertex2d(-1,-1);

    glColor3f(0,1,0);
    glVertex2d(+1,-1);

    glColor3f(0,0,1);
    glVertex2d(0,+1);

    glEnd();

    glutSwapBuffers();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("第02週的程式喔!");

    glutDisplayFunc(display);


    glutMainLoop();

}









VERY BEAUTIFUL, VERY POWERFUL

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