Example #1
1
        public static void Draw(VertexPositionColor[] Points, Texture2D Texture)
        {
            //PUT IN DRAW CODE FOR PARTICLES HERE
            mGraphics.Peek.Device().RenderState.PointSpriteEnable = true;
            mGraphics.Peek.ToggleAlphaBlending(true);
            mGraphics.Peek.Device().RenderState.DepthBufferWriteEnable = false;
            mGraphics.Peek.Device().VertexDeclaration = mGraphics.Peek.vdPositionColor;
            mEffect.Peek.PointEffect().Parameters["WVPMatrix"].SetValue(Matrix.Identity * mCamera.Peek.ReturnCamera().View * mCamera.Peek.ReturnCamera().Projection);
            mEffect.Peek.PointEffect().Parameters["SpriteTexture"].SetValue(Texture);
            mEffect.Peek.PointEffect().Parameters["ViewportHeight"].SetValue(mGraphics.Peek.Device().Viewport.Height);
            mEffect.Peek.PointEffect().Parameters["ViewportHeight"].SetValue(25.0f);

            mEffect.Peek.PointEffect().Begin();
            for (int i = 0; i < mEffect.Peek.PointEffect().CurrentTechnique.Passes.Count; i++)
            {
                mEffect.Peek.PointEffect().CurrentTechnique.Passes[i].Begin();
                mGraphics.Peek.Device().DrawUserPrimitives<VertexPositionColor>(PrimitiveType.PointList, Points, 0, Points.Length);
                mEffect.Peek.PointEffect().CurrentTechnique.Passes[i].End();
            }
            mEffect.Peek.PointEffect().End();

            mGraphics.Peek.Device().RenderState.PointSpriteEnable = false;
            mGraphics.Peek.Device().RenderState.DepthBufferWriteEnable = true;
            mGraphics.Peek.ToggleAlphaBlending(false);
        }
        public static AABBTree AABBTree(Model model, AABBNodeInfo tree_info)
        {
            List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>();
              List<Vector3> points = new List<Vector3>();
              AABBFactory.ExtractData(model, points, indices, true);

              VertexPositionColor[] vertices = new VertexPositionColor[indices.Count * 3];

              List<float[]> triangles = new List<float[]>();

              int i = 0;
              foreach (TriangleVertexIndices index in indices)
              {
            vertices[i++] = new VertexPositionColor(points[index.I0], Color.White);
            vertices[i++] = new VertexPositionColor(points[index.I1], Color.White);
            vertices[i++] = new VertexPositionColor(points[index.I2], Color.White);

            float[] tri = new float[3];
            tri[0] = points[index.I0].X;
            tri[1] = points[index.I1].Y;
            tri[2] = points[index.I2].Z;
            triangles.Add(tri);
              }
              return new AABBTree(triangles, tree_info);
        }
Example #3
0
        public static void DrawBBox(List<BoundingBox> boundingBoxes, Matrix Projection, Matrix View,Matrix localWorld)
        {
            // Use inside a drawing loop
            foreach (BoundingBox box in boundingBoxes)
            {
                Vector3[] corners = box.GetCorners();
                VertexPositionColor[] primitiveList = new VertexPositionColor[corners.Length];

                // Assign the 8 box vertices
                for (int i = 0; i < corners.Length; i++)
                {
                    primitiveList[i] = new VertexPositionColor(corners[i], Color.White);
                }

                /* Set your own effect parameters here */

                boxEffect.World = localWorld;
                boxEffect.View = View;
                boxEffect.Projection = Projection;
                boxEffect.TextureEnabled = false;

                // Draw the box with a LineList
                foreach (EffectPass pass in boxEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    device.DrawUserIndexedPrimitives(
                        PrimitiveType.LineList, primitiveList, 0, 8,
                        bBoxIndices, 0, 12);
                }
            }
        }
Example #4
0
        public WorldAxes()
        {
            // load our vertices and there color
            vertices = new VertexPositionColor[3][];
            for (int x = 0; x < 3; x++)
            {
                vertices[x] = new VertexPositionColor[2];
                for (int y = 0; y < 2; y++)
                    vertices[x][y] = new VertexPositionColor();
            }

            vertices[0][0].Color = Color.Red;
            vertices[0][1].Color = Color.Red;
            vertices[1][0].Color = Color.Green;
            vertices[1][1].Color = Color.Green;
            vertices[2][0].Color = Color.Blue;
            vertices[2][1].Color = Color.Blue;

            // the first vertex is at the origin
            vertices[0][0].Position = Vector3.Zero;
            vertices[1][0].Position = Vector3.Zero;
            vertices[2][0].Position = Vector3.Zero;

            Size = 5;
            CreateLines();
        }
            public ConcavePolygonOutline(Vector3 position, Vector3[] points, Color[] pointColors)
            {
                throw new NotImplementedException();

                VertexPositionColor[] vertices = new VertexPositionColor[points.Length];
                for (int index = 0; index < points.Length; index++) {
                    vertices[index] = new VertexPositionColor(points[index], pointColors[index]);
                }

                List<VertexPositionColor> concavePoints = new List<VertexPositionColor>();
                bool isConcave = ConcavePolygonGeometry.Process(vertices, ref concavePoints);

                if (!isConcave) {
                    IComplex convex = new ConvexPolygonOutline(position, points, pointColors);
                    this.primitives = convex.Primitives;
                    this.primitivesCount = convex.PrimitivesCount;
                    //? throw new InvalidOperationException("Given polygon isn't concave!");
                }
                else {
                    this.primitives = new IPrimitive[concavePoints.Count];
                    this.primitivesCount = this.primitives.Length;

                    for (int index = 0; index < this.primitivesCount - 1; index++) {
                        this.primitives[index] = new Line(concavePoints[index].Position + position, concavePoints[index + 1].Position + position, concavePoints[index].Color, concavePoints[index + 1].Color);
                    }
                    this.primitives[this.primitivesCount - 1] = new Line(concavePoints[0].Position + position, concavePoints[this.primitivesCount - 1].Position + position, concavePoints[0].Color, concavePoints[this.primitivesCount - 1].Color);
                }
            }
        public static void Draw(this Fixture fixture, GraphicsDevice graphics, Color color, Matrix? matrix = null)
        {
            VertexPositionColor[] vertices;

            switch (fixture.ShapeType)
            {
                case ShapeType.Polygon:
                    {
                        vertices = ((PolygonShape)fixture.Shape).ToVertices(color, matrix);
                    }
                    break;
                case ShapeType.Circle:
                    {
                        CircleShape circle = ((CircleShape)fixture.Shape);

                        vertices = new VertexPositionColor[]
                    {
                        new VertexPositionColor(new Vector3(Vector2.Transform(Vector2.Zero, matrix ?? Matrix.Identity), 0.0f), color),
                        new VertexPositionColor(new Vector3(Vector2.Transform(new Vector2(circle.Radius), matrix ?? Matrix.Identity), 0.0f), color)
                    };
                    }
                    break;
                default: throw new InvalidOperationException(String.Format("Unable to render ShapeType {0}", fixture.ShapeType));
            }

            graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, vertices.Length - 1);
        }
Example #7
0
 /// <summary>
 /// Change the colour of an existing list of type VertexPositionColor
 /// </summary>
 /// <param name="pointList">Array of points</param>
 /// <param name="colour">The colour e.g. Color.White or Color.Red</param>
 public void ChangeColour(ref VertexPositionColor[] pointList, Color colour)
 {
     for (int i = 0; i < pointList.Length; i++)
     {
         pointList[i].Color = colour;
     }
 }
 public override void Initialize()
 {
    Sommets1 = new VertexPositionColor[NB_SOMMETS];
    Sommets2 = new VertexPositionColor[NB_SOMMETS];
    PositionsSommets = new Vector3[NB_POSITIONS_SOMMETS];
    base.Initialize();
 }
Example #9
0
        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.RasterizerState = _solidRasterizer;
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, cubeLineVertices, 0, 8, cubeLineIndices, 0, 12);
            }
        }
Example #10
0
        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;
            foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
               // device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
                device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, sphereLineVertices, 0, 3);
            }
        }
Example #11
0
 private unsafe void StartDrawing(VertexFragment vertexFragment, out VertexPositionColor* vertices, out VertexPositionNormalTexture* textures, out short* indices, out short baseIndex)
 {
     textures = null;
     if (vertexFragment.PrimitiveType == PrimitiveType.LineList)
     {
         if ((this.SortMode == DrawingSortMode.Order) && (this._triangleVertexCount > 0))
         {
             Flush();
             StartLineDrawing(vertexFragment, out vertices, out indices, out baseIndex);
         }
         else
         {
             StartLineDrawing(vertexFragment, out vertices, out indices, out baseIndex);
         }
     }
     else if (vertexFragment.PrimitiveType == PrimitiveType.TriangleList)
     {
         if ((this.SortMode == DrawingSortMode.Order) && (this._lineVertexCount > 0))
         {
             Flush();
             StartTriangleDrawing(vertexFragment, out vertices, out textures, out indices, out baseIndex);
         }
         else
         {
             StartTriangleDrawing(vertexFragment, out vertices, out textures, out indices, out baseIndex);
         }
     }
     else
     {
         throw new NotSupportedException(string.Format("PrimitiveType: {0} is not supported.", vertexFragment.PrimitiveType));
     }
 }
Example #12
0
 public static void DebugDrawPolyline(DebugDrawContext context, params Vector2[] vertices)
 {
     var vertexData = new VertexPositionColor[vertices.Length];
     for (int i = 0; i < vertices.Length; i++)
         vertexData[i] = new VertexPositionColor(new Vector3(vertices[i], DEBUG_DRAW_Z), context.Color);
     DebugDraw(context, vertexData, PrimitiveType.LineStrip);
 }
Example #13
0
        public static void RenderVertexPositionColorList(GraphicsDevice gd, 
            BasicEffect effect, Matrix world, Matrix view, Matrix proj,
            VertexPositionColor[] vertices, VertexDeclaration vertexDeclaration,
            VertexBuffer vertex_buffer)
        {
            // gd.VertexDeclaration = vertexDeclaration;

              effect.World = world;
              effect.View = view;
              effect.Projection = proj;
              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 / 3);

              }
        }
Example #14
0
        public static VertexPositionColor[] GetVerticesFromBounds(BoundingBox bounds, Color hitboxColor)
        {
            Vector3[] corners = bounds.GetCorners();
            VertexPositionColor[] debugVerts = new VertexPositionColor[24];
            debugVerts[0] = new VertexPositionColor(corners[0], hitboxColor);
            debugVerts[1] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[2] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[3] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[4] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[5] = new VertexPositionColor(corners[4], hitboxColor);
            debugVerts[6] = new VertexPositionColor(corners[4], hitboxColor);
            debugVerts[7] = new VertexPositionColor(corners[0], hitboxColor);

            debugVerts[8] = new VertexPositionColor(corners[3], hitboxColor);
            debugVerts[9] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[10] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[11] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[12] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[13] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[14] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[15] = new VertexPositionColor(corners[3], hitboxColor);

            debugVerts[16] = new VertexPositionColor(corners[3], hitboxColor);
            debugVerts[17] = new VertexPositionColor(corners[0], hitboxColor);
            debugVerts[18] = new VertexPositionColor(corners[2], hitboxColor);
            debugVerts[19] = new VertexPositionColor(corners[1], hitboxColor);
            debugVerts[20] = new VertexPositionColor(corners[6], hitboxColor);
            debugVerts[21] = new VertexPositionColor(corners[5], hitboxColor);
            debugVerts[22] = new VertexPositionColor(corners[7], hitboxColor);
            debugVerts[23] = new VertexPositionColor(corners[4], hitboxColor);

            return debugVerts;
        }
 /// <summary>
 /// Add a Line
 /// You cant remove it        
 /// </summary>
 /// <param name="StartPoint">The start point.</param>
 /// <param name="EndPoint">The end point.</param>
 /// <param name="color">The box's color.</param>
 public void AddLine(Vector3 StartPoint, Vector3 EndPoint, Color color)
 {
     VertexPositionColor vp1 = new VertexPositionColor(StartPoint, color);
     VertexPositionColor vp2 = new VertexPositionColor(EndPoint, color);
     verts.Add(vp1);
     verts.Add(vp2);            
 }
Example #16
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            zNear = 0.001f;
            zFar = 1000.0f;
            fov = MathHelper.Pi * 70.0f / 180.0f;
            eye = new Vector3(0.0f, 0.7f, 1.5f);
            at = new Vector3(0.0f, 0.0f, 0.0f);
            up = new Vector3(0.0f, 1.0f, 0.0f);

            cube = new VertexPositionColor[8];
            cube[0] = new VertexPositionColor(new Vector3(-0.5f, -0.5f, -0.5f), new Color(0.0f, 0.0f, 0.0f));
            cube[1] = new VertexPositionColor(new Vector3(-0.5f, -0.5f,  0.5f), new Color(0.0f, 0.0f, 1.0f));
            cube[2] = new VertexPositionColor(new Vector3(-0.5f,  0.5f, -0.5f), new Color(0.0f, 1.0f, 0.0f));
            cube[3] = new VertexPositionColor(new Vector3(-0.5f,  0.5f,  0.5f), new Color(0.0f, 1.0f, 1.0f));
            cube[4] = new VertexPositionColor(new Vector3( 0.5f, -0.5f, -0.5f), new Color(1.0f, 0.0f, 0.0f));
            cube[5] = new VertexPositionColor(new Vector3( 0.5f, -0.5f,  0.5f), new Color(1.0f, 0.0f, 1.0f));
            cube[6] = new VertexPositionColor(new Vector3( 0.5f,  0.5f, -0.5f), new Color(1.0f, 1.0f, 0.0f));
            cube[7] = new VertexPositionColor(new Vector3( 0.5f,  0.5f,  0.5f), new Color(1.0f, 1.0f, 1.0f));

            vertexBuffer = new DynamicVertexBuffer(graphics.GraphicsDevice, typeof(VertexPositionColor), 8, BufferUsage.WriteOnly);
            indexBuffer = new DynamicIndexBuffer(graphics.GraphicsDevice, typeof(ushort), 36, BufferUsage.WriteOnly);

            basicEffect = new BasicEffect(graphics.GraphicsDevice); //(device, null);
            basicEffect.LightingEnabled = false;
            basicEffect.VertexColorEnabled = true;
            basicEffect.TextureEnabled = false;

            graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            base.Initialize();
        }
        public override void Initialize()
        {
            int widthNum = this.witdth / Map.GridWidth;
            int heightNum = this.heigh / Map.GridWidth;
            this.pointMatrics = new VertexPositionColor[heightNum][];

            for (int row = 0; row < heightNum; row++)
            {
                VertexPositionColor[] temp = new VertexPositionColor[widthNum * 2 + 2];
                for (int col = 0; col <= widthNum; col++)
                {
                    temp[col * 2].Position = new Vector3(this.start.X + (Map.GridWidth * col),
                                                     this.start.Y + (this.start.Y + Map.GridWidth * row) ,
                                                     this.start.Z);
                    temp[col * 2 + 1].Position = new Vector3(this.start.X + (Map.GridWidth * col),
                                                         this.start.Y + (this.start.Y + Map.GridWidth * row) +  Map.GridWidth,
                                                         this.start.Z);
                    temp[col * 2].Color = Map.DefaultColor;
                    temp[col * 2 + 1].Color = Map.DefaultColor;
                }
                this.pointMatrics[row] = temp;
            }

            base.Initialize();
        }
Example #18
0
        public void DrawDebugWorld(DynamicsWorld world)
        {
            world.DebugDrawWorld();

            if (lines.Count == 0)
                return;

            if (effect == null)
            {
                effect = new BasicEffect(graphics.Device);
                effect.World = Microsoft.Xna.Framework.Matrix.Identity;
                effect.VertexColorEnabled = true;
                pass = effect.CurrentTechnique.Passes[0];
            }

            effect.Projection = graphics.GetEffect().Projection;
            effect.View = graphics.GetEffect().View;
            pass.Apply();

            int pointCount = lines.Count;
            int linesCount = pointCount / 2;
            VertexPositionColor[] linesArray = new VertexPositionColor[pointCount];
            for (int i = 0; i < pointCount; i++)
            {
                int color = lines[i].Color;
                linesArray[i].Color = new Color(color & 0xff, (color & 0xff00) >> 8, (color & 0xff0000) >> 16, 1);
                linesArray[i].Position = MathHelper.Convert(lines[i].Position);
            }
            graphics.Device.DrawUserPrimitives(PrimitiveType.LineList, linesArray, 0, linesCount);
            lines.Clear();
        }
        public static void InitializeGraphics(GraphicsDevice graphicsDevice,
                                              Triangle[] triangles,
                                              Guid id)
        {
            var basicEffect = new BasicEffect(graphicsDevice)
                                  {
                                      LightingEnabled = false,
                                      VertexColorEnabled = false
                                  };

            var index = 0;
            var vertices = new VertexPositionColor[triangles.SelectMany(i => i.Points).Count()];

            foreach (var point in triangles.SelectMany(triangle => triangle.Points))
                vertices[index++] = new VertexPositionColor(new Vector3(point.X,
                                                                        point.Y,
                                                                        point.Z),
                                                            Color.White);

            var vertexBuffer = new VertexBuffer(graphicsDevice,
                                                typeof (VertexPositionColor),
                                                vertices.Length,
                                                BufferUsage.None);
            vertexBuffer.SetData(vertices);

            Subscriptions.Add(id, new RendererHelperData
                                       {
                                           BasicEffect = basicEffect,
                                           VertexBuffer = vertexBuffer
                                       });
        }
Example #20
0
        private ReferenceAxis()
        {
            vertices = new VertexPositionColor[3][];
            for (int x = 0; x < 3; x++)
            {
                vertices[x] = new VertexPositionColor[2];
                for (int y = 0; y < 2; y++)
                    vertices[x][y] = new VertexPositionColor();
            }

            vertices[0][0].Color = Color.Red;
            vertices[0][1].Color = Color.Red;
            vertices[1][0].Color = Color.Green;
            vertices[1][1].Color = Color.Green;
            vertices[2][0].Color = Color.Blue;
            vertices[2][1].Color = Color.Blue;

            // the first vertex is at the origin
            vertices[0][0].Position = Vector3.Zero;
            vertices[1][0].Position = Vector3.Zero;
            vertices[2][0].Position = Vector3.Zero;

            Size = 10;
            CreateLines();
        }
Example #21
0
        public Earth()
        {
            Sun = Game.Sun;
            Rotation = 0;
            RotationInFastSpeed = 0;
            RotationAxisPointList = new VertexPositionColor[2];

            // vernal equinox
            RevolutionBasis = new Vector3(0, 0, -RevolutionRadius);

            Scale = Matrix.CreateScale(new Vector3(Radius, Radius, Radius));

            BasicEffect = new BasicEffect(Game.GraphicsDevice);

            InitLineStrip();
            InitRevPointList();

            BasicEffect.VertexColorEnabled = true;
            BasicEffect.World = Matrix.Identity;

            // up
            Up = Vector3.Transform(Vector3.Up, Matrix.CreateRotationZ(EclipticObliquity));
            Up.Normalize();

            // rotation axis
            RotationAxis = Up * Radius * 7f;
        }
Example #22
0
        private void InitVertices()
        {
            vertices = new VertexPositionColor[30];

            vertices[0] = new VertexPositionColor(new Vector3(0, 0, 0), Color.White);
            vertices[1] = new VertexPositionColor(Vector3.Right * 5, Color.White);
            vertices[2] = new VertexPositionColor(new Vector3(5, 0, 0), Color.White);
            vertices[3] = new VertexPositionColor(new Vector3(4.5f, 0.5f, 0), Color.White);
            vertices[4] = new VertexPositionColor(new Vector3(5, 0, 0), Color.White);
            vertices[5] = new VertexPositionColor(new Vector3(4.5f, -0.5f, 0), Color.White);

            vertices[6] = new VertexPositionColor(new Vector3(0, 0, 0), Color.White);
            vertices[7] = new VertexPositionColor(Vector3.Up * 5, Color.White);
            vertices[8] = new VertexPositionColor(new Vector3(0, 5, 0), Color.White);
            vertices[9] = new VertexPositionColor(new Vector3(0.5f, 4.5f, 0), Color.White);
            vertices[10] = new VertexPositionColor(new Vector3(0, 5, 0), Color.White);
            vertices[11] = new VertexPositionColor(new Vector3(-0.5f, 4.5f, 0), Color.White);

            vertices[12] = new VertexPositionColor(new Vector3(0, 0, 0), Color.White);
            vertices[13] = new VertexPositionColor(-Vector3.Forward * 5, Color.White);
            vertices[14] = new VertexPositionColor(new Vector3(0, 0, 5), Color.White);
            vertices[15] = new VertexPositionColor(new Vector3(0, 0.5f, 4.5f), Color.White);
            vertices[16] = new VertexPositionColor(new Vector3(0, 0, 5), Color.White);
            vertices[17] = new VertexPositionColor(new Vector3(0, -0.5f, 4.5f), Color.White);
        }
Example #23
0
        public ControlTriangle(ControlEdge edge1, ControlEdge edge2, ControlEdge edge3)
            : this()
        {
            List<Vector3> temp = new List<Vector3>();

            if (!temp.Contains(edge1.FirstVertex))
                temp.Add(edge1.FirstVertex);
            if (!temp.Contains(edge1.SecondVertex))
                temp.Add(edge1.SecondVertex);
            if (!temp.Contains(edge2.FirstVertex))
                temp.Add(edge2.FirstVertex);
            if (!temp.Contains(edge2.SecondVertex))
                temp.Add(edge2.SecondVertex);
            if (!temp.Contains(edge3.FirstVertex))
                temp.Add(edge3.FirstVertex);
            if (!temp.Contains(edge3.SecondVertex))
                temp.Add(edge3.SecondVertex);

            FirstVertex = temp[0];
            SecondVertex = temp[1];
            ThirdVertex = temp[2];

            _vertexData[0] = new VertexPositionColor(FirstVertex, Color.White);
            _vertexData[1] = new VertexPositionColor(SecondVertex, Color.White);
            _vertexData[2] = new VertexPositionColor(ThirdVertex, Color.White);
        }
Example #24
0
 public CollisionElement(GraphicsDevice device)
 {
     _texture = new Texture2D(device, 1, 1);
     _texture.SetData(new Color[]{ Color.White });
     BoxCoords = new Rectangle();
     TriangleCoords = new VertexPositionColor[3];
 }
Example #25
0
        public void Draw(GraphicsDevice device, Matrix view, Matrix projection, SpriteBatch batch, SpriteFont font)
        {
            vertices[0] = new VertexPositionColor(from, color);
            vertices[1] = new VertexPositionColor(to,   color);

            Vector3 delt = Vector3.Multiply(Vector3.Subtract(to, from), 0.1f);

            Vector3 perp = Vector3.Cross(Vector3.Forward, delt);
            Vector3 arrowBase = Vector3.Subtract(to, delt);

            vertices[2] = new VertexPositionColor(Vector3.Add(arrowBase, perp), color);
            vertices[3] = new VertexPositionColor(to, color);
            vertices[4] = new VertexPositionColor(Vector3.Subtract(arrowBase, perp), color);
            vertices[5] = new VertexPositionColor(to, color);

            effect.World = Matrix.Identity;
            effect.View = view;
            effect.Projection = projection;
            effect.VertexColorEnabled = true;
            effect.LightingEnabled = false;

            for (int i = 0; i < effect.CurrentTechnique.Passes.Count; ++i)
            {
                effect.CurrentTechnique.Passes[i].Apply();
                device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vertices, 0, 3);
            }

            Vector3 txtPos = device.Viewport.Project(Vector3.Lerp(from, to, 0.5f), projection, view, Matrix.Identity);
            Console.WriteLine(txtPos.ToString());
            batch.DrawString(font, text, new Vector2(txtPos.X + 20, txtPos.Y - 10), color);
        }
        public void Draw(GameTime gameTime, BoundingFrustum VisibleArea)
        {
            if (units.Count > 0)
            {
                VertexPositionColor[] display = new VertexPositionColor[units.Count * 2];
                int[] pointIndex = new int[units.Count];
                for (int i = 0; i < units.Count; i++)
                {
                    display[i * 2] = new VertexPositionColor(units[i].Position, DisplayColor);
                    pointIndex[i] = i * 2;
                    if (units[i].Target != null)
                    {
                        display[i * 2 + 1] = new VertexPositionColor(units[i].Target.Position, DisplayColor);
                    }
                    else
                    {
                        display[i * 2 + 1] = display[i * 2];
                    }
                }

                Manager.ResetFor3D();
                MyGame.graphics.GraphicsDevice.VertexDeclaration = UnitDeclaration;
                MyGame.graphics.GraphicsDevice.RenderState.PointSize = 5.0f;
                Manager.OrdinaryEffect.CurrentTechnique = Manager.OrdinaryEffect.Techniques["Ordinary"];
                Manager.OrdinaryEffect.Parameters["World"].SetValue(Matrix.Identity);
                Manager.OrdinaryEffect.Begin();
                Manager.OrdinaryEffect.CurrentTechnique.Passes.First<EffectPass>().Begin();
                MyGame.graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, display, 0, display.Length / 2);
                MyGame.graphics.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.PointList, display, 0, display.Length
                    , pointIndex, 0, pointIndex.Length);
                Manager.OrdinaryEffect.CurrentTechnique.Passes.First<EffectPass>().End();
                Manager.OrdinaryEffect.End();
            }
        }
Example #27
0
        public VariableVertexes(Vector3 position, float size, int nLados)
        {
            this.nLados = nLados;
            vertexes = new VertexPositionColor[10];

            float graus = 0;
            float step = MathHelper.ToRadians(360 / nLados);

            Vector3 topo = new Vector3(0, 1, 0);

            Vector3 v0 = new Vector3(1, 0, 0);
            Vector3 v1 = topo;
            Vector3 v2 = new Vector3(0, 0, -1);
            Vector3 v3 = topo;
            Vector3 v4 = new Vector3(-1, 0, 0);
            Vector3 v5 = topo;
            Vector3 v6 = new Vector3(0, 0, 1);
            Vector3 v7 = topo;
            Vector3 v8 = v0;
            Vector3 v9 = topo;

            vertexes[0] = new VertexPositionColor(v0, Color.Red);
            vertexes[1] = new VertexPositionColor(v1, Color.Red);
            vertexes[2] = new VertexPositionColor(v2, Color.Red);
            vertexes[3] = new VertexPositionColor(v3, Color.Green);
            vertexes[4] = new VertexPositionColor(v4, Color.Green);
            vertexes[5] = new VertexPositionColor(v5, Color.Green);
            vertexes[6] = new VertexPositionColor(v6, Color.Blue);
            vertexes[7] = new VertexPositionColor(v7, Color.Blue);
            vertexes[8] = new VertexPositionColor(v8, Color.Blue);
            vertexes[9] = new VertexPositionColor(v9, Color.Blue);
        }
Example #28
0
        public PyramidIndices()
        {
            vertexes = new VertexPositionColor[5];

            vertexes[0] = new VertexPositionColor(new Vector3(1, 0, 0), Color.Red);
            vertexes[1] = new VertexPositionColor(new Vector3(0, 0, -1), Color.Red);
            vertexes[2] = new VertexPositionColor(new Vector3(-1, 0, 0), Color.Red);
            vertexes[3] = new VertexPositionColor(new Vector3(0, 0, 1), Color.Red);
            vertexes[4] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Red);

            indices = new short[9];
            indices[0] = 0;
            indices[1] = 4;
            indices[2] = 1;
            indices[3] = 4;
            indices[4] = 2;
            indices[5] = 4;
            indices[6] = 3;
            indices[7] = 4;
            indices[8] = 0;

            /*

            Gerar estes indices programaticamente:

            for(int i = 0; i <= n; i++){
               ind[2i] = (i % n);
               ind[2i+1] = 4
            }

            */
        }
        public void Draw(
            ref BoundingFrustum boundingFrustum,
            Effect effect,
            ref Color vertexColor)
        {
            var coners = boundingFrustum.GetCorners();
            var vertices = new VertexPositionColor[8];
            for (int i = 0; i < 8; i++)
            {
                vertices[i].Position = coners[i];
                vertices[i].Color = vertexColor;
            }

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                    PrimitiveType.LineList,
                    vertices,
                    0,
                    8,
                    indices,
                    0,
                    primitiveCount);
            }
        }
        public TerrainModel(ContentManager content, string heightMapTexture, float scale, Vector3 position, Matrix rotation)
        {
            this.Scale = scale;
            this.Position = position;
            this.Rotation = rotation;
            Texture2D textureTemp = content.Load<Texture2D>(heightMapTexture);
            _nCols = textureTemp.Width - 1;
            _nRows = textureTemp.Height - 1;
            Color[] textureColors = new Color[textureTemp.Width * textureTemp.Height];
            textureTemp.GetData(textureColors);
            _nVetices = _nCols * _nRows * 6;
            _Vetices = new VertexPositionColor[_nVetices];
            /*
             * --------->x
             * A---B |
             * |   | |
             * D---C |
             *       y
             */

            for (int x = 0; x < textureTemp.Height; x++)
                for (int z = 0; z < textureTemp.Width; z++)
                {
                    _Vetices[x*z + 1] = new VertexPositionColor(new Vector3(x, textureColors[x * textureTemp.Height + z * textureTemp.Width].R/6, z), Color.White); // A
                    _Vetices[x * z + 1] = new VertexPositionColor(new Vector3(x + 1, textureColors[(x + 1)* textureTemp.Height + textureTemp.Width].R / 6, z), Color.White); //B
                    _Vetices[x * z + 1] = new VertexPositionColor(new Vector3(x, textureColors[x * textureTemp.Height + textureTemp.Width].R / 6, z), Color.White); //C

                    _Vetices[x * z + 1] = new VertexPositionColor(new Vector3(x, textureColors[x * textureTemp.Height + textureTemp.Width].R / 6, z), Color.White);
                    _Vetices[x * z + 1] = new VertexPositionColor(new Vector3(x, textureColors[x * textureTemp.Height + textureTemp.Width].R / 6, z), Color.White);
                    _Vetices[x * z + 1] = new VertexPositionColor(new Vector3(x, textureColors[x * textureTemp.Height + textureTemp.Width].R / 6, z), Color.White);

                }
        }
        public void TestSelectWithoutIndices()
        {
            using (Creator creator = new Creator()) {
                TestVertex[] vertices = new TestVertex[9];

                creator.BatchDrawer.Select(vertices, 9);
            }
        }
        public void TestSelectMultipleWithoutIndices()
        {
            using (Creator creator = new Creator()) {
                TestVertex[] vertices = new TestVertex[9];

                // This will cause the drawer to run out of buffer segments and cause
                // a discarding lock on the buffers
                for (int index = 0; index < 8; ++index)
                {
                    creator.BatchDrawer.Select(vertices, 9);
                }
            }
        }
        public void TestDrawWithoutIndices()
        {
            using (Creator creator = new Creator()) {
                TestVertex[] vertices = new TestVertex[9];

                creator.BatchDrawer.Select(vertices, 9);
                creator.BatchDrawer.Draw(
                    0, 9,
                    PrimitiveType.TriangleList,
                    new BasicEffectDrawContext(creator.GraphicsDevice)
                    );
            }
        }
Example #34
0
        public static unsafe void _PrepareRing(ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref GeometryDrawCall dc)
        {
            int numPoints = ComputeRingPoints(ref dc.Vector2);

            const int vertexStride = 2;
            const int indexStride  = 6;

            var vw = vb.GetWriter(numPoints * vertexStride);
            var iw = ib.GetWriter((numPoints - 1) * indexStride, ref vw);

            float a = dc.Scalar0;
            float step = (float)((dc.Scalar1 - dc.Scalar0) / (numPoints - 1));
            float cos, sin;
            float colorA = 0, colorStep = 1.0f / (numPoints - 1);
            var   vertexInner = new GeometryVertex(new Vector3(0, 0, dc.Z), dc.Color0);
            var   vertexOuter = new GeometryVertex(new Vector3(0, 0, dc.Z), dc.Color1);

            fixed(GeometryVertex *pVertices = &vw.Storage.Array[vw.Storage.Offset])
            fixed(ushort *pIndices = &iw.Storage.Array[iw.Storage.Offset])
            for (int i = 0, j = 0, k = 0; i < numPoints; i++, j += vertexStride, k += indexStride)
            {
                cos = (float)Math.Cos(a);
                sin = (float)Math.Sin(a);

                vertexInner.Position.X = dc.Vector0.X + (float)(cos * dc.Vector1.X);
                vertexInner.Position.Y = dc.Vector0.Y + (float)(sin * dc.Vector1.Y);
                vertexInner.Color      = Color.Lerp(dc.Color0, dc.Color2, colorA);
                pVertices[j]           = vertexInner;

                vertexOuter.Position.X = dc.Vector0.X + (float)(cos * dc.Vector2.X);
                vertexOuter.Position.Y = dc.Vector0.Y + (float)(sin * dc.Vector2.Y);
                vertexOuter.Color      = Color.Lerp(dc.Color1, dc.Color3, colorA);
                pVertices[j + 1]       = vertexOuter;

                if (i == (numPoints - 1))
                {
                    break;
                }

                pIndices[k]     = (ushort)(j + vw.IndexOffset);
                pIndices[k + 1] = (ushort)(j + 1 + vw.IndexOffset);
                pIndices[k + 2] = (ushort)(j + 3 + vw.IndexOffset);
                pIndices[k + 3] = (ushort)(j + 2 + vw.IndexOffset);
                pIndices[k + 4] = (ushort)(j + vw.IndexOffset);
                pIndices[k + 5] = (ushort)(j + 3 + vw.IndexOffset);

                a      += step;
                colorA += colorStep;
            }
        }
Example #35
0
        /// <summary>Static constructor that initializes the test vertex array</summary>
        static QueuerTest()
        {
            const int TestVertexCount = 64;

            TestVertices = new TestVertex[TestVertexCount];
            TestIndices  = new short[TestVertexCount];

            for (int index = 0; index < TestVertexCount; ++index)
            {
                TestVertices[index] = new TestVertex(
                    new Vector3((float)index, (float)index, (float)index), Color.White
                    );
                TestIndices[index] = (short)(index + 2);
            }
        }
Example #36
0
        protected static void _PrepareQuadBorder(ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref GeometryDrawCall dc)
        {
            var vw = vb.GetWriter(8);
            var iw = ib.GetWriter(QuadBorderIndices.Length, ref vw);

            var tl = dc.Vector0;
            var br = dc.Vector1;

            var border = dc.Scalar0;

            var vInner = new GeometryVertex(new Vector3(tl.X, tl.Y, dc.Z), dc.Color0);
            var vOuter = new GeometryVertex(new Vector3(tl.X - border, tl.Y - border, dc.Z), dc.Color1);

            vw.Write(ref vInner);
            vw.Write(ref vOuter);

            vInner.Position.X = br.X;
            vOuter.Position.X = br.X + border;

            vw.Write(ref vInner);
            vw.Write(ref vOuter);

            vInner.Position.Y = br.Y;
            vOuter.Position.Y = br.Y + border;

            vw.Write(ref vInner);
            vw.Write(ref vOuter);

            vInner.Position.X = tl.X;
            vOuter.Position.X = tl.X - border;

            vw.Write(ref vInner);
            vw.Write(ref vOuter);

            iw.Write(QuadBorderIndices);
        }