• 検索結果がありません。

イントロダクション

N/A
N/A
Protected

Academic year: 2021

シェア "イントロダクション"

Copied!
13
0
0

読み込み中.... (全文を見る)

全文

(1)

埼玉大学 情報システム工学科

小林 貴訓

プログラミング演習

IV

7回 マウス,キーボード,サウンド,

(2)

マウス入力

クリックイベントのコールバック関数の登録

クリックイベントのコールバック関数

glutMouseFunc(mouse); // マウスクリックコールバック関数の指定

static int MouseLB_ON=0; //左マウスボタン押下フラグ

static int MouseRB_ON=0; //右マウスボタン押下フラグ

void mouse(int button, int state, int x, int y){

if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){

MouseLB_ON = 1; printf("(%3d,%3d)で左ボタンが押されました¥n", x, y); }else if (button == GLUT_LEFT_BUTTON && state == GLUT_UP){

MouseLB_ON = 0; printf("(%3d,%3d)で左ボタンを離しました¥n", x, y);

}else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN){ MouseRB_ON = 1; printf("(%3d,%3d)で右ボタンが押されました¥n", x, y); }else if (button == GLUT_RIGHT_BUTTON && state == GLUT_UP){

MouseRB_ON = 0; printf("(%3d,%3d)で右ボタンを離しました¥n", x, y); }

(3)

マウス入力

ドラッグイベントのコールバック関数の登録

ドラッグイベントのコールバック関数

マウス移動のコールバック関数の登録

マウス移動のコールバック関数

glutMotionFunc(dragMotion); // マウスドラッグコールバック関数の指定

void dragMotion(int x, int y){

if (MouseLB_ON==1) printf(“(%3d,%3d)で左ドラッグ中...¥n", x, y);

else if (MouseRB_ON==1) printf(“(%3d,%3d)で右ドラッグ中...¥n", x, y); }

glutPassiveMotionFunc(passiveMotion);// マウス移動コールバック関数の指定

void passiveMotion(int x, int y){

printf("(%3d,%3d)でマウス移動中...¥n", x, y); }

(4)

キー入力

通常キーのコールバック関数(押したとき)の登録

通常キーのコールバック関数(押したとき)

glutKeyboardFunc(keyboard); //通常キーコールバック関数の指定(押したとき)

void keyboard(unsigned char key, int x, int y){ switch (key) { case '1': printf("(%3d,%3d)で1が押されました¥n", x, y); break; case '2': printf("(%3d,%3d)で2が押されました¥n", x, y); break; case '3': printf("(%3d,%3d)で3が押されました¥n", x, y); break; } }

(5)

キー入力

通常キーのコールバック関数(離したとき)の登録

通常キーのコールバック関数(離したとき)

glutKeyboardUpFunc(keyboardUp); //通常キーコールバック関数の指定(離したとき)

void keyboardUp(unsigned char key, int x, int y){ switch (key) { case '1': printf("(%3d,%3d)で1が離されました¥n", x, y); break; case '2': printf("(%3d,%3d)で2が離されました¥n", x, y); break; case '3': printf("(%3d,%3d)で3が離されました¥n", x, y); break; }

(6)

キー入力

特殊キーのコールバック関数(押したとき)の登録

特殊キーのコールバック関数(押したとき)

glutSpecialFunc(specialKey); //特殊キーコールバック関数の指定(押したとき)

void specialKey(int key, int x, int y){ switch (key) { case GLUT_KEY_UP: printf("(%3d,%3d)で[↑]が押されました¥n", x, y); break; case GLUT_KEY_DOWN: printf("(%3d,%3d)で[↓]が押されました¥n", x, y); break; case GLUT_KEY_LEFT: printf("(%3d,%3d)で[←]が押されました¥n", x, y); break; case GLUT_KEY_RIGHT: printf("(%3d,%3d)で[→]が押されました¥n", x, y); break; } }

(7)

キー入力

特殊キーのコールバック関数(離したとき)の登録

特殊キーのコールバック関数(離したとき)

glutSpecialUpFunc(specialKeyUp); //特殊キーコールバック関数の指定(離したとき)

void specialKeyUp(int key, int x, int y){ switch (key) { case GLUT_KEY_UP: printf("(%3d,%3d)で[↑]が離されました¥n", x, y); break; case GLUT_KEY_DOWN: printf("(%3d,%3d)で[↓]が離されました¥n", x, y); break; case GLUT_KEY_LEFT: printf("(%3d,%3d)で[←]が離されました¥n", x, y); break; case GLUT_KEY_RIGHT: printf("(%3d,%3d)で[→]が離されました¥n", x, y); break; }

(8)

キーリピート

キーリピートを無効にするには以下を書く

(9)

サウンドを鳴らす

Playsound

1.

windows.hをインクルード

2.

winmm.libをリンク

3.

再生したい

wavファイルをソースと同じフォルダに配置

4.

PlaySound命令を発行する

PlaySound( “bgm.wav”, NULL,

SND_FILENAME | SND_ASYNC | SND_LOOP );

※この方法が最も簡単だが,同時に再生できるのは1つのwavファイルのみ

無限ループ 非同期再生

(10)

サウンドを鳴らす

MCI(Media Control Interface)コマンドを使う

1.

windows.hをインクルード

2.

winmm.libをリンク

デバイスの準備

static MCI_OPEN_PARMS mciOpenParam1; mciOpenParam1.lpstrDeviceType

=(LPSTR)MCI_DEVTYPE_WAVEFORM_AUDIO; // メディアの種類

mciOpenParam1.lpstrElementName=“bell.wav”; // ファイル名 // mciデバイスのオープン

mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_TYPE |

MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT, (DWORD_PTR)&mciOpenParam1);

(11)

サウンドを鳴らす

サウンドの再生

終了処理

巻き戻し

// 現在の場所から再生なので,何度も繰り返して鳴らす時は先に巻き戻す mciSendCommand(mciOpenParam1.wDeviceID, MCI_PLAY, 0, 0); // mciデバイスのクローズ mciSendCommand(mciOpenParam1.wDeviceID, MCI_CLOSE, 0, 0); mciSendCommand(mciOpenParam1.wDeviceID, MCI_SEEK, MCI_SEEK_TO_START, 0);

(12)

文字列の描画

glRasterPos3fで位置を指定して

glutBitmapCharacterで描画する

とすると座標

(1.0f, 1.0f, 1.0f)に”Teapot”と描画される

常にカメラ方向を向いていて回転や拡大縮小はできない

// 文字列の描画 glRasterPos3f(1.0f, 1.0f, 1.0f); char *str = "Teapot"; while(*str){ glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *str); ++str; }

(13)

演習

作成したモデルをマウスまたはキーボードで動かす

BGMと効果音を同時に鳴らしてみる

課題

「オブジェクトを

2つ作って,距離を表示し,

片方のオブジェクトをキーボードで操作して,

もう片方に近づいたら色を変えて,ドカーンと鳴らす」

来週,私がみなさんのところを回って確認をします

ドカーン

参照

関連したドキュメント

In the present study, we evaluated the effectiveness of static/nonfreezing hypothermic preservation of rat hearts in a preservative solution with added AFGP based on our

The present study is the first to demonstrate that medaka scales respond to G-loading by using ALP and TRAP as marker enzymes of osteoblasts and osteoclasts stained by the

Instantaneous force with static deflection feedback model is applied to predict cutting force and dimensional surface error generation in peripheral milling with irregular tooth

REPRESENTATION FORMULAS OF GENERAL SOLUTIONS TO THE STATIC EQUATIONS OF THE HEMITROPIC ELASTICITY THEORY... of elasticity of

Acute effects of static stretching on the hamstrings using shear elastic modulus determined by ultrasound shear wave elastography: Differences in flexibility between

[11] ISO 23830 Surface chemical analysis -- Secondary- ion mass spectrometry -- Repeatability and constancy of the relative-intensity scale in static secondary-ion

A mathematical formulation of well-posed initial boundary value problems for viscous incompressible fluid flow-through-bounded domain is described for the case where the values

Solutions of this equation can describe the outer or inner free surface of a static meniscus the static liquid bridge free surface between the shaper and the crystal surface