|
ベクトルによる移動処理(上級編) |
| ダウンロード : ベクトル移動サンプル2(2008/01/26) |

|
TVector2 g_vec2MyPos; // 現在位置 float g_fDirec; // 移動方向 float g_fSpeed; // 移動速度 const float c_fUnitDir = 0.01f; // 単位回転角度 const float c_fMinSpeed = 1.5f; // 最低移動速度 const float c_fMaxSpeed = 30.0f; // 最高移動速度 const float c_fStopSpeed = 6.0f; // 停止時回転速度 |
|
// 回転方向を求める(単位角度) float fRotate = 0.0f + (::GetKeyState(VK_RIGHT) < 0 ? c_fUnitDir : 0.0f) // 右回転? - (::GetKeyState(VK_LEFT) < 0 ? c_fUnitDir : 0.0f); // 左回転? // 回転角を移動速度で確定する g_fDirec += fRotate * (g_fSpeed > 0.0f ? g_fSpeed : c_fStopSpeed); // 移動する TVector2 vec2Direc = GetUnitVector2(g_fDirec); g_vec2MyPos = AddVec2(g_vec2MyPos, MultiVec2Scalar(vec2Direc, g_fSpeed)); |
このこの宇宙船は4つの頂点から出来ています。|
// モデルデータ情報定義 const int c_nNumMyShip = 4; const TVector2 c_vec2MyShip[c_nNumMyShip] = { { 9, 0 }, { -5, -5 }, { -3, 0 }, { -5, 5 }, }; |
|
TVector2 g_vec2MyShip[c_nNumMyShip]; // 自機の頂点情報 |
|
// ------------------------------------------------------------------- // 自分の表示形状を計算する // ------------------------------------------------------------------- void MakeMyShipModel() { // 自機の頂点演算を行う float fScale = BASE_SCALE; TVector2 vec2Pos = g_vec2MyPos; TMatrix2 mtxRotate = Matrix2Rotation(-g_fMoveDirec); TVector2 vec2Temp; int i; for (i = 0; i < c_nNumMyShip; i++) { // 自機を回転させる vec2Temp = CalcVec2TransformCoord(c_vec2MyShip[i], mtxRotate); // 自機を拡大縮小させる vec2Temp = MultiVec2Scalar(vec2Temp, fScale); // 自機を移動させる g_vec2MyShip[i] = AddVec2(vec2Temp, vec2Pos); } } |
|
< 初級編に戻る
< 中級編に戻る
|