MIDITrail をピカピカにする。鍵盤方向自動切替・多ポート・歌詞対応等
Revision | a350541fc73729924bdb3b1cfa47c3e287fa2dd5 (tree) |
---|---|
Time | 2018-04-12 08:44:05 |
Author | yoshy <yoshy@user...> |
Commiter | yoshy |
[CLEAN] キーボードの基準座標の計算をデザインクラス側に移動
@@ -49,14 +49,6 @@ int MTGridBoxMod::Transform( | ||
49 | 49 | D3DXMatrixIdentity(&moveMatrix); |
50 | 50 | D3DXMatrixIdentity(&worldMatrix); |
51 | 51 | |
52 | - if(rollAngle < 0.0f) { | |
53 | - rollAngle += 360.0f; | |
54 | - } | |
55 | - | |
56 | - if((rollAngle > 120.0f) && (rollAngle < 300.0f)) { | |
57 | - rollAngle -= 180.0f; | |
58 | - } | |
59 | - | |
60 | 52 | //回転行列 |
61 | 53 | D3DXMatrixRotationX(&rotateMatrix, D3DXToRadian(rollAngle)); |
62 | 54 |
@@ -201,14 +201,12 @@ int MTPianoKeyboardCtrlMod::Transform( | ||
201 | 201 | ); |
202 | 202 | |
203 | 203 | float boardHeight = portWindowLU.y - portWindowLD.y; |
204 | - float keyboardWidth = m_KeyboardDesignMod.GetPortOriginX(0) * -2.0f; | |
205 | - float portWidth = m_KeyboardDesignMod.GetChStep() * 16.0f; | |
204 | + float keyboardWidth = m_KeyboardDesignMod.GetPortOriginX() * -2.0f; | |
206 | 205 | |
207 | 206 | float resizeSacle = boardHeight / keyboardWidth; |
208 | - float antiResizeScale = keyboardWidth / boardHeight; | |
209 | 207 | |
210 | 208 | float rippleSpacing = m_NoteDesignMod.GetRippleSpacing(); |
211 | - float rippleMargin = rippleSpacing * (MTNOTELYRICS_MAX_LYRICS_NUM + MTNOTERIPPLE_MAX_RIPPLE_NUM) * antiResizeScale; | |
209 | + float rippleMargin = rippleSpacing * (MTNOTELYRICS_MAX_LYRICS_NUM + MTNOTERIPPLE_MAX_RIPPLE_NUM); // * antiResizeScale; | |
212 | 210 | |
213 | 211 | //移動ベクトル:再生面に追従する |
214 | 212 | playbackPosVector = m_NoteDesignMod.GetWorldMoveVector(); |
@@ -236,43 +234,11 @@ int MTPianoKeyboardCtrlMod::Transform( | ||
236 | 234 | } |
237 | 235 | |
238 | 236 | //移動ベクトル:キーボード基準座標 |
239 | - transformVector = m_KeyboardDesignMod.GetKeyboardBasePos(keyboardIndex, 0, antiResizeScale); | |
237 | + transformVector = m_KeyboardDesignMod.GetKeyboardBasePos(keyboardIndex, rippleMargin, boardHeight, rollAngle); | |
240 | 238 | |
241 | 239 | //移動ベクトル:ピッチベンドシフトを反映 |
242 | 240 | transformVector.x += GetMaxPitchBendShift(portNo); |
243 | 241 | |
244 | - if(rollAngle < 0.0f) { | |
245 | - rollAngle += 360.0f; | |
246 | - } | |
247 | - | |
248 | - float portOriginY = portWidth * (m_PortList.GetSize() - keyboardIndex - 1) * antiResizeScale; | |
249 | - | |
250 | - //鍵盤の1/2の幅だけ高音側に | |
251 | - transformVector.x += m_KeyboardDesignMod.GetWhiteKeyStep() / 2.0f; | |
252 | - | |
253 | - //鍵盤の1/4の高さだけ下に | |
254 | - transformVector.y -= m_KeyboardDesignMod.GetWhiteKeyHeight() / 4.0f; | |
255 | - | |
256 | - if((rollAngle > 120.0f) && (rollAngle < 300.0f)) { | |
257 | - | |
258 | - //ポート原点Y | |
259 | - transformVector.y -= portOriginY; | |
260 | - | |
261 | - //鍵盤の原点をCh15に | |
262 | - transformVector.y -= m_KeyboardDesignMod.GetChStep() * 15.0f * antiResizeScale; | |
263 | - | |
264 | - //鍵盤の長さ+リップルマージン+歌詞マージンだけ手前に | |
265 | - transformVector.z -= m_KeyboardDesignMod.GetWhiteKeyLen() + rippleMargin; | |
266 | - | |
267 | - } else { | |
268 | - | |
269 | - //ポート原点Y | |
270 | - transformVector.y += portOriginY; | |
271 | - | |
272 | - //リップルマージン+歌詞マージンだけ奥に | |
273 | - transformVector.z += rippleMargin; | |
274 | - } | |
275 | - | |
276 | 242 | //キーボード移動 |
277 | 243 | result = m_pPianoKeyboard[keyboardIndex]->Transform(pD3DDevice, transformVector, playbackPosVector, resizeSacle, portWindowLU.z, rollAngle); |
278 | 244 | if (result != 0) goto EXIT; |
@@ -67,10 +67,8 @@ public: | ||
67 | 67 | |
68 | 68 | //ポート原点座標取得 |
69 | 69 | float GetPortOriginX(unsigned char portNo); |
70 | -// >>> modify 20120728 yossiepon begin | |
71 | - virtual float GetPortOriginY(unsigned char portNo); | |
72 | - virtual float GetPortOriginZ(unsigned char portNo); | |
73 | -// <<< modify 20120728 yossiepon end | |
70 | + float GetPortOriginY(unsigned char portNo); | |
71 | + float GetPortOriginZ(unsigned char portNo); | |
74 | 72 | |
75 | 73 | //キー種別取得 |
76 | 74 | KeyType GetKeyType(unsigned char noteNo); |
@@ -182,9 +180,7 @@ public: | ||
182 | 180 | ); |
183 | 181 | |
184 | 182 | //キーボード基準座標取得 |
185 | -// >>> modify 20120728 yossiepon begin | |
186 | - virtual D3DXVECTOR3 GetKeyboardBasePos(unsigned char portNo, unsigned char chNo); | |
187 | -// <<< modify 20120728 yossiepon end | |
183 | + D3DXVECTOR3 GetKeyboardBasePos(unsigned char portNo, unsigned char chNo); | |
188 | 184 | |
189 | 185 | //キーボード最大表示数取得 |
190 | 186 | unsigned long GetKeyboardMaxDispNum(); |
@@ -75,24 +75,162 @@ void MTPianoKeyboardDesignMod::_Initialize() | ||
75 | 75 | } |
76 | 76 | |
77 | 77 | //****************************************************************************** |
78 | +// ポート原点X座標取得 | |
79 | +//****************************************************************************** | |
80 | +float MTPianoKeyboardDesignMod::GetPortOriginX() | |
81 | +{ | |
82 | + // angle: 120°〜300°(rotateX: 90°, rotateZ: 90°) | |
83 | + // +z | |
84 | + // | | |
85 | + // -x<----------0---------->+x | |
86 | + // | -RippleMargin | |
87 | + // +----+----+ | |
88 | + // | | | @:OriginX | |
89 | + // | | | | |
90 | + // | | | | |
91 | + // | | | | |
92 | + // @----+----+ | |
93 | + // Note #0 | #127 | |
94 | + // -z | |
95 | + | |
96 | + // angle: 0°〜120°or 300°〜360°(rotateX: -90°, rotateZ: 90°) | |
97 | + // +z | |
98 | + // | | |
99 | + // Note #0 | #127 | |
100 | + // +----+----+ | |
101 | + // | | | @:OriginX | |
102 | + // | | | | |
103 | + // | | | | |
104 | + // | | | | |
105 | + // @----+----+ | |
106 | + // | +RippleMargin | |
107 | + // -x<----------0---------->+x | |
108 | + // | | |
109 | + // -z | |
110 | + | |
111 | + float originX = MTPianoKeyboardDesign::GetPortOriginX(0); | |
112 | + | |
113 | + //鍵盤の1/2の幅だけ高音側に移動 | |
114 | + return originX + GetWhiteKeyStep() / 2.0f; | |
115 | +} | |
116 | + | |
117 | +//****************************************************************************** | |
78 | 118 | // ポート原点Y座標取得 |
79 | 119 | //****************************************************************************** |
80 | 120 | float MTPianoKeyboardDesignMod::GetPortOriginY( |
81 | - unsigned char portNo | |
121 | + int keyboardIndex, | |
122 | + float antiResizeScale, | |
123 | + bool flip | |
82 | 124 | ) |
83 | 125 | { |
84 | - return 0; | |
126 | + // angle: 120°〜300°(rotateX: 90°, rotateZ: 90°) | |
127 | + // +y | |
128 | + // | | |
129 | + // +z<---0-----------------------------Ch.15------------>-z | |
130 | + // | | |
131 | + // | +--------------+ | |
132 | + // | portC +--------------@ Ch.0 | |
133 | + // | Ch.15 | |
134 | + // | | |
135 | + // | +--------------+ | |
136 | + // | portB +--------------@ Ch.0 | |
137 | + // | Ch.15 | |
138 | + // | | |
139 | + // | +--------------+ @:OriginY(for portA,B,C) | |
140 | + // | portA +--------------@ Ch.0 | |
141 | + // | | |
142 | + // -y | |
143 | + | |
144 | + // angle: 0°〜120°or 300°〜360°(rotateX: -90°, rotateZ: 90°) | |
145 | + // +y | |
146 | + // Ch.15 | | |
147 | + // | | |
148 | + // +--------------+ | | |
149 | + // portA +--------------@ Ch.0 | | |
150 | + // Ch.15 | | |
151 | + // | | |
152 | + // +--------------+ | | |
153 | + // portB +--------------@ Ch.0 | | |
154 | + // Ch.15 | | |
155 | + // | | |
156 | + // +--------------+ | | |
157 | + // +z<----------portC +--------------@ Ch.0---0-------------->-z | |
158 | + // | | |
159 | + // | @:OriginY(for portA,B,C) | |
160 | + // -y | |
161 | + | |
162 | + float portWidth = GetChStep() * 16.0f; | |
163 | + | |
164 | + // TODO シングルキーボードの判定方法を再検討 | |
165 | + int keyboardDispNum = GetKeyboardMaxDispNum() > 1 ? m_PortList.GetSize() : 1; | |
166 | + | |
167 | + float originY = portWidth * (keyboardDispNum - keyboardIndex - 1); | |
168 | + | |
169 | + if (!flip) { | |
170 | + originY = -(originY + GetChStep() * 15.0f); | |
171 | + } | |
172 | + | |
173 | + //キーボードリサイズ後に正しいポート間隔となるよう逆比をかける | |
174 | + originY *= antiResizeScale; | |
175 | + | |
176 | + //鍵盤の1/4の高さだけ下に | |
177 | + originY -= GetWhiteKeyHeight() / 4.0f; | |
178 | + | |
179 | + return originY; | |
85 | 180 | } |
86 | 181 | |
87 | 182 | //****************************************************************************** |
88 | 183 | // ポート原点Z座標取得 |
89 | 184 | //****************************************************************************** |
90 | 185 | float MTPianoKeyboardDesignMod::GetPortOriginZ( |
91 | - unsigned char portNo | |
186 | + int keyboardIndex, | |
187 | + float rippleMargin, | |
188 | + float antiResizeScale, | |
189 | + bool flip | |
92 | 190 | ) |
93 | 191 | { |
192 | + // angle: 120°〜300°(rotateX: 90°, rotateZ: 90°) | |
193 | + // +z | |
194 | + // | | |
195 | + // -x<----------0---------->+x | |
196 | + // | -RippleMargin | |
197 | + // +----+----+ | |
198 | + // | | | @:OriginZ | |
199 | + // | | | | |
200 | + // | | | | |
201 | + // | | | | |
202 | + // @----+----+ | |
203 | + // Note #0 | #127 | |
204 | + // -z | |
205 | + | |
206 | + // angle: 0°〜120°or 300°〜360°(rotateX: -90°, rotateZ: 90°) | |
207 | + // +z | |
208 | + // | | |
209 | + // Note #0 | #127 | |
210 | + // +----+----+ | |
211 | + // | | | @:OriginZ | |
212 | + // | | | | |
213 | + // | | | | |
214 | + // | | | | |
215 | + // @----+----+ | |
216 | + // | +RippleMargin | |
217 | + // -x<----------0---------->+x | |
218 | + // | | |
219 | + // -z | |
220 | + | |
221 | + float originZ; | |
222 | + | |
223 | + //キーボードリサイズ後に正しいリップルマージンとなるよう逆比をかける | |
224 | + rippleMargin *= antiResizeScale; | |
225 | + | |
226 | + if (!flip) { | |
227 | + originZ = -(GetWhiteKeyLen() + rippleMargin); | |
228 | + } | |
229 | + else { | |
230 | + originZ = rippleMargin; | |
231 | + } | |
94 | 232 | |
95 | - return 0; | |
233 | + return originZ; | |
96 | 234 | } |
97 | 235 | |
98 | 236 | //****************************************************************************** |
@@ -171,17 +309,28 @@ D3DXCOLOR MTPianoKeyboardDesignMod::GetActiveKeyColor( | ||
171 | 309 | // キーボード基準座標取得 |
172 | 310 | //****************************************************************************** |
173 | 311 | D3DXVECTOR3 MTPianoKeyboardDesignMod::GetKeyboardBasePos( |
174 | - unsigned char portNo, | |
175 | - unsigned char chNo, | |
176 | - float scale | |
312 | + int keyboardIndex, | |
313 | + float rippleMargin, | |
314 | + float boardHeight, | |
315 | + float angle | |
177 | 316 | ) |
178 | 317 | { |
179 | 318 | float ox, oy, oz = 0.0f; |
180 | 319 | |
320 | + //ロール角度によって描画方法を切り替える | |
321 | + angle += angle < 0.0f ? 360.0f : 0.0f; | |
322 | + bool flip = !((angle > 120.0f) && (angle < 300.0f)); | |
323 | + | |
324 | + float keyboardWidth = MTPianoKeyboardDesign::GetPortOriginX(0) * -2.0f; | |
325 | + | |
326 | + //キーボード描画時にリサイズがかかってはならない相対座標用の逆リサイズ比 | |
327 | + //対象:ポート間隔、リップルマージン | |
328 | + float antiResizeScale = keyboardWidth / boardHeight; | |
329 | + | |
181 | 330 | //ポート単位の原点座標 |
182 | - ox = GetPortOriginX(portNo); | |
183 | - oy = GetPortOriginY(portNo); | |
184 | - oz = GetPortOriginZ(portNo); | |
331 | + ox = GetPortOriginX(); | |
332 | + oy = GetPortOriginY(keyboardIndex, antiResizeScale, flip); | |
333 | + oz = GetPortOriginZ(keyboardIndex, rippleMargin, antiResizeScale, flip); | |
185 | 334 | |
186 | 335 | return D3DXVECTOR3(ox, oy, oz); |
187 | 336 | } |
@@ -28,8 +28,9 @@ public: | ||
28 | 28 | virtual int Initialize(const TCHAR* pSceneName, SMSeqData* pSeqData); |
29 | 29 | |
30 | 30 | //ポート原点座標取得 |
31 | - virtual float GetPortOriginY(unsigned char portNo); | |
32 | - virtual float GetPortOriginZ(unsigned char portNo); | |
31 | + float GetPortOriginX(); | |
32 | + float GetPortOriginY(int keyboardIndex, float antiResizeScale, bool flip); | |
33 | + float GetPortOriginZ(int keyboardIndex, float rippleMargin, float antiResizeScale, bool flip); | |
33 | 34 | |
34 | 35 | //チャンネル間隔取得 |
35 | 36 | float GetChStep(); |
@@ -43,7 +44,7 @@ public: | ||
43 | 44 | ); |
44 | 45 | |
45 | 46 | //キーボード基準座標取得 |
46 | - virtual D3DXVECTOR3 GetKeyboardBasePos(unsigned char portNo, unsigned char chNo, float scale); | |
47 | + D3DXVECTOR3 GetKeyboardBasePos(int keyboardIndex, float rippleMargin, float boardHeight, float angle); | |
47 | 48 | |
48 | 49 | protected: |
49 | 50 |
@@ -92,8 +92,7 @@ int MTPianoKeyboardMod::Transform( | ||
92 | 92 | D3DXMATRIX moveMatrix1; |
93 | 93 | D3DXMATRIX moveMatrix2; |
94 | 94 | D3DXMATRIX moveMatrix3; |
95 | - D3DXMATRIX worldMatrix1; | |
96 | - D3DXMATRIX worldMatrix2; | |
95 | + D3DXMATRIX worldMatrix; | |
97 | 96 | |
98 | 97 | //行列初期化 |
99 | 98 | D3DXMatrixIdentity(&scaleMatrix); |
@@ -102,8 +101,7 @@ int MTPianoKeyboardMod::Transform( | ||
102 | 101 | D3DXMatrixIdentity(&rotateMatrix3); |
103 | 102 | D3DXMatrixIdentity(&moveMatrix1); |
104 | 103 | D3DXMatrixIdentity(&moveMatrix2); |
105 | - D3DXMatrixIdentity(&worldMatrix1); | |
106 | - D3DXMatrixIdentity(&worldMatrix2); | |
104 | + D3DXMatrixIdentity(&worldMatrix); | |
107 | 105 | |
108 | 106 | //回転行列 |
109 | 107 |
@@ -112,11 +110,11 @@ int MTPianoKeyboardMod::Transform( | ||
112 | 110 | } |
113 | 111 | |
114 | 112 | if((rollAngle > 120.0f) && (rollAngle < 300.0f)) { |
115 | - D3DXMatrixRotationX(&rotateMatrix1, D3DXToRadian(90.0f)); | |
116 | - D3DXMatrixRotationZ(&rotateMatrix2, D3DXToRadian(90.0f)); | |
113 | + D3DXMatrixRotationX(&rotateMatrix1, D3DX_PI / 2.0f); | |
114 | + D3DXMatrixRotationZ(&rotateMatrix2, D3DX_PI / 2.0f); | |
117 | 115 | } else { |
118 | - D3DXMatrixRotationX(&rotateMatrix1, D3DXToRadian(-90.0f)); | |
119 | - D3DXMatrixRotationZ(&rotateMatrix2, D3DXToRadian(90.0f)); | |
116 | + D3DXMatrixRotationX(&rotateMatrix1, -D3DX_PI / 2.0f); | |
117 | + D3DXMatrixRotationZ(&rotateMatrix2, D3DX_PI / 2.0f); | |
120 | 118 | } |
121 | 119 | |
122 | 120 | D3DXMatrixRotationX(&rotateMatrix3, D3DXToRadian(rollAngle)); |
@@ -130,15 +128,16 @@ int MTPianoKeyboardMod::Transform( | ||
130 | 128 | D3DXMatrixScaling(&scaleMatrix, scale, scale, scale); |
131 | 129 | |
132 | 130 | //行列の合成:ピッチベンド移動1→鍵盤向き補正回転1・2→グリッド面まで移動3→ホイール回転3→スケール→再生面追従移動2 |
133 | - D3DXMatrixMultiply(&worldMatrix1, &moveMatrix1, &rotateMatrix1); | |
134 | - D3DXMatrixMultiply(&worldMatrix2, &worldMatrix1, &rotateMatrix2); | |
135 | - D3DXMatrixMultiply(&worldMatrix1, &worldMatrix2, &moveMatrix3); | |
136 | - D3DXMatrixMultiply(&worldMatrix2, &worldMatrix1, &rotateMatrix3); | |
137 | - D3DXMatrixMultiply(&worldMatrix1, &worldMatrix2, &scaleMatrix); | |
138 | - D3DXMatrixMultiply(&worldMatrix2, &worldMatrix1, &moveMatrix2); | |
131 | + D3DXMatrixMultiply(&worldMatrix, &worldMatrix, &moveMatrix1); | |
132 | + D3DXMatrixMultiply(&worldMatrix, &worldMatrix, &rotateMatrix1); | |
133 | + D3DXMatrixMultiply(&worldMatrix, &worldMatrix, &rotateMatrix2); | |
134 | + D3DXMatrixMultiply(&worldMatrix, &worldMatrix, &moveMatrix3); | |
135 | + D3DXMatrixMultiply(&worldMatrix, &worldMatrix, &rotateMatrix3); | |
136 | + D3DXMatrixMultiply(&worldMatrix, &worldMatrix, &scaleMatrix); | |
137 | + D3DXMatrixMultiply(&worldMatrix, &worldMatrix, &moveMatrix2); | |
139 | 138 | |
140 | 139 | //変換行列設定 |
141 | - m_PrimitiveKeyboard.Transform(worldMatrix2); | |
140 | + m_PrimitiveKeyboard.Transform(worldMatrix); | |
142 | 141 | |
143 | 142 | //EXIT:; |
144 | 143 | return result; |