1.將freeglut資料夾放在桌面
2.開啟貝殼專案設定在桌面

3.專案設定
加咒語



4.將 freeglut.dll 丟在專案資料夾裡

5.打出以下程式碼

6.成功

<課堂作業二>
依課堂作業一加上自轉及公轉
打出以下程式碼

成功

<課堂作業三>
做出機器人
以下程式碼:
#include <GL/glut.h>
float rot1=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutWireCube(0.2);///body
glPushMatrix();
glTranslatef(0, 0.15 ,0);
glutWireCube(0.1);///head
glPopMatrix();
glPushMatrix();
glTranslatef(0.15, 0, 0);
glutWireCube(0.1);///right upper arm
glTranslatef(0.1, 0, 0);
glutWireCube(0.1);///right lower arm
glTranslatef(0.1, 0, 0);
glutWireCube(0.1);///head
glPopMatrix();
glPushMatrix();
glTranslatef(-0.15, 0, 0);
glutWireCube(-0.1);///left upper arm
glTranslatef(-0.1, 0, 0);
glutWireCube(-0.1);///left lower arm
glTranslatef(-0.1, 0, 0);
glutWireCube(-0.1);///head
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)
{
rot1=x;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Robot");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}



讓機器人的手臂會動
機器人右邊手臂程式碼如下:
glPushMatrix();
///glTranslatef(0.15, 0, 0);
glTranslatef(0.10, 0.05, 0);
glRotatef(rot1,0,0,1);
glTranslatef(0.05, 0, 0);
glutWireCube(0.1);///right upper arm
///glTranslatef(0.1, 0, 0);
glTranslatef(0.05, 0, 0);
glRotatef(rot1,0,0,1);
glTranslatef(0.05, 0, 0);
glutWireCube(0.1);///right lower arm
///glTranslatef(0.1, 0, 0);
glTranslatef(0.05, 0, 0);
glRotatef(rot1,0,0,1);
glTranslatef(0.05, 0, 0);
glutWireCube(0.1);///head
glPopMatrix();

加上左手

沒有留言:
張貼留言