public void UpdateBoneTransformations(Track[] tracks) { for (int i = 0; i < this.vertexTransformations.Length && i < this.bones.Length; i++ ) { Matrix4 blended = new Matrix4(); float sumWeights = 0; if (tracks != null) { for (int j = 0; j < tracks.Length; j++) { Matrix4 trackMatrix = this.bones[i].GetAnimationMatrix(tracks[j].Time); float trackWeight = tracks[j].Weight; blended.Row0 += trackMatrix.Row0 * trackWeight; blended.Row1 += trackMatrix.Row1 * trackWeight; blended.Row2 += trackMatrix.Row2 * trackWeight; blended.Row3 += trackMatrix.Row3 * trackWeight; sumWeights += trackWeight; } blended.Row0 /= sumWeights; blended.Row1 /= sumWeights; blended.Row2 /= sumWeights; blended.Row3 /= sumWeights; } this.vertexTransformations[i] = Matrix4.Invert(this.bones[i].globalTransformationMatrix) * blended; } Matrix4Helper.ToOpenGL(vertexTransformations, ref vertexTransformationsBuffer); shader.SetMatrix4(vertexTransformationsUniformName, vertexTransformationsBuffer); }
public Track AddTrack(string sampleName) { Track track = FindSample(sampleName); if (track != null) return track; track = new Track(Sample.FindSample(this.samples, sampleName)); List<Track> tracks = new List<Track>(this.tracks); tracks.Add(track); this.tracks = tracks.ToArray(); return track; }