public void Update(ITimer timer)
        {
            float t = timer == null ? 0.0f : (float)timer.TotalSeconds;

            this.worldMatrix = XMMatrix.RotationY(t);

            this.meshColor = new XMVector(
                (XMScalar.Sin(t * 1.0f) + 1.0f) * 0.5f,
                (XMScalar.Cos(t * 3.0f) + 1.0f) * 0.5f,
                (XMScalar.Sin(t * 5.0f) + 1.0f) * 0.5f,
                1.0f);
        }
Esempio n. 2
0
        public static bool SolveCubic(float e, float f, float g, out float t, out float u, out float v)
        {
            float p, q, h, rc, d, theta, costh3, sinth3;

            p = f - (e * e / 3.0f);
            q = g - (e * f / 3.0f) + (e * e * e * 2.0f / 27.0f);
            h = (q * q / 4.0f) + (p * p * p / 27.0f);

            if (h > 0.0f)
            {
                t = u = v = 0.0f;
                return(false); // only one real root
            }

            // all the same root
            if ((h == 0.0f) && (q == 0.0f))
            {
                t = -e / 3;
                u = -e / 3;
                v = -e / 3;

                return(true);
            }

            d = (float)Math.Sqrt((q * q / 4.0f) - h);

            if (d < 0)
            {
                rc = (float)-Math.Pow(-d, 1.0f / 3.0f);
            }
            else
            {
                rc = (float)Math.Pow(d, 1.0f / 3.0f);
            }

            theta  = XMScalar.ACos(-q / (2.0f * d));
            costh3 = XMScalar.Cos(theta / 3.0f);
            sinth3 = (float)Math.Sqrt(3.0f) * XMScalar.Sin(theta / 3.0f);

            t = (2.0f * rc * costh3) - (e / 3.0f);
            u = (-rc * (costh3 + sinth3)) - (e / 3.0f);
            v = (-rc * (costh3 - sinth3)) - (e / 3.0f);

            return(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);
        }