コード例 #1
0
        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));
        }
コード例 #2
0
        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);
        }