/* * Camera.cs * Authors: Benjamin Nitschke (based on his tutorial project SkinningWithColladaModelsInXna at abi.exdream.com) * August Zinsser * * Copyright August Zinsser 2007 * This program is distributed under the terms of the GNU General Public License */ using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; namespace Pina3D { /// /// Bone loaded from a Collada File. This class virtually untouched from abi.exdream.com. /// class ColladaBone { /// /// Parent bone, very important to get all parent matrices when /// building the finalMatrix for rendering. /// public ColladaBone parent = null; /// /// Children bones, not really used anywhere except for the ShowBones /// helper method, but also useful for debugging. /// public List children = new List(); /// /// Position, very useful to position bones to show bones in 3D, also /// only used for debugging and testing purposes. /// public Vector3 pos; /// /// Initial matrix we get from loading the collada model, it contains /// the start position and is used for the calculation to get the /// absolute and final matrices (see below). /// public Matrix initialMatrix; /// /// Bone number for the skinning process. This is just our internal /// number and children do always have higher numbers, this way going /// through the bones list is quicker and easier. The collada file /// might use a different order, see LoadAnimation for details. /// public int num; /// /// Id and name of this bone, makes debugging and testing easier, but /// it is also used to identify this bone later on in the loading process /// because our bone order might be different from the one in the file. /// public string id; /// /// Animation matrices for the precalculated bone animations. /// These matrices must be set each frame (use time) in order /// for the animation to work. /// public List animationMatrices = new List(); /// /// invBoneMatrix is a special helper matrix loaded directly from /// the collada file. It is used to transform the final matrix /// back to a relative format after transforming and rotating each /// bone with the current animation frame. This is very important /// because else we would always move and rotate vertices around the /// center, but thanks to this inverted skin matrix the correct /// rotation points are used. /// public Matrix invBoneSkinMatrix; /// /// Final absolute matrix, which is calculated in UpdateAnimation each /// frame after all the loading is done. It can directly be used to /// find out the current bone positions, but for rendering we have /// to apply the invBoneSkinMatrix first to transform all vertices into /// the local space. /// public Matrix finalMatrix; /// /// Create bone /// /// Set matrix /// Set parent bone /// Set number /// Set id name public ColladaBone(Matrix setMatrix, ColladaBone setParentBone, int setNum, string setId) { initialMatrix = setMatrix; pos = initialMatrix.Translation; parent = setParentBone; num = setNum; id = setId; invBoneSkinMatrix = Matrix.Identity; } // Bone(setMatrix, setParentBone, setNum) /// /// Get matrix recursively /// /// Matrix public Matrix GetMatrixRecursively() { Matrix ret = initialMatrix; // If we have a parent mesh, we have to multiply the matrix with the // parent matrix. if (parent != null) ret *= parent.GetMatrixRecursively(); return ret; } // GetMatrixRecursively() /// /// To string, useful for debugging and testing. /// /// String public override string ToString() { return "Bone: Id=" + id + ", Num=" + num + ", Position=" + pos; } } }