2.機器人Robot
3.關節轉動T-R-T
4.期末作品
課堂作業一:有個方塊
先開啟一個貝殼專案
設定咒語
設定路徑
將freeglut.dll放到專案資料夾中(不然會遺失位置)
程式碼:
#include <GL/glut.h>
void display()
{
glutWireCube(0.3);
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Robot");
glutDisplayFunc(display);
glutMainLoop();
}
課堂作業二:公轉+自轉
程式碼:
#include <GL/glut.h>
float rot1=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);///清除背景
glPushMatrix();
glutSolidTeapot(0.2);
glRotatef(rot1,0,0,1);///公轉
glTranslatef(0.6,0,0);
glRotatef(4*rot1,0,0,1);///自轉
glutSolidTeapot(0.2);
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();
}
外面的繞著中間的轉
自轉比公轉快
課堂作業三:機器人
程式碼:
#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.02,0.15,0);
glutWireCube(0.015);///右眼
glTranslatef(-0.04,0,0);
glutWireCube(-0.015);///左眼
glPopMatrix();
glPushMatrix();
///glTranslatef(0.13,0,0);移動值先不要
glTranslatef(0.08,0.03,0);
glRotatef(rot1,0,0,1);
glTranslatef(0.05,0,0);
glutWireCube(0.05);///right upper arm
glTranslatef(0.05,0,0);
glutWireCube(0.05);///right lower arm
///glTranslatef(0.05,0,0);
glTranslatef(0.03,0,0);
glRotatef(rot1,0,0,0.05);
glTranslatef(0.03,0,0);
glutWireCube(0.05);///hand
glPopMatrix();
glPushMatrix();
glTranslatef(-0.13,0,0);
glutWireCube(-0.05);///left upper arm
glTranslatef(-0.05,0,0);
glutWireCube(-0.05);///left lower arm
glTranslatef(-0.05,0,0);
glutWireCube(-0.05);///hand
glPopMatrix();
glPushMatrix();
glTranslatef(0.05,-0.13,0);
glutWireCube(-0.05);///head
glPopMatrix();
glPushMatrix();
glTranslatef(-0.05,-0.13,0);
glutWireCube(-0.05);///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();
}
可以旋轉揮手












沒有留言:
張貼留言