• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision673 (tree)
Zeit2011-02-20 18:47:31
Autorwilfrem

Log Message

無視ファイル追加

Ändern Zusammenfassung

Diff

--- branches/XNA4/MikuMikuDanceXNA/MikuMikuDanceXNA.cs (revision 672)
+++ branches/XNA4/MikuMikuDanceXNA/MikuMikuDanceXNA.cs (nonexistent)
@@ -1,45 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
5-using MikuMikuDance.XNA.Model;
6-using Microsoft.Xna.Framework.Content;
7-using MikuMikuDance.XNA.Motion;
8-using MikuMikuDance.XNA.Misc;
9-
10-namespace MikuMikuDance.XNA
11-{
12- public class MikuMikuDanceXNA
13- {
14- public static MikuMikuDanceXNA m_inst;
15- public static MikuMikuDanceXNA Instance
16- {
17- get
18- {
19- if (m_inst == null)
20- m_inst = new MikuMikuDanceXNA();
21- return m_inst;
22- }
23- }
24-
25- public IIKSolver IKSolver { get; set; }
26- public IIKLimitter IKLimitter { get; set; }
27- protected MikuMikuDanceXNA()
28- {
29- //外部からつくらせない
30- //IKソルバとリミッター
31- IKSolver = new CCDSolver();
32- IKLimitter = new DefaltIKLimitter();
33- }
34-
35-
36- public MMDModel LoadModel(string assetName, ContentManager content)
37- {
38- return content.Load<MMDModel>(assetName);
39- }
40- public MMDMotionData LoadMotion(string assetName, ContentManager content)
41- {
42- return content.Load<MMDMotionData>(assetName);
43- }
44- }
45-}
--- branches/XNA4/MikuMikuDanceXNA/Misc/MMDMath.cs (revision 672)
+++ branches/XNA4/MikuMikuDanceXNA/Misc/MMDMath.cs (nonexistent)
@@ -1,132 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
5-using Microsoft.Xna.Framework;
6-
7-namespace MikuMikuDance.XNA.Misc
8-{
9- public static class MMDMath
10- {
11- /// <summary>
12- /// クォータニオンをYaw(Y回転), Pitch(X回転), Roll(Z回転)に分解する関数
13- /// </summary>
14- /// <param name="input">分解するクォータニオン</param>
15- /// <param name="ZRot">Z軸回転</param>
16- /// <param name="XRot">X軸回転(-PI/2~PI/2)</param>
17- /// <param name="YRot">Y軸回転</param>
18- /// <returns>ジンバルロックが発生した時はfalse。ジンバルロックはX軸回転で発生</returns>
19- public static bool FactoringQuaternionZXY(Quaternion input, out float ZRot, out float XRot, out float YRot)
20- {
21- //クォータニオンの正規化
22- Quaternion inputQ = new Quaternion(input.X, input.Y, input.Z, input.W);
23- inputQ.Normalize();
24- //マトリクスを生成する
25- Matrix rot = Matrix.CreateFromQuaternion(inputQ);
26- //ヨー(X軸周りの回転)を取得
27- if (rot.M32 > 1 - 1.0e-4 || rot.M32 < -1 + 1.0e-4)
28- {//ジンバルロック判定
29- XRot = (rot.M32 < 0 ? MathHelper.PiOver2 : -MathHelper.PiOver2);
30- ZRot = 0; YRot = (float)Math.Atan2(-rot.M13, rot.M11);
31- return false;
32- }
33- XRot = -(float)Math.Asin(rot.M32);
34- //ロールを取得
35- ZRot = (float)Math.Asin(rot.M12 / Math.Cos(XRot));
36- if (float.IsNaN(ZRot))
37- {//漏れ対策
38- XRot = (rot.M32 < 0 ? MathHelper.PiOver2 : -MathHelper.PiOver2);
39- ZRot = 0; YRot = (float)Math.Atan2(-rot.M13, rot.M11);
40- return false;
41- }
42- if (rot.M22 < 0)
43- ZRot = MathHelper.Pi - ZRot;
44- //ピッチを取得
45- YRot = (float)Math.Atan2(rot.M31, rot.M33);
46- return true;
47- }
48- /// <summary>
49- /// クォータニオンをX,Y,Z回転に分解する関数
50- /// </summary>
51- /// <param name="input">分解するクォータニオン</param>
52- /// <param name="XRot">X軸回転</param>
53- /// <param name="YRot">Y軸回転(-PI/2~PI/2)</param>
54- /// <param name="ZRot">Z軸回転</param>
55- /// <returns></returns>
56- public static bool FactoringQuaternionXYZ(Quaternion input, out float XRot, out float YRot, out float ZRot)
57- {
58- //クォータニオンの正規化
59- Quaternion inputQ = new Quaternion(input.X, input.Y, input.Z, input.W);
60- inputQ.Normalize();
61- //マトリクスを生成する
62- Matrix rot = Matrix.CreateFromQuaternion(inputQ);
63- //Y軸回りの回転を取得
64- if (rot.M13 > 1 - 1.0e-4 || rot.M13 < -1 + 1.0e-4)
65- {//ジンバルロック判定
66- XRot = 0;
67- YRot = (rot.M13 < 0 ? MathHelper.PiOver2 : -MathHelper.PiOver2);
68- ZRot = -(float)Math.Atan2(-rot.M21, rot.M22);
69- return false;
70- }
71- YRot = -(float)Math.Asin(rot.M13);
72- //X軸回りの回転を取得
73- XRot = (float)Math.Asin(rot.M23 / Math.Cos(YRot));
74- if (float.IsNaN(XRot))
75- {//ジンバルロック判定(漏れ対策)
76- XRot = 0;
77- YRot = (rot.M13 < 0 ? MathHelper.PiOver2 : -MathHelper.PiOver2);
78- ZRot = -(float)Math.Atan2(-rot.M21, rot.M22);
79- return false;
80- }
81- if (rot.M33 < 0)
82- XRot = MathHelper.Pi - XRot;
83- //Z軸回りの回転を取得
84- ZRot = (float)Math.Atan2(rot.M12, rot.M11);
85- return true;
86- }
87- /// <summary>
88- /// クォータニオンをY,Z,X回転に分解する関数
89- /// </summary>
90- /// <param name="input">分解するクォータニオン</param>
91- /// <param name="YRot">Y軸回転</param>
92- /// <param name="ZRot">Z軸回転(-PI/2~PI/2)</param>
93- /// <param name="XRot">X軸回転</param>
94- /// <returns></returns>
95- public static bool FactoringQuaternionYZX(Quaternion input, out float YRot, out float ZRot, out float XRot)
96- {
97- //クォータニオンの正規化
98- Quaternion inputQ = new Quaternion(input.X, input.Y, input.Z, input.W);
99- inputQ.Normalize();
100- //マトリクスを生成する
101- Matrix rot = Matrix.CreateFromQuaternion(inputQ);
102- //Z軸回りの回転を取得
103- if (rot.M21 > 1 - 1.0e-4 || rot.M21 < -1 + 1.0e-4)
104- {//ジンバルロック判定
105- YRot = 0;
106- ZRot = (rot.M21 < 0 ? MathHelper.PiOver2 : -MathHelper.PiOver2);
107- XRot = -(float)Math.Atan2(-rot.M32, rot.M33);
108- return false;
109- }
110- ZRot = -(float)Math.Asin(rot.M21);
111- //Y軸回りの回転を取得
112- YRot = (float)Math.Asin(rot.M31 / Math.Cos(ZRot));
113- if (float.IsNaN(YRot))
114- {//ジンバルロック判定(漏れ対策)
115- YRot = 0;
116- ZRot = (rot.M21 < 0 ? MathHelper.PiOver2 : -MathHelper.PiOver2);
117- XRot = -(float)Math.Atan2(-rot.M32, rot.M33);
118- return false;
119- }
120- if (rot.M11 < 0)
121- YRot = MathHelper.Pi - YRot;
122- //X軸回りの回転を取得
123- XRot = (float)Math.Atan2(rot.M23, rot.M22);
124- return true;
125- }
126-
127- public static bool CheckNaN(Vector3 outPosition)
128- {
129- return float.IsNaN(outPosition.X) || float.IsNaN(outPosition.Y) || float.IsNaN(outPosition.Z);
130- }
131- }
132-}
--- branches/XNA4/MikuMikuDanceXNA/Misc/QuatTransform.cs (revision 672)
+++ branches/XNA4/MikuMikuDanceXNA/Misc/QuatTransform.cs (nonexistent)
@@ -1,247 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
5-using Microsoft.Xna.Framework;
6-
7-namespace MikuMikuDance.XNA.Misc
8-{
9-
10- /// <summary>
11- /// クォータニオンを使った回転と平行移動を表すことのできる頂点変換用構造体
12- /// 通常の行列の半分以下のメモリ使用量になる
13- /// </summary>
14- public struct QuatTransform
15- {
16- #region フィールド
17-
18- /// <summary>
19- /// 回転
20- /// </summary>
21- public Quaternion Rotation;
22-
23- /// <summary>
24- /// 平行移動
25- /// </summary>
26- public Vector3 Translation;
27-
28- #endregion
29- /// <summary>
30- /// 恒等QuatTransformを返します
31- /// </summary>
32- public static QuatTransform Identity { get { return new QuatTransform(Quaternion.Identity, Vector3.Zero); } }
33- #region 初期化
34-
35- /// <summary>
36- /// クォータニオンと平行移動を指定して生成する
37- /// </summary>
38- /// <param name="rotation"></param>
39- /// <param name="translation"></param>
40- public QuatTransform(Quaternion rotation, Vector3 translation)
41- {
42- Rotation = rotation;
43- Translation = translation;
44- }
45-
46- /// <summary>
47- /// 指定された行列から生成する
48- /// </summary>
49- /// <param name="matrix"></param>
50- /// <returns></returns>
51- public static QuatTransform FromMatrix(Matrix matrix)
52- {
53- // 行列の分解
54- Quaternion rotation;
55- Vector3 translation;
56- Vector3 scale;
57- matrix.Decompose(out scale, out rotation, out translation);
58-
59- // 一意のスケールか?
60- if (!CloseEnough(scale.X, scale.Y) || !CloseEnough(scale.X, scale.Z))
61- {
62- throw new InvalidOperationException(
63- "一意のスケール(X,Y,Zが同じスケール値)ではありません");
64- }
65-
66- if (!CloseEnough(scale.X, 1.0f))
67- throw new InvalidOperationException("スケール値が1以外です");
68-
69- return new QuatTransform(rotation, translation);
70- }
71-
72- static bool CloseEnough(float a, float b)
73- {
74- return (System.Math.Abs(a - b) < 1e-4f);
75- }
76-
77- #endregion
78-
79- /// <summary>
80- /// QuatTransformの結合
81- /// </summary>
82- public static void Multiply(ref QuatTransform value1, ref QuatTransform value2, out QuatTransform result)
83- {
84- // 平行移動の算出
85- Vector3 newTranslation;
86- value2.Rotation.Normalize();
87- Vector3.Transform(ref value1.Translation, ref value2.Rotation,
88- out newTranslation);
89-
90- newTranslation.X += value2.Translation.X;
91- newTranslation.Y += value2.Translation.Y;
92- newTranslation.Z += value2.Translation.Z;
93-
94- // 回転部分の結合
95- Quaternion.Concatenate(ref value1.Rotation, ref value2.Rotation,
96- out result.Rotation);
97-
98- result.Translation = newTranslation;
99- //正規化
100- result.Rotation.Normalize();
101-
102- }
103- /// <summary>
104- /// QuatTransformの結合
105- /// </summary>
106- public static QuatTransform operator *(QuatTransform value1, QuatTransform value2)
107- {
108- QuatTransform result;
109- QuatTransform.Multiply(ref value1, ref value2, out result);
110- return result;
111- }
112- internal Matrix CreateMatrix()
113- {
114- Matrix move = Matrix.CreateTranslation(Translation);
115- Matrix rot = Matrix.CreateFromQuaternion(Rotation);
116- Matrix result;
117- Matrix.Multiply(ref rot, ref move, out result);
118- return result;//回転・移動の順にかけ合わせる
119- }
120- public void CreateMatrix(out Matrix result)
121- {
122- float ww = Rotation.W * Rotation.W - 0.5f;
123- float num11 = ww + Rotation.X * Rotation.X;
124- float num12 = Rotation.X * Rotation.Y + Rotation.W * Rotation.Z;
125- float num13 = Rotation.X * Rotation.Z - Rotation.W * Rotation.Y;
126-
127- float num21 = Rotation.X * Rotation.Y + Rotation.W * Rotation.Z;
128- float num22 = ww - Rotation.Y * Rotation.Y;
129- float num23 = Rotation.Y * Rotation.Z + Rotation.W * Rotation.X;
130-
131- float num31 = Rotation.X * Rotation.Z + Rotation.W * Rotation.Y;
132- float num32 = Rotation.Y * Rotation.Z - Rotation.W * Rotation.X;
133- float num33 = ww + Rotation.Z * Rotation.Z;
134-
135- result.M11 = num11 * 2f;
136- result.M12 = num12 * 2f;
137- result.M13 = num13 * 2f;
138- result.M14 = 0;
139- result.M21 = num21 * 2f;
140- result.M22 = num22 * 2f;
141- result.M23 = num23 * 2f;
142- result.M24 = 0;
143- result.M31 = num31 * 2f;
144- result.M32 = num32 * 2f;
145- result.M33 = num33 * 2f;
146- result.M34 = 0;
147- result.M41 = Translation.X;
148- result.M42 = Translation.Y;
149- result.M43 = Translation.Z;
150- result.M44 = 1;
151- }
152- /// <summary>
153- /// 移動QuatTransformを返します
154- /// </summary>
155- /// <param name="x">X移動</param>
156- /// <param name="y">Y移動</param>
157- /// <param name="z">Z移動</param>
158- /// <returns>移動QuatTransform</returns>
159- public static QuatTransform CreateTranslation(float x, float y, float z)
160- {
161- return new QuatTransform(Quaternion.Identity, new Vector3(x, y, z));
162- }
163- /// <summary>
164- /// 移動QuatTransformを返します
165- /// </summary>
166- /// <param name="x">X移動</param>
167- /// <param name="y">Y移動</param>
168- /// <param name="z">Z移動</param>
169- /// <param name="result">移動QuatTransform</param>
170- public static void CreateTranslation(float x, float y, float z, out QuatTransform result)
171- {
172- result = new QuatTransform(Quaternion.Identity, new Vector3(x, y, z));
173- }
174-
175- /// <summary>
176- /// X軸回転QuatTransformを返します
177- /// </summary>
178- /// <param name="rot">X回転</param>
179- /// <returns>X軸回転QuatTransform</returns>
180- public static QuatTransform CreateRotationX(float rot)
181- {
182- return new QuatTransform(Quaternion.CreateFromYawPitchRoll(0, rot, 0), Vector3.Zero);
183- }
184- /// <summary>
185- /// X軸回転QuatTransformを返します
186- /// </summary>
187- /// <param name="rot">X回転</param>
188- /// <param name="result">X軸回転QuatTransform</param>
189- public static void CreateRotationX(float rot, out QuatTransform result)
190- {
191- result = new QuatTransform();
192- Quaternion.CreateFromYawPitchRoll(0, rot, 0, out result.Rotation);
193- }
194- /// <summary>
195- /// Y軸回転QuatTransformを返します
196- /// </summary>
197- /// <param name="rot">Y回転</param>
198- /// <returns>Y軸回転QuatTransform</returns>
199- public static QuatTransform CreateRotationY(float rot)
200- {
201- return new QuatTransform(Quaternion.CreateFromYawPitchRoll(rot, 0, 0), Vector3.Zero);
202- }
203- /// <summary>
204- /// Y軸回転QuatTransformを返します
205- /// </summary>
206- /// <param name="rot">Y回転</param>
207- /// <param name="result">Y軸回転QuatTransform</param>
208- public static void CreateRotationY(float rot, out QuatTransform result)
209- {
210- result = new QuatTransform();
211- Quaternion.CreateFromYawPitchRoll(rot, 0, 0, out result.Rotation);
212- }
213- /// <summary>
214- /// Z軸回転QuatTransformを返します
215- /// </summary>
216- /// <param name="rot">Z回転</param>
217- /// <returns>Z軸回転QuatTransform</returns>
218- public static QuatTransform CreateRotationZ(float rot)
219- {
220- return new QuatTransform(Quaternion.CreateFromYawPitchRoll(0, 0, rot), Vector3.Zero);
221- }
222- /// <summary>
223- /// Z軸回転QuatTransformを返します
224- /// </summary>
225- /// <param name="rot">Z回転</param>
226- /// <param name="result">Z軸回転QuatTransform</param>
227- public static void CreateRotationZ(float rot, out QuatTransform result)
228- {
229- result = new QuatTransform();
230- Quaternion.CreateFromYawPitchRoll(0, 0, rot, out result.Rotation);
231- }
232-
233- /// <summary>
234- /// 姿勢の線形補間
235- /// </summary>
236- /// <param name="pose1">姿勢1</param>
237- /// <param name="pose2">姿勢2</param>
238- /// <param name="amount">補完係数(0-1)</param>
239- /// <param name="result">線形補間された姿勢</param>
240- /// <remarks>Quaternionは球状線形補間を使用</remarks>
241- internal static void Lerp(ref QuatTransform pose1, ref QuatTransform pose2, float amount, out QuatTransform result)
242- {
243- Vector3.Lerp(ref pose1.Translation, ref pose2.Translation, amount, out result.Translation);
244- Quaternion.Slerp(ref pose1.Rotation, ref pose2.Rotation, amount, out result.Rotation);
245- }
246- }
247-}
--- branches/XNA4/MikuMikuDanceXNA/Misc/MMDProfiler.cs (revision 672)
+++ branches/XNA4/MikuMikuDanceXNA/Misc/MMDProfiler.cs (nonexistent)
@@ -1,35 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
5-using System.Diagnostics;
6-using Microsoft.Xna.Framework;
7-using MikuMikuDance.XNA.Threads;
8-
9-namespace MikuMikuDance.XNA.Misc
10-{
11- public delegate void BeginMarkDelegate(int mmdxThreadIndex, string key, Color color);
12- public delegate void EndMarkDelegate(int mmdxThreadIndex, string key);
13-
14- public static class MMDProfiler
15- {
16- public static event BeginMarkDelegate MMDBeginMark;
17- public static event EndMarkDelegate MMDEndMark;
18- internal static void BeginMark(string key, Color color)
19- {
20- if (MMDBeginMark != null)
21- {
22- int threadIndex = MMDThreadManager.ThreadID;//ThreadID取得
23- MMDBeginMark(threadIndex, key, color);
24- }
25- }
26- internal static void EndMark(string key)
27- {
28- if (MMDEndMark != null)
29- {
30- int threadIndex = MMDThreadManager.ThreadID;//ThreadID取得
31- MMDEndMark(threadIndex, key);
32- }
33- }
34- }
35-}
Show on old repository browser