Exemple #1
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            //X.DepthMap.StartRenderToDepthMap();
            //make a camera to look at the players camera, center and target!
            //this is for testing (very slow to remake every frame)
            //XCamera sunCam = new XCamera(X, 100f, 300f);
            //sunCam.Position = new Vector3(-X.Environment.LightDirection.X * 200f,-X.Environment.LightDirection.Y * 200f,-X.Environment.LightDirection.Z * 200f);
            //sunCam.Target = Vector3.Zero;
            //sunCam.Up = Vector3.Up;
            //sunCam.Update(ref gameTime);
            //Camera.ShadowView = sunCam.View;
            //Camera.ShadowProjection = sunCam.Projection;
            //sunCam.RenderType = RenderTypes.Depth;
            //Camera.RenderType = RenderTypes.Depth;
            //DrawScene(ref gameTime,ref Camera, DebugNoDraw, DebugNoDrawTypes);
            //sunCam.Disable();
            //X.DepthMap.EndRenderToDepthMap();

            //Camera.ShadowProjection = Camera.Projection;
            //Camera.ShadowView = Camera.View;
            Camera.RenderType = RenderTypes.Normal;
            X.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, ClearColor, 1.0f, 0);
            DrawScene(ref gameTime, ref Camera, null, null);

            //using (SpriteBatch sprite = new SpriteBatch(X.GraphicsDevice))
            //{
            //    sprite.Begin(SpriteBlendMode.None, SpriteSortMode.Texture, SaveStateMode.SaveState);
            //    sprite.Draw(X.DepthMap.depthMap, new Vector2(0, 0), null, Color.White, 0, new Vector2(0, 0), 0.2f, SpriteEffects.None, 1);
            //    sprite.End();
            //}
#if DEBUG
//            XProfile.Dump();
#endif
        }
Exemple #2
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            int offset = (int)StartPosition.Y;

            //write debug text with the camera position passed into this draw method
            string Text = "Current Camera Name: " + Camera.Name;

            X.SystemFont.Draw(Text, new Vector2(StartPosition.X, offset), Color.Black);
            offset += RowHeight;
            Text    = "Curent Camera Position X" + Camera.Position.X.ToString() + " Y:" + Camera.Position.Y.ToString() + " Z:" + Camera.Position.Z.ToString();
            X.SystemFont.Draw(Text, new Vector2(StartPosition.X, offset), Color.Black);
            offset += RowHeight;

            for (int i = 0; i < toWrite.Count; i++)
            {
                X.SystemFont.Draw(toWrite[i], new Vector2(StartPosition.X, offset), Color.Black);
                offset += RowHeight;
            }
            toWrite.Clear();

            for (int j = 0; j < toWriteStatic.Count; j++)
            {
                X.SystemFont.Draw(toWriteStatic[j], new Vector2(StartPosition.X, offset), Color.Black);
                offset += RowHeight;
            }
        }
Exemple #3
0
        public override void Draw(ref GameTime gameTime, ref XCamera camera)
        {
            if (loaded)
            {
                Matrix[] boneTransforms = new Matrix[domeModel.Bones.Count];
                domeModel.CopyAbsoluteBoneTransformsTo(boneTransforms);

                foreach (ModelMesh mesh in domeModel.Meshes)
                {
                    Matrix World = Matrix.CreateScale(10) * boneTransforms[mesh.ParentBone.Index] *
                                   Matrix.CreateTranslation(camera.Position.X, camera.Position.Y, camera.Position.Z);

                    Matrix WorldIT = Matrix.Invert(World);
                    WorldIT = Matrix.Transpose(WorldIT);

                    foreach (Effect effect in mesh.Effects)
                    {
                        effect.Parameters["WorldIT"].SetValue(WorldIT);
                        effect.Parameters["World"].SetValue(World);
                        effect.Parameters["WorldViewProj"].SetValue(World * camera.View * camera.Projection);
                        effect.Parameters["ViewInv"].SetValue(Matrix.Invert(camera.View));
                        effect.Parameters["LightDirection"].SetValue(Params.LightDirection);
                    }
                    mesh.Draw();
                }
            }
        }
Exemple #4
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            if (!loaded)
            {
                return;
            }
            //X.GraphicsDevice.RenderState.DepthBufferWriteEnable = false;
            //X.GraphicsDevice.RenderState.DepthBufferEnable = false;

            X.GraphicsDevice.RenderState.DepthBufferEnable      = true;
            X.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
            X.GraphicsDevice.RenderState.AlphaBlendEnable       = false;

            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);


            if (Filenames.Count == 1)
            {
                effect.Parameters["Projection"].SetValue(Camera.Projection);
                effect.Parameters["View"].SetValue(Camera.View);

                if (Filenames.Count == 1)
                {
                    effect.Parameters["EyePosition"].SetValue(Camera.Position);
                    effect.Parameters["skyCubeTexture"].SetValue(cube);
                }

                for (int pass = 0; pass < effect.CurrentTechnique.Passes.Count; pass++)
                {
                    for (int msh = 0; msh < model.Meshes.Count; msh++)
                    {
                        ModelMesh mesh = model.Meshes[msh];

                        effect.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * Matrix.CreateScale(100) * Matrix.CreateTranslation(Camera.Position));

                        for (int prt = 0; prt < mesh.MeshParts.Count; prt++)
                        {
                            mesh.MeshParts[prt].Effect = effect;
                        }
                        mesh.Draw();
                    }
                }
            }
            else
            {//render our other method
                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (Effect effect in mesh.Effects)
                    {
                        effect.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * Matrix.CreateScale(100) * Matrix.CreateTranslation(Camera.Position));
                        effect.Parameters["Projection"].SetValue(Camera.Projection);
                        effect.Parameters["View"].SetValue(Camera.View);
                    }
                    mesh.Draw();
                }
            }
        }
Exemple #5
0
        public XWater(ref XMain X)
            : base(ref X)
        {
            DrawOrder = 22;
            height    = 4;
            Size      = new Vector2(128 * 2, 128 * 2);
            PointOne  = new Vector2(-128, -128);
            PointTwo  = Vector2.Add(PointOne, Size);

            reflectionCamera = new XCamera(ref X, 1, 100);
        }
Exemple #6
0
        public virtual void DrawReflectedScene(GameTime gameTime, XCamera Camera)
        {
            List <XComponent> NoDraw = new List <XComponent>();

            NoDraw.Add(this);
            NoDraw.Add(X.Debug);
            NoDraw.Add(X.Console);
            NoDraw.Add(X.DebugDrawer);

            X.Renderer.DrawScene(ref gameTime, ref Camera, NoDraw, null);
        }
Exemple #7
0
        public XWater(ref XMain X, Vector2 pointOne, Vector2 size, float height) : base(ref X)
        {
            DrawOrder = 22;
            PointOne  = pointOne;
            PointTwo  = Vector2.Add(pointOne, size);
            this.Size = size;

            this.height = height;

            reflectionCamera = new XCamera(ref X, 1, 100);
        }
Exemple #8
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            if (!this.loaded)
            {
                return;
            }

            Matrix World =
                Matrix.CreateFromQuaternion(myRotation) *
                Matrix.CreateTranslation(myPosition) * Matrix.CreateScale(myScale);

            Matrix WVP   = World * Camera.View * Camera.Projection;
            Matrix WV    = World * Camera.View;
            Matrix viewI = Matrix.Invert(Camera.View);

            effect.Parameters["matWorldViewProj"].SetValue(WVP);
            effect.Parameters["matWorld"].SetValue(World);
            effect.Parameters["matWorldView"].SetValue(WV);
            effect.Parameters["matViewI"].SetValue(viewI);

            effect.Parameters["fBumpHeight"].SetValue(bumpHeight);
            effect.Parameters["vTextureScale"].SetValue(textureScale);
            effect.Parameters["vBumpSpeed"].SetValue(bumpSpeed);
            effect.Parameters["fFresnelBias"].SetValue(fresnelBias);
            effect.Parameters["fFresnelPower"].SetValue(fresnelPower);
            effect.Parameters["fHDRMultiplier"].SetValue(hdrMultiplier);
            effect.Parameters["vDeepColor"].SetValue(deepWaterColor.ToVector4());
            effect.Parameters["vShallowColor"].SetValue(shallowWaterColor.ToVector4());
            effect.Parameters["vReflectionColor"].SetValue(reflectionColor.ToVector4());
            effect.Parameters["fReflectionAmount"].SetValue(reflectionAmount);
            effect.Parameters["fWaterAmount"].SetValue(waterAmount);
            effect.Parameters["fWaveAmp"].SetValue(waveAmplitude);
            effect.Parameters["fWaveFreq"].SetValue(waveFrequency);

            X.GraphicsDevice.Vertices[0].SetSource(vb, 0, VertexMultitextured.SizeInBytes);
            X.GraphicsDevice.Indices = ib;

            //Game.GraphicsDevice.RenderState.FillMode = FillMode.WireFrame;

            effect.Begin(SaveStateMode.SaveState);
            for (int p = 0; p < effect.CurrentTechnique.Passes.Count; p++)
            {
                effect.CurrentTechnique.Passes[p].Begin();

                X.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, myWidth * myHeight, 0, (myWidth - 1) * (myHeight - 1) * 2);

                effect.CurrentTechnique.Passes[p].End();
            }
            effect.End();

            //Game.GraphicsDevice.RenderState.FillMode = FillMode.Solid;
        }
Exemple #9
0
        public XCamera(ref XMain X, float nearplane, float farplane)
            : base(ref X)
        {
            ProjectionType = ProjectionTypes.Perspective;
            RenderType     = RenderTypes.Normal;
            NearPlane      = nearplane;
            FarPlane       = farplane;
            FOV            = MathHelper.PiOver4;
            GenerateProjection(ref X, this.FOV, this.ProjectionType, NearPlane, FarPlane);

            Base      = this;
            DrawOrder = 50000;
        }
Exemple #10
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            if (loaded)
            {
                //X.GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace;

                effect.Parameters["WorldViewProj"].SetValue(World * Camera.View * Camera.Projection);
                effect.Parameters["ViewInv"].SetValue(Matrix.Invert(Camera.View));
                effect.Parameters["LightDirection"].SetValue(-Params.LightDirection);
                //effect.Parameters["xShadowMap"].SetValue(X.DepthMap.depthMap);
                //effect.Parameters["LightWorldViewProj"].SetValue(World * Camera.ShadowView * Camera.ShadowProjection);

                //if rendering a depthmap
                if (Camera.RenderType == RenderTypes.Depth)
                {
                    //override any techniques with DepthMap technique shader
                    if (effect.Techniques["DepthMapStatic"] != null)
                    {
                        effect.CurrentTechnique = effect.Techniques["DepthMapStatic"];
                    }
                    //continue;
                }
                else
                {
                    if (effect.Techniques["SkyDome"] != null)
                    {
                        effect.CurrentTechnique = effect.Techniques["SkyDome"];
                    }
                }

                effect.Begin(SaveStateMode.SaveState);
                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Begin();

                    X.GraphicsDevice.Vertices[0].SetSource(terrainVertexBuffer, 0, VertexPositionNormalTexture.SizeInBytes);
                    X.GraphicsDevice.Indices           = terrainIndexBuffer;
                    X.GraphicsDevice.VertexDeclaration = new VertexDeclaration(X.GraphicsDevice, VertexPositionNormalTexture.VertexElements);

                    X.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, WIDTH * HEIGHT, 0, (WIDTH - 1) * (HEIGHT - 1) * 2);

                    pass.End();
                }
                effect.End();
#if DEBUG
                X.DebugDrawer.DrawCube(boundingBox.Min, boundingBox.Max, Color.Yellow, World, Camera);
                X.DebugDrawer.DrawShape(Object.GetCollisionWireframe());
#endif
            }
        }
Exemple #11
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            //null checks are for editor!
            //remove these eventually maybe using a compiler directive for an editorer version of the DLL?
            if (model != null && PhysicsObject != null && model.loaded)
            {
                if (AlphaBlendable)
                {
                    X.GraphicsDevice.RenderState.AlphaBlendEnable      = true;
                    X.GraphicsDevice.RenderState.SourceBlend           = Blend.SourceAlpha;        // source rgb * source alpha
                    X.GraphicsDevice.RenderState.AlphaSourceBlend      = Blend.One;                // don't modify source alpha
                    X.GraphicsDevice.RenderState.DestinationBlend      = Blend.InverseSourceAlpha; // dest rgb * (255 - source alpha)
                    X.GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.InverseSourceAlpha; // dest alpha * (255 - source alpha)
                    X.GraphicsDevice.RenderState.BlendFunction         = BlendFunction.Add;        // add source and dest results
                }
                else
                {
                    X.GraphicsDevice.RenderState.AlphaBlendEnable = false;
                }

                //Set camera params, compute matrices
                //model.SASData.Camera.NearFarClipping.X = Camera.NearPlane;
                //model.SASData.Camera.NearFarClipping.Y = Camera.FarPlane;
                //model.SASData.Camera.Position.X = Camera.Position.X;
                //model.SASData.Camera.Position.Y = Camera.Position.Y;
                //model.SASData.Camera.Position.Z = Camera.Position.Z;
                model.SASData.Projection = Camera.Projection;
                model.SASData.View       = Camera.View;
                model.SASData.World      = PhysicsObject.GetWorldMatrix(model.Model, Vector3.Zero); //modeloffset);
                model.SASData.ComputeViewAndProjection();
                //model.SASData.ComputeModel();

                //X.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;

                X.Renderer.DrawModel(ref model, ref Camera);

                //restore render modes (shader files might have changes this!
                X.GraphicsDevice.RenderState.AlphaBlendEnable = false;

#if DEBUG
                //Render debug volumes for frustrum clulling
                XDebugVolumeRenderer.RenderSphere(model.bs, Color.Yellow, ref Camera.View, ref Camera.Projection);

                //Render debug volumes for physics
                X.DebugDrawer.DrawShape(PhysicsObject.GetCollisionWireframe(), Color.White);
#endif
            }//end if (model != null && model.loaded)
        }
Exemple #12
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            this.camera = Camera;

            effect.Parameters["xWorld"].SetValue(Matrix.Identity);
            effect.Parameters["xView"].SetValue(Camera.View);
            effect.Parameters["xProjection"].SetValue(Camera.Projection);

            if (reflectionViewMatrix != Matrix.Identity)
            {
                effect.Parameters["xReflectionView"].SetValue(reflectionViewMatrix);
                effect.Parameters["xReflectionMap"].SetValue(texreflect); //reflection.GetTexture());
                effect.Parameters["xRefractionMap"].SetValue(texrefract); //refraction.GetTexture());
            }

            effect.Parameters["xCamPos"].SetValue(Camera.Position);

            effect.Parameters["xTime"].SetValue((float)gameTime.TotalGameTime.TotalSeconds / 100);

            //if rendering a depthmap
            if (Camera.RenderType == RenderTypes.Depth)
            {
                //override any techniques with DepthMap technique shader
                if (effect.Techniques["DepthMapStatic"] != null)
                {
                    effect.CurrentTechnique = effect.Techniques["DepthMapStatic"];
                }
                //continue;
            }
            else
            {
                if (effect.Techniques["Water"] != null)
                {
                    effect.CurrentTechnique = effect.Techniques["Water"];
                }
            }

            // Draw the water
            effect.Begin(SaveStateMode.SaveState);
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                X.GraphicsDevice.VertexDeclaration = new VertexDeclaration(X.GraphicsDevice, VertexPositionTexture.VertexElements);
                X.GraphicsDevice.DrawUserPrimitives <VertexPositionTexture>(PrimitiveType.TriangleList, vertices, 0, 2);
                pass.End();
            }
            effect.End();
        }
Exemple #13
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            //World Matrix Compute function
            Matrix[] World = Car.GetWorldMatrix(Chassis.Model, Vector3.Zero);

            //Set camera params, compute matrices on chassis
            Chassis.SASData.Camera.NearFarClipping.X = Camera.NearPlane;
            Chassis.SASData.Camera.NearFarClipping.Y = Camera.FarPlane;
            Chassis.SASData.Camera.Position.X        = Camera.Position.X;
            Chassis.SASData.Camera.Position.Y        = Camera.Position.Y;
            Chassis.SASData.Camera.Position.Z        = Camera.Position.Z;
            Chassis.SASData.Projection = Camera.Projection;
            Chassis.SASData.View       = Camera.View;
            Chassis.SASData.World      = World[0];
            Chassis.SASData.ComputeViewAndProjection();

            X.Renderer.DrawModel(ref Chassis, ref Camera);

            //the car has alphablended windows turn this off now or else other things go transparent!
            X.GraphicsDevice.RenderState.AlphaBlendEnable = false;

            //Set camera params, compute matrices on WHEELS!
            Wheel.SASData.Camera.NearFarClipping.X = Camera.NearPlane;
            Wheel.SASData.Camera.NearFarClipping.Y = Camera.FarPlane;
            Wheel.SASData.Camera.Position.X        = Camera.Position.X;
            Wheel.SASData.Camera.Position.Y        = Camera.Position.Y;
            Wheel.SASData.Camera.Position.Z        = Camera.Position.Z;
            Wheel.SASData.Projection = Camera.Projection;
            Wheel.SASData.View       = Camera.View;
            Wheel.SASData.ComputeViewAndProjection();

            Wheel.SASData.World = World[1];
            X.Renderer.DrawModel(ref Wheel, ref Camera);

            Wheel.SASData.World = World[2];
            X.Renderer.DrawModel(ref Wheel, ref Camera);

            Wheel.SASData.World = World[3];
            X.Renderer.DrawModel(ref Wheel, ref Camera);

            Wheel.SASData.World = World[4];
            X.Renderer.DrawModel(ref Wheel, ref Camera);

#if DEBUG
            X.DebugDrawer.DrawShape(Car.GetCollisionWireframe(), Color.White);
#endif
        }
Exemple #14
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            //  if I have a model, set up the scene drawing parameters and draw the model
            if (loadedModel_ != null)
            {
                Matrix World = PhysicsObject.GetWorldMatrix(model.Model, Vector3.Zero); //modeloffset);

                //  draw the loaded model (the only model I have)
                //loadedModel_.Draw(ref Camera, World, blender_);
                loadedModel_.SceneDraw(ref Camera, World);

                //TODO: fix transparent rendering
                //Any shaders with the transparent annotation will draw here
                //should be done at the very end of scene
                loadedModel_.SceneDrawTransparent(ref Camera, World);
            }
        }
        public void DrawCube(Vector3 min, Vector3 max, Color color, Matrix world, XCamera camera)
        {
            DrawLine(new Vector3(max.X, min.Y, max.Z), new Vector3(max.X, min.Y, min.Z), color);
            DrawLine(new Vector3(max.X, min.Y, max.Z), new Vector3(min.X, min.Y, max.Z), color);
            DrawLine(new Vector3(min.X, min.Y, max.Z), new Vector3(min.X, min.Y, min.Z), color);
            DrawLine(new Vector3(min.X, min.Y, min.Z), new Vector3(max.X, min.Y, min.Z), color);
            DrawLine(new Vector3(max.X, min.Y, max.Z), new Vector3(max.X, max.Y, max.Z), color);
            DrawLine(new Vector3(min.X, min.Y, max.Z), new Vector3(min.X, max.Y, max.Z), color);
            DrawLine(new Vector3(max.X, min.Y, min.Z), new Vector3(max.X, max.Y, min.Z), color);
            DrawLine(new Vector3(min.X, min.Y, min.Z), new Vector3(min.X, max.Y, min.Z), color);
            DrawLine(new Vector3(max.X, max.Y, max.Z), new Vector3(max.X, max.Y, min.Z), color);
            DrawLine(new Vector3(max.X, max.Y, max.Z), new Vector3(min.X, max.Y, max.Z), color);
            DrawLine(new Vector3(min.X, max.Y, max.Z), new Vector3(min.X, max.Y, min.Z), color);
            DrawLine(new Vector3(min.X, max.Y, min.Z), new Vector3(max.X, max.Y, min.Z), color);

            //Draw(world, camera.View, camera.Projection);
        }
Exemple #16
0
        public void GenerateTrees(XCamera Camera)
        {
            //remove this later, incorp a way to get the same trees each time in my treemap using the color values
            Random rand = new Random();

            foreach (Vector3 pos in treeMap)
            {
                // Generate a tree.
                XTreeModel treemodel = new XTreeModel(ref X, "Content/XEngine/Trees/Oak.xml", "Content/XEngine/Textures/OakBark", "Content/XEngine/Textures/OakLeaf");
                treemodel.Load(X.Content);
                XTree Xtree = new XTree(ref X, treemodel, pos, Vector3.One);
                Xtree.Load(X.Content);

                //Add to TreeModel list
                trees.Add(Xtree);
            }
        }
Exemple #17
0
        void Refract(GameTime gameTime, XCamera Camera)
        {
            // Create the clip plane
            Vector3 planeNormalDirection = new Vector3(0, -1, 0);

            planeNormalDirection.Normalize();
            Vector4 planeCoefficients = new Vector4(planeNormalDirection, height + .05f);

            // Create a view matrix
            Matrix camMatrix    = Camera.View * Camera.Projection;
            Matrix invCamMatrix = Matrix.Invert(camMatrix);

            invCamMatrix = Matrix.Transpose(invCamMatrix);

            // Setup the clip plane
            planeCoefficients = Vector4.Transform(planeCoefficients, invCamMatrix);
            Plane refractionClipPlane = new Plane(planeCoefficients);

            // Enable the clip plane
            X.GraphicsDevice.ClipPlanes[0].Plane     = refractionClipPlane;
            X.GraphicsDevice.ClipPlanes[0].IsEnabled = true;

            DepthStencilBuffer prev = X.GraphicsDevice.DepthStencilBuffer;

            X.GraphicsDevice.DepthStencilBuffer = Depth;

            // Set the rener target to the refraction target
            X.GraphicsDevice.SetRenderTarget(0, refraction);
            X.GraphicsDevice.Clear(Color.Black);

            X.GraphicsDevice.RenderState.DepthBufferEnable      = true;
            X.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
            X.GraphicsDevice.RenderState.AlphaBlendEnable       = false;

            DrawRefractedScene(gameTime, Camera);

            X.GraphicsDevice.SetRenderTarget(0, null);

            X.GraphicsDevice.DepthStencilBuffer = prev;

            texrefract = refraction.GetTexture();

            X.GraphicsDevice.ClipPlanes[0].IsEnabled = false;
        }
Exemple #18
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            if (Visible)
            {
                backgroundTexture.Draw(gameTime, new Rectangle(0, 0, X.GraphicsDevice.Viewport.Width, X.Debug.RowHeight * log.Count + 30), 0, Color.White);

                for (int i = 0; i < log.Count; i++)
                {
                    X.SystemFont.Draw(log[i], new Vector2(5, i * X.Debug.RowHeight + 4), Color.White);
                }

                if (LastLineReturnValue)
                {
                    LastLineReturnValue = false;
                }

                X.SystemFont.Draw("> " + line, new Vector2(5, log.Count * X.Debug.RowHeight + 4), Color.White);
            }
        }
Exemple #19
0
        /// <summary>
        /// Render this tree in the camera frustrum
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="Camera"></param>
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            if (!loaded || tree == null)
            {
                return;
            }
            if (Camera.Frustrum.Contains(tree.boundingBox) != ContainmentType.Disjoint || NoCull)
            {
                if (Camera.RenderType == RenderTypes.Depth)
                {
                    tree.Trunk.Effect.CurrentTechnique = tree.Trunk.Effect.Techniques["DepthMapStatic"];
                    tree.Leaves.DepthMapRendering      = true;
                }
                else
                {
                    tree.Trunk.Effect.CurrentTechnique = tree.Trunk.Effect.Techniques["Static"];
                    tree.Leaves.DepthMapRendering      = false;
                }

                Matrix world = PhysicsObject.GetWorldMatrix(null, Vector3.Zero);

                // Draw the tree's trunk
                //winding is backwards for the trees
                X.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
                tree.Trunk.Draw(world, Camera.View);
                X.GraphicsDevice.RenderState.CullMode = CullMode.CullClockwiseFace;

                // Draw the tree's leaves (this has its own effect)
                if (renderLeaves)
                {
                    tree.Leaves.Draw(world, Camera.View, Camera.Position);
                }

#if DEBUG
                //model.Model.Meshes[0].BoundingSphere.
                //Draw Frustum (Yellow) and Physics Bounding (White), In XActor these should be the same but draw then both anyway just in case
                X.DebugDrawer.DrawCube(tree.boundingBox.Min, tree.boundingBox.Max, Color.Yellow, Matrix.Identity, Camera);
                //Draw physics collisionskin
                X.DebugDrawer.DrawShape(PhysicsObject.GetCollisionWireframe(), Color.White);
#endif
            }
        }//end draw
        public void DrawNormals(Model model, Color color, Matrix world, XCamera camera)
        {
            X.GraphicsDevice.Indices = null;
            X.GraphicsDevice.Vertices[0].SetSource(null, 0, 0);

            foreach (ModelMesh mesh in model.Meshes)
            {
                int vertexCount = mesh.VertexBuffer.SizeInBytes / VertexPositionNormalTexture.SizeInBytes;

                VertexPositionNormalTexture[] verts = new VertexPositionNormalTexture[vertexCount];
                mesh.VertexBuffer.GetData(verts);

                for (int i = 0; i < vertexCount; i++)
                {
                    DrawLine(verts[i].Position, verts[i].Position + verts[i].Normal, color);
                }
            }

            //Draw(world, camera.View, camera.Projection);
        }
        public override void Draw(ref GameTime gameTime, ref XCamera camera)//Matrix world, Matrix view, Matrix projection)
        {
            if (buildVertexBuffer || numOfPrimitives != numOfLines)
            {
                UpdateVertexBuffer();
            }

            if (numOfPrimitives > 0)
            {
                X.GraphicsDevice.RenderState.AlphaBlendEnable  = true;
                X.GraphicsDevice.RenderState.SourceBlend       = Blend.SourceAlpha;
                X.GraphicsDevice.RenderState.DestinationBlend  = Blend.InverseSourceAlpha;
                X.GraphicsDevice.RenderState.DepthBufferEnable = true;
                X.GraphicsDevice.VertexDeclaration             = decl;

                lineRender.Parameters["World"].SetValue(Matrix.Identity);
                lineRender.Parameters["View"].SetValue(camera.View);
                lineRender.Parameters["Projection"].SetValue(camera.Projection);
                lineRender.CurrentTechnique = lineRender.Techniques["LineRendering3D"];

                lineRender.Begin();
                lineRender.CurrentTechnique.Passes[0].Begin();

                X.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(
                    PrimitiveType.LineList, lineVertices, 0, numOfPrimitives);
                if (stripVertexData.Count != 0)
                {
                    X.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip,
                                                                              stripVertexData.ToArray(), 0, stripVertexData.Count - 1);
                }

                lineRender.CurrentTechnique.Passes[0].End();
                lineRender.End();

                numOfLines = 0;
                lines.Clear();
                stripVertexData.Clear();
            }
        }
Exemple #22
0
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            //null checks are for editor!
            //remove these eventually maybe using a compiler directive for an editorer version of the DLL?
            if (model != null && model.loaded)
            {
                if (AlphaBlendable)
                {
                    X.GraphicsDevice.RenderState.AlphaBlendEnable      = true;
                    X.GraphicsDevice.RenderState.SourceBlend           = Blend.SourceAlpha;        // source rgb * source alpha
                    X.GraphicsDevice.RenderState.AlphaSourceBlend      = Blend.One;                // don't modify source alpha
                    X.GraphicsDevice.RenderState.DestinationBlend      = Blend.InverseSourceAlpha; // dest rgb * (255 - source alpha)
                    X.GraphicsDevice.RenderState.AlphaDestinationBlend = Blend.InverseSourceAlpha; // dest alpha * (255 - source alpha)
                    X.GraphicsDevice.RenderState.BlendFunction         = BlendFunction.Add;        // add source and dest results
                }
                else
                {
                    X.GraphicsDevice.RenderState.AlphaBlendEnable = false;
                }

                //Set camera params, compute matrices
                //model.SASData.Camera.NearFarClipping.X = Camera.NearPlane;
                //model.SASData.Camera.NearFarClipping.Y = Camera.FarPlane;
                //model.SASData.Camera.Position.X = Camera.Position.X;
                //model.SASData.Camera.Position.Y = Camera.Position.Y;
                //model.SASData.Camera.Position.Z = Camera.Position.Z;
                model.SASData.Projection = Camera.Projection;
                model.SASData.View       = Camera.View;
                model.SASData.World      = this.GetWorldMatrix();
                model.SASData.ComputeViewAndProjection();
                //model.SASData.ComputeModel();

                //X.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;

                X.Renderer.DrawModel(ref model, ref Camera);
            }//end if (model != null && model.loaded)
        }
Exemple #23
0
        public XMain(GraphicsDevice GraphicsDevice, IServiceProvider Services, string ContentRootDir, XCamera defaultCamera)
        {
            Components = new List <XComponent>();

            this.Content = new ContentManager(Services);
            this.Content.RootDirectory = ContentRootDir;
            this.GraphicsDevice        = GraphicsDevice;
            this.Services = Services;

            Tools = new XTools(this);

            SystemFont  = new XFont(this, @"Content\XEngine\Fonts\System");
            Debug       = new XDebug(this);
            FrameRate   = new XFrameRate(this);
            Console     = new XConsole(this);
            DebugDrawer = new XDebugDrawer(this);
            DepthMap    = new XDepthMap(this);

            Environment = new XEnvironmentParameters(this);


            Physics = new PhysicsSystem();
            Physics.EnableFreezing  = true;
            Physics.SolverType      = PhysicsSystem.Solver.Normal;
            Physics.CollisionSystem = new CollisionSystemGrid(32, 32, 32, 32, 32, 32);
            Physics.CollisionSystem.UseSweepTests = true;

            //New system
            //Physics.CollisionSystem = new CollisionSystemSAP();

            //Rendering should be the last thing! The constructor requires some componnets like debug, debugdrawer to allready exist!
            Renderer = new XRenderer(this);

            this.DefaultCamera = defaultCamera;
            // Initialize the particle cloud system for tree leaves!
            cloudSystem = new ParticleCloudSystem(GraphicsDevice, Content, "Content/XEngine/Effects/ParticleCloud");
        }
Exemple #24
0
 public Vector3 GetScreenCoordinates(ref XCamera Camera)
 {
     return(X.Tools.UnprojectVector3(this.position, Camera, GetWorldMatrix()));
 }
 public void DrawBoundingBox(BoundingBox boundingBox, Color color, Matrix world, XCamera camera)
 {
     DrawCube(boundingBox.Min, boundingBox.Max, color, world, camera);
 }
        /// <summary>
        /// Draws the particle system.
        /// </summary>
        public override void Draw(ref GameTime gameTime, ref XCamera Camera)
        {
            effectViewParameter.SetValue(Camera.View);
            effectProjectionParameter.SetValue(Camera.Projection);

            GraphicsDevice device = X.GraphicsDevice;

            // Restore the vertex buffer contents if the graphics device was lost.
            if (vertexBuffer.IsContentLost)
            {
                vertexBuffer.SetData(particles);
            }

            // If there are any particles waiting in the newly added queue,
            // we'd better upload them to the GPU ready for drawing.
            if (firstNewParticle != firstFreeParticle)
            {
                AddNewParticlesToVertexBuffer();
            }

            // If there are any active particles, draw them now!
            if (firstActiveParticle != firstFreeParticle)
            {
                SetParticleRenderStates(device.RenderState);

                // Set an effect parameter describing the viewport size. This is needed
                // to convert particle sizes into screen space point sprite sizes.
                effectViewportHeightParameter.SetValue(device.Viewport.Height);

                // Set an effect parameter describing the current time. All the vertex
                // shader particle animation is keyed off this value.
                effectTimeParameter.SetValue(currentTime);

                //set depthmap and texture projection parameters
                effectDepthMapParameter.SetValue(X.DepthMap.depthMap);
                effectTextureProjectionParameter.SetValue(textureProjection);

                // Set the particle vertex buffer and vertex declaration.
                device.Vertices[0].SetSource(vertexBuffer, 0,
                                             XParticleVertex.SizeInBytes);

                device.VertexDeclaration = vertexDeclaration;

                // Activate the particle effect.
                particleEffect.Begin(SaveStateMode.SaveState);

                foreach (EffectPass pass in particleEffect.CurrentTechnique.Passes)
                {
                    pass.Begin();

                    if (firstActiveParticle < firstFreeParticle)
                    {
                        // If the active particles are all in one consecutive range,
                        // we can draw them all in a single call.
                        device.DrawPrimitives(PrimitiveType.PointList,
                                              firstActiveParticle,
                                              firstFreeParticle - firstActiveParticle);
                    }
                    else
                    {
                        // If the active particle range wraps past the end of the queue
                        // back to the start, we must split them over two draw calls.
                        device.DrawPrimitives(PrimitiveType.PointList,
                                              firstActiveParticle,
                                              particles.Length - firstActiveParticle);

                        if (firstFreeParticle > 0)
                        {
                            device.DrawPrimitives(PrimitiveType.PointList,
                                                  0,
                                                  firstFreeParticle);
                        }
                    }

                    pass.End();
                }

                particleEffect.End();

                // Reset a couple of the more unusual renderstates that we changed,
                // so as not to mess up any other subsequent drawing.
                device.RenderState.PointSpriteEnable      = false;
                device.RenderState.DepthBufferWriteEnable = true;
                device.RenderState.AlphaBlendEnable       = false;
                device.RenderState.DepthBufferEnable      = true;
            }

            drawCounter++;
        }
Exemple #27
0
 public override void Draw(ref GameTime gameTime, ref XCamera Camera)
 {
     X.DebugDrawer.DrawBoundingBox(box, Color.Red, Matrix.Identity, Camera);
     //XDebugVolumeRenderer.RenderBox(box.GetCentre(), Matrix.Identity, box.SideLengths, Color.White, ref Camera.View, ref Camera.Projection);
     base.Draw(ref gameTime, ref Camera);
 }
Exemple #28
0
 public Vector3 GetScreenCoordinates(XCamera Camera)
 {
     return(X.Tools.UnprojectVector3(this.PhysicsObject.PhysicsBody.Position, Camera, GetWorldMatrix()));
 }
Exemple #29
0
        /// <summary>
        /// This method only support drawing static models. If you attempt to draw an animated (skinned) model it won't look right
        /// </summary>
        /// <param name="Model"></param>
        /// <param name="Camera"></param>
        public virtual void DrawModel(ref XModel Model, ref XCamera Camera)
        {
            for (int i = 0; i < Model.Model.Meshes.Count; i++)
            {
                ModelMesh mesh = Model.Model.Meshes[i];

                //calc new boundingsphere with new position from World/Model matrix
                BoundingSphere bs = mesh.BoundingSphere.Transform(Matrix.CreateTranslation(Model.SASData.World.Translation));

                //Is it in view?
                if (Camera.Frustrum.Contains(bs) == ContainmentType.Disjoint)
                {
                    continue;
                }


#if DEBUG
                //render boundingspheres for each mesh!
                XDebugVolumeRenderer.RenderSphere(bs, Color.Yellow, ref Camera.View, ref Camera.Projection);
#endif

                Model.SASData.ComputeModel();

                for (int j = 0; j < mesh.Effects.Count; j++)
                {
                    Effect effect = mesh.Effects[j];
                    // bind SAS shader parameters
                    for (int k = 0; k < effect.Parameters.Count; k++)
                    {
                        if (effect.Parameters[k].ParameterType == EffectParameterType.String)
                        {
                            if (effect.Parameters[k].Name.Contains("AnimationFileName"))
                            {
                                string animfilename = effect.Parameters[k].GetValueString();
                                if (!string.IsNullOrEmpty(animfilename))
                                {
                                    //there is an animated texture here
                                    foreach (EffectAnnotation anno in effect.Parameters[k].Annotations)
                                    {
                                        if (anno.Name.Contains("AnimatedMap"))
                                        {
                                            effect.Parameters[anno.GetValueString()].SetValue(
                                                Model.Giftextures[j].GetTexture());
                                        }
                                    }
                                }
                            }
                        }
                        Model.SASData.SetEffectParameterValue(effect.Parameters[k]);
                    }

                    //if rendering a depthmap
                    if (Camera.RenderType == RenderTypes.Depth)
                    {
                        //override any techniques with DepthMap technique shader
                        if (effect.Techniques["DepthMapStatic"] != null)
                        {
                            effect.CurrentTechnique = effect.Techniques["DepthMapStatic"];
                        }
                        else
                        {//if we get there there is no DepthMap shader so we can't render this into our depth MAP!!
                            break;
                        }
                        continue;
                    }

                    if (effect.Techniques["Static"] != null)
                    {
                        effect.CurrentTechnique = effect.Techniques["Static"];
                    }
                    else
                    {
                        effect.CurrentTechnique = effect.Techniques[0];
                    }
                }
                mesh.Draw(SaveStateMode.SaveState);
            }
        }
Exemple #30
0
        public void DrawScene(ref GameTime gameTime, ref XCamera Camera, List <XComponent> NoDrawComponents, List <Type> NoDrawTypes)
        {
            X.GraphicsDevice.RenderState.DepthBufferEnable      = true;
            X.GraphicsDevice.RenderState.DepthBufferWriteEnable = true;
            X.GraphicsDevice.RenderState.AlphaBlendEnable       = false;

            List <XComponent> Alpha = new List <XComponent>();

            //ActorsInView.Clear();

            //Begin 2D Sprite Batch
            X.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
#if DEBUG
            //draw axis for debug info, so I can get an idea of where i am in the game
            X.DebugDrawer.DrawLine(new Vector3(-1000, 0, 0), new Vector3(1000, 0, 0), Color.Red);
            X.DebugDrawer.DrawLine(new Vector3(0, -1000, 0), new Vector3(0, 1000, 0), Color.Green);
            X.DebugDrawer.DrawLine(new Vector3(0, 0, -1000), new Vector3(0, 0, 1000), Color.Blue);

            /*X
             * for (int x = -100; x < 100; x++)
             * {
             *  X.DebugDrawer.DrawLine(new Vector3(x, -1000, 0), new Vector3(x, 1000, 0), Color.Red);
             *  for (int z = -100; z < 100; z++)
             *  {
             *      X.DebugDrawer.DrawLine(new Vector3(x, -1000, z), new Vector3(x, 1000, z), Color.Red);
             *  }
             *
             * }
             *
             * //Y
             * for (int y = -100; y < 100; y++)
             * {
             *  X.DebugDrawer.DrawLine(new Vector3(0, y, -1000), new Vector3(0, y, 1000), Color.Green);
             *  for (int z = -100; z < 100; z++)
             *  {
             *      X.DebugDrawer.DrawLine(new Vector3(-1000, y, z), new Vector3(1000, y, z), Color.Blue);
             *      X.DebugDrawer.DrawLine(new Vector3(z, y, -1000), new Vector3(z, y, 1000), Color.Green);
             *  }
             * }
             *
             * //Z
             * for (int z = -100; z < 100; z++)
             * {
             *  X.DebugDrawer.DrawLine(new Vector3(-1000, 0, z), new Vector3(1000, 0, z), Color.Blue);
             * }*/
#endif
            for (int i = 0; i < X.Components.Count; i++)
            {
                XComponent component = X.Components[i];

                //if debug rendering is on draw the XTriggerVolume(s)
#if DEBUG
                if (component is XTriggerVolume)
                {
                    component.Draw(ref gameTime, ref Camera);
                }
#endif
                //is this XComponent Drawable? and not the renderer?
                if (!(component is XIDrawable) || (component is XRenderer))
                {
                    continue;
                }

                //Is this XComponent on the NoDraw types list??
                if (NoDrawTypes != null)
                {
                    if (NoDrawTypes.Contains(component.GetType()))
                    {
                        continue;
                    }
                }

                //Is this XComponent on the NoDraw list?
                if (NoDrawComponents != null)
                {
                    if (NoDrawComponents.Contains(component))
                    {
                        continue;
                    }
                }

                //Add these components to another list to be draw at the end since they are alphablendable
                //after adding it to the list continue to the next component in this loop!
                if (component.AlphaBlendable)
                {
                    Alpha.Add(component);
                    continue;
                }

                if (component is XActor)
                {
                    //Does XActor, XHeightMap,XWater culling, add other types as create them
                    //Only enter this if the XActor is within the view or its NoCull is set
                    //if (Camera.Frustrum.Contains(((XActor)component).boundingBox) != ContainmentType.Disjoint || component.NoCull)
                    if (component.NoCull || (component is XTree) || Camera.Frustrum.Contains(((XActor)component).PhysicsObject.PhysicsBody.CollisionSkin.WorldBoundingBox) != ContainmentType.Disjoint)
                    {
                        component.Draw(ref gameTime, ref Camera);
                    }
                }
                else if (component is XHeightMap)
                {
                    if (Camera.Frustrum.Contains(((XHeightMap)component).boundingBox) != ContainmentType.Disjoint || component.NoCull)
                    {
                        component.Draw(ref gameTime, ref Camera);
                    }
                }
                else if (component is XWater)
                {
                    if (Camera.Frustrum.Contains(((XWater)component).boundingBox) != ContainmentType.Disjoint || component.NoCull)
                    {
                        component.Draw(ref gameTime, ref Camera);
                    }
                }
                else
                {
                    //Frustum testing????? Dynamicsky console debug debug drawer, menu manager
                    component.Draw(ref gameTime, ref Camera);
                }
            }//end xcomponent foreach loop

            //This list of XActors are in view and have Alphablending turned on, RENDER THEM LAST SO THEY BLEND WITH EVERYTHING!
            for (int j = 0; j < Alpha.Count; j++)
            {
                Alpha[j].Draw(ref gameTime, ref Camera);
            }

            //End Sprite Batch
            X.spriteBatch.End();
        }