顯示具有 01161194_陳昱穎 標籤的文章。 顯示所有文章
顯示具有 01161194_陳昱穎 標籤的文章。 顯示所有文章

2014年6月12日 星期四

期末作業

Youtube 網址:

https://www.youtube.com/watch?v=4KMqXAw4kXU&feature=youtu.be

運鏡

#include <GL/glut.h>
#include <math.h>
#include <stdlib.h>
float eyeX=-0.3, eyeY=1.2, eyeZ=0.4, objX=-0.2, objY=-0.5, objZ=-0.2, UpX=0, UpY=1, UpZ=0;
float angleX =0,angleA=0,angleY=0;
float thesize=0.2;
void timerRotateShow(int t);
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') angleA+=5,angleX+=5,angleY=(1);
if(key=='2') angleA-=5,angleX-=5,angleY=0;
if(key==' '){
objX+=0.02;
}
if(key=='0'){
glutTimerFunc(0, timerRotateShow,0);
}


glutPostRedisplay();
}
void timerRotateShow(int t)
{
if(t%10==0)glClearColor((rand()%255)/255.0, (rand()%255)/255.0, (rand()%255)/255.0, (rand()%255)/255.0);
glutTimerFunc(30, timerRotateShow,t+1);
eyeX=cos(t/100.0*3.1415);
eyeZ=sin(t/100.0*3.1415);
eyeY-=0.005;
thesize+=0.01;
glutPostRedisplay();
}
void myLight()
{
const GLfloat light_position[] = { 2.0f, 5.0f, -1.0f, 0.0f };
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
gluLookAt(eyeX, eyeY, eyeZ, objX, objY, objZ, UpX, UpY, UpZ);
glScalef(thesize,thesize,thesize);
glPushMatrix();//Eyes
glRotatef(angleX, 0,0.1,0);
glColor3f(0,0,0);
glTranslatef(0.1,0.3,-0.25);
glutSolidSphere(0.02,10,10);
glPushMatrix();
glTranslatef(-0.2,0,0);
glutSolidSphere(0.02,10,10);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glRotatef(angleX, 0,1,0);
glColor3f(0.5,1,2);
glTranslatef(0, 0.2, 0);
glutSolidSphere(0.25, 20, 20);
glPopMatrix();
glPushMatrix();
glRotatef(angleX, 0,1,0);
glColor3f(0.5,1,2);
glutSolidTeapot(0.29);
glutWireTeapot(0.3);
glPopMatrix();
glPushMatrix();
glRotatef(angleA, 1,0,0);
glTranslatef(-0.1, -0.4, 0);
glColor3f(0.5,1,2);
glScalef(1, 3, 1);
glutSolidCube(0.15);
glPopMatrix();
glPushMatrix();
glRotatef(angleA, 1,0,0);
glTranslatef(-0.1, -0.68, 0);
glRotatef(angleA, -0.15,0,0);
glColor3f(1,1,1);
glScalef(1.2, 2, 1.4);
glutSolidCube(0.15);
glPopMatrix();
glPushMatrix();
glRotatef(angleA, -1,0,0);
glTranslatef(0.1, -0.4, 0);
glColor3f(0.5,1,2);
glScalef(1, 3, 1);
glutSolidCube(0.15);
glPopMatrix();
glPushMatrix();
glRotatef(angleA, -1,0,0);
glTranslatef(0.1, -0.68, 0);
glRotatef(angleA, 0.15,0,0);
glColor3f(1,1,1);
glScalef(1.2, 2, 1.4);
glutSolidCube(0.15);
glPopMatrix();
glPushMatrix();
glRotatef(angleX, 0,1,0);
glColor3f(1, 1, 1);
glTranslatef(-0.4, 0, 0);
glutSolidSphere(0.15, 20, 20);
glPushMatrix();
glRotatef(angleA, 0, 1, 1);
glColor3f(0.5,1,2);
glScalef(1, 2, 1);
glTranslatef(0.02, -0.1, 0);
glutSolidCube(0.15);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glRotatef(angleX, 0, 1, 0);
glColor3f(1, 1, 1);
glTranslatef(0.4, 0, 0);
glutSolidSphere(0.15, 20, 20);
glPushMatrix();
glRotatef(angleA, 0, 1, 1);
glColor3f(0.5,1,2);
glScalef(1, 2, 1);
glTranslatef(0.02, -0.1, 0);
glutSolidCube(0.15);
glPopMatrix();
glPopMatrix();
glPopMatrix();

glutSwapBuffers();
}

int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week11");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);

myLight();

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2,-2,2,-10,10);
glMatrixMode(GL_MODELVIEW);

glutMainLoop();
}

播放音樂-使用 CMP3_MCI.h

播放音樂-使用 CMP3_MCI.h

#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main()
{
myMP3.Load("BGMusic.mp3");
myMP3.Play();
...

---------------------------------------------------------------------------

將動作儲存於txt & 小黑窗中

#include <stdio.h>
#include <GL/glut.h>

float a=0;
float angle[20]={0,90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float angleNew[20]={0,90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
float angleOld[20]={90,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int angleID =0; 
FILE * fout=NULL, *fin=NULL;

void readNext()
{
if(fin==NULL) fin=fopen("Position","r");
a+=0.1;
for(int i=0;i<20;i++) angle[i] = angleOld[i]*(1-a) + angleNew[i]*a ;
if(a>=1.0){
a=0.0;
for(int i=0; i<20 ; i++){
angleOld[i] = angleNew[i];
fscanf(fin,"%f ",&angleNew[i]);
}
}

}
void timer(int t)
{
glutTimerFunc(100,timer,0);
readNext();
glutPostRedisplay();
}
int OldX=0, OldY=0;//mouse X , mouse Y
void mouse(int button, int state, int x, int y)
{
OldX=x; OldY=y;
}
void motion(int x, int y)
{
angle[angleID]+= (x-OldX);
OldX=x;
glutPostRedisplay();
}

void keyboard(unsigned char key, int x, int y)
{
if(key=='0')angleID=0;
if(key=='1')angleID=1;
if(key=='2')angleID=2;
if(key=='3')angleID=3;
if(key=='s'){/*save*/
if(fout==NULL) fout=fopen("Position","w+");
for(int i=0;i<20;i++){
printf(  "%f",angle[i]);
fprintf(fout,"%f",angle[i]);
}
printf(  "\n");
fprintf(fout,"\n");
}
if(key=='r'){ readNext(); }
if(key=='p'){ glutTimerFunc(0,timer,0); }
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle[0],0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glPushMatrix();
glTranslatef(0.5,0,0);
glRotatef(angle[1],0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week15");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}