(1)期末作業
(2)會跳舞的機器人
(3)T-R-T對關節旋轉
(4)小考:T-R-T的觀念
(5)作業問題
TODO:
1.將windows 7z解壓縮開啟Transformation

2.codeblcoks新增專案
輸入程式碼,目的:第一版打光的3D旋轉茶壺
#include <GL/glut.h>
float angle=0;
void display()
{
{
GLfloat pos[]={0,0,-1,0};
glLightfv(GL_LIGHT0,GL_POSITION,pos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
}
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
glTranslatef(0.5,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glFlush();
}
void timer(int t)
{
glutTimerFunc(20,timer,0);
angle++;
glutPostRedisplay();
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutCreateWindow("TRT 3D");
glutDisplayFunc(display);
glutTimerFunc(20,timer,0);
glutMainLoop();
}
3.不用timer用滑鼠去控制,拖拉-移動。
#include <GL/glut.h>
float angle=0, oldX=0, oldY=0;
void display()
{
{
GLfloat pos[]={0,0,-1,0};
glLightfv(GL_LIGHT0,GL_POSITION,pos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
}
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
glTranslatef(0.5,0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glFlush();
}
void timer(int t)
{
glutTimerFunc(20,timer,0);
///angle++;
glutPostRedisplay();
}
void mouse(int button,int state, int x, int y)
{
if(state==GLUT_DOWN){ oldX=x; oldY=y;}
}
void motion(int x, int y)
{
angle +=(x-oldX);
oldX=x;
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutCreateWindow("TRT 3D");
glutDisplayFunc(display);
glutTimerFunc(20,timer,0);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
4.增加一個茶壺,將茶壺掛到該放的位置去
#include <GL/glut.h>
float angle=0, oldX=0, oldY=0;
void display()
{
{
GLfloat pos[]={0,0,-1,0};
glLightfv(GL_LIGHT0,GL_POSITION,pos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
}
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.45,0.14,0);
glRotatef(angle,0,0,1);
glTranslatef(0.45,-0.1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSolidTeapot(0.3);
glFlush();
}
void timer(int t)
{
glutTimerFunc(20,timer,0);
///angle++;
glutPostRedisplay();
}
void mouse(int button,int state, int x, int y)
{
if(state==GLUT_DOWN){ oldX=x; oldY=y;}
}
void motion(int x, int y)
{
angle +=(x-oldX);
oldX=x;
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutCreateWindow("TRT 3D");
glutDisplayFunc(display);
glutTimerFunc(20,timer,0);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
做一個cube,有會動的手
厲害的手!!
#include <GL/glut.h>
float angle=0, oldX=0, oldY=0;
void drawArm()
{
glPushMatrix();
glScalef(0.5,0.25,0.25);
glutSolidCube(1);
glPopMatrix();
}
void drawBody()
{
glPushMatrix();
glTranslatef(0,-0.5,0);
glRotatef(-90,1,0,0);
glutSolidCone(0.3,0.8,30,30);
glPopMatrix();
}
void display()
{
{
GLfloat pos[]={0,0,-1,0};
glLightfv(GL_LIGHT0,GL_POSITION,pos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
}
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.15,0,0);
glRotatef(angle,0,0,1);
glTranslatef(0.25,0,0);
drawArm();
glPushMatrix();
glTranslatef(0.25,0,0);
glRotatef(angle,0,0,1);
glTranslatef(0.25,0,0);
drawArm();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.15,0,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.25,0,0);
drawArm();
glPushMatrix();
glTranslatef(-0.25,0,0);
glRotatef(-angle,0,0,1);
glTranslatef(-0.25,0,0);
drawArm();
glPopMatrix();
glPopMatrix();
drawBody();
glPopMatrix();
glFlush();
}
void timer(int t)
{
glutTimerFunc(20,timer,0);
///angle++;
glutPostRedisplay();
}
void mouse(int button,int state, int x, int y)
{
if(state==GLUT_DOWN){ oldX=x; oldY=y;}
}
void motion(int x, int y)
{
angle +=(x-oldX);
oldX=x;
}
int main(int argc, char **argv)
{
glutInit(&argc,argv);
glutCreateWindow("TRT 3D");
glutDisplayFunc(display);
glutTimerFunc(20,timer,0);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言