做出兩個茶壺
把freeflut路徑跟咒與設好
freeglut.dll 要丟到作業裡面
程式碼
#include <GL/glut.h>
void display()
{
glPushMatrix();
glutSolidTeapot(0.3);
glTranslatef(0.5,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
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.3);///不會動的茶壺
glRotatef(rot1,0,0,1);///公轉
glTranslatef(0.5,0,0);
glRotatef(rot1, 0,0,1);///自轉
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int x,int y)///滑鼠指令
{
rot1=x;///跟著滑鼠的x改變
glutPostRedisplay();///不用等待 不然會卡卡的
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Robot");
glutDisplayFunc(display);
glutMotionFunc(motion);///要宣告不然motion不理你
glutMainLoop();
}
TRT
T--3.掛在哪裡
R--1.轉動
T--2.轉的中心要放在哪裡
#include <GL/glut.h>
float rot1=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glutSolidTeapot(0.3);
glTranslatef(0.33,0.05,0);
glRotatef(rot1, 0,0,1);
glTranslatef(0.25,0,0);
glutSolidTeapot(0.3);
glTranslatef(0.33,0.05,0);
glRotatef(rot1, 0,0,1);
glTranslatef(0.25,0,0);
glutSolidTeapot(0.3);
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();
glPushMatrix();
glutWireCube(0.3);///body
glPushMatrix();
glTranslatef(0,0.2,0);
glutWireCube(0.1);///hand
glPopMatrix();
glPushMatrix();
glTranslatef(0.2,0.1,0);
glutWireCube(0.1);///upper arm
glTranslatef(0.1,0,0);
glutWireCube(0.1);///lower arm
glTranslatef(0.1,0,0);
glutWireCube(0.1);///right hand
glPopMatrix();
glPushMatrix();
glTranslatef(-0.2,0.1,0);
glutWireCube(0.1);///upper arm
glTranslatef(-0.1,0,0);
glutWireCube(0.1);///lower arm
glTranslatef(-0.1,0,0);
glutWireCube(0.1);///right hand
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();
}
會揮手
#include <GL/glut.h>
float rot1=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glPushMatrix();
glutWireCube(0.3);///body
glPushMatrix();
glTranslatef(0,0.2,0);
glutWireCube(0.1);///hand
glPopMatrix();
glPushMatrix();
///glTranslatef(0.15,0.1,0);
glTranslatef(0.15,0,0);
glRotatef(rot1,0,0,1);
glTranslatef(0.05,0,0);
glutWireCube(0.1);///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);///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);///right hand
glPopMatrix();
glPushMatrix();
///glTranslatef(-0.2,0.1,0);
glTranslatef(-0.15,0.1,0);
glRotatef(-rot1,0,0,1);
glTranslatef(-0.05,0,0);
glutWireCube(0.1);///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);///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);///right hand
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();
}







沒有留言:
張貼留言