glPushMatrix();
glTranslatef(+0.1, +0.5, 0);
glRotatef(+30, 0, 0, 1);
glTranslatef(+0.3, 0, 0); /// 看圖的位置給予反方向(負號)
drawArm(); ///看圖給的函數
glPopMatrix();
2. MP3播放
#include "CMP3_MCI.h" /// Mp3的外掛
CMP3_MCI myMP3;
int a;
int main(int argc, char *argv[])
{
myMP3.Load("Ed.mp3");
myMP3.Play();
3.計時器Timer
#include <mmsystem.h>
void timer(int t) ///計時器函數
{
glutTimerFunc(1000, timer, t+1);
PlaySound("Do.wav", NULL, SND_ASYNC);
}
int main(int argc, char *argv[])
{
glutTimerFunc(5000, timer, 0);///呼叫計時器函數

4.線性內插動畫
-Excel

5. 茶壺自動旋轉
#include <GL/glut.h>
#include <stdio.h>
float angle = 0, oldAngle=0, newAngle= 90;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotated(angle, 0,0,1);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void timer(int t)
{
glutTimerFunc(5, timer, t+1);
float alpha = (t)/30.0;
angle = newAngle * alpha + oldAngle*(1-alpha);
glutPostRedisplay();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(640,480);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("GLUT Shapes");
glutTimerFunc(0, timer, 0);///呼叫計時器
glutDisplayFunc(display);
glutMainLoop();
}


沒有留言:
張貼留言