Exemple #1
0
 public MyModel(Project1Game game, VertexPositionColor[] shapeArray, String textureName)
 {
     this.vertices = Buffer.Vertex.New(game.GraphicsDevice, shapeArray);
     this.inputLayout = VertexInputLayout.New<VertexPositionColor>(0);
     vertexStride = Utilities.SizeOf<VertexPositionColor>();
     modelType = ModelType.Colored;
 }
Exemple #2
0
        public void Draw()
        {
            int color = DrawColor.ToArgb();
            VertexPositionColor[] vertices = new VertexPositionColor[]
            {
                new VertexPositionColor()
                {
                    Position = new Vector4(Position, 0, 0),
                    Color = color
                },
                new VertexPositionColor()
                {
                    Position = new Vector4(Position.X + Size.X, Position.Y, 0, 0),
                    Color = color
                },
                new VertexPositionColor()
                {
                    Position = new Vector4(Position.X + Size.X, Position.Y + Size.Y, 0, 0),
                    Color = color
                },
                new VertexPositionColor()
                {
                    Position = new Vector4(Position.X, Position.Y + Size.Y, 0, 0),
                    Color = color
                },
            };

            var dev = Game.GameManager.GraphicsThread.GraphicsManager.Device;
            dev.SetRenderState(RenderState.AlphaBlendEnable, true);
            dev.VertexFormat = VertexPositionColor.FVF;
            dev.DrawUserPrimitives(PrimitiveType.TriangleFan, 2, vertices);
        }
        /// <summary>
        /// Performs further custom initialization for this instance.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            VertexPositionColor[] vertices = new VertexPositionColor[3];
            vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
            vertices[0].Color = Color.Red;

            vertices[1].Position = new Vector3(0f, 0.5f, 0f);
            vertices[1].Color = Color.Green;

            vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
            vertices[2].Color = Color.Yellow;

            var vertexBuffer = new VertexBuffer(VertexPositionColor.VertexFormat);
            vertexBuffer.SetData(vertices, 3);
            
            ushort[] indices = new ushort[3];
            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;

            var indexBuffer = new IndexBuffer(indices);

            this.mesh = new Mesh(0, vertices.Length, 0, 1, vertexBuffer, indexBuffer, PrimitiveType.TriangleList);
        }
Exemple #4
0
            public static void DrawLineList(Vector3[] lineList, int vertices, Color color)
            {
                // Initialize an array of indices of type short.
                lineListIndices = new short[vertices];
                pointList = new VertexPositionColor[vertices];
                for (int p = 0; p < vertices; p++)
                {
                    pointList[p] =
                        new VertexPositionColor(
                            lineList[p], color
                        );
                    lineListIndices[p] = (short)(p);
                }
                // Initialize the vertex buffer, allocating memory for each vertex.
                vertexBuffer = new VertexBuffer(Game.Game.Graphics.GraphicsDevice, vertexDeclaration,
                    vertices, BufferUsage.None);

                // Set the vertex buffer data to the array of vertices.
                vertexBuffer.SetData<VertexPositionColor>(pointList);

                foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    Game.Game.Graphics.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(
                        PrimitiveType.LineList,
                        pointList,
                        0,  // vertex buffer offset to add to each element of the index buffer
                        vertices,  // number of vertices in pointList
                        lineListIndices,  // the index buffer
                        0,  // first index element to read
                        vertices / 2   // number of primitives to draw
                    );
                }
            }
Exemple #5
0
 public MyModel(LabGame game, VertexPositionColor[] shapeArray, String textureName, float collisionRadius)
 {
     this.vertices = Buffer.Vertex.New(game.GraphicsDevice, shapeArray);
     this.inputLayout = VertexInputLayout.New<VertexPositionColor>(0);
     vertexStride = Utilities.SizeOf<VertexPositionColor>();
     modelType = ModelType.Colored;
     this.collisionRadius = collisionRadius;
 }
Exemple #6
0
 public void DrawBorder(PrimitiveBatch<VertexPositionColor> primitiveBatch, Color color)
 {
     VertexPositionColor p1 = new VertexPositionColor(new Vector3(X, Y + Height, 1.0f), color);
     VertexPositionColor p2 = new VertexPositionColor(new Vector3(X, Y, 1.0f), color);
     VertexPositionColor p3 = new VertexPositionColor(new Vector3(X + Width, Y, 1.0f), color);
     VertexPositionColor p4 = new VertexPositionColor(new Vector3(X + Width, Y + Height, 1.0f), color);
     primitiveBatch.DrawQuad(p1, p2, p3, p4);
 }
 public override void DrawVertices(VerticesMode mode, VertexPositionColor[] vertices)
 {
     SetColor(vertices[0].Color);
     if (mode == VerticesMode.Lines)
         for (int num = 0; num + 1 < vertices.Length; num += 2)
             DrawLines(vertices[num], vertices[num + 1]);
     else
         for (int num = 0; num + 3 < vertices.Length; num += 4)
             DrawRectangles(vertices[num], vertices[num + 2]);
 }
Exemple #8
0
        public VertexPositionColor[] setVertex()
        {
            VertexPositionColor[] buffer = new VertexPositionColor[3];
            List<VertexPositionColor> colorBufferList = buffer.ToList();
            for (int i = 0; i < 2; i++)
            {
                colorBufferList.Add(this.game.assets.CreateColoredTriangle(new Vector3(10, 10, 10), Color.Red)[i]);

            }
            buffer = colorBufferList.ToArray();
            return buffer;
        }
 public void ShowRedLine(Type resolver)
 {
     var vertices = new VertexPositionColor[2];
     Drawing remDrawing = null;
     Start(resolver, (Drawing drawing, Window window) =>
     {
         remDrawing = drawing;
         vertices[0] = new VertexPositionColor(Point.Zero, Color.Red);
         vertices[1] = new VertexPositionColor(window.ViewportPixelSize, Color.Red);
         window.ViewportSizeChanged +=
             size => vertices[1] = new VertexPositionColor(size, Color.Red);
     }, () => remDrawing.DrawVertices(VerticesMode.Lines, vertices));
 }
Exemple #10
0
 public void ShowYellowLineFullscreen(Type resolver)
 {
     var vertices = new VertexPositionColor[2];
     Drawing remDrawing = null;
     Start(resolver, (Drawing drawing, Window window) =>
     {
         window.SetFullscreen(new Size(640, 480));
         remDrawing = drawing;
         vertices[0] = new VertexPositionColor(Point.Zero, Color.Yellow);
         vertices[1] = new VertexPositionColor(window.ViewportPixelSize, Color.Yellow);
         window.ViewportSizeChanged +=
             size => vertices[1] = new VertexPositionColor(size, Color.Yellow);
     }, () => remDrawing.DrawVertices(VerticesMode.Lines, vertices));
 }
Exemple #11
0
        private void DrawCharacterBoundingBox(Matrix view, Matrix projection, Vector3 position, Vector3 characterOffset, bool isCrouched)
        {
            float characterCrounched_Y_Offset;

            if (isCrouched)
            {
                characterCrounched_Y_Offset = characterOffset.Y * 6 / 20;
            }
            else
            {
                characterCrounched_Y_Offset = characterOffset.Y;
            }


            Vector3 newOriginPoint = position;

            BoundingBox characterBox;

            if (isCrouched)
            {
                characterBox = new BoundingBox(new Vector3(position.X - (characterOffset.X / 2), position.Y - characterOffset.Y, position.Z - (characterOffset.Z / 2)), new Vector3(position.X + (characterOffset.X / 2), position.Y - characterCrounched_Y_Offset + 0.14f, position.Z + (characterOffset.Z / 2)));
            }
            else
            {
                characterBox = new BoundingBox(new Vector3(position.X - (characterOffset.X / 2), position.Y - characterCrounched_Y_Offset, position.Z - (characterOffset.Z / 2)), new Vector3(position.X + (characterOffset.X / 2), position.Y + 0.14f, position.Z + (characterOffset.Z / 2)));
            }


            Vector3[]             cornerss       = characterBox.GetCorners();
            VertexPositionColor[] primitiveListt = new VertexPositionColor[cornerss.Length];

            for (int i = 0; i < cornerss.Length; i++)
            {
                primitiveListt[i] = new VertexPositionColor(cornerss[i], Color.Red);
            }

            boxEffect.World           = Matrix.Identity;
            boxEffect.View            = view;
            boxEffect.Projection      = projection;
            boxEffect.TextureEnabled  = false;
            boxEffect.LightingEnabled = false;

            foreach (EffectPass pass in boxEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                this.device.DrawUserIndexedPrimitives(
                    PrimitiveType.LineList, primitiveListt, 0, 8,
                    bBoxIndices, 0, 12);
            }
        }
Exemple #12
0
        public void ConstructTreeGrid(QuadtreeNode node)
        {
            if (node == null)
            {
                return;
            }
            VertexPositionColor[] vs = new VertexPositionColor[16];
            int x = (int)node.position.X * this.Size;
            int y = (int)node.position.Y * this.Size;

            Color c = Color.LightSteelBlue;
            Color v = Color.LightSalmon;

            float size = node.size * this.Size;

            vs[0] = new VertexPositionColor(new Vector3(x + 0 * size, y + 0 * size, 0), c);
            vs[1] = new VertexPositionColor(new Vector3(x + 1 * size, y + 0 * size, 0), c);
            vs[2] = new VertexPositionColor(new Vector3(x + 1 * size, y + 0 * size, 0), c);
            vs[3] = new VertexPositionColor(new Vector3(x + 1 * size, y + 1 * size, 0), c);
            vs[4] = new VertexPositionColor(new Vector3(x + 1 * size, y + 1 * size, 0), c);
            vs[5] = new VertexPositionColor(new Vector3(x + 0 * size, y + 1 * size, 0), c);
            vs[6] = new VertexPositionColor(new Vector3(x + 0 * size, y + 1 * size, 0), c);
            vs[7] = new VertexPositionColor(new Vector3(x + 0 * size, y + 0 * size, 0), c);

            OutlineBuffer.SetData <VertexPositionColor>(OutlineLocation * VertexPositionColor.VertexDeclaration.VertexStride, vs, 0, 8, VertexPositionColor.VertexDeclaration.VertexStride);
            OutlineLocation += 8;

            if (node.leaf && false)
            {
                x += (int)(node.dualgrid_pos.X * (float)this.Size);
                y += (int)(node.dualgrid_pos.Y * (float)this.Size);
                float r = 2;
                vs[8]  = new VertexPositionColor(new Vector3(x - r, y - r, 0), v);
                vs[9]  = new VertexPositionColor(new Vector3(x + r, y - r, 0), v);
                vs[10] = new VertexPositionColor(new Vector3(x + r, y - r, 0), v);
                vs[11] = new VertexPositionColor(new Vector3(x + r, y + r, 0), v);
                vs[12] = new VertexPositionColor(new Vector3(x + r, y + r, 0), v);
                vs[13] = new VertexPositionColor(new Vector3(x - r, y + r, 0), v);
                vs[14] = new VertexPositionColor(new Vector3(x - r, y + r, 0), v);
                vs[15] = new VertexPositionColor(new Vector3(x - r, y - r, 0), v);
                OutlineBuffer.SetData <VertexPositionColor>(OutlineLocation * VertexPositionColor.VertexDeclaration.VertexStride, vs, 0, 16, VertexPositionColor.VertexDeclaration.VertexStride);
                OutlineLocation += 16;
            }

            for (int i = 0; i < 4; i++)
            {
                ConstructTreeGrid(node.children[i]);
            }
        }
Exemple #13
0
        public void DrawBoundingBox(Camera camera, GraphicsDeviceManager graphics)
        {
            short[] bBoxIndices =
            {
                0, 1, 1, 2, 2, 3, 3, 0, // Front edges
                4, 5, 5, 6, 6, 7, 7, 4, // Back edges
                0, 4, 1, 5, 2, 6, 3, 7  // Side edges connecting front and back
            };
            List <BoundingBox> boundingBoxes = new List <BoundingBox>();

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

            foreach (ModelMesh myModelMeshes in model.Meshes)
            {
                meshTransform = transforms[myModelMeshes.ParentBone.Index];
                boundingBoxes.Add(BuildBoundingBox(myModelMeshes, meshTransform));
            }

            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 */
                BasicEffect be = new BasicEffect(graphics.GraphicsDevice);

                be.World          = World;
                be.View           = camera.view;
                be.Projection     = camera.proj;
                be.TextureEnabled = false;

                // Draw the box with a LineList
                foreach (EffectPass pass in be.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    graphics.GraphicsDevice.DrawUserIndexedPrimitives(
                        PrimitiveType.LineList, primitiveList, 0, 8,
                        bBoxIndices, 0, 12);
                }
            }
        }
        public Texture2D EllipseTexture(float radiusX, float radiusY, MaterialType type, Color color, float materialScale, float pixelsPerMeter)
        {
            VertexPositionColorTexture[] verticesFill    = new VertexPositionColorTexture[3 * (CircleSegments - 2)];
            VertexPositionColor[]        verticesOutline = new VertexPositionColor[2 * CircleSegments];
            const float segmentSize = MathHelper.TwoPi / CircleSegments;
            float       theta       = segmentSize;

            radiusX        = radiusX * pixelsPerMeter;
            radiusY        = radiusY * pixelsPerMeter;
            materialScale /= _materials[type].Width;

            Vector2 start = new Vector2(radiusX, 0f);

            for (int i = 0; i < CircleSegments - 2; ++i)
            {
                Vector2 p1 = new Vector2(radiusX * (float)Math.Cos(theta), radiusY * (float)Math.Sin(theta));
                Vector2 p2 = new Vector2(radiusX * (float)Math.Cos(theta + segmentSize),
                                         radiusY * (float)Math.Sin(theta + segmentSize));
                // fill vertices
                verticesFill[3 * i].Position              = new Vector3(start, 0f);
                verticesFill[3 * i + 1].Position          = new Vector3(p1, 0f);
                verticesFill[3 * i + 2].Position          = new Vector3(p2, 0f);
                verticesFill[3 * i].TextureCoordinate     = start * materialScale;
                verticesFill[3 * i + 1].TextureCoordinate = p1 * materialScale;
                verticesFill[3 * i + 2].TextureCoordinate = p2 * materialScale;
                verticesFill[3 * i].Color = verticesFill[3 * i + 1].Color = verticesFill[3 * i + 2].Color = color;

                // outline vertices
                if (i == 0)
                {
                    verticesOutline[0].Position = new Vector3(start, 0f);
                    verticesOutline[1].Position = new Vector3(p1, 0f);
                    verticesOutline[0].Color    = verticesOutline[1].Color = Color.Black;
                }
                if (i == CircleSegments - 3)
                {
                    verticesOutline[2 * CircleSegments - 2].Position = new Vector3(p2, 0f);
                    verticesOutline[2 * CircleSegments - 1].Position = new Vector3(start, 0f);
                    verticesOutline[2 * CircleSegments - 2].Color    = verticesOutline[2 * CircleSegments - 1].Color = Color.Black;
                }
                verticesOutline[2 * i + 2].Position = new Vector3(p1, 0f);
                verticesOutline[2 * i + 3].Position = new Vector3(p2, 0f);
                verticesOutline[2 * i + 2].Color    = verticesOutline[2 * i + 3].Color = Color.Black;

                theta += segmentSize;
            }

            return(RenderTexture((int)(radiusX * 2f), (int)(radiusY * 2f), _materials[type], verticesFill, verticesOutline));
        }
Exemple #15
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            effect      = new BasicEffect(GraphicsDevice);
            VertexPositionColor[] vertices = new VertexPositionColor[12];

            // vertex position and color information for icosahedron
            vertices[0]  = new VertexPositionColor(new Vector3(-0.26286500f, 0.0000000f, 0.42532500f), Color.Red);
            vertices[1]  = new VertexPositionColor(new Vector3(0.26286500f, 0.0000000f, 0.42532500f), Color.Orange);
            vertices[2]  = new VertexPositionColor(new Vector3(-0.26286500f, 0.0000000f, -0.42532500f), Color.Yellow);
            vertices[3]  = new VertexPositionColor(new Vector3(0.26286500f, 0.0000000f, -0.42532500f), Color.Green);
            vertices[4]  = new VertexPositionColor(new Vector3(0.0000000f, 0.42532500f, 0.26286500f), Color.Blue);
            vertices[5]  = new VertexPositionColor(new Vector3(0.0000000f, 0.42532500f, -0.26286500f), Color.Indigo);
            vertices[6]  = new VertexPositionColor(new Vector3(0.0000000f, -0.42532500f, 0.26286500f), Color.Purple);
            vertices[7]  = new VertexPositionColor(new Vector3(0.0000000f, -0.42532500f, -0.26286500f), Color.White);
            vertices[8]  = new VertexPositionColor(new Vector3(0.42532500f, 0.26286500f, 0.0000000f), Color.Cyan);
            vertices[9]  = new VertexPositionColor(new Vector3(-0.42532500f, 0.26286500f, 0.0000000f), Color.Black);
            vertices[10] = new VertexPositionColor(new Vector3(0.42532500f, -0.26286500f, 0.0000000f), Color.DodgerBlue);
            vertices[11] = new VertexPositionColor(new Vector3(-0.42532500f, -0.26286500f, 0.0000000f), Color.Crimson);
            vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 12, BufferUsage.WriteOnly);
            vertexBuffer.SetData(vertices);

            short[] indices = new short[60];
            indices[0]  = 0; indices[1] = 6; indices[2] = 1;
            indices[3]  = 0; indices[4] = 11; indices[5] = 6;
            indices[6]  = 1; indices[7] = 4; indices[8] = 0;
            indices[9]  = 1; indices[10] = 8; indices[11] = 4;
            indices[12] = 1; indices[13] = 10; indices[14] = 8;
            indices[15] = 2; indices[16] = 5; indices[17] = 3;
            indices[18] = 2; indices[19] = 9; indices[20] = 5;
            indices[21] = 2; indices[22] = 11; indices[23] = 9;
            indices[24] = 3; indices[25] = 7; indices[26] = 2;
            indices[27] = 3; indices[28] = 10; indices[29] = 7;
            indices[30] = 4; indices[31] = 8; indices[32] = 5;
            indices[33] = 4; indices[34] = 9; indices[35] = 0;
            indices[36] = 5; indices[37] = 8; indices[38] = 3;
            indices[39] = 5; indices[40] = 9; indices[41] = 4;
            indices[42] = 6; indices[43] = 10; indices[44] = 1;
            indices[45] = 6; indices[46] = 11; indices[47] = 7;
            indices[48] = 7; indices[49] = 10; indices[50] = 6;
            indices[51] = 7; indices[52] = 11; indices[53] = 2;
            indices[54] = 8; indices[55] = 10; indices[56] = 3;
            indices[57] = 9; indices[58] = 11; indices[59] = 0;

            indexBuffer = new IndexBuffer(GraphicsDevice, typeof(short), indices.Length, BufferUsage.WriteOnly);
            indexBuffer.SetData(indices);
            // TODO: use this.Content to load your game content here
        }
Exemple #16
0
        /// <summary>
        ///
        /// Requires: _width _height to be prev set.
        /// </summary>
        /// <param name="normalList"></param>
        /// <param name="vertices"></param>
        private void fillNormalVectorList(out VertexPositionColor[] normalList, ref VertexPositionNormalTexture[] vertices)
        {
            // * 2 because you always need the origin of the vector
            normalList = new VertexPositionColor[_width * _height * 2];
            int k = 0;

            for (int i = 0; i < vertices.Length; i++)
            {
                //DEBUG: this will be used to draw the normals in the terrain
                Vector3 position = vertices[i].Position;
                Vector3 normal   = vertices[i].Normal;
                normalList[k++] = new VertexPositionColor(position, Color.White);
                normalList[k++] = new VertexPositionColor(position + normal, Color.White);
            }
        }
        /// <summary>
        /// The simplest call for PrimitiveBatch. Adds a single vertex to be rendered to the batch.
        /// If called twice with different vertices while using a line list, a line would be rendered.
        /// </summary>
        /// <param name="vpc"></param>
        public void AddVertex(VertexPositionColor vpc)
        {
            if (!hasBegun)
            {
                throw new Exception("You must begin a batch before you can add vertices");
            }

            if (vertCounter >= verts.Length)
            {
                Flush();
            }

            verts[vertCounter] = vpc;
            vertCounter++;
        }
Exemple #18
0
 public static void Draw3DLine(GraphicsDevice g, Matrix View, Matrix Projection, Color LineColor, Vector3 Start, Vector3 End)
 {
     if (effect == null)
     {
         effect = new BasicEffect(g);
     }
     effect.View         = View;
     effect.Projection   = Projection;
     effect.DiffuseColor = LineColor.ToVector3();
     effect.CurrentTechnique.Passes[0].Apply();
     vertices[0]        = new VertexPositionColor(Start, LineColor);
     vertices[1]        = new VertexPositionColor(End, LineColor);
     g.SamplerStates[0] = SamplerState.PointWrap;
     g.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, 1);
 }
Exemple #19
0
        public void DrawWireShape(Vector3[] positionArray, ushort[] indexArray, Color color)
        {
            if (Reserve(positionArray.Length, indexArray.Length))
            {
                for (int i = 0; i < indexArray.Length; i++)
                {
                    Indices[IndexCount++] = (ushort)(VertexCount + indexArray[i]);
                }

                for (int i = 0; i < positionArray.Length; i++)
                {
                    Vertices[VertexCount++] = new VertexPositionColor(positionArray[i], color);
                }
            }
        }
Exemple #20
0
        public void Draw()
        {
            for (var i = 0; i < _currentTriange.Count; i++)
            {
                _currentTriange[i] = new VertexPositionColor(
                    new Vector3(
                        _initialTriange[i].Position.X + _location.X,
                        _initialTriange[i].Position.Y + _location.Y,
                        0),
                    _initialTriange[i].Color);
            }

            _basicEffect.CurrentTechnique.Passes[0].Apply();
            _graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, _currentTriange.ToArray(), 0, 1);
        }
Exemple #21
0
        public Ground()
        {
            ground   = ContentManager.Model(@"env/Ground");
            foliage  = ContentManager.Model(@"env/Planes");
            water    = ContentManager.Model(@"env/Water");
            position = Vector3.Zero;
            rotation = new Vector3(0, 180, 0);

            skyboxVerts = new VertexPositionColor[4];

            skyboxVerts[0] = new VertexPositionColor(new Vector3(-40, -1, -40), Light.SkyGradientBottom);
            skyboxVerts[1] = new VertexPositionColor(new Vector3(-40, 21, -40), Light.SkyGradientTop);
            skyboxVerts[2] = new VertexPositionColor(new Vector3(220, -1, -40), Light.SkyGradientBottom);
            skyboxVerts[3] = new VertexPositionColor(new Vector3(220, 21, -40), Light.SkyGradientTop);
        }
Exemple #22
0
        /// <summary>
        /// Add 3D line.
        /// </summary>
        /// <param name="startPos">3D world-space start position</param>
        /// <param name="endPos">3D world-space end position</param>
        /// <param name="color">Color of line</param>
        public void AddLine(Vector3 startPos, Vector3 endPos, Color color)
        {
            if (sLinesList.Count >= MAX_LINES * 2)
            {
                return;
            }
            VertexPositionColor lineVert = new VertexPositionColor();

            lineVert.Position = startPos;
            lineVert.Color    = color;
            sLinesList.Add(lineVert);
            lineVert.Position = endPos;
            lineVert.Color    = color;
            sLinesList.Add(lineVert);
        }
Exemple #23
0
        private static IEnumerable <VertexPositionColor> GetFaceVertices(IntPoint3D faceVector, int scale)
        {
            var halfScale = scale / 2f;

            foreach (var vector in Faces[faceVector])
            {
                var result = new VertexPositionColor
                {
                    Position = vector * halfScale,
                    Color    = Colors[faceVector]/*.Values.ToArray()[new Random().Next(6)]*/
                };

                yield return(result);
            }
        }
        } // DrawSolid2DPlane

        /// <summary>
        /// Render a 2D solid plane.
        /// </summary>
        /// <remarks>This work without batching and that could produce a performance penalty.</remarks>
        /// <param name="screenRect">Rectangle</param>
        /// <param name="topLeftColor">Top Left Color</param>
        /// <param name="topRightColor">Top Right Color</param>
        /// <param name="bottomLeftColor">Bottom Left Color</param>
        /// <param name="bottomRightColor">Bottom Right Color</param>
        public static void DrawSolid2DPlane(Rectangle screenRect, Color topLeftColor, Color topRightColor, Color bottomLeftColor, Color bottomRightColor)
        {
            if (!hasBegun || !begin2D)
            {
                throw new InvalidOperationException("Line Manager: you have to call Begin in 2D mode.");
            }

            planeVertices[0] = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y, 0f), topLeftColor);
            planeVertices[2] = new VertexPositionColor(new Vector3(screenRect.X, screenRect.Y + screenRect.Height, 0f), bottomLeftColor);
            planeVertices[1] = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y, 0f), topRightColor);
            planeVertices[3] = new VertexPositionColor(new Vector3(screenRect.X + screenRect.Width, screenRect.Y + screenRect.Height, 0f), bottomRightColor);

            // Submit the draw call to the graphics card
            EngineManager.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, planeVertices, 0, 2);
        } // DrawSolid2DPlane
Exemple #25
0
        public static void ccDrawLine(CCPoint origin, CCPoint destination, ccColor4F color)
        {
            float contentScaleFactor = CCDirector.sharedDirector().ContentScaleFactor;

            VertexPositionColor[] vertexPositionColor = new VertexPositionColor[] { new VertexPositionColor(new Vector3(origin.x * contentScaleFactor, origin.y * contentScaleFactor, 0f), new Color(color.r, color.g, color.b, color.a)), new VertexPositionColor(new Vector3(destination.x * contentScaleFactor, destination.y * contentScaleFactor, 0f), new Color(color.r, color.g, color.b, color.a)) };
            CCApplication         cCApplication       = CCApplication.sharedApplication();

            cCApplication.basicEffect.TextureEnabled     = false;
            cCApplication.basicEffect.VertexColorEnabled = true;
            foreach (EffectPass pass in cCApplication.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();
                cCApplication.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertexPositionColor, 0, 1);
            }
        }
        protected void AffecterSommets()
        {
            int NoSommet = -1;

            for (int j = 0; j < NbLignes; ++j)
            {
                for (int i = 0; i < NbColonnes + 1; ++i)
                {
                    //Sommets[++NoSommet] = new VertexPositionTexture(PtsSommets[i, j], PtsTexture[i, j]);
                    //Sommets[++NoSommet] = new VertexPositionTexture(PtsSommets[i, j + 1], PtsTexture[i, j + 1]);
                    Sommets[++NoSommet] = new VertexPositionColor(PtsSommets[i, j], Color);
                    Sommets[++NoSommet] = new VertexPositionColor(PtsSommets[i, j + 1], Color);
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Gera a geometria
        /// </summary>
        /// <param name="graphics"></param>
        static public void Initialize(GraphicsDevice graphics)
        {
            vertexList = new VertexPositionColor[6];
            int size = 2;

            //Eixo dos XX
            vertexList[0] = new VertexPositionColor(new Vector3(-size, 0, 0), Color.Red);
            vertexList[1] = new VertexPositionColor(new Vector3(size, 0, 0), Color.Red);
            //Eixo dos YY
            vertexList[2] = new VertexPositionColor(new Vector3(0, -size, 0), Color.Green);
            vertexList[3] = new VertexPositionColor(new Vector3(0, size, 0), Color.Green);
            //Eixo dos ZZ
            vertexList[4] = new VertexPositionColor(new Vector3(0, 0, -size), Color.Blue);
            vertexList[5] = new VertexPositionColor(new Vector3(0, 0, size), Color.Blue);
        }
Exemple #28
0
        public MyStaticMesh(IRenderConfiguration renderConfig)
            : base(renderConfig)
        {
            VertexBuffer = new VertexBuffer(renderConfig.GraphicsDevice,
                                            VertexPositionColor.VertexDeclaration, 3, BufferUsage.WriteOnly);

            VertexPositionColor vec1 = new VertexPositionColor(new Vector3(-1.5f, 0, 0), Color.Red);
            VertexPositionColor vec2 = new VertexPositionColor(new Vector3(0, 2, 0), Color.Blue);
            VertexPositionColor vec3 = new VertexPositionColor(new Vector3(1.5f, -3, 0), Color.Green);

            VertexBuffer.SetData <VertexPositionColor>(new VertexPositionColor[] { vec1, vec2, vec3 });

            PrimitiveType  = PrimitiveType.TriangleList;
            PrimitiveCount = 1;
        }
        public static void InitTestThings()
        {
            if (!Main.dedServ)
            {
                DrawOverride.basicEffect = new BasicEffect(Main.graphics.GraphicsDevice);

                VertexPositionColor[] vertices = new VertexPositionColor[3];
                vertices[0] = new VertexPositionColor(new Vector3(0, 1f, 0), Color.Red);
                vertices[1] = new VertexPositionColor(new Vector3(+1f, -1f, 0), Color.Green);
                vertices[2] = new VertexPositionColor(new Vector3(-1f, -1f, 0), Color.Blue);

                DrawOverride.vertexBuffer = new VertexBuffer(Main.graphics.GraphicsDevice, typeof(VertexPositionColor), 3, BufferUsage.WriteOnly);
                DrawOverride.vertexBuffer.SetData <VertexPositionColor>(vertices);
            }
        }
        /// <summary>
        /// Draws a polygon with the specified vertices.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="verts">Array of the vertices. The value in the last index should be equal to
        /// the first index to close the polygon.</param>
        /// <param name="color">Color of the polygon.</param>
        public static void DrawPolygon(Vector2 position, Vector2[] verts, Color color)
        {
            VertexPositionColor[] vertices = new VertexPositionColor[verts.Length + 1];

            for (int i = 0; i < verts.Length; i++)
            {
                vertices[i].Position = new Vector3(position + verts[i], 0);
                vertices[i].Color    = color;
            }

            vertices[verts.Length] = vertices[0];

            basicEffect.CurrentTechnique.Passes[0].Apply();
            graphicsDevice.DrawUserPrimitives(PrimitiveType.LineStrip, vertices, 0, vertices.Length - 1);
        }
Exemple #31
0
 protected override void Initialize()
 {
     plane[0]   = new VertexPositionColor(new Vector3(-11.0f, -0.5f, -11.0f), Color.Green);
     plane[1]   = new VertexPositionColor(new Vector3(11.0f, -0.5f, -11.0f), Color.GreenYellow);
     plane[2]   = new VertexPositionColor(new Vector3(-11.0f, -0.5f, 11.0f), Color.LightGreen);
     plane[3]   = new VertexPositionColor(new Vector3(11.0f, -0.5f, 11.0f), Color.LawnGreen);
     player     = new Player(new Vector3(0, 0, 0), new Vector2(0, 1));
     camera     = new Camera(new Vector3(0, 25, 15), Vector3.Zero, Vector3.Up);
     enemies[0] = new Enemy(new Vector3(3, 0, 3));
     enemies[1] = new Enemy(new Vector3(-3, 0, 3));
     enemies[2] = new Enemy(new Vector3(3, 0, -3));
     enemies[3] = new Enemy(new Vector3(-3, 0, -3));
     timeLeft   = 30000;
     base.Initialize();
 }
 public Polygon(Line[] lines, float angle = 0)
 {
     Lines      = lines;
     BaseWidth  = Width;
     BaseHeight = Height;
     Angle      = angle;
     _vertices  = new VertexPositionColor[lines.Length];
     for (int i = 0; i < lines.Length; i++)
     {
         _vertices[i] = new VertexPositionColor(new Vector3(lines[i].Start, 0), Color.White);
     }
     _triangulated         = false;
     _triangulatedVertices = new VertexPositionColor[_vertices.Length * 3];
     _indeces = new int[_vertices.Length];
 }
Exemple #33
0
        private void Initialize()
        {
            VertexPositionColor[] vertices = new VertexPositionColor[3];

            //Vector3 topLeft = new Vector3(-pointX, pointY, pointZ);
            //Vector3 bottomLeft = new Vector3(0, -pointY, pointZ);
            //Vector3 bottomRight = new Vector3(pointX, pointY, pointZ);

            vertices[0] = new VertexPositionColor(point1, partColor);
            vertices[1] = new VertexPositionColor(point2, partColor);
            vertices[2] = new VertexPositionColor(point3, partColor);

            VertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionColor.VertexDeclaration, 3, BufferUsage.WriteOnly);
            VertexBuffer.SetData(vertices);
        }
Exemple #34
0
        public VertexPositionColor[] GetVertices(GraphicsDevice graphicsDevice, Matrix4 world, Color4 color, out ushort[] indices)
        {
            indices = new ushort[18];
            VertexPositionColor[] vertices = new VertexPositionColor[12];
            ushort[] tmpIndices;
            int      count = 0;

            foreach (var item in new[] { new { Dir = Vector3.UnitX, Color = _xColor }, new { Dir = Vector3.UnitY, Color = _yColor }, new { Dir = Vector3.UnitZ, Color = _zColor } }.OrderByDescending(i => i.Dir, new DistanceToCameraComparer(graphicsDevice)))
            {
                new Arrow(new Vector3(0), item.Dir * _length, _headWidth, item.Color).GetVertices(graphicsDevice, world, color, out tmpIndices).CopyTo(vertices, count * 4);
                tmpIndices.Select(i => (ushort)(i + count * 4)).ToArray().CopyTo(indices, count * 6);
                count++;
            }
            return(vertices);
        }
        private Color ToColor(VertexPositionColor v1, VertexPositionColor v2, VertexPositionColor v3)
        {
            Vector3 normal = Vector3.Cross(v1.Position - v2.Position, v1.Position - v3.Position);

            normal.Normalize();

            float   dot   = Vector3.Dot(normal, Vector3.Up);
            Vector3 gray  = Color.Gray.ToVector3();
            Vector3 green = Color.Green.ToVector3();

            dot = Math.Abs(dot);
            Vector3 color = Vector3.Lerp(gray, green, dot);

            return(new Color(color));
        }
        /// <summary>
        /// draws a cubic bezier path
        /// @since v0.8
        /// </summary>
        public static void ccDrawCubicBezier(CCPoint origin, CCPoint control1, CCPoint control2, CCPoint destination, int segments, ccColor4F color)
        {
            VertexPositionColor[] vertices = new VertexPositionColor[segments + 1];
            float         factor           = CCDirector.sharedDirector().ContentScaleFactor;
            CCApplication app = CCApplication.sharedApplication();

            float t = 0;

            for (int i = 0; i < segments; ++i)
            {
                float x = (float)Math.Pow(1 - t, 3) * origin.x + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.x + 3.0f * (1 - t) * t * t * control2.x + t * t * t * destination.x;
                float y = (float)Math.Pow(1 - t, 3) * origin.y + 3.0f * (float)Math.Pow(1 - t, 2) * t * control1.y + 3.0f * (1 - t) * t * t * control2.y + t * t * t * destination.y;
                vertices[i]          = new VertexPositionColor();
                vertices[i].Position = new Vector3(x * factor, y * factor, 0);
                vertices[i].Color    = new Color(color.r, color.g, color.b, color.a);
                t += 1.0f / segments;
            }
            vertices[segments] = new VertexPositionColor()
            {
                Color    = new Color(color.r, color.g, color.b, color.a),
                Position = new Vector3(destination.x * factor, destination.y * factor, 0)
            };

            app.basicEffect.TextureEnabled     = false;
            app.basicEffect.VertexColorEnabled = true;
            foreach (var pass in app.basicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                app.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, segments);
            }

            // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
            // Needed states: GL_VERTEX_ARRAY,
            // Unneeded states: GL_TEXTURE_2D, GL_TEXTURE_COORD_ARRAY, GL_COLOR_ARRAY
            //glDisable(GL_TEXTURE_2D);
            //glDisableClientState(GL_TEXTURE_COORD_ARRAY);
            //glDisableClientState(GL_COLOR_ARRAY);

            //glVertexPointer(2, GL_FLOAT, 0, vertices);
            //glDrawArrays(GL_LINE_STRIP, 0, (GLsizei)segments + 1);
            //delete[] vertices;

            //// restore default state
            //glEnableClientState(GL_COLOR_ARRAY);
            //glEnableClientState(GL_TEXTURE_COORD_ARRAY);
            //glEnable(GL_TEXTURE_2D);
        }
Exemple #37
0
        public static void DrawWireframe(
            PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition,
            Matrix cameraView, Matrix cameraProjection,
            Vector3 center, Vector3 normal, float radius,
            Color color, bool fadeBackFace)
        {
            // Calculate basis vectors.
            Vector3 from = Vector3.Cross(normal, Vector3.Up);

            if (from.LengthSquared() < 0.0001f)
            {
                from = Vector3.Cross(normal, Vector3.Right);
            }
            from.Normalize();

            // We need two vertices per line, so we can allocate our vertices.
            const int numSegments = 64;
            const int numLines    = numSegments + 1;
            var       vertices    = new VertexPositionColor[numLines * 2];

            // Calculate initial orientation.
            Quaternion rotation = Quaternion.CreateFromAxisAngle(normal, MathHelper.TwoPi / (numSegments - 1));

            // Compute vertex positions.
            Vector3 edge = from * radius;

            for (int i = 0; i < numSegments; i++)
            {
                // Calculate line positions.
                Vector3 start = center + edge;
                edge = Vector3.Transform(edge, rotation);
                Vector3 end = center + edge;

                // Calculate line normal.
                Vector3 cameraToEdge = start - cameraPosition;
                var     lineColor    = color;
                if (fadeBackFace && Vector3.Dot(cameraToEdge, edge) > 0)
                {
                    lineColor = Color.FromNonPremultiplied(color.R, color.G, color.B, 25);
                }

                vertices[(i * 2) + 0] = new VertexPositionColor(start, lineColor);
                vertices[(i * 2) + 1] = new VertexPositionColor(end, lineColor);
            }

            primitiveDrawer.Draw(Matrix.Identity, cameraView, cameraProjection,
                                 Color.White, null, PrimitiveType.LineList, vertices, false);
        }
        private void SetupBuffers()
        {
            effect                    = new BasicEffect(GraphicsDevice);
            effect.Projection         = Camera.ProjectionMatrix;
            effect.View               = Camera.ViewMatrix;
            effect.VertexColorEnabled = true;

            Color[] faceColors = new Color[] { Color.Green, Color.Blue, Color.Yellow,
                                               Color.White, Color.Red, Color.DarkOrange };
            Color unusedColor = Color.Black;

            vertexStarts = new int[26];
            indexStarts  = new int[26];

            int vertexStart = 0;

            VertexPositionColor[] vertices = new VertexPositionColor[26 * 6 * 4];

            int indexStart = 0;

            short[] indices = new short[26 * 6 * 6];

            for (int i = 0; i < 26; i++)
            {
                bool cubeletFound = false;
                for (int j = 0; !cubeletFound && j < cubelets.Length; j++)
                {
                    if (cubelets[j].FaceCode == i)
                    {
                        vertexStarts[i] = vertexStart;
                        indexStarts[i]  = indexStart;

                        CreateCubeletVertices(vertices, ref vertexStart, indices, ref indexStart,
                                              cubelets[j].StartingOrientation, faceColors);

                        cubeletFound = true;
                    }
                }
            }

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

            indexBuffer = new IndexBuffer(GraphicsDevice, IndexElementSize.SixteenBits,
                                          indices.Length, BufferUsage.None);
            indexBuffer.SetData(indices);
        }
Exemple #39
0
        public void Draw()
        {
            if (_debugEffect == null)
            {
                _debugEffect = new BasicEffect(GameEngine.Device);
            }

            _debugEffect.View       = GameEngine.Camera.View;
            _debugEffect.World      = Matrix.Identity;
            _debugEffect.Projection = GameEngine.Camera.Projection;;
            DebugRenderable debugRenderable = Scene.GetDebugRenderable();

            //GameEngine.Device.VertexDeclaration = new VertexDeclaration(VertexPositionColor.VertexDeclaration.GetVertexElements());

            foreach (EffectPass pass in _debugEffect.CurrentTechnique.Passes)
            {
                if (debugRenderable.PointCount > 0)
                {
                    DebugPoint[] debugPoints = debugRenderable.GetDebugPoints();
                    //GameEngine.Device.DrawUserPrimitives<DebugPoint>(PrimitiveType.LineList, debugPoints, 0, debugPoints.Length);
                }
                if (debugRenderable.LineCount > 0)
                {
                    DebugLine[]           debugLines = debugRenderable.GetDebugLines();
                    VertexPositionColor[] vertexData = new VertexPositionColor[debugRenderable.LineCount * 2];
                    for (int i = 0; i < debugRenderable.LineCount; i++)
                    {
                        DebugLine line = debugLines[i];
                        vertexData[i * 2]       = new VertexPositionColor(line.Point0, Color.White);
                        vertexData[(i * 2) + 1] = new VertexPositionColor(line.Point1, Color.White);
                    }
                    GameEngine.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertexData, 0, debugLines.Length);
                }
                if (debugRenderable.TriangleCount > 0)
                {
                    DebugTriangle[]       debugTriangles = debugRenderable.GetDebugTriangles();
                    VertexPositionColor[] colorArray2    = new VertexPositionColor[debugRenderable.TriangleCount * 3];
                    for (int j = 0; j < debugRenderable.TriangleCount; j++)
                    {
                        DebugTriangle triangle = debugTriangles[j];
                        colorArray2[j * 3]       = new VertexPositionColor(triangle.Point0, Color.White);
                        colorArray2[(j * 3) + 1] = new VertexPositionColor(triangle.Point1, Color.White);
                        colorArray2[(j * 3) + 2] = new VertexPositionColor(triangle.Point2, Color.White);
                    }
                    GameEngine.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, colorArray2, 0, debugTriangles.Length);
                }
            }
        }
Exemple #40
0
        public Crosshair(GraphicsDevice device, Vector3 position, Vector3 scale, Color color) : base(device, position, scale)
        {
            Color = color;

            // Setting up buffers - for crossing lines
            VertexPositionColor[] vertices = new VertexPositionColor[4]
            {
                new VertexPositionColor(new Vector3(-1, 0, 0), Color),
                new VertexPositionColor(new Vector3(1, 0, 0), Color),

                new VertexPositionColor(new Vector3(0, -1, 0), Color),
                new VertexPositionColor(new Vector3(0, 1, 0), Color)
            };

            VertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), vertices.Length, BufferUsage.WriteOnly);
            VertexBuffer.SetData <VertexPositionColor>(vertices);

            short[] indicesH = new short[2] {
                0, 1
            };
            IndexBufferH = new IndexBuffer(GraphicsDevice, typeof(short), indicesH.Length, BufferUsage.WriteOnly);
            IndexBufferH.SetData(indicesH);

            short[] indicesV = new short[2] {
                2, 3
            };
            IndexBufferV = new IndexBuffer(GraphicsDevice, typeof(short), indicesV.Length, BufferUsage.WriteOnly);
            IndexBufferV.SetData(indicesV);

            // For outer square
            VertexPositionColor[] squareVertices = new VertexPositionColor[4]
            {
                new VertexPositionColor(new Vector3(-1, 1, 0), Color),
                new VertexPositionColor(new Vector3(1, 1, 0), Color),

                new VertexPositionColor(new Vector3(1, -1, 0), Color),
                new VertexPositionColor(new Vector3(-1, -1, 0), Color)
            };

            SquareVertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), squareVertices.Length, BufferUsage.WriteOnly);
            SquareVertexBuffer.SetData <VertexPositionColor>(squareVertices);

            short[] squareIndices = new short[8] {
                0, 1, 1, 2, 2, 3, 3, 0
            };
            SquareIndexBuffer = new IndexBuffer(GraphicsDevice, typeof(short), squareIndices.Length, BufferUsage.WriteOnly);
            SquareIndexBuffer.SetData(squareIndices);
        }
Exemple #41
0
        public VertexPositionColor[] CreateColoredTriangle(Vector3 size, Color color)
        {
            VertexPositionColor[] shapeArray = new VertexPositionColor[]{
            new VertexPositionColor(new Vector3(-1.0f, -1.0f, -1.0f), color), // Front
            new VertexPositionColor(new Vector3(1.0f, 1.0f, -1.0f), color),
            new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f),color)
            };

            for (int i = 0; i < shapeArray.Length; i++)
            {
                shapeArray[i].Position.X *= size.X / 2;
                shapeArray[i].Position.Y *= size.Y / 2;
                shapeArray[i].Position.Z *= size.Z / 2;
            }

            return shapeArray;
        }
        public void DrawLine(JVector p0, JVector p1, Color color)
        {
            lineIndex += 2;

            if (lineIndex == LineList.Length)
            {
                VertexPositionColor[] temp = new VertexPositionColor[LineList.Length + 50];
                LineList.CopyTo(temp, 0);
                LineList = temp;
            }

            LineList[lineIndex - 2].Color = color;
            LineList[lineIndex - 2].Position = PhysicsSystem.toVector3(p0);

            LineList[lineIndex - 1].Color = color;
            LineList[lineIndex - 1].Position = PhysicsSystem.toVector3(p1);
        }
    /// <summary>
    /// Initializes the graphics objects for rendering the spheres. If this method isn't
    /// run manually, it will be called the first time you render a sphere.
    /// </summary>
    /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
    /// <param name="sphereResolution">The number of line segments
    ///     to use for each of the three circles.</param>
    public static void InitializeGraphics(GraphicsDevice graphicsDevice, int sphereResolution)
    {
        BoundingSphereRenderer.sphereResolution = sphereResolution;

        //vertDecl = new VertexDeclaration(
        effect = new BasicEffect(graphicsDevice);
        effect.LightingEnabled = false;
        effect.VertexColorEnabled = false;

        VertexPositionColor[] verts = new VertexPositionColor[(sphereResolution + 1) * 3];

        int index = 0;

        float step = MathHelper.TwoPi / (float)sphereResolution;

        //create the loop on the XY plane first
        for (float a = 0f; a <= MathHelper.TwoPi; a += step)
        {
            verts[index++] = new VertexPositionColor(
                new Vector3((float)Math.Cos(a), (float)Math.Sin(a), 0f),
                Color.White);
        }

        //next on the XZ plane
        for (float a = 0f; a <= MathHelper.TwoPi; a += step)
        {
            verts[index++] = new VertexPositionColor(
                new Vector3((float)Math.Cos(a), 0f, (float)Math.Sin(a)),
                Color.White);
        }

        //finally on the YZ plane
        for (float a = 0f; a <= MathHelper.TwoPi; a += step)
        {
            verts[index++] = new VertexPositionColor(
                new Vector3(0f, (float)Math.Cos(a), (float)Math.Sin(a)),
                Color.White);
        }

        vertBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionColor), verts.Length, BufferUsage.None);
        vertBuffer.SetData(verts);
    }
        public void DrawTriangle(JVector p0, JVector p1, JVector p2, Color color)
        {
            triangleIndex += 3;

            if (triangleIndex == TriangleList.Length)
            {
                VertexPositionColor[] temp = new VertexPositionColor[TriangleList.Length + 300];
                TriangleList.CopyTo(temp, 0);
                TriangleList = temp;
            }

            TriangleList[triangleIndex - 2].Color = color;
            TriangleList[triangleIndex - 2].Position = PhysicsSystem.toVector3(p0);

            TriangleList[triangleIndex - 1].Color = color;
            TriangleList[triangleIndex - 1].Position = PhysicsSystem.toVector3(p1);

            TriangleList[triangleIndex - 3].Color = color;
            TriangleList[triangleIndex - 3].Position = PhysicsSystem.toVector3(p2);
        }
        private NormalBuffers GetNormalBuffers(ModelMesh mesh)
        {
            if (!_normals.ContainsKey(mesh))
            {
                NormalBuffers normalBuffers = new NormalBuffers();

                Line3D[] normalLines = NormalLinesGenerator.Generate(mesh.SourceMesh);
                normalBuffers.PrimitiveCount = normalLines.Length;
                normalBuffers.VertexCount = normalLines.Length * 2;

                VertexBuffer vertexBuffer = new VertexBuffer(_device,
                    normalBuffers.VertexCount * VertexPositionColor.SizeInBytes,
                    Usage.WriteOnly, VertexFormat.None, Pool.Default);
                DataStream vertexDataStream = vertexBuffer.Lock(0,
                    normalBuffers.VertexCount * VertexPositionColor.SizeInBytes,
                    LockFlags.None);
                VertexPositionColor[] vertices = new VertexPositionColor[normalBuffers.VertexCount];
                int counter = 0;
                for (int i = 0; i < normalLines.Length; ++i)
                {
                    Vector3D normalColor = Vector3D.Normalize(normalLines[i].Direction);
                    normalColor += Vector3D.One;
                    normalColor *= 0.5f;
                    vertices[counter++] = new VertexPositionColor(normalLines[i].Start, normalColor);
                    vertices[counter++] = new VertexPositionColor(normalLines[i].End, normalColor);
                }
                vertexDataStream.WriteRange(vertices);
                vertexBuffer.Unlock();
                normalBuffers.Vertices = vertexBuffer;

                IndexBuffer indexBuffer = new IndexBuffer(_device, normalBuffers.VertexCount * sizeof(int),
                    Usage.WriteOnly, Pool.Default, false);
                DataStream indexDataStream = indexBuffer.Lock(0, normalBuffers.VertexCount * sizeof(int), LockFlags.None);
                indexDataStream.WriteRange(Enumerable.Range(0, normalBuffers.VertexCount).ToArray());
                indexBuffer.Unlock();
                normalBuffers.Indices = indexBuffer;

                _normals.Add(mesh, normalBuffers);
            }
            return _normals[mesh];
        }
Exemple #46
0
		private void PopulatePrimitivesBuffer(VertexPositionColor[] vertices)
		{
			var dataBox = this.GraphicsDevice.ImmediateContext.MapSubresource(_userPrimitivesBuffer, 0, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None);
			SharpDX.Utilities.Write(IntPtr.Add(dataBox.DataPointer, 0), vertices, 0, vertices.Length);
			this.GraphicsDevice.ImmediateContext.UnmapSubresource(_userPrimitivesBuffer, 0);
		}
        /// <summary>
        /// Performs further custom initialization for this instance.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            VertexPositionColor[] vertices = new VertexPositionColor[3];
            vertices[0].Position = new Vector3(-0.5f, -0.5f, 0f);
            vertices[0].Color = Color.Red;

            vertices[1].Position = new Vector3(0f, 0.5f, 0f);
            vertices[1].Color = Color.Green;

            vertices[2].Position = new Vector3(0.5f, -0.5f, 0f);
            vertices[2].Color = Color.Yellow;

            this.vertexBuffer = new VertexBuffer(VertexPositionColor.VertexFormat);

            this.vertexBuffer.SetData(vertices, 3);
            this.GraphicsDevice.BindVertexBuffer(this.vertexBuffer);

            ushort[] indices = new ushort[3];
            indices[0] = 0;
            indices[1] = 1;
            indices[2] = 2;

            this.indexBuffer = new IndexBuffer(indices);
            this.GraphicsDevice.BindIndexBuffer(this.indexBuffer);
        }
        public override void debugDrawMe(GraphicsDevice device, Effect effect)
        {
            if (mVertexDecl == null)
            {
                mVertexDecl = new VertexDeclaration(device, VertexPositionColor.VertexElements);
            }

            // now draw the goal positions.
            VertexPositionColor[] shape = new VertexPositionColor[mPointMasses.Count * 2];
            VertexPositionColor[] springs = new VertexPositionColor[mSprings.Count * 2];

            mBaseShape.transformVertices(ref mDerivedPos, mDerivedAngle, ref mScale, ref mGlobalShape);
            for (int i = 0; i < mPointMasses.Count; i++)
            {
                shape[(i * 2) + 0].Position = VectorTools.vec3FromVec2(mPointMasses[i].Position);
                shape[(i * 2) + 0].Color = Color.LawnGreen;

                shape[(i * 2) + 1].Position = VectorTools.vec3FromVec2(mGlobalShape[i]);
                shape[(i * 2) + 1].Color = Color.LightSeaGreen;
            }

            for (int i = 0; i < mSprings.Count; i++)
            {
                springs[(i * 2) + 0].Position = VectorTools.vec3FromVec2(mPointMasses[mSprings[i].pointMassA].Position);
                springs[(i * 2) + 0].Color = Color.LawnGreen;
                springs[(i * 2) + 1].Position = VectorTools.vec3FromVec2(mPointMasses[mSprings[i].pointMassB].Position);
                springs[(i * 2) + 1].Color = Color.LightSeaGreen;
            }

            device.VertexDeclaration = mVertexDecl;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, shape, 0, mPointMasses.Count);
                device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, springs, 0, mSprings.Count);
                pass.End();
            }
            effect.End();

            base.debugDrawMe(device, effect);
        }
        public override void debugDrawMe(GraphicsDevice device, Effect effect)
        {
            base.debugDrawMe(device, effect);

            // draw edge normals!
            VertexPositionColor[] normals = new VertexPositionColor[mPointMasses.Count*2];

            for (int i = 0; i < mPointMasses.Count; i++)
            {
                int prev = (i > 0) ? i - 1 : mPointMasses.Count - 1;
                int next = (i < mPointMasses.Count - 1) ? i + 1 : 0;

                // currently we are talking about the edge from i --> j.
                // first calculate the volume of the body, and cache normals as we go.
                Vector2 edge1N = VectorTools.getPerpendicular(mPointMasses[i].Position - mPointMasses[prev].Position);
                edge1N.Normalize();

                Vector2 edge2N = VectorTools.getPerpendicular(mPointMasses[next].Position - mPointMasses[i].Position);
                edge2N.Normalize();

                Vector2 norm = edge1N + edge2N;
                float nL = norm.Length();
                if (nL > 0.001f)
                    norm.Normalize();

                normals[(i * 2) + 0].Position = VectorTools.vec3FromVec2(mPointMasses[i].Position);
                normals[(i * 2) + 0].Color = Color.Yellow;

                normals[(i * 2) + 1].Position = VectorTools.vec3FromVec2(mPointMasses[i].Position + norm);
                normals[(i * 2) + 1].Color = Color.Honeydew;
            }

            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, normals, 0, mPointMasses.Count);
                pass.End();
            }
            effect.End();
        }
Exemple #50
0
		private void PopulatePrimitivesBuffer(VertexPositionColor[] vertices)
		{
			using (var stream = _userPrimitivesBuffer.Map(MapMode.WriteDiscard, SlimDX.Direct3D10.MapFlags.None))
			{
				for (int i = 0; i < vertices.Length; i++)
				{
					stream.Write(vertices[i]);
				}
			}
			_userPrimitivesBuffer.Unmap();
		}
Exemple #51
0
        /// <summary>
        /// draw the world extents on-screen.
        /// </summary>
        /// <param name="device">Graphics Device</param>
        /// <param name="effect">An Effect to draw the lines with (should implement vertex color diffuse)</param>
        public void debugDrawMe(GraphicsDevice device, Effect effect)
        {
            if (mVertexDecl == null)
            {
                mVertexDecl = new VertexDeclaration(device, VertexPositionColor.VertexElements);
            }

            // draw the world limits.
            VertexPositionColor[] limits = new VertexPositionColor[5];

            limits[0].Position = new Vector3(mWorldLimits.Min.X, mWorldLimits.Max.Y, 0);
            limits[0].Color = Color.SlateGray;

            limits[1].Position = new Vector3(mWorldLimits.Max.X, mWorldLimits.Max.Y, 0);
            limits[1].Color = Color.SlateGray;

            limits[2].Position = new Vector3(mWorldLimits.Max.X, mWorldLimits.Min.Y, 0);
            limits[2].Color = Color.SlateGray;

            limits[3].Position = new Vector3(mWorldLimits.Min.X, mWorldLimits.Min.Y, 0);
            limits[3].Color = Color.SlateGray;

            limits[4].Position = new Vector3(mWorldLimits.Min.X, mWorldLimits.Max.Y, 0);
            limits[4].Color = Color.SlateGray;

            device.VertexDeclaration = mVertexDecl;
            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, limits, 0, 4);
                pass.End();
            }
            effect.End();
        }
 private void DrawRectangles(VertexPositionColor topLeft, VertexPositionColor bottomRight)
 {
     var sharpRect = new RectangleF(topLeft.Position.X, topLeft.Position.Y,
         bottomRight.Position.X, bottomRight.Position.Y);
     device.RenderTarget.FillRectangle(sharpRect, brush);
 }
Exemple #53
0
        /// <summary>
        /// draw the velocities of all PointMasses in the simulation on-screen in an orange/yellow color.
        /// </summary>
        /// <param name="device">GraphicsDevice</param>
        /// <param name="effect">An Effect to draw the lines with</param>
        public void debugDrawPointVelocities(GraphicsDevice device, Effect effect)
        {
            if (mVertexDecl == null)
            {
                mVertexDecl = new VertexDeclaration(device, VertexPositionColor.VertexElements);
            }

            for (int i = 0; i < mBodies.Count; i++)
            {
                VertexPositionColor[] vels = new VertexPositionColor[mBodies[i].PointMassCount * 2];

                for (int pm = 0; pm < mBodies[i].PointMassCount; pm++)
                {
                    vels[(pm * 2) + 0].Position = VectorTools.vec3FromVec2(mBodies[i].getPointMass(pm).Position);
                    vels[(pm * 2) + 0].Color = Color.Yellow;
                    vels[(pm * 2) + 1].Position = VectorTools.vec3FromVec2(mBodies[i].getPointMass(pm).Position + (mBodies[i].getPointMass(pm).Velocity * 0.25f));
                    vels[(pm * 2) + 1].Color = Color.Orange;
                }

                effect.Begin();
                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Begin();
                    device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineList, vels, 0, mBodies[i].PointMassCount);
                    pass.End();
                }
                effect.End();
            }
        }
    /// <summary>
    /// Renders a Ray for debugging purposes.
    /// </summary>
    /// <param name="ray">The ray to render.</param>
    /// <param name="length">The distance along the ray to render.</param>
    /// <param name="graphicsDevice">The graphics device to use when rendering.</param>
    /// <param name="view">The current view matrix.</param>
    /// <param name="projection">The current projection matrix.</param>
    /// <param name="color">The color to use drawing the ray.</param>
    public static void Render(Ray ray, float length, GraphicsDevice graphicsDevice, Matrix view, Matrix projection, Color color)
    {
        if (effect == null)
            {
                effect = new BasicEffect(graphicsDevice);
                effect.VertexColorEnabled = false;
                effect.LightingEnabled = false;
            }

            verts[0] = new VertexPositionColor(ray.Position, Color.White);
            verts[1] = new VertexPositionColor(ray.Position + (ray.Direction * length), Color.White);

            effect.DiffuseColor = color.ToVector3();
            effect.Alpha = (float)color.A / 255f;

            effect.World = Matrix.Identity;
            effect.View = view;
            effect.Projection = projection;

            //note you may wish to comment these next 2 lines out and set the RasterizerState elswehere in code
            //rather than here for every ray draw call.
            RasterizerState rs = graphicsDevice.RasterizerState;
            graphicsDevice.RasterizerState = RasterizerState.CullNone;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();

                graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, verts, 0, 1);

                effect.World = Matrix.Invert(Matrix.CreateLookAt(
                    verts[1].Position,
                    verts[0].Position,
                    (ray.Direction != Vector3.Up) ? Vector3.Up : Vector3.Left));

                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, arrowVerts, 0, 5, arrowIndexs, 0, 4);
            }

            //note you may wish to comment the next line out and set the RasterizerState elswehere in code
            //rather than here for every ray draw call.
            graphicsDevice.RasterizerState = rs;
    }
Exemple #55
0
		private void DrawVertices(VertexPositionColor[] vertices, PrimitiveTopology top)
		{
			PopulatePrimitivesBuffer(vertices);

			this.GraphicsDevice.InputAssembler.SetPrimitiveTopology(top);
			this.GraphicsDevice.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_userPrimitivesBuffer, VertexPositionColor.SizeInBytes, 0));
			this.GraphicsDevice.Draw(vertices.Length, 0);
		}
Exemple #56
0
        protected void InitializeVertexData()
        {
            if( primitiveType == PrimitiveType.LineList )
            {
                List<PolygonPoint> points = GetPoints();

                foreach( PolygonPoint point in points )
                {
                    // It seems silly to not just say "VertexPositionColor v = new VertexPositionColor(new Vector3(vertex, 0), color);"
                    // but its actually a JIT optimization to make sure this statement always gets inlined.
                    // Reference: Downloaded powerpoint (Understanding XNA Framework Performance) at http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=16477
                    VertexPositionColor vpc = new VertexPositionColor();
                    vpc.Position.X = (float)point.X;
                    vpc.Position.Y = (float)point.Y;

                    if( vertexPositionColors.Count > 1 )
                    {
                        vertexPositionColors.Add( lastVertexPositionColor );
                    }

                    lastVertexPositionColor = vpc;
                    vertexPositionColors.Add( vpc );
                }
            }
            else if( primitiveType == PrimitiveType.TriangleList )
            {
                Polygon polygon = GetPolygon();
                P2T.Triangulate( polygon );
                PolygonCount = polygon.Triangles.Count;

                foreach( DelaunayTriangle triangle in polygon.Triangles )
                {
                    foreach( TriangulationPoint point in triangle.Points )
                    {
                        VertexPositionColor vpc = new VertexPositionColor();
                        vpc.Position.X = (float)point.X;
                        vpc.Position.Y = (float)point.Y;
                        vertexPositionColors.Add( vpc );
                    }
                }
            }

            tranformedVPCs = vertexPositionColors.ToArray();
        }
 private void DrawLines(VertexPositionColor start, VertexPositionColor end)
 {
     var sharpStart = new DrawingPointF(start.Position.X, start.Position.Y);
     var sharpEnd = new DrawingPointF(end.Position.X, end.Position.Y);
     device.RenderTarget.DrawLine(sharpStart, sharpEnd, brush);
 }
		public ShapeData(int numVert, int numIndices)
		{
			m_verticesArray = new VertexPositionColor[numVert];
			m_indexArray = new short[numIndices];

		}
Exemple #59
0
        public VertexPositionColor[] getVPCs(ColorGenerator gen)
        {
            Vector3[] vertices;
            VertexPositionColor[] VPCs;

            // get the vertices for the landscape
            vertices = getVertices();

            // initialize the VPCs array to that same size
            VPCs = new VertexPositionColor[vertices.Length];

            // add color to each vertex
            for (int i = 0; i < vertices.Length; i++)
            {
                VPCs[i] = new VertexPositionColor(vertices[i], gen.getColor(vertices[i].Y));
            }

            // return the VPCs array
            return VPCs;
        }
Exemple #60
0
		private void DrawDebug(RenderBuffer data)
		{
			var pass = _visualizationEffect.RenderScenePass0;

			_visualizationEffect.World.SetMatrix(Matrix.Identity);
			_visualizationEffect.View.SetMatrix(this.Camera.View);
			_visualizationEffect.Projection.SetMatrix(this.Camera.Projection);

			this.GraphicsDevice.InputAssembler.SetInputLayout(_inputLayout);

			pass.Apply();

			if (data.NumberOfPoints > 0)
			{
				var vertices = new VertexPositionColor[data.Points.Length];
				for (int i = 0; i < data.Points.Length; i++)
				{
					var point = data.Points[i];

					vertices[i * 2 + 0] = new VertexPositionColor(point.Point.As<Vector3>(), Color.FromArgb(point.Color));
				}

				DrawVertices(vertices, PrimitiveTopology.PointList);
			}

			if (data.NumberOfLines > 0)
			{
				var vertices = new VertexPositionColor[data.Lines.Length * 2];
				for (int x = 0; x < data.Lines.Length; x++)
				{
					DebugLine line = data.Lines[x];

					vertices[x * 2 + 0] = new VertexPositionColor(line.Point0.As<Vector3>(), Color.FromArgb(line.Color0));
					vertices[x * 2 + 1] = new VertexPositionColor(line.Point1.As<Vector3>(), Color.FromArgb(line.Color1));
				}

				DrawVertices(vertices, PrimitiveTopology.LineList);
			}

			if (data.NumberOfTriangles > 0)
			{
				var vertices = new VertexPositionColor[data.Triangles.Length * 3];
				for (int x = 0; x < data.Triangles.Length; x++)
				{
					DebugTriangle triangle = data.Triangles[x];

					vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0.As<Vector3>(), Color.FromArgb(triangle.Color0));
					vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1.As<Vector3>(), Color.FromArgb(triangle.Color1));
					vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2.As<Vector3>(), Color.FromArgb(triangle.Color2));
				}

				DrawVertices(vertices, PrimitiveTopology.TriangleList);
			}
		}