protected override void LoadContent()
        {
            device      = graphics.GraphicsDevice;
            basicEffect = new BasicEffect(device, null);
            cCross      = new CoordCross(device);

            myModel = XNAUtils.LoadModelWithBoundingSphere(ref modelTransforms, "Ship", Content);
        }
        private VertexPositionNormalTexture[] GenerateTrackVertices(List <Vector3> trackPoints)
        {
            float halfTrackWidth = 0.2f;
            List <VertexPositionNormalTexture> verticesList = new List <VertexPositionNormalTexture>();
            List <Vector3> supportList = new List <Vector3>();

            float distance      = 0;
            float textureLenght = 0.5f;

            Vector3 currentNormal = Vector3.Up;

            for (int i = 1; i < trackPoints.Count - 1; i++)
            {
                Vector3 next2 = trackPoints[i + 1] - trackPoints[i];
                next2.Normalize();
                Vector3 previous = trackPoints[i] - trackPoints[i - 1];
                previous.Normalize();

                Vector3 split  = Vector3.Cross(next2, previous);
                Vector3 mySide = Vector3.Cross(next2, split);

                currentNormal = currentNormal + 0.2f * Vector3.Up + mySide * 2.0f;

                supportList.Add(new Vector3(trackPoints[i].X, -0.5f, trackPoints[i].Z));
                supportList.Add(trackPoints[i]);

                Vector3 side = Vector3.Cross(currentNormal, next2);
                side.Normalize();
                currentNormal = Vector3.Cross(next2, side);

                Vector3 outerPoint = trackPoints[i] + side * halfTrackWidth;
                Vector3 innerPoint = trackPoints[i] - side * halfTrackWidth;

                distance += next2.Length();
                VertexPositionNormalTexture vertex;
                vertex = new VertexPositionNormalTexture(innerPoint, currentNormal, new Vector2(0, distance / textureLenght));
                verticesList.Add(vertex);
                vertex = new VertexPositionNormalTexture(outerPoint, currentNormal, new Vector2(1, distance / textureLenght));
                verticesList.Add(vertex);
            }
            verticesList.Add(verticesList[0]);
            verticesList.Add(verticesList[1]);

            supportList.Add(Vector3.Zero);
            supportList.Add(Vector3.Zero);
            supportVertices = XNAUtils.VerticesFromVector3List(supportList, Color.Yellow);

            VertexPositionNormalTexture[] trackVertices = verticesList.ToArray();

            return(trackVertices);
        }
Пример #3
0
        public static Model LoadModelWithBoundingSphere(ref Matrix[] modelTransforms, string asset, ContentManager content)
        {
            Model newModel = content.Load <Model>(asset);

            modelTransforms = new Matrix[newModel.Bones.Count];
            newModel.CopyAbsoluteBoneTransformsTo(modelTransforms);

            BoundingSphere completeBoundingSphere = new BoundingSphere();

            foreach (ModelMesh mesh in newModel.Meshes)
            {
                BoundingSphere origMeshSphere  = mesh.BoundingSphere;
                BoundingSphere transMeshSphere = XNAUtils.TransformBoundingSphere(origMeshSphere, modelTransforms[mesh.ParentBone.Index]);
                completeBoundingSphere = BoundingSphere.CreateMerged(completeBoundingSphere, transMeshSphere);
            }
            newModel.Tag = completeBoundingSphere;

            return(newModel);
        }
        public void Draw(Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, BoundingFrustum cameraFrustum)
        {
            BoundingBox     transformedBBox       = XNAUtils.TransformBoundingBox(nodeBoundingBox, worldMatrix);
            ContainmentType cameraNodeContainment = cameraFrustum.Contains(transformedBBox);

            if (cameraNodeContainment != ContainmentType.Disjoint)
            {
                if (isEndNode)
                {
                    DrawCurrentNode(worldMatrix, viewMatrix, projectionMatrix);
                }
                else
                {
                    nodeUL.Draw(worldMatrix, viewMatrix, projectionMatrix, cameraFrustum);
                    nodeUR.Draw(worldMatrix, viewMatrix, projectionMatrix, cameraFrustum);
                    nodeLL.Draw(worldMatrix, viewMatrix, projectionMatrix, cameraFrustum);
                    nodeLR.Draw(worldMatrix, viewMatrix, projectionMatrix, cameraFrustum);
                }
            }
        }
        protected override void Initialize()
        {
            fpsCam = new QuakeCamera(GraphicsDevice.Viewport, new Vector3(5, 2, 15), 0, 0);

            List <Vector3> points = new List <Vector3>();

            points.Add(new Vector3(0, 0, 0));
            points.Add(new Vector3(2, 2, 0));
            points.Add(new Vector3(4, 0, 0));
            points.Add(new Vector3(6, 6, 0));
            points.Add(new Vector3(8, 2, 0));
            points.Add(new Vector3(10, 0, 0));

            List <Vector3> crList1 = InterpolateCR(points[0], points[1], points[2], points[3]);
            List <Vector3> crList2 = InterpolateCR(points[1], points[2], points[3], points[4]);
            List <Vector3> crList3 = InterpolateCR(points[2], points[3], points[4], points[5]);

            straightVertices = XNAUtils.VerticesFromVector3List(points, Color.Red);
            crVertices1      = XNAUtils.VerticesFromVector3List(crList1, Color.Green);
            crVertices2      = XNAUtils.VerticesFromVector3List(crList2, Color.Blue);
            crVertices3      = XNAUtils.VerticesFromVector3List(crList3, Color.Yellow);

            base.Initialize();
        }