示例#1
0
        /// <summary>
        /// Draws the Target vox for the player
        /// </summary>
        /// <param name="cam">Camera MAtrices class</param>
        /// <param name="currentPlayerforViewport">The current player for the viewport</param>
        public void drawSuroundingBox(SpriteBatch b, Camera.CameraMatrices cam, playerObject currentPlayerforViewport)
        {
            //if its the current player dont draw it
            if (this is playerObject)
            {
                if (((playerObject)this).getViewport.Equals(Game.GraphicsDevice.Viewport))
                {
                    return;
                }
            }

            if (this is Objects.Bullet || this is Objects.Planets.Planet || this is Objects.Asteroid) // dont draw for bullets
            {
                return;
            }

            if ((cam.Position - Position).Length() > 800) // depth culling
            {
                return;
            }

            if (IsVisible(cam))
            {
                Vector2 screenViewport = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

                if (setVertexCoords(b, cam, screenViewport, currentPlayerforViewport))
                {
                    drawBox(screenViewport);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Draws the Sphere
        /// </summary>
        /// <param name="device">Graphics device</param>
        /// <param name="camera">What camera to draw on</param>
        public void draw(GraphicsDevice device, Camera.CameraMatrices camera)
        {
            device.VertexDeclaration = vDecl;
            device.Vertices[0].SetSource(vBuffer, 0, vertexPos.SizeInBytes);

            device.DrawPrimitives(PrimitiveType.TriangleList, 0, numV / 2);
        }
示例#3
0
        /// <summary>
        /// Draw method for the object
        /// This draws without lighting effects and fog
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="cam">Camera class</param>
        public virtual void Draw(GameTime gameTime, Camera.CameraMatrices cam)
        {
            if (!IsVisible(cam))
            {
                return;
            }

            if (((cam.Position - Position).Length() > 600) && !(this is Planets.Planet) && !(this is Asteroid)) // depth culling
            {
                return;
            }


            foreach (ModelMesh m in model.Meshes)
            {
                foreach (BasicEffect e in m.Effects)
                {
                    e.Parameters["World"].SetValue(world);
                    e.Parameters["View"].SetValue(cam.View);
                    e.Parameters["Projection"].SetValue(cam.Projection);
                    e.LightingEnabled = true;

                    e.PreferPerPixelLighting          = true;
                    e.DirectionalLight0.Enabled       = true;
                    e.DirectionalLight0.DiffuseColor  = new Vector3(0.9f, 0.9f, 0.9f);
                    e.DirectionalLight0.SpecularColor = new Vector3(0.7f, 0.7f, 0.7f);
                    e.AmbientLightColor           = new Vector3(0.6f, 0.6f, 0.6f);
                    e.DirectionalLight0.Direction = new Vector3(-1, 0, 0);
                }
                m.Draw();
            }

            base.Draw(gameTime);
        }
示例#4
0
        /// <summary>
        /// Draw method for the entire skybox
        /// </summary>
        /// <param name="gt">The game time</param>
        /// <param name="cam">The camera class</param>
        /// <param name="playerPos">The players position</param>
        public void Draw(GameTime gt, Camera.CameraMatrices cam)
        {
            Matrix worldMatrix = Matrix.Identity;

            e.Begin();
            e.Techniques[0].Passes[0].Begin();

            world.SetValue(worldMatrix);
            view.SetValue(cam.View);
            projection.SetValue(cam.Projection);
            diffuseTex.SetValue(text);

            e.CommitChanges();

            GraphicsDevice.RenderState.CullMode = CullMode.None;
            GraphicsDevice.RenderState.DepthBufferWriteEnable = false;

            cube.draw(GraphicsDevice, cam);

            GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
            GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;

            e.Techniques[0].Passes[0].End();
            e.End();
        }
示例#5
0
        /// <summary>
        /// Draws the Sphere
        /// </summary>
        /// <param name="device">Graphics device</param>
        /// <param name="camera">What camera to draw on</param>
        public void draw(GraphicsDevice device, Camera.CameraMatrices camera)
        {
            for (int i = 0; i < numB; i++)
            {
                device.VertexDeclaration = vDecl;
                device.Vertices[0].SetSource(vBuffer, 0, vertexPos.SizeInBytes);
                device.Indices = iBuffer[i];

                device.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, numV, 0, numI - 2);
            }
        }
示例#6
0
        /// <summary>
        /// Sets up the viewport of the object
        /// </summary>
        /// <param name="cam">The camera MAtrices</param>
        /// <param name="screenViewport">The Screen viewport dimensions</param>
        /// <param name="player">The player for the current viewport</param>
        /// <returns></returns>
        private Boolean setVertexCoords(SpriteBatch b, Camera.CameraMatrices cam, Vector2 screenViewport, playerObject player)
        {
            Color col;

            if (this is Objects.Turret)
            {
                col = ((Objects.Turret) this).Repairing ? Color.Aqua : this.Equals(player.Target) ? Color.Red : this.team.Equals(Team.neutral) ? Color.Yellow :
                      this.Team.Equals(player.team) ? Color.Green : Color.Orange;
            }
            else
            {
                col = this.Equals(player.Target) ? Color.Red : this.team.Equals(Team.neutral) ? Color.Yellow :
                      this.Team.Equals(player.team) ? Color.Green : Color.Orange;
            }

            float radiusOfObject;

            radiusOfObject = greatestLength * 5f;                // sets the greatest size of the object

            float distance = (Position - cam.Position).Length(); // distance the object is from the camera
            float radius   = (greatestLength / 2);               // a variable for checking distances away from camera

            //Check if the objectis further away from the camera than its actual size.
            if (distance > radius)
            {
                float angularSize = (float)Math.Tan(radius / distance);                                              // calculate the size differance due to distance away
                radiusOfObject = angularSize * GraphicsDevice.Viewport.Height / MathHelper.ToRadians(cam.viewAngle); // change the size of the object in accordance to the viewing angle
            }

            // The view and projection matrices together
            Matrix  viewProj  = cam.View * cam.Projection;
            Vector4 screenPos = Vector4.Transform(Position, viewProj);                 // the position the screen is at according to the matrices

            float halfScreenY = screenViewport.Y / 2.0f;                               // half the size of the screen
            float halfScreenX = screenViewport.X / 2.0f;                               // half the size of the screen

            float screenY = ((screenPos.Y / screenPos.W) * halfScreenY) + halfScreenY; // the position of the object in 2d space y
            float screenX = ((screenPos.X / screenPos.W) * halfScreenX) + halfScreenX; // the position of the object in 2d space x

            // set positions for lines to draw
            setVertexPosition(screenX, screenY, radiusOfObject, col);

            // set the y back to the non depth version
            screenY = halfScreenY - ((screenPos.Y / screenPos.W) * halfScreenY);
            float distanceToPlayer = (cam.Position - Position).Length();

            drawData(b, distanceToPlayer, screenX, screenY, radiusOfObject, col, player); // draw the distances to the object

            // set the variable to the new position vectors
            targetBoxVB.SetData <VertexPositionColor>(targetBoxVertices);
            return(true);
        }
示例#7
0
        public void draw(Matrix world, Camera.CameraMatrices cam, GraphicsDevice g)
        {
            e.AmbientLightColor = new Vector3(1f, 1f, 1f);
            //sun.Draw(cam.View, world, cam.Projection, e);
            BlendFunction prev = g.RenderState.BlendFunction;

            g.RenderState.BlendFunction = BlendFunction.Add;
            e.AmbientLightColor         = new Vector3(1f, 0.8f, 0.5f);
            e.DiffuseColor = new Vector3(1f, 0.8f, 0.5f);
            //e.SpecularColor = new Vector3(1f, 0.8f, 0.5f);
            glare.Draw(cam.View, world, cam.Projection, e);
            g.RenderState.BlendFunction = prev;
        }
示例#8
0
        /// <summary>
        /// Determines if the object is currently visible with the current camera
        /// </summary>
        /// <param name="camera">Camera Class</param>
        /// <returns>Boolean value - True is visible -- false - not visible</returns>
        public virtual bool IsVisible(Camera.CameraMatrices camera)
        {
            BoundingSphere localSphere = Bsphere;

            localSphere.Center = Position;

            ContainmentType contains = camera.getBoundingFrustum.Contains(localSphere);

            if (contains == ContainmentType.Contains || contains == ContainmentType.Intersects)
            {
                return(true);
            }

            return(false);
        }
示例#9
0
        protected Boolean isMoonVis(Camera.CameraMatrices camera)
        {
            BoundingSphere localSphere = moonSphere;

            localSphere.Center = moonPos;

            ContainmentType contains = camera.getBoundingFrustum.Contains(localSphere);

            if (contains == ContainmentType.Contains || contains == ContainmentType.Intersects)
            {
                return(true);
            }

            return(false);
        }
示例#10
0
 public override void Draw(GameTime gameTime, Camera.CameraMatrices cam)
 {
     if (isMoonVis(cam))
     {
         foreach (ModelMesh m in moon.Meshes)
         {
             foreach (BasicEffect e in m.Effects)
             {
                 e.EnableDefaultLighting();
                 e.PreferPerPixelLighting = true;
                 e.Parameters["World"].SetValue(moonWorld);
                 e.Parameters["View"].SetValue(cam.View);
                 e.Parameters["Projection"].SetValue(cam.Projection);
             }
             m.Draw();
         }
     }
     base.Draw(gameTime, cam);
 }