public void Render(RenderContext render_context, GameTime gameTime) { /// since we are only using one vertex declaration, we can just set the /// GraphicsDevice.VertexDeclaration once in the Initialize() method call. GraphicsDevice gd = render_context.GraphicsDevice; BasicEffect effect = render_context.BasicEffect; VertexDeclaration vertexDeclaration = VertexPositionColor.VertexDeclaration; //gd.VertexDeclaration = vertexDeclaration; effect.World = Matrix.CreateTranslation(origin); effect.View = render_context.Camera.View; effect.Projection = render_context.Camera.Projection; effect.VertexColorEnabled = true; if (vertex_buffer == null) { vertex_buffer = new VertexBuffer(gd, typeof(VertexPositionColor), vertices.Length, BufferUsage.WriteOnly); vertex_buffer.SetData<VertexPositionColor>(vertices); } foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); gd.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, vertices.Length / 2); } }
public virtual void Render(RenderContext renderContext, GameTime gameTime) { if (SpriteBatch == null) { return; } if (Target == null) { ReticuleColor = Color.White; } else { ReticuleColor = Color.Red; } Viewport viewport = renderContext.GraphicsDevice.Viewport; int middlePixelX = viewport.Width / 2; int middlePixelY = viewport.Height / 2; int halfSize = 15; SpriteBatch.Begin(); SpriteBatch.Draw(ReticuleTexture, new Rectangle(middlePixelX - halfSize, middlePixelY - halfSize, halfSize * 2, halfSize * 2), ReticuleColor ); SpriteBatch.End(); }
public static void Render(Primitive prim, RenderContext context, Color color) { if (prim.PrimType == Forever.Physics.Collide.CollideType.Sphere) { Sphere sphere = (Sphere)prim; BoundingSphere bs = new BoundingSphere(prim.Body.Position, sphere.Radius); BoundingSphereRenderer.Render(bs, context, color); } else if (prim.PrimType == Forever.Physics.Collide.CollideType.Box) { Box b = (Box)prim; Matrix world = prim.Body.World; BoundingBoxRenderer.Render( BoundingBox.CreateFromPoints(b.LocalVerts()), context.GraphicsDevice, world * b.OffsetMatrix, context.Camera.View, context.Camera.Projection, color ); }else if(prim.PrimType == Forever.Physics.Collide.CollideType.Plane){ Render((Forever.Physics.Collide.Plane)prim, context, color); } else { throw new Exception("I don't know how to draw that!"); } }
public static void Render(BoundingSphere sphere, RenderContext context, Color color) { GraphicsDevice gd = context.GraphicsDevice; Matrix view = context.Camera.View; Matrix proj = context.Camera.Projection; Render(sphere, gd, view, proj, color); }
public static void RenderVertexPositionColorList(RenderContext render_context, Matrix world, VertexPositionColor[] vertices, VertexDeclaration vertexDeclaration, VertexBuffer vertex_buffer) { GraphicsDevice gd = render_context.GraphicsDevice; BasicEffect effect = render_context.BasicEffect; Matrix view = render_context.Camera.View; Matrix proj = render_context.Camera.Projection; /* Would the real RenderVertexPositionColorList please stand up? */ RenderVertexPositionColorList(gd, effect, world, view, proj, vertices, vertexDeclaration, vertex_buffer); }
public Demo( ContentManager contentManager, RenderContext renderContext, QueuedList<IRenderable> renderGroup, QueuedList<IGameEntity> gameObjects) : base() { content = contentManager; this.renderContext = renderContext; this.renderGroup = renderGroup; this.gameObjects = gameObjects; ForceRegistry = new ForceRegistry(); }
public static void RenderNode(AABBNode node, Matrix world, Matrix view, Matrix proj, RenderContext render_context, Color leaf_color, Color marked_color) { if (node.IsLeaf) { Color color = leaf_color; if (node.Marked) { color = marked_color; } BoundingBoxRenderer.Render(node.BBox, render_context.GraphicsDevice, world, view, proj, color); }else{ RenderNode(node.Left, world, view, proj, render_context, leaf_color, marked_color); RenderNode(node.Right, world, view, proj, render_context, leaf_color, marked_color); } }
public static void RenderNode(AABBNode node, Matrix world, Matrix view, Matrix proj, RenderContext render_context, Color leaf_color) { RenderNode(node, world, view, proj, render_context, leaf_color, leaf_color); }
public static void Render(AABBTree tree, Matrix world, Matrix view, Matrix proj, RenderContext render_context, Color color) { RenderNode(tree.Root, world, view, proj, render_context, color); }
public void Render(RenderContext render_context, GameTime gameTime) { Renderer.RenderModel(model, world, render_context); if (debug) { debug_compass.Render(render_context, gameTime); if (tree != null) { AABBTreeRenderer.RenderNode( tree.Root, world, render_context.Camera.View, render_context.Camera.Projection, render_context, Color.Red, Color.SkyBlue ); } } }
public static void RenderModel(Model model, Matrix world, RenderContext renderContext) { Renderer.RenderModel(model, world, renderContext.Camera.View, renderContext.Camera.Projection); }
public static void Render(Forever.Physics.Collide.Plane plane, RenderContext context, Color color) { if (effect == null) { InitializeGraphics(context.GraphicsDevice); } Matrix view = context.Camera.View; Matrix projection = context.Camera.Projection; GraphicsDevice graphicsDevice = context.GraphicsDevice; Vector3 w_point = context.Camera.Position; Vector3 point = plane.ClosestPoint(w_point); Vector3 away = point - plane.PrinciplePoint; Vector3 a = Vector3.Cross(away, plane.Normal); Vector3 b = Vector3.Cross(a, plane.Normal); if (a.Length() != 0) { a.Normalize(); } if (b.Length() != 0) { b.Normalize(); } float check = Vector3.Dot(plane.Normal, b); Vector3 planeOrigin = plane.PrinciplePoint; planeVerts[3].Position = planeOrigin + (a * -10000f) + (b * 10000f); planeVerts[2].Position = planeOrigin + (a * 10000f) + (b * 10000f); planeVerts[1].Position = planeOrigin + (a * 10000f) + (b * -10000f); planeVerts[0].Position = planeOrigin + (a * -10000f) + (b * -10000f); for (int i = 0; i < 4; i++) { planeVerts[i].Color = color; } //graphicsDevice.VertexDeclaration = vertDecl; effect.World = Matrix.Identity; effect.View = view; effect.Projection = projection; //effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawUserIndexedPrimitives( Microsoft.Xna.Framework.Graphics.PrimitiveType.TriangleList, planeVerts, 0, 4, planeIndices, 0, 4 ); //pass.End(); } //effect.End(); }
public static void Render(Sphere sphere, RenderContext context, Color color) { BoundingSphere bs = new BoundingSphere(sphere.Body.Position, sphere.Radius); BoundingSphereRenderer.Render(bs, context, color); }
public void Render(RenderContext renderContext, GameTime gameTime) { //renderContext.GraphicsDevice.Clear(Color.Black); // Render a set of quads tiled with a texture centered at the place where the // cam position is projected on to our plane Vector3 camPosition = renderContext.Camera.Position; BasicEffect quadEffect = renderContext.BasicEffect; quadEffect.EnableDefaultLighting(); quadEffect.View = renderContext.Camera.View; quadEffect.Projection = renderContext.Camera.Projection; quadEffect.TextureEnabled = true; quadEffect.Texture = Texture; int numTilesPerSide = 10; Matrix instancingOffset; Vector3 quadCenter; Forever.Physics.Collide.Plane plane = geometryData.Prim as Forever.Physics.Collide.Plane; float tileSize = 10f; Matrix scale = Matrix.CreateScale(tileSize); // back, left Vector3 renderOrigin = plane.PrinciplePoint; //+ plane.Right * -1f * ((numTilesPerSide * tileSize * 0.5f)) //+ plane.Forward * -1f * ((numTilesPerSide * tileSize * 0.5f)); float visableRegionSize = numTilesPerSide * tileSize; Vector3 camOnPlane = plane.ClosestPoint(camPosition); Vector3 planarDiff = camOnPlane - renderOrigin; int originRegionX = 0;// (int)(renderOrigin.X / visableRegionSize); int originRegionZ = 0;// (int)(renderOrigin.Z / visableRegionSize); float camRegionX = (camOnPlane.X / visableRegionSize); float camRegionZ = (camOnPlane.Z / visableRegionSize); if (camRegionX < originRegionX || camRegionX > originRegionX) { int regionsX = ((int)planarDiff.X / (int)visableRegionSize) + -1; renderOrigin += new Vector3(regionsX * visableRegionSize, 0f, 0f); } if (camRegionZ < originRegionZ || camRegionZ > originRegionZ) { int regionsZ = ((int)planarDiff.Z / (int)visableRegionSize) + -1; renderOrigin += new Vector3(0f, 0f, regionsZ * visableRegionSize); } renderContext.GraphicsDevice.DepthStencilState = DepthStencilState.Default; foreach (EffectPass pass in quadEffect.CurrentTechnique.Passes) { for (int i = -1; i < 3; i++) { for (int j = -1; j < 3; j++) { Vector3 regionOffset = new Vector3(i * visableRegionSize, 0f, j * visableRegionSize); for (int x = 0; x < numTilesPerSide; x++) { float localX = tileSize * x; for (int z = 0; z < numTilesPerSide; z++) { float localZ = tileSize * z; quadCenter = renderOrigin + regionOffset + (plane.Right * localX) + (plane.Forward * localZ); quadCenter = new Vector3(quadCenter.X, plane.PrinciplePoint.Y, quadCenter.Z); instancingOffset = Matrix.CreateTranslation( quadCenter ); quadEffect.World = scale * instancingOffset; pass.Apply(); renderContext.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>( PrimitiveType.TriangleList, Vertices, 0, 4, Indices, 0, 2 ); } } } } } }
protected void SetupRenderContextAndCamera() { ICamera cam = new EyeCamera(); renderContext = new RenderContext( cam, this.ScreenManager.Game.GraphicsDevice ); float radius = 2f; float mass = 1f; CamBody = new RigidBody(cam.Position); CamBody.Label = "Camera Body"; CamBody.Awake = true; CamBody.LinearDamping = 0.9f; CamBody.AngularDamping = 0.7f; CamBody.Mass = mass; CamBody.InertiaTensor = InertiaTensorFactory.Sphere(mass, radius); CamControls = new UserControls(PlayerIndex.One, 0.000015f, 0.25f, 0.0003f, 1f); }
//public override void Draw(GameTime gameTime) public void Render(RenderContext renderContext, GameTime gameTime) { ICamera camera = renderContext.Camera; Matrix[] boneTransforms = new Matrix[domeModel.Bones.Count]; domeModel.CopyAbsoluteBoneTransformsTo(boneTransforms); Matrix View = camera.View; Matrix Projection = camera.Projection; //game.GraphicsDevice.RenderState.DepthBufferEnable = false; //game.GraphicsDevice.RenderState.DepthBufferWriteEnable = false; GraphicsDevice graphics = renderContext.GraphicsDevice; graphics.BlendState = BlendState.AlphaBlend; graphics.DepthStencilState = DepthStencilState.DepthRead; foreach (ModelMesh mesh in domeModel.Meshes) { //TODO - magic number, parameterize this class Matrix World = boneTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(camera.Position.X, -10.0f, 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["WorldViewProj"].SetValue(World * View * Projection); effect.Parameters["ViewInv"].SetValue(Matrix.Invert(View)); effect.Parameters["World"].SetValue(World); effect.Parameters["SkyTextureNight"].SetValue(night); effect.Parameters["SkyTextureSunset"].SetValue(sunset); effect.Parameters["SkyTextureDay"].SetValue(day); effect.Parameters["isSkydome"].SetValue(true); effect.Parameters["LightDirection"].SetValue(parameters.LightDirection); effect.Parameters["LightColor"].SetValue(parameters.LightColor); effect.Parameters["LightColorAmbient"].SetValue(parameters.LightColorAmbient); effect.Parameters["FogColor"].SetValue(parameters.FogColor); effect.Parameters["fDensity"].SetValue(parameters.FogDensity); effect.Parameters["SunLightness"].SetValue(parameters.SunLightness); effect.Parameters["sunRadiusAttenuation"].SetValue(parameters.SunRadiusAttenuation); effect.Parameters["largeSunLightness"].SetValue(parameters.LargeSunLightness); effect.Parameters["largeSunRadiusAttenuation"].SetValue(parameters.LargeSunRadiusAttenuation); effect.Parameters["dayToSunsetSharpness"].SetValue(parameters.DayToSunsetSharpness); effect.Parameters["hazeTopAltitude"].SetValue(parameters.HazeTopAltitude); mesh.Draw(); } } //game.GraphicsDevice.RenderState.DepthBufferWriteEnable = true; //game.GraphicsDevice.RenderState.DepthBufferEnable = true; }