#week10
#week10-0_sample
1.安裝freeglut 解壓縮放置桌面 更改檔名 libglut32.a
2.新增專案 week10-0_sample
#week10-1_TRT_SolidCube_myBody_myArm
1.新增專案week10-1_TRT_SolidCube_myBody_myArm
2.貼上上週程式
3.用glutSolodCube(0.3) 用兩次 紅色身體 綠色手臂
-身體程式放置 void myBody()函式
-手臂程式放置 void myArm()函式
#程式碼
#include <GL/glut.h>
void myBody(){
glColor3f(1,0,0);
glutSolidCube(0.3);
}
void myArm(){
glColor3f(0,1,0);
glScalef(1.1,0.5,0.5);
glutSolidCube(0.3);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.6,+0.3,0);
mtBody();
glPopMatrix();
glPushMatrix();
glTranslatef(+0.0,+0.3,0);
myArm();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week09-2_glutSolidCube_glutSoildTeapot_flutSoildSphere");
glutDisplayFunc(display);
glutMainLoop();
}
void myBody(){
glColor3f(1,0,0);
glutSolidCube(0.3);
}
void myArm(){
glColor3f(0,1,0);
glScalef(1.1,0.5,0.5);
glutSolidCube(0.3);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.6,+0.3,0);
mtBody();
glPopMatrix();
glPushMatrix();
glTranslatef(+0.0,+0.3,0);
myArm();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week09-2_glutSolidCube_glutSoildTeapot_flutSoildSphere");
glutDisplayFunc(display);
glutMainLoop();
}
#week10-2_TRT_glutIdleFunc_rotate
1.新稱專案 week10-2_TRT_glutIdleFunc_rotate
2.貼上 week10-1程式
3.加上三段程式碼 float angle=0; glRotatef(angle++,0,0,1); glutIdleFunc(display);
#程式碼
#include <GL/glut.h>
void myBody(){
glColor3f(1,0,0);
glutSolidCube(0.3);
}
void myArm(){
glColor3f(0,1,0);
glScalef(1.1,0.5,0.5);
glutSolidCube(0.3);
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.6,+0.3,0);
myBody();
glPopMatrix();
glPushMatrix();
glRotatef(angle++,0,0,1);
myArm();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week09-2_glutSolidCube_glutSoildTeapot_flutSoildSphere");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
void myBody(){
glColor3f(1,0,0);
glutSolidCube(0.3);
}
void myArm(){
glColor3f(0,1,0);
glScalef(1.1,0.5,0.5);
glutSolidCube(0.3);
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.6,+0.3,0);
myBody();
glPopMatrix();
glPushMatrix();
glRotatef(angle++,0,0,1);
myArm();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week09-2_glutSolidCube_glutSoildTeapot_flutSoildSphere");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
##week10-3_TRT_glRotatef_glTranslatef
1.新增專案 week10-3_TRT_glRotatef_glTranslatef
2.貼上week10-2程式
##week10-4_TRT_glTranslatef_glRotatef_glTranslate
1.新稱專案week10-4_TRT_glTranslatef_glRotatef_glTranslate
2.貼上week10-3程式
3.更改程式碼 使綠色長方形移至紅色正方形頂點上轉動
##程式碼
#include <GL/glut.h>
void myBody(){
glColor3f(1,0,0);
glutWireCube(0.6);
}
void myArm(){
glColor3f(0,1,0);
glScalef(1.5,0.5,0.5);
glutWireCube(0.3);
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
myBody();
glPopMatrix();
glPushMatrix();
glTranslatef(+0.3,+0.3,0);
glRotatef(angle++,0,0,1);
glTranslatef(0.225,0,0);
myArm();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week10-4_TRT_glTranslatef_glRotatef_glTranslate");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
void myBody(){
glColor3f(1,0,0);
glutWireCube(0.6);
}
void myArm(){
glColor3f(0,1,0);
glScalef(1.5,0.5,0.5);
glutWireCube(0.3);
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
myBody();
glPopMatrix();
glPushMatrix();
glTranslatef(+0.3,+0.3,0);
glRotatef(angle++,0,0,1);
glTranslatef(0.225,0,0);
myArm();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week10-4_TRT_glTranslatef_glRotatef_glTranslate");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
##week10-5_TRT_two_layers
1.新稱專案 week10-5_TRT_two_layers
2.貼上week10-4 程式
3.畫手臂下一行
#include <GL/glut.h>
void myBody(){
glColor3f(1,0,0);
glutWireCube(0.6);
}
void myArm(){
glPushMatrix();
glColor3f(0,1,0);
glScalef(1.5,0.5,0.5);
glutWireCube(0.3);
glPopMatrix();
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
myBody();
glPopMatrix();
glPushMatrix();
glTranslatef(+0.3,+0.3,0);
glRotatef(angle++,0,0,1);
glTranslatef(0.225,0,0);
myArm();
glPushMatrix();
glTranslatef(0.225,0,0);
glRotatef(angle++,0,0,1);
glTranslatef(0.225,0,0);
myArm();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week10-4_TRT_glTranslatef_glRotatef_glTranslate");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
1.新稱專案 week10-6_TRT_left_right
2.貼上 week10-5程式
##程式碼
#include <GL/glut.h>
void myBody(){
glColor3f(1,0,0);
glutWireCube(0.6);
}
void myArm(){
glPushMatrix();
glColor3f(0,1,0);
glScalef(1.5,0.5,0.5);
glutWireCube(0.3);
glPopMatrix();
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
myBody();
glPopMatrix();
glPushMatrix();
glTranslatef(+0.3,+0.3,0);
glRotatef(angle++,0,0,1);
glTranslatef(0.225,0,0);
myArm();
glPushMatrix();
glTranslatef(0.225,0,0);
glRotatef(angle++,0,0,1);
glTranslatef(0.225,0,0);
myArm();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.3,+0.3,0);
glRotatef(angle++,0,0,1);
glTranslatef(-0.225,0,0);
myArm();
glPushMatrix();
glTranslatef(-0.225,0,0);
glRotatef(angle++,0,0,1);
glTranslatef(-0.225,0,0);
myArm();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week10-4_TRT_glTranslatef_glRotatef_glTranslate");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}
##week10-7_TRT_mouse_motion_angle
1.新增專案 week10-7_TRT_mouse_motion_angle
2.貼上 week10-6程式 增加程式碼
滑鼠滑動可轉動手臂
##程式碼
#include <GL/glut.h>
void myBody(){
glColor3f(1,0,0);
glutWireCube(0.6);
}
void myArm(){
glPushMatrix();
glColor3f(0,1,0);
glScalef(1.5,0.5,0.5);
glutWireCube(0.3);
glPopMatrix();
}
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
myBody();
glPopMatrix();
glPushMatrix();
glTranslatef(+0.3,+0.3,0);
glRotatef(angle,0,0,1);
glTranslatef(0.225,0,0);
myArm();
glPushMatrix();
glTranslatef(0.225,0,0);
glRotatef(angle,0,0,1);
glTranslatef(0.225,0,0);
myArm();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.3,+0.3,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.225,0,0);
myArm();
glPushMatrix();
glTranslatef(-0.225,0,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.225,0,0);
myArm();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y){
angle=x;
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow(" week10-4_TRT_glTranslatef_glRotatef_glTranslate");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutIdleFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言