internal void TransformFrameAbsolute(SdkMeshFile file, double time)
        {
            int tick = file.GetAnimationKeyFromTime(time);

            if (this.AnimationFrameIndex != -1)
            {
                SdkMeshAnimationFrame animationFrame   = file.AnimationFrames[this.AnimationFrameIndex];
                SdkMeshAnimationKey   animationKey     = animationFrame.AnimationKeys[tick];
                SdkMeshAnimationKey   animationKeyOrig = animationFrame.AnimationKeys[0];

                XMMatrix mTrans1 = XMMatrix.Translation(-animationKeyOrig.Translation.X, -animationKeyOrig.Translation.Y, -animationKeyOrig.Translation.Z);
                XMMatrix mTrans2 = XMMatrix.Translation(animationKey.Translation.X, animationKey.Translation.Y, animationKey.Translation.Z);

                XMVector quat1 = animationKeyOrig.Orientation;
                quat1 = XMQuaternion.Inverse(quat1);
                XMMatrix mRot1  = XMMatrix.RotationQuaternion(quat1);
                XMMatrix mInvTo = mTrans1 * mRot1;

                XMVector quat2 = animationKey.Orientation;
                XMMatrix mRot2 = XMMatrix.RotationQuaternion(quat2);
                XMMatrix mFrom = mRot2 * mTrans2;

                XMMatrix mOutput = mInvTo * mFrom;
                this.TransformedFrameMatrix = mOutput;
            }
        }
        internal void TransformFrame(SdkMeshFile file, XMMatrix parentWorld, double time)
        {
            // Get the tick data
            XMMatrix mLocalTransform;

            int tick = file.GetAnimationKeyFromTime(time);

            if (this.AnimationFrameIndex == -1)
            {
                mLocalTransform = this.Matrix;
            }
            else
            {
                SdkMeshAnimationFrame animationFrame = file.AnimationFrames[this.AnimationFrameIndex];
                SdkMeshAnimationKey   animationKey   = animationFrame.AnimationKeys[tick];

                // turn it into a matrix (Ignore scaling for now)
                XMFloat3 parentPos  = animationKey.Translation;
                XMMatrix mTranslate = XMMatrix.Translation(parentPos.X, parentPos.Y, parentPos.Z);

                XMVector quat = animationKey.Orientation;

                if (XMVector4.Equal(quat, XMVector.Zero))
                {
                    quat = XMQuaternion.Identity;
                }

                quat = XMQuaternion.Normalize(quat);
                XMMatrix mQuat = XMMatrix.RotationQuaternion(quat);
                mLocalTransform = mQuat * mTranslate;
            }

            // Transform ourselves
            XMMatrix mLocalWorld = mLocalTransform * parentWorld;

            this.TransformedFrameMatrix = mLocalWorld;
            this.WorldPoseFrameMatrix   = mLocalWorld;

            // Transform our siblings
            if (this.SiblingFrameIndex != -1)
            {
                file.Frames[this.SiblingFrameIndex].TransformFrame(file, parentWorld, time);
            }

            // Transform our children
            if (this.ChildFrameIndex != -1)
            {
                file.Frames[this.ChildFrameIndex].TransformFrame(file, mLocalWorld, time);
            }
        }
        private void InitializeObjects()
        {
            // Set up the primary frustum object from a D3D projection matrix
            // NOTE: This can also be done on your camera's projection matrix.  The projection
            // matrix built here is somewhat contrived so it renders well.
            XMMatrix xmProj = XMMatrix.PerspectiveFovLH(XMMath.PIDivFour, 1.77778f, 0.5f, 10.0f);

            this.primaryFrustum        = BoundingFrustum.CreateFromMatrix(xmProj);
            this.primaryFrustum.Origin = new XMFloat3(this.primaryFrustum.Origin.X, this.primaryFrustum.Origin.Y, -7.0f);
            this.cameraOrigins[0]      = new XMVector(0, 0, 0, 0);

            // Set up the primary axis aligned box
            this.primaryAABox.Center  = new XMFloat3(CameraSpacing, 0, 0);
            this.primaryAABox.Extents = new XMFloat3(5, 5, 5);
            this.cameraOrigins[1]     = new XMVector(CameraSpacing, 0, 0, 0);

            // Set up the primary oriented box with some rotation
            this.primaryOrientedBox.Center      = new XMFloat3(-CameraSpacing, 0, 0);
            this.primaryOrientedBox.Extents     = new XMFloat3(5, 5, 5);
            this.primaryOrientedBox.Orientation = XMQuaternion.RotationRollPitchYaw(XMMath.PIDivFour, XMMath.PIDivFour, 0);
            this.cameraOrigins[2] = new XMVector(-CameraSpacing, 0, 0, 0);

            // Set up the primary ray
            this.primaryRay.Origin    = new XMVector(0, 0, CameraSpacing, 0);
            this.primaryRay.Direction = new XMVector(0, 0, 1, 0);
            this.cameraOrigins[3]     = new XMVector(0, 0, CameraSpacing, 0);

            // Initialize all of the secondary objects with default values
            for (int i = 0; i < GroupCount; i++)
            {
                this.secondarySpheres[i].Sphere    = new BoundingSphere(new XMFloat3(0, 0, 0), 1.0f);
                this.secondarySpheres[i].Collision = ContainmentType.Disjoint;

                this.secondaryOrientedBoxes[i].Box       = new BoundingOrientedBox(new XMFloat3(0, 0, 0), new XMFloat3(0.5f, 0.5f, 0.5f), new XMFloat4(0, 0, 0, 1));
                this.secondaryOrientedBoxes[i].Collision = ContainmentType.Disjoint;

                this.secondaryAABoxes[i].Box       = new BoundingBox(new XMFloat3(0, 0, 0), new XMFloat3(0.5f, 0.5f, 0.5f));
                this.secondaryAABoxes[i].Collision = ContainmentType.Disjoint;

                this.secondaryTriangles[i].PointA    = XMVector.Zero;
                this.secondaryTriangles[i].PointB    = XMVector.Zero;
                this.secondaryTriangles[i].PointC    = XMVector.Zero;
                this.secondaryTriangles[i].Collision = ContainmentType.Disjoint;
            }

            // Set up ray hit result box
            this.rayHitResultBox.Box = new BoundingBox(new XMFloat3(0, 0, 0), new XMFloat3(0.05f, 0.05f, 0.05f));
        }
        public override void SetViewParams(XMVector vEyePt, XMVector vLookatPt)
        {
            base.SetViewParams(vEyePt, vLookatPt);

            // Propogate changes to the member arcball
            XMMatrix mRotation = XMMatrix.LookAtLH(vEyePt, vLookatPt, XMVector.FromFloat(0.0f, 1.0f, 0.0f, 0.0f));
            XMVector quat      = XMQuaternion.RotationMatrix(mRotation);

            m_ViewArcBall.SetQuatNow(quat);

            // Set the radius according to the distance
            XMVector vEyeToPoint = XMVector.Subtract(vLookatPt, vEyePt);
            float    len         = XMVector3.Length(vEyeToPoint).X;

            SetRadius(len);

            // View information changed. FrameMove should be called.
            m_bDragSinceLastUpdate = true;
        }
        private void Animate(double fTime)
        {
            float t = (float)(fTime * 0.2);

            float camera0OriginX = this.cameraOrigins[0].X;
            float camera1OriginX = this.cameraOrigins[1].X;
            float camera2OriginX = this.cameraOrigins[2].X;
            float camera3OriginX = this.cameraOrigins[3].X;
            float camera3OriginZ = this.cameraOrigins[3].Z;

            // animate sphere 0 around the frustum
            {
                BoundingSphere sphere = this.secondarySpheres[0].Sphere;

                sphere.Center = new XMFloat3
                {
                    X = 10 * XMScalar.Sin(3 * t),
                    Y = 7 * XMScalar.Cos(5 * t),
                    Z = sphere.Center.Z
                };

                this.secondarySpheres[0].Sphere = sphere;
            }

            // animate oriented box 0 around the frustum
            {
                BoundingOrientedBox box = this.secondaryOrientedBoxes[0].Box;

                box.Center = new XMFloat3
                {
                    X = 8 * XMScalar.Sin(3.5f * t),
                    Y = 5 * XMScalar.Cos(5.1f * t),
                    Z = box.Center.Z
                };

                box.Orientation = XMQuaternion.RotationRollPitchYaw(t * 1.4f, t * 0.2f, t);

                this.secondaryOrientedBoxes[0].Box = box;
            }

            // animate aligned box 0 around the frustum
            {
                BoundingBox box = this.secondaryAABoxes[0].Box;

                box.Center = new XMFloat3
                {
                    X = 10 * XMScalar.Sin(2.1f * t),
                    Y = 7 * XMScalar.Cos(3.8f * t),
                    Z = box.Center.Z
                };

                this.secondaryAABoxes[0].Box = box;
            }

            // animate sphere 1 around the aligned box
            {
                BoundingSphere sphere = this.secondarySpheres[1].Sphere;

                sphere.Center = new XMFloat3
                {
                    X = 8 * XMScalar.Sin(2.9f * t) + camera1OriginX,
                    Y = 8 * XMScalar.Cos(4.6f * t),
                    Z = 8 * XMScalar.Cos(1.6f * t)
                };

                this.secondarySpheres[1].Sphere = sphere;
            }

            // animate oriented box 1 around the aligned box
            {
                BoundingOrientedBox box = this.secondaryOrientedBoxes[1].Box;

                box.Center = new XMFloat3
                {
                    X = 8 * XMScalar.Sin(3.2f * t) + camera1OriginX,
                    Y = 8 * XMScalar.Cos(2.1f * t),
                    Z = 8 * XMScalar.Sin(1.6f * t)
                };

                box.Orientation = XMQuaternion.RotationRollPitchYaw(t * 0.7f, t * 1.3f, t);

                this.secondaryOrientedBoxes[1].Box = box;
            }

            // animate aligned box 1 around the aligned box
            {
                BoundingBox box = this.secondaryAABoxes[1].Box;

                box.Center = new XMFloat3
                {
                    X = 8 * XMScalar.Sin(1.1f * t) + camera1OriginX,
                    Y = 8 * XMScalar.Cos(5.8f * t),
                    Z = 8 * XMScalar.Cos(3.0f * t)
                };

                this.secondaryAABoxes[1].Box = box;
            }

            // animate sphere 2 around the oriented box
            {
                BoundingSphere sphere = this.secondarySpheres[2].Sphere;

                sphere.Center = new XMFloat3
                {
                    X = 8 * XMScalar.Sin(2.2f * t) + camera2OriginX,
                    Y = 8 * XMScalar.Cos(4.3f * t),
                    Z = 8 * XMScalar.Cos(1.8f * t)
                };

                this.secondarySpheres[2].Sphere = sphere;
            }

            // animate oriented box 2 around the oriented box
            {
                BoundingOrientedBox box = this.secondaryOrientedBoxes[2].Box;

                box.Center = new XMFloat3
                {
                    X = 8 * XMScalar.Sin(3.7f * t) + camera2OriginX,
                    Y = 8 * XMScalar.Cos(2.5f * t),
                    Z = 8 * XMScalar.Sin(1.1f * t)
                };

                box.Orientation = XMQuaternion.RotationRollPitchYaw(t * 0.9f, t * 1.8f, t);

                this.secondaryOrientedBoxes[2].Box = box;
            }

            // animate aligned box 2 around the oriented box
            {
                BoundingBox box = this.secondaryAABoxes[2].Box;

                box.Center = new XMFloat3
                {
                    X = 8 * XMScalar.Sin(1.3f * t) + camera2OriginX,
                    Y = 8 * XMScalar.Cos(5.2f * t),
                    Z = 8 * XMScalar.Cos(3.5f * t)
                };

                this.secondaryAABoxes[2].Box = box;
            }

            // triangle points in local space - equilateral triangle with radius of 2
            XMVector trianglePointA = new(0, 2, 0, 0);
            XMVector trianglePointB = new(1.732f, -1, 0, 0);
            XMVector trianglePointC = new(-1.732f, -1, 0, 0);

            XMMatrix triangleCoords;
            XMMatrix translation;

            // animate triangle 0 around the frustum
            triangleCoords = XMMatrix.RotationRollPitchYaw(t * 1.4f, t * 2.5f, t);
            translation    = XMMatrix.Translation(
                5 * XMScalar.Sin(5.3f * t) + camera0OriginX,
                5 * XMScalar.Cos(2.3f * t),
                5 * XMScalar.Sin(3.4f * t));
            triangleCoords = XMMatrix.Multiply(triangleCoords, translation);
            this.secondaryTriangles[0].PointA = XMVector3.Transform(trianglePointA, triangleCoords);
            this.secondaryTriangles[0].PointB = XMVector3.Transform(trianglePointB, triangleCoords);
            this.secondaryTriangles[0].PointC = XMVector3.Transform(trianglePointC, triangleCoords);

            // animate triangle 1 around the aligned box
            triangleCoords = XMMatrix.RotationRollPitchYaw(t * 1.4f, t * 2.5f, t);
            translation    = XMMatrix.Translation(
                8 * XMScalar.Sin(5.3f * t) + camera1OriginX,
                8 * XMScalar.Cos(2.3f * t),
                8 * XMScalar.Sin(3.4f * t));
            triangleCoords = XMMatrix.Multiply(triangleCoords, translation);
            this.secondaryTriangles[1].PointA = XMVector3.Transform(trianglePointA, triangleCoords);
            this.secondaryTriangles[1].PointB = XMVector3.Transform(trianglePointB, triangleCoords);
            this.secondaryTriangles[1].PointC = XMVector3.Transform(trianglePointC, triangleCoords);

            // animate triangle 2 around the oriented box
            triangleCoords = XMMatrix.RotationRollPitchYaw(t * 1.4f, t * 2.5f, t);
            translation    = XMMatrix.Translation(
                8 * XMScalar.Sin(5.3f * t) + camera2OriginX,
                8 * XMScalar.Cos(2.3f * t),
                8 * XMScalar.Sin(3.4f * t));
            triangleCoords = XMMatrix.Multiply(triangleCoords, translation);
            this.secondaryTriangles[2].PointA = XMVector3.Transform(trianglePointA, triangleCoords);
            this.secondaryTriangles[2].PointB = XMVector3.Transform(trianglePointB, triangleCoords);
            this.secondaryTriangles[2].PointC = XMVector3.Transform(trianglePointC, triangleCoords);

            // animate primary ray (this is the only animated primary object)
            this.primaryRay.Direction = new XMVector(XMScalar.Sin(t * 3), 0, XMScalar.Cos(t * 3), 0);

            // animate sphere 3 around the ray
            {
                BoundingSphere sphere = this.secondarySpheres[3].Sphere;

                sphere.Center = new XMFloat3(camera3OriginX - 3, 0.5f * XMScalar.Sin(t * 5), camera3OriginZ);

                this.secondarySpheres[3].Sphere = sphere;
            }

            // animate aligned box 3 around the ray
            {
                BoundingBox box = this.secondaryAABoxes[3].Box;

                box.Center = new XMFloat3(camera3OriginX + 3, 0.5f * XMScalar.Sin(t * 4), camera3OriginZ);

                this.secondaryAABoxes[3].Box = box;
            }

            // animate oriented box 3 around the ray
            {
                BoundingOrientedBox box = this.secondaryOrientedBoxes[3].Box;

                box.Center      = new XMFloat3(camera3OriginX, 0.5f * XMScalar.Sin(t * 4.5f), camera3OriginZ + 3);
                box.Orientation = XMQuaternion.RotationRollPitchYaw(t * 0.9f, t * 1.8f, t);

                this.secondaryOrientedBoxes[3].Box = box;
            }

            // animate triangle 3 around the ray
            triangleCoords = XMMatrix.RotationRollPitchYaw(t * 1.4f, t * 2.5f, t);
            translation    = XMMatrix.Translation(
                camera3OriginX,
                0.5f * XMScalar.Cos(4.3f * t),
                camera3OriginZ - 3);
            triangleCoords = XMMatrix.Multiply(triangleCoords, translation);
            this.secondaryTriangles[3].PointA = XMVector3.Transform(trianglePointA, triangleCoords);
            this.secondaryTriangles[3].PointB = XMVector3.Transform(trianglePointB, triangleCoords);
            this.secondaryTriangles[3].PointC = XMVector3.Transform(trianglePointC, triangleCoords);
        }