Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/tsoview/TDCG/TMOFile.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2274 by nomeu, Mon Oct 13 18:56:07 2014 UTC revision 2275 by nomeu, Fri Dec 22 00:21:06 2017 UTC
# Line 204  namespace TDCG Line 204  namespace TDCG
204              Dictionary<string, TMONode> motion_nodes = new Dictionary<string, TMONode>();              Dictionary<string, TMONode> motion_nodes = new Dictionary<string, TMONode>();
205    
206              foreach (TMONode node in motion.nodes)              foreach (TMONode node in motion.nodes)
207                  try {                  try
208                    {
209                      motion_nodes.Add(node.Name, node);                      motion_nodes.Add(node.Name, node);
210                  } catch (ArgumentException) {                  }
211                    catch (ArgumentException)
212                    {
213                      Console.WriteLine("node {0} already exists.", node.Name);                      Console.WriteLine("node {0} already exists.", node.Name);
214                  }                  }
215              foreach (TMONode node in nodes)              foreach (TMONode node in nodes)
216              {              {
217                  if (! motion_nodes.ContainsKey(node.Name))                  if (!motion_nodes.ContainsKey(node.Name))
218                  {                  {
219                      throw new ArgumentException("error: node not found in motion: " + node.Name);                      throw new ArgumentException("error: node not found in motion: " + node.Name);
220                  }                  }
221                  try {                  try
222                    {
223                      source_nodes.Add(node.Name, node);                      source_nodes.Add(node.Name, node);
224                  } catch (ArgumentException) {                  }
225                    catch (ArgumentException)
226                    {
227                      Console.WriteLine("node {0} already exists.", node.Name);                      Console.WriteLine("node {0} already exists.", node.Name);
228                  }                  }
229              }              }
# Line 243  namespace TDCG Line 249  namespace TDCG
249              TMOFrame[] append_frames = new TMOFrame[append_length];              TMOFrame[] append_frames = new TMOFrame[append_length];
250              for (int i = 0; i < motion.frames.Length; i++)              for (int i = 0; i < motion.frames.Length; i++)
251                  append_frames[i] = TMOFrame.Select(source_frame, motion.frames[i], id_pair);                  append_frames[i] = TMOFrame.Select(source_frame, motion.frames[i], id_pair);
252                    
253              int old_length = frames.Length;              int old_length = frames.Length;
254              Array.Resize(ref frames, frames.Length + append_length);              Array.Resize(ref frames, frames.Length + append_length);
255              Array.Copy(append_frames, 0, frames, old_length, append_length);              Array.Copy(append_frames, 0, frames, old_length, append_length);
256              this.opt0 = frames.Length-1;              this.opt0 = frames.Length - 1;
257          }          }
258    
259          /// <summary>          /// <summary>
# Line 261  namespace TDCG Line 267  namespace TDCG
267              int[] id_pair = CreateNodeIdPair(motion);              int[] id_pair = CreateNodeIdPair(motion);
268    
269              int i0 = (frames.Length > 1) ? frames.Length - 1 - 1 : 0;              int i0 = (frames.Length > 1) ? frames.Length - 1 - 1 : 0;
270              int i1 = frames.Length-1;              int i1 = frames.Length - 1;
271              int i2 = 0;              int i2 = 0;
272              int i3 = ( motion.frames.Length > 1 ) ? 1 : 0;              int i3 = (motion.frames.Length > 1) ? 1 : 0;
273    
274              TMOFrame frame0 = frames[i0];              TMOFrame frame0 = frames[i0];
275              TMOFrame frame1 = frames[i1];              TMOFrame frame1 = frames[i1];
# Line 274  namespace TDCG Line 280  namespace TDCG
280              int old_length = frames.Length;              int old_length = frames.Length;
281              Array.Resize(ref frames, frames.Length + append_length);              Array.Resize(ref frames, frames.Length + append_length);
282              Array.Copy(interp_frames, 0, frames, old_length, append_length);              Array.Copy(interp_frames, 0, frames, old_length, append_length);
283              this.opt0 = frames.Length-1;              this.opt0 = frames.Length - 1;
284          }          }
285    
286          /// <summary>          /// <summary>
# Line 306  namespace TDCG Line 312  namespace TDCG
312                  return;                  return;
313              if (frame_index < 0)              if (frame_index < 0)
314                  return;                  return;
315              if (frame_index > frames.Length-1)              if (frame_index > frames.Length - 1)
316                  return;                  return;
317              if (frame_index > 0)              if (frame_index > 0)
318                  Array.Copy(frames, frame_index, frames, 0, 1);                  Array.Copy(frames, frame_index, frames, 0, 1);
# Line 367  namespace TDCG Line 373  namespace TDCG
373              TMOFrame[] interp_frames = new TMOFrame[append_length];              TMOFrame[] interp_frames = new TMOFrame[append_length];
374              for (int i = 0; i < motion.frames.Length; i++)              for (int i = 0; i < motion.frames.Length; i++)
375                  interp_frames[i] = TMOFrame.AddSub(source_frame, motion.frames[i], motion_frame, id_pair);                  interp_frames[i] = TMOFrame.AddSub(source_frame, motion.frames[i], motion_frame, id_pair);
376                    
377              int old_length = frames.Length;              int old_length = frames.Length;
378              Array.Resize(ref frames, frames.Length + append_length);              Array.Resize(ref frames, frames.Length + append_length);
379              Array.Copy(interp_frames, 0, frames, old_length, append_length);              Array.Copy(interp_frames, 0, frames, old_length, append_length);
380              this.opt0 = frames.Length-1;              this.opt0 = frames.Length - 1;
381          }          }
382    
383          /// <summary>          /// <summary>
# Line 728  namespace TDCG Line 734  namespace TDCG
734    
735              float p0 = 0.0f;              float p0 = 0.0f;
736              float p2 = 1.0f;              float p2 = 1.0f;
737              float dt = 1.0f/length;              float dt = 1.0f / length;
738              for (int i = 0; i < length; i++)              for (int i = 0; i < length; i++)
739              {              {
740                  float t = dt*i;                  float t = dt * i;
741                  float p = t*t*(p2-2*p1+p0) + t*(2*p1-2*p0) + p0;                  float p = t * t * (p2 - 2 * p1 + p0) + t * (2 * p1 - 2 * p0) + p0;
742                  Matrix m = Matrix.Scaling(Vector3.Lerp(scaling1, scaling2, p)) * Matrix.RotationQuaternion(Quaternion.Slerp(q1, q2, p)) * Matrix.Translation(Vector3.CatmullRom(v0, v1, v2, v3, p));                  Matrix m = Matrix.Scaling(Vector3.Lerp(scaling1, scaling2, p)) * Matrix.RotationQuaternion(Quaternion.Slerp(q1, q2, p)) * Matrix.Translation(Vector3.CatmullRom(v0, v1, v2, v3, p));
743                  ret[i] = new TMOMat(ref m);                  ret[i] = new TMOMat(ref m);
744              }              }
# Line 891  namespace TDCG Line 897  namespace TDCG
897              ret.matrices = new TMOMat[frame0.matrices.Length];              ret.matrices = new TMOMat[frame0.matrices.Length];
898              for (int i = 0; i < frame0.matrices.Length; i++)              for (int i = 0; i < frame0.matrices.Length; i++)
899              {              {
900                  ret.matrices[i] = TMOMat.AddSub( frame0.matrices[i], frame1.matrices[id_pair[i]], frame2.matrices[id_pair[i]] );                  ret.matrices[i] = TMOMat.AddSub(frame0.matrices[i], frame1.matrices[id_pair[i]], frame2.matrices[id_pair[i]]);
901              }              }
902              return ret;              return ret;
903          }          }
# Line 1266  namespace TDCG Line 1272  namespace TDCG
1272              }              }
1273          }          }
1274    
1275            static Vector3 Reciprocal(Vector3 v)
1276            {
1277                return new Vector3(1 / v.X, 1 / v.Y, 1 / v.Z);
1278            }
1279    
1280            static void ScalingLocal(ref Matrix m, Vector3 scaling)
1281            {
1282                m.M11 *= scaling.X;
1283                m.M21 *= scaling.X;
1284                m.M31 *= scaling.X;
1285                m.M41 *= scaling.X;
1286    
1287                m.M12 *= scaling.Y;
1288                m.M22 *= scaling.Y;
1289                m.M32 *= scaling.Y;
1290                m.M42 *= scaling.Y;
1291    
1292                m.M13 *= scaling.Z;
1293                m.M23 *= scaling.Z;
1294                m.M33 *= scaling.Z;
1295                m.M43 *= scaling.Z;
1296            }
1297    
1298          /// <summary>          /// <summary>
1299          /// 変形行列。これは 拡大行列 x 回転行列 x 位置行列 です。          /// 変形行列。これは 拡大行列 x 回転行列 x 位置行列 です。
1300          /// </summary>          /// </summary>
# Line 1275  namespace TDCG Line 1304  namespace TDCG
1304              {              {
1305                  if (need_update_transformation)                  if (need_update_transformation)
1306                  {                  {
1307                      transformation_matrix = ScalingMatrix * RotationMatrix * TranslationMatrix;                      Matrix m = ScalingMatrix * RotationMatrix;
1308                        m.M41 = translation.X;
1309                        m.M42 = translation.Y;
1310                        m.M43 = translation.Z;
1311                        if (parent != null)
1312                            ScalingLocal(ref m, Reciprocal(parent.Scaling));
1313                        transformation_matrix = m;
1314                      need_update_transformation = false;                      need_update_transformation = false;
1315                  }                  }
1316                  return transformation_matrix;                  return transformation_matrix;
# Line 1283  namespace TDCG Line 1318  namespace TDCG
1318              set              set
1319              {              {
1320                  transformation_matrix = value;                  transformation_matrix = value;
1321                  translation = Helper.DecomposeMatrix(ref value, out scaling);                  Matrix m = value;
1322                  rotation = Quaternion.RotationMatrix(value);                  if (parent != null)
1323                        ScalingLocal(ref m, parent.Scaling);
1324                    translation = Helper.DecomposeMatrix(ref m, out scaling);
1325                    rotation = Quaternion.RotationMatrix(m);
1326              }              }
1327          }          }
1328      }      }

Legend:
Removed from v.2274  
changed lines
  Added in v.2275

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26