public SelectableCurve(Color color)
        {
            this.color = color;

            screenPoints = new VertexPositionColorTexture[subdivisions * 2];
            selectPoints = new VertexPositionColorTexture[subdivisions * 2];
            indices = new int[3 * subdivisions];

            cornerAlpha = new float[4] { 1, 1, 1, 1 };

            // create left points array and initialize each vertex
            leftPoints = new VertexPositionColorTexture[GetNumPointsAfterIterations(6, iterations)];
            for (int i = 0; i < leftPoints.Length; i++)
            {
                leftPoints[i] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);
            }
            intermediary = new Vector3[iterations + 1][];
            for (int i = 0; i < iterations + 1; i++)
            {
                intermediary[i] = new Vector3[GetNumPointsAfterIterations(6, i)];
            }

            screenPoints[0] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);
            screenPoints[1] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);
            screenPoints[2] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);
            screenPoints[3] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);

            selectPoints[0] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);
            selectPoints[1] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);
            selectPoints[2] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);
            selectPoints[3] = new VertexPositionColorTexture(Vector3.Zero, color, Vector2.Zero);

            ComputeIndices();
        }
Esempio n. 2
0
        public static void DrawDottedCircle(float radius, Vector2 center, int segments, float rotation, Renderer renderer, 
            Color col)
        {
            if (segments == 0)
                return;
            VertexPositionColorTexture[] arr = new VertexPositionColorTexture[segments];

            int c = 0;
            Vector2 off = center;
            for (double i = 0; i <= Math.PI * 2 - 0.001d; i += Math.PI * 2 / segments)
            {
                arr[c] = new VertexPositionColorTexture(
                    new Vector3((float)Math.Cos(i + rotation) * radius + off.X, (float)Math.Sin(i + rotation) * radius + off.Y, 0),
                    col, new Vector2());
                c++;
            }

            bool a = renderer.IsDrawing;
            bool b = renderer.IsScaeld;
            if (!renderer.IsDrawing)
                renderer.BeginUnscaled();
            Main.renderer.Draw(MicroWorld.Graphics.GraphicsEngine.pixel, new Rectangle(0, 0, 0, 0), Color.White);
            renderer.End();

            renderer.GraphicsDevice.DrawUserPrimitives<VertexPositionColorTexture>(PrimitiveType.LineList,
                arr, 0, arr.Length / 2);

            if (a) renderer.Begin(b);
        }
        public void Draw(Rectangle dstRectangle, Color color)
        {
            //  ensure space for my vertices and indices.
            this.EnsureSpace(6, 4);

            //  add the new indices
            indices[indexCount++] = (short)(vertexCount + 0);
            indices[indexCount++] = (short)(vertexCount + 1);
            indices[indexCount++] = (short)(vertexCount + 3);
            indices[indexCount++] = (short)(vertexCount + 1);
            indices[indexCount++] = (short)(vertexCount + 2);
            indices[indexCount++] = (short)(vertexCount + 3);

            // add the new vertices
            vertices[vertexCount++] = new VertexPositionColorTexture(
                new Vector3(dstRectangle.Left, dstRectangle.Top, 0)
                , color, new Vector2(1,1));
            vertices[vertexCount++] = new VertexPositionColorTexture(
                new Vector3(dstRectangle.Right, dstRectangle.Top, 0)
                , color, new Vector2(0, 1));
            vertices[vertexCount++] = new VertexPositionColorTexture(
                new Vector3(dstRectangle.Right, dstRectangle.Bottom, 0)
                , color, new Vector2(0, 0));
            vertices[vertexCount++] = new VertexPositionColorTexture(
                new Vector3(dstRectangle.Left, dstRectangle.Bottom, 0)
                , color, new Vector2(1, 0));

            //  we premultiply all vertices times the world matrix.
            //  the world matrix changes alot and we don't want to have to flush
            //  every time it changes.
            Matrix world = this.World;
            for (int i = vertexCount - 4; i < vertexCount; i++)
                Vector3.Transform(ref vertices[i].Position, ref world, out vertices[i].Position);
        }
Esempio n. 4
0
 public void AddLazer(Vector3 startPos, Vector3 endPos, Color color)
 {
     VertexPositionColorTexture start = new VertexPositionColorTexture();
     VertexPositionColorTexture end = new VertexPositionColorTexture();
     start.Position = startPos;
     start.Color = color;
     start.TextureCoordinate = Vector2.UnitX * currentTime;
     end.Position = endPos;
     end.Color = color;
     end.TextureCoordinate = Vector2.UnitX * currentTime;
     vertices.Add(start); //1
     vertices.Add(end);   //2
     start.Position.X += 1; end.Position.X += 1;
     vertices.Add(start); //3
     vertices.Add(end);   //4
     start.Position.X -= 2; end.Position.X -= 2;
     vertices.Add(start); //5
     vertices.Add(end);   //6
     start.Position.Y += 1; end.Position.Y += 1;
     vertices.Add(start); //7
     vertices.Add(end);   //8
     start.Position.Y -= 2; end.Position.Y -= 2;
     vertices.Add(start); //9
     vertices.Add(end);   //10
 }
Esempio n. 5
0
        public void AddQuad(T topLeft, T topRight, T botLeft, T botRigth)
        {
            if (IsDisposed)
            {
                throw new InvalidOperationException("Object is already disposed");
            }
            if (VertexBuffer != null)
            {
                throw new InvalidOperationException("The buffers are already transfered");
            }

            int iTL = vertices.Count;

            vertices.Add(topLeft);
            int iTR = vertices.Count;

            vertices.Add(topRight);
            int iBL = vertices.Count;

            vertices.Add(botLeft);
            int iBR = vertices.Count;

            vertices.Add(botRigth);

            indices.Add(iTL);
            indices.Add(iTR);
            indices.Add(iBL);

            indices.Add(iTR);
            indices.Add(iBR);
            indices.Add(iBL);
        }
Esempio n. 6
0
 public SpriteBatchItem()
 {
   this.vertexTL = new VertexPositionColorTexture();
   this.vertexTR = new VertexPositionColorTexture();
   this.vertexBL = new VertexPositionColorTexture();
   this.vertexBR = new VertexPositionColorTexture();
 }
Esempio n. 7
0
        public Border(World world, ScreenManager screenManager, Camera2D camera)
        {
            _screenManager = screenManager;
            _camera = camera;

            float halfWidth = ConvertUnits.ToSimUnits(screenManager.GraphicsDevice.Viewport.Width) / 2f - 0.75f;
            float halfHeight = ConvertUnits.ToSimUnits(screenManager.GraphicsDevice.Viewport.Height) / 2f - 0.75f;

            Vertices borders = new Vertices(4);
            borders.Add(new Vector2(-halfWidth, halfHeight));
            borders.Add(new Vector2(halfWidth, halfHeight));
            borders.Add(new Vector2(halfWidth, -halfHeight));
            borders.Add(new Vector2(-halfWidth, -halfHeight));

            _anchor = BodyFactory.CreateLoopShape(world, borders);
            _anchor.CollisionCategories = Category.All;
            _anchor.CollidesWith = Category.All;

            _basicEffect = new BasicEffect(screenManager.GraphicsDevice);
            _basicEffect.VertexColorEnabled = true;
            _basicEffect.TextureEnabled = true;
            _basicEffect.Texture = screenManager.Content.Load<Texture2D>("Materials/pavement");

            VertexPositionColorTexture[] vertice = new VertexPositionColorTexture[8];
            vertice[0] = new VertexPositionColorTexture(new Vector3(-halfWidth, -halfHeight, 0f), Color.LightGray, new Vector2(-halfWidth, -halfHeight) / 5.25f);
            vertice[1] = new VertexPositionColorTexture(new Vector3(halfWidth, -halfHeight, 0f), Color.LightGray, new Vector2(halfWidth, -halfHeight) / 5.25f);
            vertice[2] = new VertexPositionColorTexture(new Vector3(halfWidth, halfHeight, 0f), Color.LightGray, new Vector2(halfWidth, halfHeight) / 5.25f);
            vertice[3] = new VertexPositionColorTexture(new Vector3(-halfWidth, halfHeight, 0f), Color.LightGray, new Vector2(-halfWidth, halfHeight) / 5.25f);
            vertice[4] = new VertexPositionColorTexture(new Vector3(-halfWidth - 2f, -halfHeight - 2f, 0f), Color.LightGray, new Vector2(-halfWidth - 2f, -halfHeight - 2f) / 5.25f);
            vertice[5] = new VertexPositionColorTexture(new Vector3(halfWidth + 2f, -halfHeight - 2f, 0f), Color.LightGray, new Vector2(halfWidth + 2f, -halfHeight - 2f) / 5.25f);
            vertice[6] = new VertexPositionColorTexture(new Vector3(halfWidth + 2f, halfHeight + 2f, 0f), Color.LightGray, new Vector2(halfWidth + 2f, halfHeight + 2f) / 5.25f);
            vertice[7] = new VertexPositionColorTexture(new Vector3(-halfWidth - 2f, halfHeight + 2f, 0f), Color.LightGray, new Vector2(-halfWidth - 2f, halfHeight + 2f) / 5.25f);

            _borderVerts = new VertexPositionColorTexture[24];
            _borderVerts[0] = vertice[0];
            _borderVerts[1] = vertice[5];
            _borderVerts[2] = vertice[4];
            _borderVerts[3] = vertice[0];
            _borderVerts[4] = vertice[1];
            _borderVerts[5] = vertice[5];
            _borderVerts[6] = vertice[1];
            _borderVerts[7] = vertice[6];
            _borderVerts[8] = vertice[5];
            _borderVerts[9] = vertice[1];
            _borderVerts[10] = vertice[2];
            _borderVerts[11] = vertice[6];
            _borderVerts[12] = vertice[2];
            _borderVerts[13] = vertice[7];
            _borderVerts[14] = vertice[6];
            _borderVerts[15] = vertice[2];
            _borderVerts[16] = vertice[3];
            _borderVerts[17] = vertice[7];
            _borderVerts[18] = vertice[3];
            _borderVerts[19] = vertice[4];
            _borderVerts[20] = vertice[7];
            _borderVerts[21] = vertice[3];
            _borderVerts[22] = vertice[0];
            _borderVerts[23] = vertice[4];
        }
 public SelectableLine(Vector3 start, Vector3 end, Color color, float thickness)
     : base(color)
 {
     linePoints[0] = new VertexPositionColorTexture(start, color, Vector2.Zero);
     linePoints[1] = new VertexPositionColorTexture(end, color, Vector2.Zero);
     selectableThickness = thickness;
     Recompute();
 }
        public void Draw(Texture2D texture, Vector2 position, Color color)
        {
            _texture = texture; //Hack sorta

            _vertexArray[_index++] = new VertexPositionColorTexture(new Vector3(position.X, position.Y, 0), color, Vector2.Zero);
            _vertexArray[_index++] = new VertexPositionColorTexture(new Vector3(position.X + texture.Width, position.Y, 0), color, Vector2.UnitX);
            _vertexArray[_index++] = new VertexPositionColorTexture(new Vector3(position.X, position.Y + texture.Height, 0), color, Vector2.UnitY);
            _vertexArray[_index++] = new VertexPositionColorTexture(new Vector3(position.X + texture.Width, position.Y + texture.Height, 0), color, Vector2.One);
        }
Esempio n. 10
0
 public SelectableQuad(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Color color)
     : base()
 {
     screenPoints[0] = new VertexPositionColorTexture(p1, color, Vector2.Zero);
     screenPoints[1] = new VertexPositionColorTexture(p2, color, Vector2.UnitX);
     screenPoints[2] = new VertexPositionColorTexture(p3, color, Vector2.One);
     screenPoints[3] = new VertexPositionColorTexture(p4, color, Vector2.UnitY);
     Synchronize();
 }
Esempio n. 11
0
 public PolygonRect(float X, float Y, float Z, float Width, float Height, Texture2D tex)
 {
     vertices = new VertexPositionColorTexture[6];
     vertices[0] = new VertexPositionColorTexture(new Vector3(X, Y, Z), Color.White, Vector2.Zero);
     vertices[1] = new VertexPositionColorTexture(new Vector3(X + Width, Y, Z), Color.White, new Vector2(1,0));
     vertices[2] = new VertexPositionColorTexture(new Vector3(X + Width, Y + Height, Z), Color.White, new Vector2(1,1));
     vertices[3] = new VertexPositionColorTexture(new Vector3(X + Width, Y + Height, Z), Color.White, new Vector2(1, 1));
     vertices[4] = new VertexPositionColorTexture(new Vector3(X, Y + Height, Z), Color.White, new Vector2(0, 1));
     vertices[5] = new VertexPositionColorTexture(new Vector3(X, Y, Z), Color.White, Vector2.Zero);
 }
Esempio n. 12
0
        public void getVertices(VertexPositionColorTexture[] vertices,int offset)
        {
            vertices[offset++] = verts[0];
            vertices[offset++] = verts[1];
            vertices[offset++] = verts[3];

            vertices[offset++] = verts[1];
            vertices[offset++] = verts[3];
            vertices[offset++] = verts[2];
        }
 private static VertexBuffer CreateTexturedVertexBuffer(ModelMeshData mesh)
 {
     var vertices = new VertexPositionColorTexture[mesh.Vertices.Count];
      for (var i = 0; i != mesh.Vertices.Count; ++i)
     vertices[i] = new VertexPositionColorTexture(mesh.Vertices[i], mesh.Colors[i], mesh.TextureCoords[i]);
      VertexBuffer vertexBuffer = new VertexBuffer(GraphicsDeviceHolder.Device,
     mesh.Vertices.Count * VertexPositionColorTexture.SizeInBytes, BufferUsage.WriteOnly);
      vertexBuffer.SetData(vertices);
      return vertexBuffer;
 }
 public TexturedPrimitiveObject(string id, ObjectType objectType,
     Transform3D transform, VertexPositionColorTexture[] vertices,
     BasicEffect effect, PrimitiveType primitiveType, int primitiveCount, Texture2D texture)
     : base(id, objectType, transform)
 {
     this.vertices = vertices;
     this.effect = effect;
     this.primitiveType = primitiveType;
     this.primitiveCount = primitiveCount;
     this.texture = texture;
 }
        public void CreateCube(Color color, out VertexPositionColorTexture[] vertexData, out int[] indexData)
        {

            vertexData = new VertexPositionColorTexture[]
            {

                // front
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, -0.5f), color, new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(0.5f, -0.5f, -0.5f), color, new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, 0.5f, -0.5f), color, new Vector2(0, 1)),
                new VertexPositionColorTexture(new Vector3(0.5f, 0.5f, -0.5f), color, new Vector2(1, 1)),

                // top
                new VertexPositionColorTexture(new Vector3(-0.5f, 0.5f, -0.5f), color, new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(0.5f, 0.5f, -0.5f), color, new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, 0.5f, 0.5f), color, new Vector2(0, 1)),
                new VertexPositionColorTexture(new Vector3(0.5f, 0.5f, 0.5f), color, new Vector2(1, 1)),

                // back
                new VertexPositionColorTexture(new Vector3(0.5f, -0.5f, 0.5f), color, new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, 0.5f), color, new Vector2(0, 1)),
                new VertexPositionColorTexture(new Vector3(0.5f, 0.5f, 0.5f), color, new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, 0.5f, 0.5f), color, new Vector2(0, 0)),

                // bottom
                new VertexPositionColorTexture(new Vector3(0.5f, -0.5f, -0.5f), color, new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, -0.5f), color, new Vector2(0, 1)),
                new VertexPositionColorTexture(new Vector3(0.5f, -0.5f, 0.5f), color, new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, 0.5f), color, new Vector2(0, 0)),

                // left
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, 0.5f), color, new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, -0.5f, -0.5f), color, new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(-0.5f, 0.5f, 0.5f), color, new Vector2(1, 1)),
                new VertexPositionColorTexture(new Vector3(-0.5f, 0.5f, -0.5f), color, new Vector2(0, 1)),

                // right
                new VertexPositionColorTexture(new Vector3(0.5f, -0.5f, -0.5f), color, new Vector2(0, 0)),
                new VertexPositionColorTexture(new Vector3(0.5f, -0.5f, 0.5f), color, new Vector2(1, 0)),
                new VertexPositionColorTexture(new Vector3(0.5f, 0.5f, -0.5f), color, new Vector2(0, 1)),
                new VertexPositionColorTexture(new Vector3(0.5f, 0.5f, 0.5f), color, new Vector2(1, 1)),

            };

            indexData = new int[] { 
                0, 1, 2, 3, 2, 1,
                4, 5, 6, 7, 6, 5,
                8, 9, 10, 11, 10, 9,
                12, 13, 14, 15, 14, 13,
                16, 17, 18, 19, 18, 17,
                20, 21, 22, 23, 22, 21
             };

        }
Esempio n. 16
0
        public int UseVertex(XY position, float z, Microsoft.Xna.Framework.Color color, XY uv)
        {
            var v = new VERTEX
            {
                Position          = new Microsoft.Xna.Framework.Vector3(position.X, position.Y, z),
                Color             = color,
                TextureCoordinate = uv.ToXna()
            };

            return(_Vertices.Use(v));
        }
Esempio n. 17
0
        public List<TriangleData> GetFaces()
        {
            Matrix rootTransform = sceneModel.Root.Transform;

            List<TriangleData> faceList = new List<TriangleData>();// new TriangleData[totalNumFaces];

            foreach (ModelMesh mesh in sceneModel.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    VertexPositionColorTexture[] meshPartVertices = new VertexPositionColorTexture[meshPart.NumVertices];
                    meshPart.VertexBuffer.GetData<VertexPositionColorTexture>(meshPartVertices);

                    if (meshPart.IndexBuffer.IndexElementSize == IndexElementSize.SixteenBits)
                    {
                        short[] meshIndices = new short[meshPart.IndexBuffer.IndexCount];
                        meshPart.IndexBuffer.GetData<short>(meshIndices);

                        for (int cFaces = 0; cFaces < meshPart.PrimitiveCount; cFaces++)
                        {
                            Vector3[] vertices = new Vector3[3];
                            for (int cFaceVertice = 0; cFaceVertice < 3; cFaceVertice++)
                            {
                                vertices[cFaceVertice] = Vector3.Transform(meshPartVertices[meshIndices[meshPart.VertexOffset + (cFaces * 3) + cFaceVertice]].Position, rootTransform);
                            }
                            TriangleData triangleData = new TriangleData(ref vertices);
                            faceList.Add(triangleData);

                        }

                    }
                    else
                    {
                        int[] meshIndices = new int[meshPart.IndexBuffer.IndexCount];
                        meshPart.IndexBuffer.GetData<int>(meshIndices);

                        for (int cFaces = 0; cFaces < meshPart.PrimitiveCount; cFaces++)
                        {
                            Vector3[] vertices = new Vector3[3];
                            for (int cFaceVertice = 0; cFaceVertice < 3; cFaceVertice++)
                            {
                                vertices[cFaceVertice] = Vector3.Transform(meshPartVertices[meshIndices[meshPart.VertexOffset + (cFaces * 3) + cFaceVertice]].Position, rootTransform);
                            }
                            TriangleData triangleData = new TriangleData(ref vertices);
                            faceList.Add(triangleData);

                        }

                    }

                }
            }
            return faceList;
        }
Esempio n. 18
0
        public Texture2D EllipseTexture(float radiusX, float radiusY, MaterialType type, Color color,
                                        float materialScale)
        {
            VertexPositionColorTexture[] verticesFill = new VertexPositionColorTexture[3 * (CircleSegments - 2)];
            VertexPositionColor[] verticesOutline = new VertexPositionColor[2 * CircleSegments];
            const float segmentSize = MathHelper.TwoPi / CircleSegments;
            float theta = segmentSize;

            radiusX = ConvertUnits.ToDisplayUnits(radiusX);
            radiusY = ConvertUnits.ToDisplayUnits(radiusY);
            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);
        }
Esempio n. 19
0
        public void Create3DAxis(GraphicsDevice device)
        {
            int vertexCount = 6;
            vertices = new VertexPositionColorTexture[vertexCount];

            vertices[0] = new VertexPositionColorTexture(new Vector3(-axisLenght, 0.0f, -axisLenght), Color.White, new Vector2(0f, 0f));
            vertices[1] = new VertexPositionColorTexture(new Vector3(axisLenght, 0.0f, -axisLenght), Color.White, new Vector2(1f, 0f));
            vertices[2] = new VertexPositionColorTexture(new Vector3(-axisLenght, 0.0f, axisLenght), Color.White, new Vector2(0f, 1f));
            vertices[3] = new VertexPositionColorTexture(new Vector3(axisLenght, 0.0f, axisLenght), Color.White, new Vector2(1f, 1f));

            vBuffer = new VertexBuffer(device, typeof(VertexPositionColorTexture), vertices.GetLength(0), BufferUsage.WriteOnly);
        }
Esempio n. 20
0
        public void LoadContent(ContentManager content)
        {
            Model model = content.Load<Model>("AntonPhibesCollision");

            //////START collision stuff
            Matrix[] M = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(M);

            foreach (ModelMesh mesh in model.Meshes)
            {// For accumulating the triangles for this mesh
                List<Vector2> triangles = new List<Vector2>();

                // Loop over the mesh parts
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    //
                    // Obtain the vertices for the mesh part
                    //

                    int numVertices = meshPart.VertexBuffer.VertexCount;
                    VertexPositionColorTexture[] verticesRaw = new VertexPositionColorTexture[numVertices];
                    meshPart.VertexBuffer.GetData<VertexPositionColorTexture>(verticesRaw);

                    //
                    // Obtain the indices for the mesh part
                    //

                    int numIndices = meshPart.IndexBuffer.IndexCount;
                    short[] indices = new short[numIndices];
                    meshPart.IndexBuffer.GetData<short>(indices);

                    //
                    // Build the list of triangles
                    //

                    for (int i = 0; i < meshPart.PrimitiveCount * 3; i++)
                    {
                        // The actual index is relative to a supplied start position
                        int index = i + meshPart.StartIndex;

                        // Transform the vertex into world coordinates
                        Vector3 v = Vector3.Transform(verticesRaw[indices[index] + meshPart.VertexOffset].Position, M[mesh.ParentBone.Index]);
                        triangles.Add(new Vector2(v.X, v.Z));
                    }
                }

                regions[mesh.Name] = triangles;

            }
            //END COllision stuff
        }
Esempio n. 21
0
        private static VertexPositionColorTexture[] CreateQuadVertices(int width, int height)
        {
            int halfWidth = width / 2;
            int halfHeight = height / 2;

            VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[4];

            vertices[0] = new VertexPositionColorTexture(new Vector3(-halfWidth, halfHeight, 0), Color.Red, UpperLeft);
            vertices[1] = new VertexPositionColorTexture(new Vector3(halfWidth, halfHeight, 0), Color.Red, UpperRight);
            vertices[2] = new VertexPositionColorTexture(new Vector3(-halfWidth, -halfHeight, 0), Color.Red, BottomLeft);
            vertices[3] = new VertexPositionColorTexture(new Vector3(halfWidth, -halfHeight, 0), Color.Red, BottomRight);

            return vertices;
        }
Esempio n. 22
0
        public override void Initialize()
        {
            effect = new BasicEffect(game.graphics.GraphicsDevice);

            vertexData = new VertexPositionColorTexture[4];
            vertexData[TOP_LEFT] =     new VertexPositionColorTexture(new Vector3(minX, allZ, maxY), col, new Vector2(0, 0));
            vertexData[TOP_RIGHT] =    new VertexPositionColorTexture(new Vector3(maxX, allZ, maxY), col, new Vector2(1, 0));
            vertexData[BOTTOM_RIGHT] = new VertexPositionColorTexture(new Vector3(maxX, allZ, minY), col, new Vector2(1, 1));
            vertexData[BOTTOM_LEFT] =  new VertexPositionColorTexture(new Vector3(minX, allZ, minY), col, new Vector2(0, 1));

            indexData = new int[] { TOP_LEFT, BOTTOM_RIGHT, BOTTOM_LEFT, TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT };

            base.Initialize();
        }
Esempio n. 23
0
        public override void blit()
        {
            int n = m_sGridSize.x * m_sGridSize.y;

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

            //////glVertexPointer(3, GL_FLOAT, 0, m_pVertices);
            //////glTexCoordPointer(2, GL_FLOAT, 0, m_pTexCoordinates);
            //////glDrawElements(GL_TRIANGLES, (GLsizei)n * 6, GL_UNSIGNED_SHORT, m_pIndices);

            //////// restore GL default state
            //////glEnableClientState(GL_COLOR_ARRAY);

            Application app = Application.SharedApplication;
            CCSize size = Director.SharedDirector.DesignSize;

            //app.basicEffect.World = app.worldMatrix * TransformUtils.CGAffineToMatrix(this.nodeToWorldTransform());
            app.BasicEffect.Texture = this.m_pTexture.Texture2D;
            app.BasicEffect.TextureEnabled = true;
            app.GraphicsDevice.BlendState = BlendState.AlphaBlend;
            app.BasicEffect.VertexColorEnabled = true;
            //RasterizerState rs = new RasterizerState();
            //rs.CullMode = CullMode.None;
            //app.GraphicsDevice.RasterizerState = rs;

            List<VertexPositionColorTexture> vertices = new List<VertexPositionColorTexture>();
            for (int i = 0; i < (m_sGridSize.x + 1) * (m_sGridSize.y + 1); i++)
            {
                VertexPositionColorTexture vct = new VertexPositionColorTexture();
                vct.Position = new Vector3(m_pVertices[i].x, m_pVertices[i].y, m_pVertices[i].z);
                vct.TextureCoordinate = new Vector2(m_pTexCoordinates[i].X, m_pTexCoordinates[i].Y);
                vct.Color = Color.White;
                vertices.Add(vct);
            }

            short[] indexes = m_pIndices;

            foreach (var pass in app.BasicEffect.CurrentTechnique.Passes)
            {
                pass.Apply();

                app.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColorTexture>(
                    PrimitiveType.TriangleList,
                    vertices.ToArray(), 0, vertices.Count,
                    indexes, 0, indexes.Length / 3);
            }
        }
Esempio n. 24
0
File: gxtLine.cs Progetto: Loko/GXT
        public gxtLine(Vector2 start, Vector2 end)
        {
            gxtDebug.Assert(gxtRoot.SingletonIsInitialized);

            vertices = new VertexPositionColorTexture[2];
            vertices[0] = new VertexPositionColorTexture(new Vector3(start.X, start.Y, 0.0f), gxtMaterial.DEFAULT_COLOR_OVERLAY, Vector2.Zero);
            vertices[1] = new VertexPositionColorTexture(new Vector3(end.X, end.Y, 0.0f), gxtMaterial.DEFAULT_COLOR_OVERLAY, Vector2.UnitY);
            vertexBuffer = new VertexBuffer(gxtRoot.Singleton.Graphics, typeof(VertexPositionColorTexture), 2, BufferUsage.WriteOnly);
            vertexBuffer.SetData<VertexPositionColorTexture>(vertices);

            indices = new int[] { 0, 1 };
            indexBuffer = new IndexBuffer(gxtRoot.Singleton.Graphics, typeof(int), 2, BufferUsage.WriteOnly);
            indexBuffer.SetData<int>(indices);
        }
Esempio n. 25
0
 public SelectableQuad(Vector2 position, Vector2 size, Color color)
     : base()
 {
     //screenPoints[0] = new VertexPositionColorTexture(new Vector3(position.X, position.Y, 0), color, Vector2.UnitX);
     //screenPoints[1] = new VertexPositionColorTexture(new Vector3(position.X + size.X, position.Y, 0), color, Vector2.UnitX);
     //screenPoints[2] = new VertexPositionColorTexture(new Vector3(position.X + size.X, position.Y + size.Y, 0), color, Vector2.UnitX);
     //screenPoints[3] = new VertexPositionColorTexture(new Vector3(position.X, position.Y + size.Y, 0), color, Vector2.UnitX);
     screenPoints[0] = new VertexPositionColorTexture(new Vector3(position.X, position.Y, 0), color, Vector2.Zero);
     screenPoints[1] = new VertexPositionColorTexture(new Vector3(position.X + size.X, position.Y, 0), color, Vector2.UnitX);
     screenPoints[2] = new VertexPositionColorTexture(new Vector3(position.X + size.X, position.Y + size.Y, 0), color, Vector2.One);
     screenPoints[3] = new VertexPositionColorTexture(new Vector3(position.X, position.Y + size.Y, 0), color, Vector2.UnitY);
     center = new Vector3(position.X + size.X / 2, position.Y + size.Y / 2, 0);
     Synchronize();
 }
Esempio n. 26
0
        public DrawCacheUnit (VertexPositionColorTexture[] vertexBuffer, int vertexOffset, int vertexCount, short[] indexBuffer, int indexOffset, int indexCount, Texture2D texture)
        {
            if (vertexCount > vertexBuffer.Length - vertexOffset)
                throw new ArgumentException("vertexBuffer is too small for the given vertexOffset and vertexCount.");
            if (indexCount > indexBuffer.Length - indexOffset)
                throw new ArgumentException("indexBuffer is too small for the given indexOffset and indexCount.");

            _texture = texture;

            _vertexBuffer = new VertexPositionColorTexture[vertexCount];
            _indexBuffer = new short[indexCount];

            Array.Copy(vertexBuffer, vertexOffset, _vertexBuffer, 0, vertexCount);
            Array.Copy(indexBuffer, indexOffset, _indexBuffer, 0, indexCount);
        }
Esempio n. 27
0
File: gxtLine.cs Progetto: Loko/GXT
        public gxtLine(Vector2 start, Vector2 end, gxtIMaterial material)
        {
            gxtDebug.Assert(gxtRoot.SingletonIsInitialized);
            gxtDebug.Assert(material != null);

            this.material = material;
            vertices = new VertexPositionColorTexture[2];
            Color overlay = (material != null) ? material.ColorOverlay : gxtMaterial.DEFAULT_COLOR_OVERLAY;
            vertices[0] = new VertexPositionColorTexture(new Vector3(start.X, start.Y, 0.0f), overlay, Vector2.Zero);
            vertices[1] = new VertexPositionColorTexture(new Vector3(end.X, end.Y, 0.0f), overlay, Vector2.One);
            vertexBuffer = new VertexBuffer(gxtRoot.Singleton.Graphics, typeof(VertexPositionColorTexture), 2, BufferUsage.WriteOnly);
            vertexBuffer.SetData<VertexPositionColorTexture>(vertices);

            indices = new int[] { 0, 1 };
            indexBuffer = new IndexBuffer(gxtRoot.Singleton.Graphics, typeof(int), 2, BufferUsage.WriteOnly);
            indexBuffer.SetData<int>(indices);
        }
        public static void DrawFov(AtlasGlobal atlas, Entity e)
        {
            VertexPositionColorTexture[] vpct = new VertexPositionColorTexture[4];

            vpct[0].Color = vpct[2].Color = Color.Blue;
            vpct[0].Position = vpct[2].Position = new Vector3(e.Position, 0);

            vpct[1].Position = new Vector3(
                e.Position.X + (float)Math.Cos(e.Angle + e.FOV * 0.5f) * 64,
                e.Position.Y + (float)Math.Sin(e.Angle + e.FOV * 0.5f) * 64, 0);
            vpct[3].Position = new Vector3(
                e.Position.X + (float)Math.Cos(e.Angle - e.FOV * 0.5f) * 64,
                e.Position.Y + (float)Math.Sin(e.Angle - e.FOV * 0.5f) * 64, 0);

            atlas.Graphics.SetPrimitiveType(PrimitiveType.LineList);
            atlas.Graphics.DrawVector(vpct);
        }
        public static void DrawPath(AtlasGlobal atlas, List<Vector2> path)
        {
            if (path == null || path.Count == 2)
            {
                return;
            }

            VertexPositionColorTexture[] vpct = new VertexPositionColorTexture[path.Count];

            for (int i = 0; i < path.Count; i++)
            {
                vpct[i].Position = new Vector3(path[i], 0);
                vpct[i].Color = AtlasColorSystem.RGBFromHSL(i * 16, 0.2f, 0.2f) * 0.5f;
            }

            atlas.Graphics.SetPrimitiveType(PrimitiveType.LineStrip);
            atlas.Graphics.DrawVector(vpct);
        }
        //Dictionary
        //Key - Circle, radius, angle
        //private static Dictionary<string, VertexPositionColor[]> dictionary;
        public static VertexPositionColorTexture[] GetTextureQuadVertices()
        {
            float halfLength = 0.5f;

            Vector3 topLeft = new Vector3(-halfLength, halfLength, 0);
            Vector3 topRight = new Vector3(halfLength, halfLength, 0);
            Vector3 bottomLeft = new Vector3(-halfLength, -halfLength, 0);
            Vector3 bottomRight = new Vector3(halfLength, -halfLength, 0);

            //quad coplanar with the XY-plane (i.e. forward facing normal along UnitZ)
            VertexPositionColorTexture[] vertices = new VertexPositionColorTexture[4];
            vertices[0] = new VertexPositionColorTexture(topLeft, Color.White, Vector2.Zero);
            vertices[1] = new VertexPositionColorTexture(topRight, Color.White, Vector2.UnitX);
            vertices[2] = new VertexPositionColorTexture(bottomLeft, Color.White, Vector2.UnitY);
            vertices[3] = new VertexPositionColorTexture(bottomRight, Color.White, Vector2.One);

            return vertices;
        }
Esempio n. 31
0
        public gxtRectangle(float width, float height)
        {
            gxtDebug.Assert(width >= 0.0f && height >= 0.0f);
            gxtDebug.Assert(gxtRoot.SingletonIsInitialized);
            this.size = new Vector2(width, height);
            float rX = width * 0.5f, rY = height * 0.5f;

            vertices = new VertexPositionColorTexture[4];
            vertices[0] = new VertexPositionColorTexture(new Vector3(-rX, -rY, 0.0f), gxtMaterial.DEFAULT_COLOR_OVERLAY, Vector2.Zero);
            vertices[1] = new VertexPositionColorTexture(new Vector3(-rX, rY, 0.0f), gxtMaterial.DEFAULT_COLOR_OVERLAY, Vector2.UnitY);
            vertices[2] = new VertexPositionColorTexture(new Vector3(rX, rY, 0.0f), gxtMaterial.DEFAULT_COLOR_OVERLAY, Vector2.One);
            vertices[3] = new VertexPositionColorTexture(new Vector3(rX, -rY, 0.0f), gxtMaterial.DEFAULT_COLOR_OVERLAY, Vector2.UnitX);
            vertexBuffer = new VertexBuffer(gxtRoot.Singleton.Graphics, typeof(VertexPositionColorTexture), 4, BufferUsage.WriteOnly);
            vertexBuffer.SetData<VertexPositionColorTexture>(vertices);

            indices = new int[] { 0, 1, 2, 0, 2, 3 };
            indexBuffer = new IndexBuffer(gxtRoot.Singleton.Graphics, typeof(int), 6, BufferUsage.WriteOnly);
            indexBuffer.SetData<int>(indices);
        }
Esempio n. 32
0
 public void GenLines()
 {
     lines[0] = new VertexPositionColorTexture(new Vector3(3, 3, 0), Color.White, new Vector2());
     lines[1] = new VertexPositionColorTexture(new Vector3(size.X, 3, 0), Color.White, new Vector2());
     lines[2] = lines[1];
     lines[3] = new VertexPositionColorTexture(new Vector3(size.X, 185 * Main.WindowHeight / 1080, 0),
         Color.White, new Vector2());
     lines[4] = lines[3];
     lines[5] = new VertexPositionColorTexture(new Vector3(3, 185 * Main.WindowHeight / 1080, 0),
         Color.White, new Vector2());
     lines[6] = lines[5];
     lines[7] = lines[0];
     lines[8] = lines[5];
     lines[9] = new VertexPositionColorTexture(new Vector3(3, size.Y, 0), Color.White, new Vector2());
     lines[10] = new VertexPositionColorTexture(new Vector3(0, 92 * Main.WindowHeight / 1080, 0),
         Color.White, new Vector2());
     lines[11] = new VertexPositionColorTexture(new Vector3(3, 92 * Main.WindowHeight / 1080, 0),
         Color.White, new Vector2());
 }
        public static VertexPositionColorTexture[] GetVerts(this ModelMeshPart Part)
        {
            MeshDataContainer data = Part.GetPartData();

            if (data == null)
            {
                return(null);
            }
            if (data.Vertices == null)
            {
                VertexBuffer vb = Part.VertexBuffer;
                VertexPositionColorTexture[] verts = new VertexPositionColorTexture[Part.NumVertices];
                byte[] vb_verts = vb.Tag as byte[];
                if (vb_verts == null)
                {
                    vb_verts = new byte[vb.VertexCount * vb.VertexDeclaration.VertexStride];
                    vb.GetData <byte>(vb_verts);
                    vb.Tag = vb_verts;
                }
                int offset     = Part.VertexOffset;
                int vertStride = vb.VertexDeclaration.VertexStride;
                var elements   = vb.VertexDeclaration.GetVertexElements();
                for (int v = 0; v < verts.Length; ++v)
                {
                    verts[v].Color = Color.White;
                }
                foreach (var element in elements)
                {
                    switch (element.VertexElementUsage)
                    {
                    case VertexElementUsage.Position: {
                        for (int v = 0; v < verts.Length; ++v)
                        {
                            verts[v].Position = vb_verts.ToVector3((v + offset) * vertStride + element.Offset);
                        }
                    } break;

                    /*case VertexElementUsage.Normal: {
                     *  for (int v = 0; v < verts.Length; ++v) {
                     *      verts[v].Normal = vb_verts.ToVector3((v + offset) * vertStride + element.Offset);
                     *  }
                     * } break;*/
                    case VertexElementUsage.TextureCoordinate: {
                        for (int v = 0; v < verts.Length; ++v)
                        {
                            verts[v].TextureCoordinate = vb_verts.ToVector2((v + offset) * vertStride + element.Offset);
                        }
                    } break;

                    case VertexElementUsage.Color: {
                        for (int v = 0; v < verts.Length; ++v)
                        {
                            verts[v].Color = vb_verts.ToColor((v + offset) * vertStride + element.Offset);
                        }
                    } break;
                    }
                }

                /*for (int v = 0; v < verts.Length; ++v) {
                 *  verts[v].Position = vb_verts[v + offset].Position;
                 *  verts[v].TextureCoordinate = vb_verts[v + offset].TextureCoordinate;
                 *  verts[v].Normal = vb_verts[v + offset].Normal;
                 *  verts[v].Color = Color.White;
                 * }*/
                data.Vertices = verts;
            }
            return(data.Vertices);
        }