Ejemplo n.º 1
0
        private void importSkeletonJoints(Skeleton skeleton, ASFJoint asfJoint, Joint joint)
        {
            joint.CalculateAbsoluteMatrix();
            for (int i = 0; i < asfJoint.children.Count; i++)
            {
                var asfChild = asfJoint.children[i];
                var child    = new Joint();
                child.Parent = joint;
                child.Name   = asfChild.name;
                child.Length = asfChild.length;

                //get rotation component inherited from the parent rotation
                child.CalculateInitialRelativeMatrix(Matrix.Identity);
                child.CalculateAbsoluteMatrix();
                var trans       = Vector3.TransformCoordinate(Vector3.Zero, child.AbsoluteMatrix);
                var rotationMat = child.AbsoluteMatrix * Matrix.Translation(-trans);

                child.CalculateInitialRelativeMatrix(XnaMathExtensions.CreateRotationMatrixMapDirection(Vector3.UnitX.xna(), asfChild.direction.xna()).dx() * Matrix.Invert(rotationMat));
                //Undo rotation of parent
                //child.RelativeMatrix = XnaMathExtensions.CreateRotationMatrixMapDirection(Vector3.UnitX, asfChild.direction) * Matrix.CreateTranslation(trans) * Matrix.Invert(child.AbsoluteMatrix);
                //child.RelativeMatrix = Matrix.Invert(rotationMat) * XnaMathExtensions.CreateRotationMatrixMapDirection(Vector3.UnitX, asfChild.direction);


                skeleton.Joints.Add(child);
                importSkeletonJoints(skeleton, asfChild, child);
            }
        }
Ejemplo n.º 2
0
        public void ApplyUpdatePacket(IStaticWorldObject obj, StaticWorldObjectUpdatePacket p)
        {
            var o = obj as SimpleStaticWorldObject;

            var newMesh = meshFactory.GetMesh(p.MeshGuid);


            if (o.Mesh != newMesh)
            {
                o.ChangeMesh(newMesh);
            }

            o.WorldMatrix = XnaMathExtensions.CreateMatrixFromFloatArray(p.WorldMatrix, 0);
        }
Ejemplo n.º 3
0
        public void TestXnaMathExtensionCreateRotationMatrixFromDirection()
        {
            XNAGame game = new XNAGame();

            game.DrawEvent +=
                delegate
            {
                var v1 = Vector3.Normalize(new Vector3(1, 4, 2));
                var v2 = Vector3.Normalize(new Vector3(-21, -4, 2));

                var m1 = Vector3.Transform(Vector3.Forward,
                                           XnaMathExtensions.CreateRotationMatrixFromDirectionVector(v1));
                var m2 = Vector3.Transform(Vector3.Forward,
                                           XnaMathExtensions.CreateRotationMatrixFromDirectionVector(v2));
                game.LineManager3D.AddLine(Vector3.Zero, v1 * 2, Color.Red);
                game.LineManager3D.AddLine(Vector3.Zero, v2 * 2, Color.Red);

                game.LineManager3D.AddLine(m1 * 2, m1 * 4, Color.Yellow);
                game.LineManager3D.AddLine(m2 * 2, m2 * 4, Color.Yellow);
            };

            game.Run();
        }