public MatrixIndexer(List <float[]> fFrames, BVHContent bvh) { for (int f = 0; f < fFrames.Count; f++) { indices.Add(new List <int>()); //Add new frame to collection. for (int b = 0; b < bvh.Skeleton.BoneCount; b++) { #region Set indices BVHNode bone = bvh[b]; FrameCalc fc = bone.calc_fc_from_frame(fFrames[f]); //get frame calc of current matrix. indices[indices.Count - 1].Add(get_index(fc, b, f)); //find index of matrix and add it to frame. #endregion } } #region Calculate matrices from frmCalcs matrices = new Matrix[frmCalcs.Count]; for (int i = 0; i < matrices.Length; i++) { matrices[i] = frmCalcs[i].calc_frame(); } #endregion frmCalcs = null;//Allows Garbage Collector to dispose }
/// <summary> /// init data /// </summary> /// <param name="bvh">bone</param> /// <param name="content">content</param> public BVHNode(BVHNodeString bvh, BVHContent content, int ParentLevel) { #region Set fields value. this.Level = ++ParentLevel; this.Name = StringProccesing.CleanUp(bvh.Name); this.Id = content.Skeleton.BoneCount; #endregion content.Skeleton.BoneCount++; #region Calculate offset and channels. this.Offset = StringProccesing.StringToVector3(bvh.Offset.Replace("OFFSET", "")); this.Channels = StringToChannels( bvh.Channels.Remove(bvh.Channels.IndexOf("CHANNELS"), "CHANNELS".Length + 2)); #endregion #region Add this bones channel to content channel collection. for (int i = 0; i < Channels.Length; i++) { Channels[i].pifl = content.Skeleton.BoneChannels.Count; content.Skeleton.BoneChannels.Add(Channels[i]); } #endregion #region Set EndsiteOffset if needed. if (bvh.EndSiteOffset != null) { EndSiteOffset = StringProccesing.StringToVector3(bvh.EndSiteOffset.Replace("OFFSET", "")); } #endregion #region Initialize children and add them from BVHNodeString. Children = new List <BVHNode>(); for (int i = 0; i < bvh.Children.Count; i++) { Children.Add(new BVHNode(bvh.Children[i], content, Level)); } #endregion #region If bone has children, set EndSiteOffset as Offset of first one. if (EndSiteOffset == null) { EndSiteOffset = Children[0].Offset; } #endregion }
public void calc_cylinder_matrices(BVHContent bvh) { CylinderScaleOffset = new Matrix[bvh.Skeleton.BoneCount]; for (int i = 0; i < BoneCount; i++) { #region point to axis angle Vector3 offset = bvh[i].EndSiteOffset.Value; Vector3 normal = Vector3.Normalize(offset); float length = offset.Length(); float angle = (float)Math.Atan2( (double)new Vector2(normal.X, normal.Z).Length(), normal.Y); Vector3 axis = new Vector3(normal.Z, 0, -normal.X); axis.Normalize(); if (float.IsNaN(axis.X) || float.IsNaN(axis.Y) || float.IsNaN(axis.Z)) { axis = Vector3.UnitX; angle = MathHelper.Pi; } #endregion if (bvh[i].Name == "Head") { CylinderScaleOffset[i] = Matrix.CreateScale(length) * Matrix.CreateScale(new Vector3(3, 0.4f, 3)) * Matrix.CreateFromAxisAngle(axis, angle); } else { CylinderScaleOffset[i] = Matrix.CreateScale(length) * Matrix.CreateFromAxisAngle(axis, angle); } } }
public void calc_cylinder_matrices(BVHContent bvh) { CylinderScaleOffset = new Matrix[BoneCount]; for (int i = 0; i < BoneCount; i++) { #region point to axis angle Vector3 offset = bvh[i].EndSiteOffset.Value; float length = offset.Length(); float angle = (float)Math.Atan2( (double)new Vector2(offset.X, offset.Z).Length(), offset.Y); Vector3 axis = new Vector3(offset.Z, 0, -offset.X); axis.Normalize(); if (float.IsNaN(axis.X) || float.IsNaN(axis.Y) || float.IsNaN(axis.Z)) //if empty offset, set deault axis and angle. { axis = Vector3.UnitX; angle = MathHelper.Pi; } #endregion if (bvh[i].Name == "Head") //rescale head for a better figure. { CylinderScaleOffset[i] = Matrix.CreateScale(length) * Matrix.CreateScale(new Vector3(3, 0.4f, 3)) * Matrix.CreateFromAxisAngle(axis, angle); } else { CylinderScaleOffset[i] = Matrix.CreateScale(length) * Matrix.CreateFromAxisAngle(axis, angle); } } }