Пример #1
0
        private void DrawMesh(Mesh mesh, Texture2D texture)
        {
            //glTranslatef(Character.Translation.x, Character.Translation.y, zoom + Character.Translation.z);
            //glRotatef(Character.Rotation.x, 1.0f, 0.0f, 0.0f);
            //glRotatef(Character.Rotation.y, 0.0f, 1.0f, 0.0f);
            //glRotatef(Character.Rotation.z, 0.0f, 0.0f, 1.0f);

            var device = GraphicsDevice;

            device.VertexDeclaration = new VertexDeclaration(GraphicsDevice, MeshVertex.VertexElements);
            device.RenderState.CullMode = CullMode.None;

            var effect = new BasicEffect(GraphicsDevice, null);
            effect.Texture = texture;
            effect.TextureEnabled = true;
            effect.VertexColorEnabled = false;
            effect.World = World;
            effect.View = View;
            effect.Projection = Projection;
            effect.CommitChanges();

            effect.Begin();
            foreach (var pass in effect.Techniques[0].Passes)
            {
                pass.Begin();

                foreach (var face in mesh.FaceData)
                {
                    var vertexA = mesh.TransformedVertex[face.VertexA];
                    var vertexB = mesh.TransformedVertex[face.VertexB];
                    var vertexC = mesh.TransformedVertex[face.VertexC];

                    var vertexList = new MeshVertex[3] { vertexA.Vertex, vertexB.Vertex, vertexC.Vertex };
                    device.DrawUserPrimitives(PrimitiveType.TriangleList, vertexList, 0, 1);
                }

                //device.DrawUserPrimitives(PrimitiveType.TriangleList, mesh.TransformedVertexData, 0, mesh.TransformedVertexData.Length / 3);
                pass.End();
            }
            effect.End();
        }
Пример #2
0
        private void DrawBones(Skelenton skel)
        {
            var device = GraphicsDevice;

            device.RenderState.PointSize = 10.0f;
            device.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);
            device.RenderState.CullMode = CullMode.None;

            var effect = new BasicEffect(GraphicsDevice, null);

            //effect.Texture = TextureUtils.TextureFromColor(device, color);
            //effect.TextureEnabled = true;

            effect.World = World;
            effect.View = View;
            effect.Projection = Projection;
            effect.VertexColorEnabled = true;
            effect.EnableDefaultLighting();

            effect.CommitChanges();
            effect.Begin();
            foreach (var pass in effect.Techniques[0].Passes)
            {
                pass.Begin();

                foreach(var bone in skel.Bones){
                    var color = Color.Green;

                    if (bone.Name == "ROOT")
                    {
                        color = Color.Red;
                    }
                    else if (bone.Name == "HEAD")
                    {
                        color = Color.Yellow;
                    }

                    var vertex = new VertexPositionColor(bone.AbsolutePosition, color);
                    var vertexList = new VertexPositionColor[1]{vertex};
                    device.DrawUserPrimitives(PrimitiveType.PointList, vertexList, 0, 1);
                }
                pass.End();
            }
            effect.End();
        }
Пример #3
0
        public static void Draw(this Utilities.GridTransform transform, GraphicsDevice graphicsDevice, BasicEffect basicEffect)
        {
            VertexPositionColor[] ctrlVerticies = new VertexPositionColor[transform.mapPoints.Length];
            VertexPositionColor[] mapVerticies = new VertexPositionColor[transform.mapPoints.Length];

            List<int> listIndicies = new List<int>(transform.Edges.Count / 2);
            foreach(int iStartPoint in transform.Edges.Keys)
            {
                List<int> edgeList = transform.Edges[iStartPoint];

                foreach (int iEndPoint in edgeList)
                {
                    //Skip if we would have added it earlier
                    if (iEndPoint < iStartPoint)
                        continue;

                    listIndicies.AddRange(new int[] { iStartPoint, iEndPoint});
                }
            }

            int[] indicies = listIndicies.ToArray();

            for (int i = 0; i < transform.mapPoints.Length; i++)
            {
                GridVector2 CtrlP = transform.mapPoints[i].ControlPoint;
                GridVector2 MapP = transform.mapPoints[i].MappedPoint;
                Vector3 ctrlPosition = new Vector3((Single)CtrlP.X, (Single)CtrlP.Y, 1);
                Vector3 mapPosition = new Vector3((Single)MapP.X, (Single)MapP.Y, 1);

                ctrlVerticies[i] = new VertexPositionColor(ctrlPosition, Microsoft.Xna.Framework.Graphics.Color.Gold);
                mapVerticies[i] = new VertexPositionColor(mapPosition, Microsoft.Xna.Framework.Graphics.Color.Red);
            }

            graphicsDevice.RenderState.PointSize = 5.0f;

            VertexDeclaration oldVertexDeclaration = graphicsDevice.VertexDeclaration;

            if (DrawExtensions.VertexPositionColorDeclaration == null)
            {
                DrawExtensions.VertexPositionColorDeclaration = new VertexDeclaration(
                    graphicsDevice,
                    VertexPositionColor.VertexElements
                    );
            }

            graphicsDevice.VertexDeclaration = DrawExtensions.VertexPositionColorDeclaration;

            basicEffect.Texture = null;
            basicEffect.TextureEnabled = false;
            basicEffect.VertexColorEnabled = true;
            basicEffect.CommitChanges();

            basicEffect.Begin();

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

            //        graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, mapVerticies, 0, mapVerticies.Length, indicies, 0, indicies.Length / 2);
                if(ctrlVerticies != null && ctrlVerticies.Length > 0)
                    graphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineList, ctrlVerticies, 0, ctrlVerticies.Length, indicies, 0, indicies.Length / 2);

                pass.End();
            }

            basicEffect.End();

            graphicsDevice.VertexDeclaration = oldVertexDeclaration;
        }
Пример #4
0
        public void Draw(GraphicsDevice device)
        {
            device.RenderState.PointSize = 30.0f;
            device.VertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
            //device.RenderState.CullMode = CullMode.None;

            var effect = new BasicEffect(device, null);

            //effect.Texture = TextureUtils.TextureFromColor(device, color);
            //effect.TextureEnabled = true;

            effect.World = Matrix.Identity;
            effect.View = View;
            effect.Projection = Projection;
            effect.VertexColorEnabled = true;
            //effect.EnableDefaultLighting();

            effect.CommitChanges();
            effect.Begin();
            foreach (var pass in effect.Techniques[0].Passes)
            {
                pass.Begin();

                var vertex = new VertexPositionColor(Position, Color.Green);
                var vertexList = new VertexPositionColor[1] { vertex };
                device.DrawUserPrimitives(PrimitiveType.PointList, vertexList, 0, 1);

                vertex.Color = Color.Red;
                vertex.Position = Target;
                device.DrawUserPrimitives(PrimitiveType.PointList, vertexList, 0, 1);

                pass.End();
            }
            effect.End();
        }
Пример #5
0
        private void RenderSpriteList(List<_3DSprite> sprites, BasicEffect effect, EffectTechnique technique)
        {
            ApplyCamera(effect);
            effect.TextureEnabled = true;

            var byTexture = sprites.GroupBy(x => x.Texture);
            foreach (var group in byTexture){
                effect.Texture = group.Key;
                effect.CommitChanges();

                effect.Begin();
                foreach (var pass in technique.Passes)
                {
                    pass.Begin();
                    foreach (var geom in group){
                        effect.World = geom.World;
                        effect.CommitChanges();

                        geom.Geometry.DrawGeometry(this.Device);
                    }
                    pass.End();
                }
                effect.End();
            }
        }