public void Draw() { Engine.Device.RenderState.CullMode = CullMode.CullClockwiseFace; Matrix worldMatrix = Matrix.CreateTranslation(0, 0, -TILES_Z+1); worldMatrix *= Matrix.CreateScale(10, 1, 10); BasicEffect effect = new BasicEffect(Engine.Device, null); effect.World = worldMatrix; effect.View = Engine.Camera.View; effect.Projection = Engine.Camera.Projection; effect.Texture = Engine.ContentManager.Load<Texture2D>("Content\\Textures\\grass"); effect.TextureEnabled = true; Engine.Device.SamplerStates[0].AddressU = TextureAddressMode.Wrap; Engine.Device.SamplerStates[0].AddressV = TextureAddressMode.Wrap; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); Engine.Device.Vertices[0].SetSource(vb, 0, VertexPositionNormalTexture.SizeInBytes); Engine.Device.Indices = ib; Engine.Device.VertexDeclaration = new VertexDeclaration(Engine.Device, VertexPositionNormalTexture.VertexElements); Engine.Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, TILES_X * TILES_Z, 0, (TILES_X - 1) * (TILES_Z - 1) * 2); } effect.End(); }
public void DrawLine(Vector3 or, Vector3 end, Color c) { #if DEBUG BasicEffect effect; GraphicsDeviceManager gdm = ResourcesManager.GetInstance().GetGraphicsDeviceManager(); VertexPositionColor[] v = new VertexPositionColor[2]; v[0] = new VertexPositionColor(or, c); v[1] = new VertexPositionColor(end, c); effect = new BasicEffect(gdm.GraphicsDevice, null); Camera cam = CameraManager.GetInstance().GetActiveCamera(); effect.View = cam.GetViewMatrix(); effect.Projection = cam.GetProjectionMatrix(); effect.VertexColorEnabled = true; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); gdm.GraphicsDevice.VertexDeclaration = new VertexDeclaration(gdm.GraphicsDevice, VertexPositionColor.VertexElements); gdm.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, v, 0, 1); pass.End(); } effect.End(); #endif }
public static void DrawBoundingBox(BoundingBox bBox, GraphicsDevice device, BasicEffect basicEffect, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix) { Vector3 v1 = bBox.Min; Vector3 v2 = bBox.Max; VertexPositionColor[] cubeLineVertices = new VertexPositionColor[8]; cubeLineVertices[0] = new VertexPositionColor(v1, Color.White); cubeLineVertices[1] = new VertexPositionColor(new Vector3(v2.X, v1.Y, v1.Z), Color.Red); cubeLineVertices[2] = new VertexPositionColor(new Vector3(v2.X, v1.Y, v2.Z), Color.Green); cubeLineVertices[3] = new VertexPositionColor(new Vector3(v1.X, v1.Y, v2.Z), Color.Blue); cubeLineVertices[4] = new VertexPositionColor(new Vector3(v1.X, v2.Y, v1.Z), Color.White); cubeLineVertices[5] = new VertexPositionColor(new Vector3(v2.X, v2.Y, v1.Z), Color.Red); cubeLineVertices[6] = new VertexPositionColor(v2, Color.Green); cubeLineVertices[7] = new VertexPositionColor(new Vector3(v1.X, v2.Y, v2.Z), Color.Blue); short[] cubeLineIndices = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 }; basicEffect.World = worldMatrix; basicEffect.View = viewMatrix; basicEffect.Projection = projectionMatrix; basicEffect.VertexColorEnabled = true; device.RenderState.FillMode = FillMode.Solid; basicEffect.Begin(); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, cubeLineVertices, 0, 8, cubeLineIndices, 0, 12); pass.End(); } basicEffect.End(); }
public void Draw(GraphicsDevice gd, Camera camera) { effect = new BasicEffect(gd, null); effect.Begin(); effect.World = Matrix.Identity; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); effect.Texture = texture; RenderFloor(gd, camera); pass.End(); } effect.End(); }
public override void Draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice device) { if (Mesh == null) { return; } var effect = new BasicEffect(device, null); effect.World = World; effect.View = View; effect.Projection = Projection; effect.Begin(); if (Texture != null) { effect.TextureEnabled = true; effect.Texture = Texture; } foreach (var pass in effect.CurrentTechnique.Passes) { pass.Begin(); Mesh.Draw(device); pass.End(); } effect.End(); }
public void Render(GraphicsDevice device, BasicEffect basicEffect, ObjectShip ship, LevelBackgroundGF levelBackground) { basicEffect.World = Matrix.Identity; basicEffect.LightingEnabled = false; device.RenderState.DepthBufferEnable = false; device.RenderState.CullMode = CullMode.None; device.RenderState.PointSpriteEnable = true; //device.RenderState.PointScaleEnable = true ; device.RenderState.PointSize = 10.0f; device.RenderState.PointSizeMin = 0.00f; device.RenderState.PointSizeMax = 100.00f; //device.RenderState.PointScaleA = 0.00f; //device.RenderState.PointScaleB = 0.00f; //device.RenderState.PointScaleC = 1.00f; device.RenderState.AlphaBlendEnable = true; device.RenderState.SourceBlend = Blend.One; device.RenderState.DestinationBlend = Blend.One; basicEffect.Texture = texture; basicEffect.TextureEnabled = true; int count = 0; bool hackColliding = false; for(int i = 0; i < 6; i++) { Vector3 v = ship.colisionPoints[i]; //v = Vector3.TransformCoordinate(v, ship.renderMatrix); v = Vector3.Transform(v, ship.renderMatrix); //// Vector3 v = ship.Position; //// v.Y = v.Y + (float)(ship.boundingBoxMax.Y * ship.scale * Math.Cos(ship.Rotation.Z)); //// v.X = v.X - (float)(ship.boundingBoxMax.Y * ship.scale * Math.Sin(ship.Rotation.Z)); bool collide = levelBackground.CheckCollision(v); VertexPositionColor pv; pv.Position = v; pv.Color = collide ? Color.Yellow : Color.White; if(collide) { vertices[count] = pv; count++; } hackColliding |= collide; } if(!ship.hackColliding && hackColliding) { ship.Position = ship.OldPosition; ship.Speed = -ship.Speed * 0.3f; SoundHandler.Checkpoint(); } ship.hackColliding = hackColliding; device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); //// Unlock the vertex buffer //vertexBuffer.Unlock(); //// Render any remaining particles if (count > 0) { basicEffect.Begin(); foreach(EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); device.DrawUserPrimitives(PrimitiveType.PointList, vertices, 0, count); pass.End(); } basicEffect.End(); } //// Reset render states //device.RenderState.PointSpriteEnable = false; //device.RenderState.PointScaleEnable = false; //device.RenderState.PointSpriteEnable = true; //device.RenderState.PointScaleEnable = true ; //device.RenderState.AlphaBlendEnable = false; device.RenderState.PointSpriteEnable = false; device.RenderState.DepthBufferWriteEnable = true; device.RenderState.SourceBlend = Blend.SourceAlpha; device.RenderState.DestinationBlend = Blend.InverseSourceAlpha; }
public void Draw(GraphicsDevice graphics, BasicEffect effect) { effect.LightingEnabled = true; effect.AmbientLightColor = new Vector3(1f, 1f, 1f); effect.Texture = this.texture; effect.TextureEnabled = true; effect.Alpha = this.Materiel.alpha; effect.Begin(); graphics.RenderState.AlphaBlendEnable = Convert.ToBoolean(this.Materiel.alpha_enabled); if (Convert.ToBoolean(this.Materiel.alpha_enabled)) { graphics.RenderState.AlphaTestEnable = Convert.ToBoolean(this.Materiel.alpha_test_enabled); if (this.Materiel.blending_mode == 1) { graphics.RenderState.SourceBlend = Blend.One; } else { graphics.RenderState.SourceBlend = Blend.SourceAlpha; } if (this.Materiel.blending_mode == 1) { graphics.RenderState.DestinationBlend = Blend.One; } else { graphics.RenderState.DestinationBlend = Blend.InverseSourceAlpha; } graphics.RenderState.ReferenceAlpha = (int)this.Materiel.alpha_ref_enabled; graphics.RenderState.AlphaFunction = CompareFunction.GreaterEqual; graphics.RenderState.BlendFunction = BlendFunction.Add; } else { graphics.RenderState.AlphaTestEnable = false; graphics.RenderState.SourceBlend = Blend.One; graphics.RenderState.DestinationBlend = Blend.Zero; graphics.RenderState.ReferenceAlpha = 0; graphics.RenderState.AlphaFunction = CompareFunction.Always; graphics.RenderState.BlendFunction = BlendFunction.Add; } for (int i = 0; i < effect.CurrentTechnique.Passes.Count; i++) { effect.CurrentTechnique.Passes[i].Begin(); graphics.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, this.vertex, 0, this.vertex.Length, this.Indices, 0, this.Indices.Length / 3); effect.CurrentTechnique.Passes[i].End(); } effect.End(); }
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionNormalTexture.VertexElements); effect = new BasicEffect(GraphicsDevice, null); effect.World = worldRotation * worldTranslation; effect.View = camera.view; effect.Projection = camera.project; effect.Texture = tex[0]; effect.TextureEnabled = true; //loads a side, changes texture, loads next side, repeat effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, cube.ffront, 0, 2); pass.End(); effect.Texture = tex[1]; effect.TextureEnabled = true; pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, cube.bback, 0, 2); pass.End(); effect.Texture = tex[2]; effect.TextureEnabled = true; pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, cube.lleft, 0, 2); pass.End(); effect.Texture = tex[3]; effect.TextureEnabled = true; pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, cube.rright, 0, 2); pass.End(); effect.Texture = tex[4]; effect.TextureEnabled = true; pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, cube.ttop, 0, 2); pass.End(); effect.Texture = tex[5]; effect.TextureEnabled = true; pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, cube.bbot, 0, 2); pass.End(); } effect.End(); base.Draw(gameTime); }
private void DrawBones(Skelenton skel) { var device = GraphicsDevice; device.RenderState.PointSize = 10.0f; device.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements); device.RenderState.CullMode = CullMode.None; var effect = new BasicEffect(GraphicsDevice, null); //effect.Texture = TextureUtils.TextureFromColor(device, color); //effect.TextureEnabled = true; effect.World = World; effect.View = View; effect.Projection = Projection; effect.VertexColorEnabled = true; effect.EnableDefaultLighting(); effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.Techniques[0].Passes) { pass.Begin(); foreach(var bone in skel.Bones){ var color = Color.Green; if (bone.Name == "ROOT") { color = Color.Red; } else if (bone.Name == "HEAD") { color = Color.Yellow; } var vertex = new VertexPositionColor(bone.AbsolutePosition, color); var vertexList = new VertexPositionColor[1]{vertex}; device.DrawUserPrimitives(PrimitiveType.PointList, vertexList, 0, 1); } pass.End(); } effect.End(); }
private void DrawMesh(Mesh mesh, Texture2D texture) { //glTranslatef(Character.Translation.x, Character.Translation.y, zoom + Character.Translation.z); //glRotatef(Character.Rotation.x, 1.0f, 0.0f, 0.0f); //glRotatef(Character.Rotation.y, 0.0f, 1.0f, 0.0f); //glRotatef(Character.Rotation.z, 0.0f, 0.0f, 1.0f); var device = GraphicsDevice; device.VertexDeclaration = new VertexDeclaration(GraphicsDevice, MeshVertex.VertexElements); device.RenderState.CullMode = CullMode.None; var effect = new BasicEffect(GraphicsDevice, null); effect.Texture = texture; effect.TextureEnabled = true; effect.VertexColorEnabled = false; effect.World = World; effect.View = View; effect.Projection = Projection; effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.Techniques[0].Passes) { pass.Begin(); foreach (var face in mesh.FaceData) { var vertexA = mesh.TransformedVertex[face.VertexA]; var vertexB = mesh.TransformedVertex[face.VertexB]; var vertexC = mesh.TransformedVertex[face.VertexC]; var vertexList = new MeshVertex[3] { vertexA.Vertex, vertexB.Vertex, vertexC.Vertex }; device.DrawUserPrimitives(PrimitiveType.TriangleList, vertexList, 0, 1); } //device.DrawUserPrimitives(PrimitiveType.TriangleList, mesh.TransformedVertexData, 0, mesh.TransformedVertexData.Length / 3); pass.End(); } effect.End(); }
private void RenderSpriteList(List<_3DSprite> sprites, BasicEffect effect, EffectTechnique technique) { ApplyCamera(effect); effect.TextureEnabled = true; var byTexture = sprites.GroupBy(x => x.Texture); foreach (var group in byTexture){ effect.Texture = group.Key; effect.CommitChanges(); effect.Begin(); foreach (var pass in technique.Passes) { pass.Begin(); foreach (var geom in group){ effect.World = geom.World; effect.CommitChanges(); geom.Geometry.DrawGeometry(this.Device); } pass.End(); } effect.End(); } }
public void Draw(GraphicsDevice device) { device.RenderState.PointSize = 30.0f; device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); //device.RenderState.CullMode = CullMode.None; var effect = new BasicEffect(device, null); //effect.Texture = TextureUtils.TextureFromColor(device, color); //effect.TextureEnabled = true; effect.World = Matrix.Identity; effect.View = View; effect.Projection = Projection; effect.VertexColorEnabled = true; //effect.EnableDefaultLighting(); effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.Techniques[0].Passes) { pass.Begin(); var vertex = new VertexPositionColor(Position, Color.Green); var vertexList = new VertexPositionColor[1] { vertex }; device.DrawUserPrimitives(PrimitiveType.PointList, vertexList, 0, 1); vertex.Color = Color.Red; vertex.Position = Target; device.DrawUserPrimitives(PrimitiveType.PointList, vertexList, 0, 1); pass.End(); } effect.End(); }
/// <summary> /// This method gets the debug geometry from the PhysX scene, and draws it to the screen. This is useful for /// making sure that models are being correctly placed within their PhysX bounding boxes, and for checking to /// see if things are physically working without actually drawing them. /// </summary> /// <param name="scene">The PhysX scene that we want to draw debug geometry for.</param> public void DrawPhysXDebug(StillDesign.PhysX.Scene scene) { Camera cam = (Camera)this.Game.Services.GetService(typeof(ICameraService)); _graphics.VertexDeclaration = new VertexDeclaration(_graphics, VertexPositionColor.VertexElements); BasicEffect debugEffect = new BasicEffect(_graphics, null); debugEffect.World = Matrix.Identity; debugEffect.View = cam.View; debugEffect.Projection = cam.Projection; DebugRenderable data = scene.GetDebugRenderable(); debugEffect.Begin(); foreach (EffectPass pass in debugEffect.CurrentTechnique.Passes) { pass.Begin(); if (data.PointCount > 0) { DebugPoint[] points = data.GetDebugPoints(); _graphics.DrawUserPrimitives<DebugPoint>(PrimitiveType.PointList, points, 0, points.Length); } if (data.LineCount > 0) { DebugLine[] lines = data.GetDebugLines(); VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2]; for (int x = 0; x < data.LineCount; x++) { DebugLine line = lines[x]; vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color)); vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color)); } _graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length); } if (data.TriangleCount > 0) { DebugTriangle[] triangles = data.GetDebugTriangles(); VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3]; for (int x = 0; x < data.TriangleCount; x++) { DebugTriangle triangle = triangles[x]; vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color)); } _graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length); } pass.End(); } debugEffect.End(); }
public void Render(GraphicsDevice device, BasicEffect be) { //san #if false be.World = Matrix.Identity; //device.RenderState.DepthBufferEnable = false; // dx: device.RenderState.ZBufferEnable = false; be.LightingEnabled = false; //dx: device.RenderState.Lighting = false; device.RenderState.CullMode = CullMode.None; be.Texture = texture; be.TextureEnabled = true; // dx: device.SetTexture(0, texture); //device.SamplerState[0].MagFilter = TextureFilter.Linear; //device.TextureState[0].ColorOperation = TextureOperation.Modulate; //device.TextureState[0].ColorArgument1 = TextureArgument.Texture; //device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse; //device.TextureState[0].AlphaOperation = TextureOperation.Disable; //device.SetStreamSource(0, vertexes, 0); //device.VertexFormat = Direct3D.CustomVertex.PositionTextured.Format; //device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2); //VertexBuffer vb = new VertexBuffer(device, typeof(VertexPositionTexture), 4, BufferUsage.None); //vb.SetData(vertexes); //device.Vertices[0].SetSource(vb, 0, VertexPositionTexture.SizeInBytes); be.Begin(); device.VertexDeclaration = declaration; //foreach(EffectPass pass in be.CurrentTechnique.Passes) { //pass.Begin(); be.CurrentTechnique.Passes[0].Begin(); device.DrawUserPrimitives(PrimitiveType.TriangleFan, vertexes, 0, 2); be.CurrentTechnique.Passes[0].End(); //pass.End(); } be.End(); #else SpriteBatch sb = new SpriteBatch(device); sb.Begin(); sb.Draw(texture, new Vector2(0,0), Color.White); sb.End(); #endif }
public void DrawSphere(Vector3 c, float rad, Color color) { #if DEBUG Matrix sphereMatrix = Matrix.CreateScale(rad) * Matrix.CreateTranslation(c); int iCountVerts = 0; //create the loop on the XY plane first for (float a = 0f; a <= MathHelper.TwoPi; a += BSPHERE_STEP) { Vector3 position = new Vector3((float)Math.Cos(a), (float)Math.Sin(a), 0f); position = Vector3.Transform(position, sphereMatrix); BSphereVerts[iCountVerts++] = new VertexPositionColor(position, color); } //next on the XZ plane for (float a = 0f; a <= MathHelper.TwoPi; a += BSPHERE_STEP) { Vector3 position = new Vector3((float)Math.Cos(a), 0f, (float)Math.Sin(a)); position = Vector3.Transform(position, sphereMatrix); BSphereVerts[iCountVerts++] = new VertexPositionColor(position, color); } //finally on the YZ plane for (float a = 0f; a <= MathHelper.TwoPi; a += BSPHERE_STEP) { Vector3 position = new Vector3(0f, (float)Math.Cos(a), (float)Math.Sin(a)); position = Vector3.Transform(position, sphereMatrix); BSphereVerts[iCountVerts++] = new VertexPositionColor(position, color); } BasicEffect effect; GraphicsDeviceManager gdm = ResourcesManager.GetInstance().GetGraphicsDeviceManager(); effect = new BasicEffect(gdm.GraphicsDevice, null); Camera cam = CameraManager.GetInstance().GetActiveCamera(); effect.View = cam.GetViewMatrix(); effect.Projection = cam.GetProjectionMatrix(); effect.VertexColorEnabled = true; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); gdm.GraphicsDevice.VertexDeclaration = new VertexDeclaration(gdm.GraphicsDevice, VertexPositionColor.VertexElements); gdm.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, BSphereVerts, 0, iCountVerts / 2); pass.End(); } effect.End(); #endif }
public void Draw(GraphicsDevice device, BasicEffect effect) { CalculateWorldMatrix(); effect.World = World; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, Vertices, 0, Vertices.Length, Indices, 0, Indices.Length / 3); //VertexPositionColor[] lineVerts = new VertexPositionColor[6]{ new VertexPositionColor( -Vector3.One, Color.Blue), // new VertexPositionColor(-Vector3.One+LocalForward , Color.Blue), // new VertexPositionColor( -Vector3.One, Color.Red), // new VertexPositionColor(-Vector3.One+ LocalLeft , Color.Red), // new VertexPositionColor( -Vector3.One, Color.Green), //new VertexPositionColor(Vector3.Transform((Vector3.One +LocalUp),Quaternion.Inverse( Rotation)) , Color.Green), }; //device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, lineVerts, 0, lineVerts.Length, new short[] { 0, 1, 2, 3, 4, 5 }, 0, 3); pass.End(); } effect.End(); }
public virtual void Draw(GameTime gameTime) { // Setup the graphics device to receive the vertex if (useTexture) Manager.Game.GraphicsDevice.VertexDeclaration = new VertexDeclaration(Manager.Game.GraphicsDevice, VertexPositionTexture.VertexElements); else Manager.Game.GraphicsDevice.VertexDeclaration = new VertexDeclaration(Manager.Game.GraphicsDevice, VertexPositionColor.VertexElements); if (effects == null || effects.Count < 1) { // We have not added any special effects, use the basic BasicEffect effect = new BasicEffect(Manager.Game.GraphicsDevice, null); effect.World = GenerateWorldMatrix(); effect.View = camera.View; effect.Projection = camera.Projection; if (useTexture) { effect.Texture = texture; effect.TextureEnabled = true; } else effect.VertexColorEnabled = true; // Begin effect and draw for each pass effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); if (useTexture) Manager.Game.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, vertexTextures, 0, vertexTextures.Length / 2); else Manager.Game.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, vertexColors, 0, vertexColors.Length / 2); pass.End(); } effect.End(); } else { // Go through each effect foreach (VideoEffect effect in effects) { // Setup the technique to be performed foreach (VideoTechnique technique in effect.Techniques) { effect.SetCurrentTechnique(technique); // Call the technique's setup technique.Setup(camera, GenerateWorldMatrix()); effect.Begin(); foreach (EffectPass pass in effect.GetCurrentTechnique().Passes) { pass.Begin(); if (useTexture) Manager.Game.GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleStrip, vertexTextures, 0, vertexTextures.Length / 2); else Manager.Game.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, vertexColors, 0, vertexColors.Length / 2); pass.End(); } effect.End(); } } } }
/// <summary> /// Draws the Quad /// </summary> /// <param name="View">The view Matrix</param> /// <param name="World">The World matrix</param> /// <param name="Projection">The projection Matrix</param> /// <param name="effectSetup">A Basic Effect to draw with</param> public void Draw(Matrix View, Matrix World, Matrix Projection, BasicEffect effectSetup) { effectSetup.Texture = texture; effectSetup.View = View; effectSetup.World = World; effectSetup.Projection = Projection; effectSetup.TextureEnabled = true; effectSetup.VertexColorEnabled = false; dev.VertexDeclaration = this.quadVertexDecl; effectSetup.Begin(); foreach (EffectPass pass in effectSetup.CurrentTechnique.Passes) { pass.Begin(); dev.DrawUserIndexedPrimitives<VertexPositionNormalTexture>( PrimitiveType.TriangleList, this.Vertices, 0, 4, this.Indices, 0, 2); pass.End(); } effectSetup.End(); effectSetup.TextureEnabled = false; effectSetup.VertexColorEnabled = true; }
public override void Draw(GameTime GameTime) { base.Draw( GameTime ); if( Debug ) { GameArgs.Current.GraphicsDevice.VertexDeclaration = new VertexDeclaration( GameArgs.Current.GraphicsDevice, VertexPositionColor.VertexElements ); BasicEffect BasicEffect = new BasicEffect( GameArgs.Current.GraphicsDevice, null ); GameArgs.Current.setBasicEffectMatrices( BasicEffect ); BasicEffect.World *= Matrix.CreateTranslation( -Location ); BasicEffect.World *= Matrix.CreateRotationX( Rotation.X ); BasicEffect.World *= Matrix.CreateRotationY( Rotation.Y ); BasicEffect.World *= Matrix.CreateRotationZ( Rotation.Z ); BasicEffect.Begin(); BasicEffect.CurrentTechnique.Passes[ 0 ].Begin(); VertexPositionColor[] vertices = new VertexPositionColor[ 10 ]; vertices[ 0 ].Position = new Vector3( -5.0f, 5.0f, 5.0f ); vertices[ 0 ].Color = Color.Red; vertices[ 1 ].Position = new Vector3( 5.0f, 5.0f, 5.0f ); vertices[ 1 ].Color = Color.Red; vertices[ 2 ].Position = new Vector3( -5.0f, -5.0f, 5.0f ); vertices[ 2 ].Color = Color.Red; vertices[ 3 ].Position = new Vector3( 5.0f, -5.0f, 5.0f ); vertices[ 3 ].Color = Color.Red; vertices[ 4 ].Position = new Vector3( -5.0f, -5.0f, -5.0f ); vertices[ 4 ].Color = Color.Red; vertices[ 5 ].Position = new Vector3( 5.0f, -5.0f, -5.0f ); vertices[ 5 ].Color = Color.Red; vertices[ 6 ].Position = new Vector3( -5.0f, 5.0f, -5.0f ); vertices[ 6 ].Color = Color.Red; vertices[ 7 ].Position = new Vector3( 5.0f, 5.0f, -5.0f ); vertices[ 7 ].Color = Color.Red; vertices[ 8 ].Position = new Vector3( -5.0f, -5.0f, -5.0f ); vertices[ 8 ].Color = Color.Red; vertices[ 9 ].Position = new Vector3( 5.0f, -5.0f, -5.0f ); vertices[ 9 ].Color = Color.Red; GameArgs.Current.GraphicsDevice.DrawUserPrimitives( PrimitiveType.TriangleStrip, vertices, 0, 5 ); BasicEffect.CurrentTechnique.Passes[ 0 ].End(); BasicEffect.End(); } /* if (mDebug) { Gl.glDisable(Gl.GL_LIGHTING); Gl.glColor3f(1.0f, 0.0f, 0.0f); Gl.glTranslatef(mLocation.X, mLocation.Y, mLocation.Z); Gl.glBegin(Gl.GL_QUAD_STRIP); Gl.glVertex3f(-5.0f, -5.0f, -5.0f); Gl.glVertex3f(5.0f, -5.0f, -5.0f); Gl.glVertex3f(-5.0f, 5.0f, -5.0f); Gl.glVertex3f(5.0f, 5.0f, -5.0f); Gl.glVertex3f(-5.0f, 5.0f, 5.0f); Gl.glVertex3f(5.0f, 5.0f, 5.0f); Gl.glVertex3f(-5.0f, -5.0f, 5.0f); Gl.glVertex3f(5.0f, -5.0f, 5.0f); Gl.glVertex3f(-5.0f, -5.0f, -5.0f); Gl.glVertex3f(5.0f, -5.0f, -5.0f); Gl.glEnd(); // Gl.glBegin(Gl.GL_QUADS); // Gl.glEnd(); Gl.glTranslatef(-mLocation.X, -mLocation.Y, -mLocation.Z); Gl.glEnable(Gl.GL_LIGHTING); }*/ }
public void Draw(BasicEffect effect) { effect.Begin(); foreach (EffectPass current in effect.CurrentTechnique.Passes) { current.Begin(); this.graphics.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, this.vertices, 0, this.vertices.Length, this.indices, 0, this.vertices.Length - 1); current.End(); } effect.End(); }
public static void DrawSphereSpikes(BoundingSphere sphere, GraphicsDevice device, BasicEffect basicEffect, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix) { Vector3 up = sphere.Center + sphere.Radius * Vector3.Up; Vector3 down = sphere.Center + sphere.Radius * Vector3.Down; Vector3 right = sphere.Center + sphere.Radius * Vector3.Right; Vector3 left = sphere.Center + sphere.Radius * Vector3.Left; Vector3 forward = sphere.Center + sphere.Radius * Vector3.Forward; Vector3 back = sphere.Center + sphere.Radius * Vector3.Backward; VertexPositionColor[] sphereLineVertices = new VertexPositionColor[6]; sphereLineVertices[0] = new VertexPositionColor(up, Color.White); sphereLineVertices[1] = new VertexPositionColor(down, Color.White); sphereLineVertices[2] = new VertexPositionColor(left, Color.White); sphereLineVertices[3] = new VertexPositionColor(right, Color.White); sphereLineVertices[4] = new VertexPositionColor(forward, Color.White); sphereLineVertices[5] = new VertexPositionColor(back, Color.White); basicEffect.World = worldMatrix; basicEffect.View = viewMatrix; basicEffect.Projection = projectionMatrix; basicEffect.VertexColorEnabled = true; basicEffect.Begin(); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements); device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, sphereLineVertices, 0, 3); pass.End(); } basicEffect.End(); }
/// <summary> /// Method to draw a line in 3D /// </summary> /// <param name="color">Color of line</param> /// <param name="point1">first point</param> /// <param name="point2">second point</param> /// <param name="effect">Basic effects object</param> /// <param name="gfxDevice">Graphics device</param> /// <param name="projection">Projection matrix</param> /// <param name="view">view matrix</param> /// <param name="world">world matrix</param> public static void Draw3DLine(Microsoft.Xna.Framework.Graphics.Color color, Vector3 point1, Vector3 point2, BasicEffect effect, GraphicsDevice gfxDevice, Matrix projection, Matrix view, Matrix world) { VertexPositionColor[] vertexList = new VertexPositionColor[2]; vertexList[0] = new VertexPositionColor(point1, color); vertexList[1] = new VertexPositionColor(point2, color); gfxDevice.VertexDeclaration = new VertexDeclaration(gfxDevice,VertexPositionColor.VertexElements); effect.Projection = projection; effect.View = view; effect.World = world; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); gfxDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertexList, 0, 1); pass.End(); } effect.End(); }
private void DrawDebug(GameTime gameTime) { this.GraphicsDevice.VertexDeclaration = new VertexDeclaration(this.GraphicsDevice, VertexPositionColor.VertexElements); BasicEffect debugEffect = new BasicEffect(this.GraphicsDevice, null); debugEffect.World = Matrix.Identity; debugEffect.View = this._camera.View; debugEffect.Projection = this._camera.Projection; DebugRenderable data = this.Scene.GetDebugRenderable(); debugEffect.Begin(); foreach (EffectPass pass in debugEffect.CurrentTechnique.Passes) { pass.Begin(); if (data.PointCount > 0) { DebugPoint[] points = data.GetDebugPoints(); this.GraphicsDevice.DrawUserPrimitives<DebugPoint>(PrimitiveType.PointList, points, 0, points.Length); } if (data.LineCount > 0) { DebugLine[] lines = data.GetDebugLines(); VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2]; for (int x = 0; x < data.LineCount; x++) { DebugLine line = lines[x]; vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color)); vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color)); } this.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length); } if (data.TriangleCount > 0) { DebugTriangle[] triangles = data.GetDebugTriangles(); VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3]; for (int x = 0; x < data.TriangleCount; x++) { DebugTriangle triangle = triangles[x]; vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color)); } this.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length); } pass.End(); } debugEffect.End(); }
public void Run() { using (var form = EmptyWindow.CreateForm()) { PresentationParameters presentationParameters = EmptyWindow.CreatePresentationParameters(); var device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, form.Handle, presentationParameters); Vertex[] vertices = CreateVertices(); var vertexBuffer = new VertexBuffer(device, typeof(Vertex), vertices.Length, BufferUsage.None); vertexBuffer.SetData(vertices, 0, vertices.Length); var indices = CreateIndices(); var indexBuffer = new IndexBuffer(device, sizeof (int) * indices.Length, BufferUsage.None, IndexElementSize.ThirtyTwoBits); indexBuffer.SetData(indices); VertexDeclaration vertexDeclaration = TriangleWithVertexBuffer.CreateVertexDeclaration(device); var basicEffect = new BasicEffect(device, new EffectPool()) { LightingEnabled = false, TextureEnabled = false, VertexColorEnabled = true }; Application.Idle += delegate { device.Clear(Color.Blue); device.VertexDeclaration = vertexDeclaration; device.Vertices[0].SetSource(vertexBuffer, 0, 24); device.Indices = indexBuffer; device.RenderState.CullMode = CullMode.None; basicEffect.Projection = Matrix.CreatePerspectiveFieldOfView( (float)(System.Math.PI / 3), 800f / 600.0f, 0.01f, 100f); basicEffect.View = Matrix.CreateLookAt( new Vector3(0, 0, -3), new Vector3(), new Vector3(0, 1, 0)); basicEffect.World = Matrix.Identity; basicEffect.Begin(); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, 2); pass.End(); } basicEffect.End(); device.Present(); Application.DoEvents(); }; Application.Run(form); } }
public void Draw(Matrix projection, Matrix view) { // draw the bounding box BasicEffect basicEffect = new BasicEffect(GraphicsDevice, null); basicEffect.VertexColorEnabled = true; basicEffect.World = Matrix.Identity; basicEffect.View = view; basicEffect.Projection = projection; basicEffect.Begin(); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>( PrimitiveType.LineList, boundVertices, 0, // vertex buffer offset to add to each element of the index buffer 4, // number of vertices in pointList boundIndices, // the index buffer 0, // first index element to read 4 // number of primitives to draw ); GraphicsDevice.RenderState.PointSize = 2; GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.PointList, gridVerts, 0, // index of the first vertex to draw gridSize * gridSize / 2 // number of primitives ); GraphicsDevice.RenderState.FillMode = FillMode.Solid; pass.End(); } basicEffect.End(); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.RenderState.CullMode = CullMode.None; graphics.GraphicsDevice.RenderState.FillMode = FillMode.Solid; graphics.GraphicsDevice.RenderState.PointSize = 5; BasicEffect fx = new BasicEffect(GraphicsDevice, null); fx.VertexColorEnabled = true; fx.TextureEnabled = true; fx.World = Matrix.CreateRotationX(Rotation.X) * Matrix.CreateRotationY(Rotation.Y); fx.View = Matrix.CreateLookAt(Position + LookAt, LookAt, Vector3.Up); fx.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f); fx.Begin(); foreach (EffectPass pass in fx.CurrentTechnique.Passes) { pass.Begin(); field.Draw(); puck.Draw(); Spieler1.Draw(); Spieler2.Draw(); graphics.GraphicsDevice.RenderState.FillMode = FillMode.Solid; hudtext.Draw(gameTime); pass.End(); } fx.End(); base.Draw(gameTime); }
public static void Draw(this Utilities.GridTransform transform, GraphicsDevice graphicsDevice, BasicEffect basicEffect) { VertexPositionColor[] ctrlVerticies = new VertexPositionColor[transform.mapPoints.Length]; VertexPositionColor[] mapVerticies = new VertexPositionColor[transform.mapPoints.Length]; List<int> listIndicies = new List<int>(transform.Edges.Count / 2); foreach(int iStartPoint in transform.Edges.Keys) { List<int> edgeList = transform.Edges[iStartPoint]; foreach (int iEndPoint in edgeList) { //Skip if we would have added it earlier if (iEndPoint < iStartPoint) continue; listIndicies.AddRange(new int[] { iStartPoint, iEndPoint}); } } int[] indicies = listIndicies.ToArray(); for (int i = 0; i < transform.mapPoints.Length; i++) { GridVector2 CtrlP = transform.mapPoints[i].ControlPoint; GridVector2 MapP = transform.mapPoints[i].MappedPoint; Vector3 ctrlPosition = new Vector3((Single)CtrlP.X, (Single)CtrlP.Y, 1); Vector3 mapPosition = new Vector3((Single)MapP.X, (Single)MapP.Y, 1); ctrlVerticies[i] = new VertexPositionColor(ctrlPosition, Microsoft.Xna.Framework.Graphics.Color.Gold); mapVerticies[i] = new VertexPositionColor(mapPosition, Microsoft.Xna.Framework.Graphics.Color.Red); } graphicsDevice.RenderState.PointSize = 5.0f; VertexDeclaration oldVertexDeclaration = graphicsDevice.VertexDeclaration; if (DrawExtensions.VertexPositionColorDeclaration == null) { DrawExtensions.VertexPositionColorDeclaration = new VertexDeclaration( graphicsDevice, VertexPositionColor.VertexElements ); } graphicsDevice.VertexDeclaration = DrawExtensions.VertexPositionColorDeclaration; basicEffect.Texture = null; basicEffect.TextureEnabled = false; basicEffect.VertexColorEnabled = true; basicEffect.CommitChanges(); basicEffect.Begin(); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); // graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, mapVerticies, 0, mapVerticies.Length, indicies, 0, indicies.Length / 2); if(ctrlVerticies != null && ctrlVerticies.Length > 0) graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, ctrlVerticies, 0, ctrlVerticies.Length, indicies, 0, indicies.Length / 2); pass.End(); } basicEffect.End(); graphicsDevice.VertexDeclaration = oldVertexDeclaration; }
void DrawLaser() { using (BasicEffect effect = new BasicEffect(Game.GraphicsDevice, null)) { effect.DiffuseColor = Color.Black.ToVector3(); effect.World = Matrix.Identity; effect.View = camera.View; effect.Projection = camera.Projection; effect.Begin(); effect.EnableDefaultLighting(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); VertexPositionNormalTexture[] line; line = new VertexPositionNormalTexture[2]; line[0] = new VertexPositionNormalTexture(Position, Vector3.Forward, Vector2.One); line[1] = new VertexPositionNormalTexture(farPoint, Vector3.Forward, Vector2.One); Game.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>( PrimitiveType.LineList, line, 0, 2, new short[2] { 0, 1 }, 0, 1); pass.End(); } effect.End(); } }
public void DrawQuad( Vector2 min, Vector2 max, BasicEffect effect ) { effect.Begin(); effect.Techniques[ 0 ].Passes[ 0 ].Begin(); DrawQuad( min, max ); effect.Techniques[ 0 ].Passes[ 0 ].End(); effect.End(); }