介紹Transformation
和上星期一樣去 https://jsyeh.org/3dcg10/
下載date.zip--->解壓縮至此
下載windows.zip--->解壓縮至此啟動Transformation.exe
translatef 左右移動
rotatef 以軸為中心轉動
scalef 長胖的
begin.... 藍色車子
Translatef在前面是自轉
Rotatef在前面是全世界一起轉
想吃一番地 我是壽喜燒大師
GLUT專案
week05-1_TRT_rotate_translate
把week04-1拿來用
#include <GL/glut.h>
float angle =0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glColor3f(0,1,0);///綠色
glPushMatrix();
glTranslatef(0.8,0,0);///最後是綠色的移動
glRotatef(angle,0 ,0 ,1);///改對Z軸轉
glutSolidTeapot(0.3);
glPopMatrix();
glColor3f(1,0,0);///紅色
glPushMatrix();
glRotatef(angle,0 ,0 ,1);///改對Z軸轉
glTranslatef(0.8,0,0);///最後是紅色的移動
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
angle++;///角度++
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05");
glutDisplayFunc(display);
glutIdleFunc(display);///有空idle時就重畫畫面
glutMainLoop();
}
綠色自轉 紅色公轉
week05-2_TRT_robot
把week05-1拿來用
#include <GL/glut.h>
float angle =0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glColor3f(0,1,0);///綠色
glPushMatrix();
glutSolidCube(0.5);
glPushMatrix();
glTranslatef(0.25,0.25,0);///3.整個東西放在右上角
glRotatef(angle,0 ,0 ,1);///2.轉動
glTranslatef(0.25,0.25,0);///1.把旋轉中心放在中心點
glColor3f(1,0,0);///紅色
glutSolidCube(0.5);
glPopMatrix();
glutSwapBuffers();
angle++;///角度++
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week05");
glutDisplayFunc(display);
glutIdleFunc(display);///有空idle時就重畫畫面
glutMainLoop();
}
*glutSolidCube 畫方塊
紅色方塊會旋轉
Processing
打開老師給的檔案
劃出兩塊圖案
切英文輸入法按空白鍵可轉動
把圖案抓到白色的點上
就可以讓他以白色的點為中心轉
^_^






沒有留言:
張貼留言