1. 複習上週 T-R-T 及 glPushMatrix(); glPopMatrix() 的小考
2. 期末作品
3. 建出全身關節
4. 滑鼠/鍵盤操控動作
5. 存檔、播放Play
2. 期末作品
3. 建出全身關節
4. 滑鼠/鍵盤操控動作
5. 存檔、播放Play
#include <GL/glut.h>
float x1=-0.4,y1=0,x2=0.4,y2=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(x1,y1,0);
glColor3f(1,1,0);
glutSolidTeapot(0.2);
glPopMatrix();
glPushMatrix();
glTranslatef(x2,y2,0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);
glPopMatrix();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
float x1=-0.4,y1=0,x2=0.4,y2=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(x1,y1,0);
glColor3f(1,1,0);
glutSolidTeapot(0.2);
glPopMatrix();
glPushMatrix();
glTranslatef(x2,y2,0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);
glPopMatrix();
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') y1+=0.1;
if(key=='2') y1-=0.1;
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
float x1=-0.4,y1=0,x2=0.4,y2=0;
float angle=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(x1,y1,0);
glRotatef(angle, 0,0,1);
glTranslatef(-0.25,-0.11,0);
glColor3f(1,1,0);
glutSolidTeapot(0.2);
glPopMatrix();
glPushMatrix();
glTranslatef(x2,y2,0);
glColor3f(1,0,0);
glutSolidTeapot(0.2);
glPopMatrix();
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') y1+=0.1;
if(key=='2') y1-=0.1;
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
float x1=-0.4, y1=0, x2=0.4, y2=0;
float angle=0, angle2=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///BLUE
glTranslatef(x2,y2,0);
glRotatef(angle, 0,0,1);
glColor3f(0,0,1);
glutSolidTeapot(0.2);
glPushMatrix();///GREEN
glTranslatef(x1,y1,0);
glRotatef(angle2, 0,0,1);
glTranslatef(-0.25,-0.11,0);
glColor3f(0,1,0);
glutSolidTeapot(0.2);
glPopMatrix();
glPopMatrix();
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') x1+=0.1;
if(key=='2') x1-=0.1;
if(key=='3') y1+=0.1;
if(key=='4') y1-=0.1;
if(key=='5') angle+=10;
if(key=='6') angle-=10;
if(key=='7') angle2+=10;
if(key=='8') angle2-=10;
printf("%f %f\n",x1,y1);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <stdio.h>
float x1=-0.4, y1=0, x2=0.4, y2=0;
float angle=0, angle2=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();///BLUE
glTranslatef(x2,y2,0);
glRotatef(angle, 0,0,1);
glColor3f(0,0,1);
glutSolidTeapot(0.2);
glPushMatrix();///GREEN
glTranslatef(x1,y1,0);
glRotatef(angle2, 0,0,1);
glTranslatef(-0.25,-0.11,0);
glColor3f(0,1,0);
glutSolidTeapot(0.2);
glPopMatrix();
glPopMatrix();
glFlush();
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') x1+=0.1;
if(key=='2') x1-=0.1;
if(key=='3') y1+=0.1;
if(key=='4') y1-=0.1;
if(key=='5') angle+=10;
if(key=='6') angle-=10;
if(key=='7') angle2+=10;
if(key=='8') angle2-=10;
printf("%f %f\n",x1,y1);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
float x1=-0.4, y1=0, x2=0.4, y2=0, oldX=0, oldY=0;;
float angle=0, angle2=0, angle3=0, angle4=0;
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') angle++;
if(key=='2') angle2++;
if(key=='3') angle3++;
if(key=='4') angle4++;
printf("%f %f\n",x1,y1);
glutPostRedisplay();
}
void drawBody()
{
glPushMatrix();
glScalef(1,0.5,0.5);
glutSolidCube(1);
glPopMatrix();
}
void drawArm()
{
glPushMatrix();
glScalef(0.6,0.3,0.3);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
{///Lighting
glColor3ub(166,132,100);
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.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle, 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,0,1);
drawArm();///這是個Arm --- Right Upper Arm
glPushMatrix();
glTranslatef(0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle2, 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,1,0);
drawArm(); ///Right Lower Arm
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle3, 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,0.5,1);
drawArm();///這是個Arm --- Left Upper Arm
glPushMatrix();
glTranslatef(-0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle4, 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,1,0.5);
drawArm(); ///Left Lower Arm
glPopMatrix();
glPopMatrix();
drawBody();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
float x1=-0.4, y1=0, x2=0.4, y2=0, oldX=0, oldY=0;;
float angle=0, angle2=0, angle3=0, angle4=0;
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') angle++;
if(key=='2') angle2++;
if(key=='3') angle3++;
if(key=='4') angle4++;
if(key=='5') angle--;
if(key=='6') angle2--;
if(key=='7') angle3--;
if(key=='8') angle4--;
printf("%f %f\n",x1,y1);
glutPostRedisplay();
}
void drawBody()
{
glPushMatrix();
glScalef(1,0.5,0.5);
glutSolidCube(1);
glPopMatrix();
}
void drawArm()
{
glPushMatrix();
glScalef(0.6,0.3,0.3);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
{///Lighting
glColor3ub(166,132,100);
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.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle, 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,0,1);
drawArm();///這是個Arm --- Right Upper Arm
glPushMatrix();
glTranslatef(0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle2, 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,1,0);
drawArm(); ///Right Lower Arm
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle3, 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,0.5,1);
drawArm();///這是個Arm --- Left Upper Arm
glPushMatrix();
glTranslatef(-0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle4, 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,1,0.5);
drawArm(); ///Left Lower Arm
glPopMatrix();
glPopMatrix();
drawBody();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>
float oldX=0, oldY=0;;
float angle[10]={0,0,0,0,0,0,0,0,0,0};
int now=0;
void motion(int x,int y)
{
angle[now]-= y-oldY;
oldY=y;
oldX=x;
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') now=1;
if(key=='2') now=2;
if(key=='3') now=3;
if(key=='4') now=4;
glutPostRedisplay();
}
void drawBody()
{
glPushMatrix();
glScalef(1,0.5,0.5);
glutSolidCube(1);
glPopMatrix();
}
void drawArm()
{
glPushMatrix();
glScalef(0.6,0.3,0.3);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
{///Lighting
glColor3ub(166,132,100);
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.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle[1], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,0,1);
drawArm();///這是個Arm --- Right Upper Arm
glPushMatrix();
glTranslatef(0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle[2], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,1,0);
drawArm(); ///Right Lower Arm
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle[3], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,0.5,1);
drawArm();///這是個Arm --- Left Upper Arm
glPushMatrix();
glTranslatef(-0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle[4], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,1,0.5);
drawArm(); ///Left Lower Arm
glPopMatrix();
glPopMatrix();
drawBody();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>///要存檔用的
FILE * fout=NULL;///要存檔用的 file for output
float oldX=0, oldY=0;;
float angle[8]={0,0,0,0,0,0,0,0};
int now=0;
void motion(int x,int y)
{
angle[now]-= y-oldY;
oldY=y;
oldX=x;
for(int i=0;i<8;i++)///要存檔用的
{
printf("%.lf\t", angle[i]);
}
printf("\n");
}
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') now=1;
if(key=='2') now=2;
if(key=='3') now=3;
if(key=='4') now=4;
glutPostRedisplay();
}
void drawBody()
{
glPushMatrix();
glScalef(1,0.5,0.5);
glutSolidCube(1);
glPopMatrix();
}
void drawArm()
{
glPushMatrix();
glScalef(0.6,0.3,0.3);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
{///Lighting
glColor3ub(166,132,100);
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.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle[1], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,0,1);
drawArm();///這是個Arm --- Right Upper Arm
glPushMatrix();
glTranslatef(0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle[2], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,1,0);
drawArm(); ///Right Lower Arm
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle[3], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,0.5,1);
drawArm();///這是個Arm --- Left Upper Arm
glPushMatrix();
glTranslatef(-0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle[4], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,1,0.5);
drawArm(); ///Left Lower Arm
glPopMatrix();
glPopMatrix();
drawBody();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>///要存檔用的
FILE * fout=NULL;///要存檔用的 file for output
float oldX=0, oldY=0;;
float angle[8]={0,0,0,0,0,0,0,0};
int now=0;
void motion(int x,int y)
{
angle[now]-= y-oldY;
oldY=y;
oldX=x;
if(fout==NULL) fout=fopen("02160562.txt","w+");///file for output
for(int i=0;i<8;i++)///file for output
{
fprintf(fout,"%.1f\t",angle[i]);
}
fprintf(fout,"\n");
}///txt檔案在freeglut-->bin資料夾裡
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') now=1;
if(key=='2') now=2;
if(key=='3') now=3;
if(key=='4') now=4;
glutPostRedisplay();
}
void drawBody()
{
glPushMatrix();
glScalef(1,0.5,0.5);
glutSolidCube(1);
glPopMatrix();
}
void drawArm()
{
glPushMatrix();
glScalef(0.6,0.3,0.3);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
{///Lighting
glColor3ub(166,132,100);
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.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle[1], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,0,1);
drawArm();///這是個Arm --- Right Upper Arm
glPushMatrix();
glTranslatef(0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(angle[2], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0,1,0);
drawArm(); ///Right Lower Arm
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle[3], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,0.5,1);
drawArm();///這是個Arm --- Left Upper Arm
glPushMatrix();
glTranslatef(-0.25, 0, 0);///把樓下的 "會對Arm Joint做旋轉的東西" 再移到右上 掛上去
glRotatef(-angle[4], 0,0,1);///把下面整團, 都對中間做旋轉
glTranslatef(-0.25, 0,0);///這是把它往右移, Arm Joint在中間
glColor3f(0.5,1,0.5);
drawArm(); ///Left Lower Arm
glPopMatrix();
glPopMatrix();
drawBody();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutCreateWindow("02160562");
glutDisplayFunc(display);
glutMainLoop();
}
沒有留言:
張貼留言