MIDITrail をピカピカにする。鍵盤方向自動切替・多ポート・歌詞対応等
修订版 | f1bebbec186165b6cd1acfc45d3c4f7fcc7f34ba (tree) |
---|---|
时间 | 2019-08-28 07:06:19 |
作者 | yoshy <yoshy@user...> |
Commiter | yoshy |
[UPDATE] カメラ位置によるキーボード描画順の変更を実装
@@ -1611,6 +1611,8 @@ int MTPianoKeyboard::Transform( | ||
1611 | 1611 | LPDIRECT3DDEVICE9 pD3DDevice, |
1612 | 1612 | D3DXVECTOR3 basePosVector, |
1613 | 1613 | D3DXVECTOR3 playbackPosVector, |
1614 | + D3DXVECTOR3 camVector, | |
1615 | + D3DXVECTOR3 lookVector, | |
1614 | 1616 | float rollAngle |
1615 | 1617 | ) |
1616 | 1618 | { |
@@ -47,14 +47,16 @@ public: | ||
47 | 47 | //更新 |
48 | 48 | int Transform(LPDIRECT3DDEVICE9 pD3DDevice, D3DXVECTOR3 moveVector, float rollAngle); |
49 | 49 | // >>> add 20120729 yossiepon begin |
50 | -// >>> modify 20180411 yossiepon begin | |
50 | +// >>> modify 20180414 yossiepon begin | |
51 | 51 | virtual int Transform( |
52 | 52 | LPDIRECT3DDEVICE9 pD3DDevice, |
53 | 53 | D3DXVECTOR3 basePosVector, |
54 | 54 | D3DXVECTOR3 playbackPosVector, |
55 | + D3DXVECTOR3 camVector, | |
56 | + D3DXVECTOR3 lookVector, | |
55 | 57 | float rollAngle |
56 | 58 | ); |
57 | -// <<< modify 20180411 yossiepon end | |
59 | +// <<< modify 20180414 yossiepon end | |
58 | 60 | // <<< add 20120729 yossiepon end |
59 | 61 | |
60 | 62 | // >>> modify function decl to virtual 20180412 yossiepon begin |
@@ -139,6 +139,7 @@ EXIT:; | ||
139 | 139 | int MTPianoKeyboardCtrlMod::Transform( |
140 | 140 | LPDIRECT3DDEVICE9 pD3DDevice, |
141 | 141 | D3DXVECTOR3 camVector, |
142 | + D3DXVECTOR3 lookVector, | |
142 | 143 | float rollAngle |
143 | 144 | ) |
144 | 145 | { |
@@ -171,7 +172,7 @@ int MTPianoKeyboardCtrlMod::Transform( | ||
171 | 172 | basePosVector.x += _GetMaxPitchBendShift(index); |
172 | 173 | |
173 | 174 | //キーボード移動 |
174 | - result = m_pPianoKeyboard[index]->Transform(pD3DDevice, basePosVector, playbackPosVector, rollAngle); | |
175 | + result = m_pPianoKeyboard[index]->Transform(pD3DDevice, basePosVector, playbackPosVector, camVector, lookVector, rollAngle); | |
175 | 176 | if (result != 0) goto EXIT; |
176 | 177 | } |
177 | 178 |
@@ -39,6 +39,7 @@ public: | ||
39 | 39 | int Transform( |
40 | 40 | LPDIRECT3DDEVICE9 pD3DDevice, |
41 | 41 | D3DXVECTOR3 camVector, |
42 | + D3DXVECTOR3 lookVector, | |
42 | 43 | float rollAngle |
43 | 44 | ); |
44 | 45 |
@@ -42,6 +42,10 @@ MTPianoKeyboardMod::MTPianoKeyboardMod(void) | ||
42 | 42 | m_pRevIndexBuffer = NULL; |
43 | 43 | m_RevIndexNum = 0; |
44 | 44 | m_IsRevIndexLocked = false; |
45 | + | |
46 | + //キーボード描画範囲 | |
47 | + m_noteNoLow = -1; | |
48 | + m_noteNoHigh = -1; | |
45 | 49 | } |
46 | 50 | |
47 | 51 | //****************************************************************************** |
@@ -103,12 +107,16 @@ int MTPianoKeyboardMod::Draw( | ||
103 | 107 | pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); |
104 | 108 | |
105 | 109 | //正順側キーボードの描画 |
106 | - result = m_PrimitiveKeyboard.Draw(pD3DDevice, m_pTexture, m_BufInfo[63].indexTotal / 3); | |
107 | - if (result != 0) goto EXIT; | |
110 | + if (m_noteNoLow != -1) { | |
111 | + result = m_PrimitiveKeyboard.Draw(pD3DDevice, m_pTexture, m_BufInfo[m_noteNoLow].indexTotal / 3); | |
112 | + if (result != 0) goto EXIT; | |
113 | + } | |
108 | 114 | |
109 | 115 | //逆順側キーボードの描画 |
110 | - result = m_PrimitiveKeyboard.Draw(pD3DDevice, m_pRevIndexBuffer, m_pTexture, m_BufInfo[64].revIndexTotal / 3); | |
111 | - if (result != 0) goto EXIT; | |
116 | + if (m_noteNoHigh != -1) { | |
117 | + result = m_PrimitiveKeyboard.Draw(pD3DDevice, m_pRevIndexBuffer, m_pTexture, m_BufInfo[m_noteNoHigh].revIndexTotal / 3); | |
118 | + if (result != 0) goto EXIT; | |
119 | + } | |
112 | 120 | |
113 | 121 | EXIT:; |
114 | 122 | return result; |
@@ -121,6 +129,8 @@ int MTPianoKeyboardMod::Transform( | ||
121 | 129 | LPDIRECT3DDEVICE9 pD3DDevice, |
122 | 130 | D3DXVECTOR3 basePosVector, |
123 | 131 | D3DXVECTOR3 playbackPosVector, |
132 | + D3DXVECTOR3 camVector, | |
133 | + D3DXVECTOR3 lookVector, | |
124 | 134 | float rollAngle |
125 | 135 | ) |
126 | 136 | { |
@@ -176,6 +186,9 @@ int MTPianoKeyboardMod::Transform( | ||
176 | 186 | //変換行列設定 |
177 | 187 | m_PrimitiveKeyboard.Transform(worldMatrix); |
178 | 188 | |
189 | + //キーボード描画順の生成 | |
190 | + _MakeRenderingOrder(basePosVector, camVector, lookVector); | |
191 | + | |
179 | 192 | //EXIT:; |
180 | 193 | return result; |
181 | 194 | } |
@@ -217,6 +230,46 @@ EXIT:; | ||
217 | 230 | } |
218 | 231 | |
219 | 232 | //****************************************************************************** |
233 | +// 描画順の作成 | |
234 | +//****************************************************************************** | |
235 | +int MTPianoKeyboardMod::_MakeRenderingOrder( | |
236 | + D3DXVECTOR3 basePosVector, | |
237 | + D3DXVECTOR3 camVector, | |
238 | + D3DXVECTOR3 lookVector | |
239 | + ) | |
240 | +{ | |
241 | + float origin = basePosVector.x; | |
242 | + | |
243 | + float camPos = -camVector.z; | |
244 | + | |
245 | + m_noteNoLow = (int)::floor((camPos - origin) / m_KeyboardDesignMod.GetNoteStep()); | |
246 | + m_noteNoHigh = m_noteNoLow + 1; | |
247 | + | |
248 | + //char buf[256]; | |
249 | + //::sprintf(buf, "O:%f, P:%f, L:%d, H:%d\n", origin, camPos, m_noteNoLow, m_noteNoHigh); | |
250 | + //::OutputDebugStringA(buf); | |
251 | + | |
252 | + if (m_noteNoLow < 0) { | |
253 | + m_noteNoLow = -1; | |
254 | + } | |
255 | + | |
256 | + if (m_noteNoLow >= SM_MAX_NOTE_NUM) { | |
257 | + m_noteNoLow = SM_MAX_NOTE_NUM - 1; | |
258 | + } | |
259 | + | |
260 | + | |
261 | + if (m_noteNoHigh < 0) { | |
262 | + m_noteNoHigh = 0; | |
263 | + } | |
264 | + | |
265 | + if (m_noteNoHigh >= SM_MAX_NOTE_NUM) { | |
266 | + m_noteNoHigh = -1; | |
267 | + } | |
268 | + | |
269 | + return 0; | |
270 | +} | |
271 | + | |
272 | +//****************************************************************************** | |
220 | 273 | // 逆順インデックス生成 |
221 | 274 | //****************************************************************************** |
222 | 275 | int MTPianoKeyboardMod::_CreateRevIndex(LPDIRECT3DDEVICE9 pD3DDevice) |
@@ -41,6 +41,8 @@ public: | ||
41 | 41 | LPDIRECT3DDEVICE9 pD3DDevice, |
42 | 42 | D3DXVECTOR3 basePosVector, |
43 | 43 | D3DXVECTOR3 playbackPosVector, |
44 | + D3DXVECTOR3 camVector, | |
45 | + D3DXVECTOR3 lookVector, | |
44 | 46 | float rollAngle |
45 | 47 | ); |
46 | 48 |
@@ -55,6 +57,13 @@ public: | ||
55 | 57 | |
56 | 58 | private: |
57 | 59 | |
60 | + //描画順の作成 | |
61 | + int _MakeRenderingOrder( | |
62 | + D3DXVECTOR3 basePosVector, | |
63 | + D3DXVECTOR3 camVector, | |
64 | + D3DXVECTOR3 lookVector | |
65 | + ); | |
66 | + | |
58 | 67 | //逆順インデックスの生成 |
59 | 68 | int _CreateRevIndex(LPDIRECT3DDEVICE9 pD3DDevice); |
60 | 69 |
@@ -106,6 +115,10 @@ private: | ||
106 | 115 | LPDIRECT3DINDEXBUFFER9 m_pRevIndexBuffer; |
107 | 116 | unsigned long m_RevIndexNum; |
108 | 117 | bool m_IsRevIndexLocked; |
118 | + | |
119 | + //キーボード描画範囲 | |
120 | + int m_noteNoLow; | |
121 | + int m_noteNoHigh; | |
109 | 122 | }; |
110 | 123 | |
111 | 124 |
@@ -106,6 +106,11 @@ int MTScenePianoRoll3DMod::Transform( | ||
106 | 106 | int result = 0; |
107 | 107 | float rollAngle = 0.0f; |
108 | 108 | D3DXVECTOR3 camVector; |
109 | + D3DXVECTOR3 lookVector; | |
110 | + float phi; | |
111 | + float phiRad; | |
112 | + float theta; | |
113 | + float thetaRad; | |
109 | 114 | |
110 | 115 | //基底クラスの変換処理を呼び出す |
111 | 116 | result = MTScenePianoRoll3D::Transform(pD3DDevice); |
@@ -114,6 +119,16 @@ int MTScenePianoRoll3DMod::Transform( | ||
114 | 119 | //カメラ座標取得 |
115 | 120 | m_FirstPersonCam.GetPosition(&camVector); |
116 | 121 | |
122 | + //カメラ視線方向取得 | |
123 | + m_FirstPersonCam.GetDirection(&phi, &theta); | |
124 | + | |
125 | + //視線ベクトル(極座標から直交座標へ変換) | |
126 | + phiRad = D3DXToRadian(phi); | |
127 | + thetaRad = D3DXToRadian(theta); | |
128 | + lookVector.x = 10.0f * sin(thetaRad) * cos(phiRad); | |
129 | + lookVector.y = 10.0f * cos(thetaRad); | |
130 | + lookVector.z = 10.0f * sin(thetaRad) * sin(phiRad); | |
131 | + | |
117 | 132 | //回転角度取得 |
118 | 133 | rollAngle = m_FirstPersonCam.GetManualRollAngle(); |
119 | 134 |
@@ -134,7 +149,7 @@ int MTScenePianoRoll3DMod::Transform( | ||
134 | 149 | if (result != 0) goto EXIT; |
135 | 150 | |
136 | 151 | //ピアノキーボード更新 |
137 | - result = m_PianoKeyboardCtrlMod.Transform(pD3DDevice, camVector, rollAngle); | |
152 | + result = m_PianoKeyboardCtrlMod.Transform(pD3DDevice, camVector, lookVector, rollAngle); | |
138 | 153 | if (result != 0) goto EXIT; |
139 | 154 | |
140 | 155 | EXIT:; |