/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.Pi / 4.0f, GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height, 1.0f, 2000.0f); View = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up); World = Matrix.Identity; Head = new Mesh(); Head.Read(File.ReadAllBytes("head.mesh")); Body = new Mesh(); Body.Read(File.ReadAllBytes("body.mesh")); HeadTexture = Texture2D.FromFile(GraphicsDevice, "head.jpg"); BodyTexture = Texture2D.FromFile(GraphicsDevice, "body.jpg"); RightHand = new Mesh(); RightHand.Read(File.ReadAllBytes("rhand.mesh")); LeftHand = new Mesh(); LeftHand.Read(File.ReadAllBytes("lhand.mesh")); RightHandTexture = Texture2D.FromFile(GraphicsDevice, "hand.jpg"); LeftHandTexture = Texture2D.FromFile(GraphicsDevice, "hand.jpg"); Skelenton = new Skelenton(); Skelenton.Read(File.ReadAllBytes("skeleton.skel")); }
private void DrawBones(Skelenton skel) { var device = GraphicsDevice; device.RenderState.PointSize = 10.0f; device.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements); device.RenderState.CullMode = CullMode.None; var effect = new BasicEffect(GraphicsDevice, null); //effect.Texture = TextureUtils.TextureFromColor(device, color); //effect.TextureEnabled = true; effect.World = World; effect.View = View; effect.Projection = Projection; effect.VertexColorEnabled = true; effect.EnableDefaultLighting(); effect.CommitChanges(); effect.Begin(); foreach (var pass in effect.Techniques[0].Passes) { pass.Begin(); foreach (var bone in skel.Bones) { var color = Color.Green; if (bone.Name == "ROOT") { color = Color.Red; } else if (bone.Name == "HEAD") { color = Color.Yellow; } var vertex = new VertexPositionColor(bone.AbsolutePosition, color); var vertexList = new VertexPositionColor[1] { vertex }; device.DrawUserPrimitives(PrimitiveType.PointList, vertexList, 0, 1); } pass.End(); } effect.End(); }
private void 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(); }