顯示具有 Week12 標籤的文章。 顯示所有文章
顯示具有 Week12 標籤的文章。 顯示所有文章

2018年6月9日 星期六

Week12歐耶

先到moodle下載老師的freeglut那個東東
記得要用note++修改開啟的路徑
不然會開不起來


去 Moodle 下載 CMP3_MCI.h依樣打開note++修改一下程式碼


使用timer 1     (內插法)新舊內插
是為了讓每個我們設定的動作點 連接起來  好讓模型有做動作

2018年6月4日 星期一

WEEK12 QAQ筆記

WEEK12:計時器、內插、線性內插、動畫


1.把聲音先放入桌面的freeglut/bin

在main程式前加
#include <mmsystem.h>///(0)呼叫Multimedia多媒體系統的外掛
main程式裡加
 PlaySound("madmoo.wav",NULL,SND_ASYNC);///(1)播放聲音,毒入wav檔
    ///PlaySound()其實就是PlaySoundA(),輸入的檔名,會是正常的ASCII字串
    ///三個參數 (檔名,NULL,SND_ASYNC)
    ///小心,要在 working_dir工作執行的目錄裡面找到他

/

#include <windows.h>///(0)要有windows才會認識
#include <mmsystem.h>///(0)使用mmsystem外掛
#include <stdio.h>
int main()
{

    PlaySound("madmoo.wav",NULL,SND_SYNC);///等人(ASYNC  不等人不同步)
    printf("Hello world\n");
}













點擊滑鼠發出砲彈聲

2.內插 (借老師的圖,這樣觀念比較清楚)













3.計時器











2018年6月2日 星期六

Week12 計時器

主題: 計時器 / 內插 / 線性內插 / 動畫

 playSound  MP3播放
(1) 建立GLUT project
(2) 把 CodeBlock的 .cbp檔 裡的working-dir 改成 "."
(3) 把C:\Users\user\Desktop\freeglut\bin\freeglut.dll copy and paste in your project file

(4) #include"CMP3_MCI.h"
      CMP3_MCI mymp3;
      int main(int argc, char *argv[])
      {
          mymp3.Load("Do.mp3");
          mymp3.Play();
          ...
          ...
      }


計時器
(1) int main(int argc, char *argv[]){
          ....
          glutCreateWindow("GLUT Shapes");
          glutTimerFunc(2000, timer, 0); // 要在 glutCreateWindow() 之後,
          ....
      }
(2) void timer(int t){
         glutTimerFunc(1000, timer, 0);
         PlaySound("Do.wav", NULL, SND_ASYNC);
  }


內插
new*alpha+old*(1-alpha)







2018年5月17日 星期四

Week12 來福的汪汪圖學週記

電腦圖學 week12' 0514

1)小考:T-R-T觀念
2)上週:PlaySound,MP3播放
3)主題:計時器Timer
4)主題:內插 線性內插 動畫


上週我們 GLUT專案  用的是freeglut檔案的資料夾
現在改成在專案資料夾
用notepad++打開專案的cbp檔案

working_dir="C:/Users/bp6ru/Desktop/freeglut/bin" />
改成
working_dir="." />
(有2個)


下載"CMP_MCI.h"  並且放到專案檔資料夾
設定播放MP3

CMP3_MCI xxxMP3///宣告一個叫做xxxMP3的變數

在main裡面加上
xxxMP3_Load("音樂名字.mp3");///讀入檔案
xxxMP3_Play();///播放


設定計時器
在main裡面加上計時器
>>
  glutTimerFunc( 1000, timer, 0);
/// 1000代表1秒  5000代表5秒 以此類推
在main上面宣告一個void timer外函式
代表經過多少秒要播放一次音樂


連續計時器
在void裡面加上glutTimerFunc( 1000, timer, 0);
表示間隔多少秒要重新播放一次音樂

>> 呼喚下面的glutTimerFunc,進入void
   播了void之後  要再呼喚一次void(看設定時間多少來間隔)
  void 迴圈<<


內插公式:交叉相乘

2018年5月14日 星期一

Week12

計時器TIMER

主題: 內插  線性內插  動畫

內插公式:
新 alpha  + 舊 * ( 1 - alpha )

Week 12 安淇的課堂筆記

1. 複習上週教的 T-R-T , 接著小考


2.下載 lesson32.zip 和 freeglut 並解壓縮
建一個新的glut專案 (week12_mp3)
把Shot.wav和 freeglut.dll 丟到week12_mp3資料夾裡

再來改位置


打上

就會有蹦的音效了


3.去mp3資料庫尋找想要的音效

會出現自己找的mp3音效


4.
計時器



Week 12 ADDONE notes

(1) T-R-T關節轉動
(2) PlaySound() , MP3播放
(3) 主題:計時器
(4) 內插,線性內插,動畫。

1.到moodle 下載  : freeglut,音樂, CMP3_MCI.h 2.改Project的.....cbp檔 "bin" 改成 "."
3.把freeglut  CMP3_MCI.h  MP3 檔放在Project裡


計時器

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

#include <stdlib.h>

static int slices = 16;
static int stacks = 16;

/* GLUT callback Handlers */

static void resize(int width, int height)
{
    const float ar = (float) width / (float) height;

    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity() ;
}

static void display(void)
{
    const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
    const double a = t*90.0;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3d(1,0,0);

    glPushMatrix();
        glTranslated(-2.4,1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutSolidSphere(1,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(0,1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutSolidCone(1,1,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(2.4,1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutSolidTorus(0.2,0.8,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(-2.4,-1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutWireSphere(1,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(0,-1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutWireCone(1,1,slices,stacks);
    glPopMatrix();

    glPushMatrix();
        glTranslated(2.4,-1.2,-6);
        glRotated(60,1,0,0);
        glRotated(a,0,0,1);
        glutWireTorus(0.2,0.8,slices,stacks);
    glPopMatrix();

    glutSwapBuffers();
}


static void key(unsigned char key, int x, int y)
{
    switch (key)
    {
        case 27 :
        case 'q':
            exit(0);
            break;

        case '+':
            slices++;
            stacks++;
            break;

        case '-':
            if (slices>3 && stacks>3)
            {
                slices--;
                stacks--;
            }
            break;
    }

    glutPostRedisplay();
}

static void idle(void)
{
    glutPostRedisplay();
}

const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

/* Program entry point */

#include <mmsystem.h>
#include <stdio.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
void timer(int t)
{
    glutTimerFunc(2000,timer,0);  //2000=2秒再播放
    PlaySound("Shot.wav",NULL,SND_ASYNC);
}

int main(int argc, char *argv[])
{
    myMP3.Load("MJThriller.mp3");
    myMP3.Play();
    ///PlaySound("BigDog.mp3", NULL, SND_ASYNC);

    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);
    glutTimerFunc(7000,timer,0);//7000=7秒後播放

    glClearColor(1,1,1,1);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    glutMainLoop();

    return EXIT_SUCCESS;
}


內插法

#include <Gl/glut.h>
const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

float angle=0;
float alpha=0;
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glutSolidTeapot(0.3);
        glPushMatrix();
        glTranslatef(0.4,0,0);
        glRotatef(angle,0,0,1);
        glTranslatef(0.4,0,0);
        glutSolidTeapot(0.3);
        glPopMatrix();
    glPopMatrix();
    glutSwapBuffers();
}
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
void timer(int t)
{
    glutTimerFunc(50,timer,t+1);
    alpha = t/100.0;
    angle = alpha*90 + (1-alpha)*0;
    glutPostRedisplay();
    ///PlaySound("Shot.wav",NULL,SND_ASYNC);
}

int main(int argc, char *argv[])
{
    myMP3.Load("MJThriller.mp3");
    myMP3.Play();
    ///PlaySound("BigDog.mp3", NULL, SND_ASYNC);

    glutInit(&argc, argv);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(10,10);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glutCreateWindow("GLUT Shapes");

    glutDisplayFunc(display);
    glutTimerFunc(1000,timer,0);

    glClearColor(1,1,1,1);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glEnable(GL_LIGHT0);
    glEnable(GL_NORMALIZE);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);

    glutMainLoop();

    return EXIT_SUCCESS;

}


1.MP3播放
   變更Project中的cbp檔,把bin改成 .
2.計時器

3.內插


4.動畫


Week12史蒂芬的課堂筆記

一、複習上週
1.建立GLUT專案
2.用notepad++改Projet.cbp(working-dir改成.)

3.把freeglut\bin\freeglut32.dll
 複製到專案目錄

二、加入MP3檔
加上以下幾行
#include <mmsystem.h>
#include "CMP3_MCI.h"
CMP3_MCI myMP3;
int main(int argc, char *argv[])
{
    myMP3.Load("2.mp3");
    myMP3.Play();
}

三、計時器函式
void timer (int t)
{
    glutTimerFunc(2000,timer,0);每隔2秒播一次
    PlaySound("Shot.wav",NULL,SND_ASYNC);
}

int main(int argc, char *argv[])
{
    glutReshapeFunc(resize);
    glutDisplayFunc(display);
    glutKeyboardFunc(key);
    glutIdleFunc(idle);
    glutTimerFunc(5000,timer,0);  間隔5秒播一次
}

四、內插法
公式:新*α+舊*(1-α)