旋轉 ( 安培右手旋轉的方向 )( 0,0,1 )
( 1,1,0 )
step04-2 FILE-NEW-PROJECT
step02-1 rotate
先看範例的177行程式碼 移到notepated++
貼上上周的程式碼 加3行程式碼 茶壺可以旋轉
float angle = 0;
glRotatef(angle, 0, 1, 0 );
angle++;
step02-1 rotate+ 打光
剪貼上個程式碼 茶壺會暗暗的
複製範例 ctrl+f 找light 複製程式碼
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shini
step04-3
如何分辨自轉跟公轉的差別 口訣: 左耳靠在左肩 讀程式就從
藍色的車子: glBegin( ....... )
長胖的藍色車子: glScalef( 1.53,1.00,1.00 )
glBegin( ....... )
移到右邊去的長胖藍色車子: glTranslatef( 0.59,0.00,0.00 )
glScalef( 1.53,1.00,1.00 )
glBegin( ....... )
轉動整個世界且移到右邊去的長胖藍色車子
glRotatef( 0.00,0.00,1.00,0.00 )
glTranslatef( 0.59,0.00,0.00 )
glScalef( 1.53,1.00,1.00 )
glBegin( ....... )
新開專案 複製week04-1的程式碼
glTranslated(0.5,0,0);///移動到右邊的
glRotatef(angle, 0, 1, 0 );///轉angle角度 旋轉中的
glColor3f(0,0,1);///藍色的
glutSolidTeapot( 0.3 );///茶壺
在複製剛剛茶壺的那幾行程式碼 新增另一個黃色的茶壺
glPushMatrix();///step02-1備分矩陣
glRotatef(angle, 0, 1, 0 );///step03-4轉angle角度 旋轉中的
glTranslated(0.5,0,0);///step03-4移動到右邊的
glColor3f(1,1,0);///黃色的
glTranslated(0,0.5,0);///step03-4 往上移動的
glutSolidTeapot( 0.3 );///茶壺
glPopMatrix();///還原矩陣
沒有留言:
張貼留言