1.MOODLE➡解壓縮 freeglut-MinGW-3.0.0-1.mp.zip
➡把解壓縮完的檔案移到桌面
➡把124KB的檔案改名成 libglut32.a
➡開新的專案命名week03_mouse
➡解壓縮到C:\Users\austi\OneDrive\桌面\freeglut
2.從老師的網頁(https://jsyeh.org/3dcg10/)下載兩個檔案:1.data 2.win32➡先解壓縮win32的檔案 , 然後把data資料夾移到windows資料夾
➡打開 Transformation.exe
👇
調整Y軸變高變矮
調整Z軸變長變短
#include <GL/glut.h>
void display()
{
glClearColor(1,1,0.9,1);///背景變淡黃色(R,G,B,A),Alpha的意思是半透明程度
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glColor3f(0,1,0);///茶壺變綠色
glutSolidTeapot(0.3);///畫一個實心的茶壺,大小是0.3
glutSwapBuffers();///請GLUT把畫面swap送到顯示的地方
}
int main(int argc, char *argv[])
{ ///上面是特別的main函式,有很多參數
glutInit(&argc, argv);///把GLUT開起來 (GLUT初始化)
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
///上面這行是把顯示的模式設定好
glutCreateWindow("week03 Mouse");///要開視窗
glutDisplayFunc(display);///要顯示的對應函式
glutMainLoop();///最後用main迴圈,壓在最後面
}
#include <GL/glut.h>
float s = 1;///一開始是原本一倍的大小
void display()
{
glClearColor(1,1,0.9,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glColor3f(0,1,0);
glPushMatrix();
glScalef(s,s,s);///縮放S倍
glutSolidTeapot(0.3);///畫一個實心的茶壺,大小是0.3
glPopMatrix();
glutSwapBuffers();///請GLUT把畫面swap送到顯示的地方
}
void motion(int x,int y)
{
s = 1 + (x-150)/150.0;///會變大變小的0 ~ 1 ~ 2
display();///重畫畫面
}
int main(int argc, char *argv[])
{ ///上面是特別的main函式,有很多參數
glutInit(&argc, argv);///把GLUT開起來 (GLUT初始化)
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
///上面這行是把顯示的模式設定好
glutCreateWindow("week03 Mouse");///要開視窗
glutDisplayFunc(display);///要顯示的對應函式
glutMotionFunc(motion);///拖動motion的時候
glutMainLoop();///最後用main迴圈,壓在最後面
}
交換Translatef / Rotatef
旋轉軸在人物正中間(人物自己在轉)
旋轉軸在方框的正中間(人物繞著一個柱子轉)
讓茶壺自轉
#include <GL/glut.h>
float teapotX = 0.5 , teapotY = 0;///放右邊
float angle = 0;///旋轉角度
float s = 0.3;///一開始是原本一倍的大小
void display()
{
glClearColor(1,1,0.9,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glColor3f(0,1,0);
glPushMatrix();
glTranslatef(teapotX,teapotY,0);
glRotatef(angle++,0,0,1);
glScalef(s,s,s);///縮放S倍
glutSolidTeapot(0.3);///畫一個實心的茶壺,大小是0.3
glPopMatrix();
glutSwapBuffers();///請GLUT把畫面swap送到顯示的地方
}
void motion(int x,int y)
{
s = 1 + (x-150)/150.0;///會變大變小的0 ~ 1 ~ 2
display();///重畫畫面
}
int main(int argc, char *argv[])
{ ///上面是特別的main函式,有很多參數
glutInit(&argc, argv);///把GLUT開起來 (GLUT初始化)
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
///上面這行是把顯示的模式設定好
glutCreateWindow("week03 Mouse");///要開視窗
glutDisplayFunc(display);///要顯示的對應函式
glutMotionFunc(motion);///拖動motion的時候
glutIdleFunc(display);///為了讓12行的angle一直++,所以一直畫
glutMainLoop();///最後用main迴圈,壓在最後面
}
----------------------------------------------------------------------------------------------------------------------------
#include <GL/glut.h>
float teapotX = 0.5 , teapotY = 0;///放右邊
float angle = 0;///旋轉角度
float s = 0.3;///一開始是原本一倍的大小
void display()
{
glClearColor(1,1,0.9,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清背景
glColor3f(0,1,0);
glPushMatrix();
glRotatef(angle++,0,0,1);
glTranslatef(teapotX,teapotY,0);
glScalef(s,s,s);///縮放S倍
glutSolidTeapot(0.3);///畫一個實心的茶壺,大小是0.3
glPopMatrix();
glutSwapBuffers();///請GLUT把畫面swap送到顯示的地方
}
void motion(int x,int y)
{
s = 1 + (x-150)/150.0;///會變大變小的0 ~ 1 ~ 2
display();///重畫畫面
}
int main(int argc, char *argv[])
{ ///上面是特別的main函式,有很多參數
glutInit(&argc, argv);///把GLUT開起來 (GLUT初始化)
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
///上面這行是把顯示的模式設定好
glutCreateWindow("week03 Mouse");///要開視窗
glutDisplayFunc(display);///要顯示的對應函式
glutMotionFunc(motion);///拖動motion的時候
glutIdleFunc(display);
glutMainLoop();///最後用main迴圈,壓在最後面
}
#include <stdio.h>
沒有留言:
張貼留言