public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content) { base.LoadContent(content); map = new Map(Device, "startPosTest.txt"); // map = new Map(); BlockData.Initialize(Device, content); primBatch = new PrimitiveBatch(Device); MeshBuilder mb = new MeshBuilder(Device); mb.Begin(); //mb.AddCylinder(1, 1, 50); mb.AddSphere(1, 20, 20); testMesh = mb.End(); mNode = new MeshNode(testMesh); mNode.SetPivot(new Vector3(0, -1f, 0)); mNode.SetScl(new Vector3(1, 5, 1)); MeshNode child = new MeshNode(testMesh); child.SetPos(new Vector3(0, 2, 0)); MeshNode another = new MeshNode(testMesh); another.SetPos(new Vector3(0, 2, 0)); //Mesh sphere = mb.CreateSphere(0.1f, 10, 10); //startMarker = new MeshNode(sphere); //startMarker.SetPos(map.StartPos); //child.AddChild(another); //mNode.AddChild(child); }
//A scenegraph is composed of SceneNodes public override void LoadContent(ContentManager content, GraphicsDevice g) { base.LoadContent(content, g); //Set up our camera and primitive renderer cam = new FirstPersonCamera(0.5f, 5f); //0.5f is the turn speed for the camera, and 5f is the translational speed cam.Pos = new Vector3(3, 3, 13); //Move our camera to the point (3, 3, 13) primBatch = new PrimitiveBatch(g); //Initialize our PrimitiveBatch //Define the objects in our scene Mesh sphere, cylinder, box; //Define the meshes we will use for the robot arm //A mesh holds a list of vertices, and a list of indices which represent triangles MeshNode arm, elbow, forearm, wrist, hand; //Define all the parts of the robot arm we will use MeshBuilder mb = new MeshBuilder(g); //MeshBuilder is a helper class for generating 3D geometry //It has some built in functions to create primitives, as well as //functions to create your own arbitrary meshes //Genererate our geometry //All geometry created is centered around the origin in its local coordinate system sphere = mb.CreateSphere(0.5f, 15, 15); //Create a sphere mesh, with radius 0.5 and with 15 subdivisions cylinder = mb.CreateCylinder(0.3f, 2.0f, 15); //Create a cylinder with radius 0.3, a height of 2, and 15 subdivisions box = mb.CreateBox(0.8f, 1.4f, 0.1f); //Create a box with width 0.8, height of 1.4, and depth of 0.1 shoulder = new MeshNode(sphere); //Assign the sphere mesh to our shoulder node arm = new MeshNode(cylinder); //Assign the cylinder mesh to our arm node arm.SetPos(new Vector3(0, -1, 0)); //Translate the arm down 1 on the y axis elbow = new MeshNode(sphere); //Assign a sphere to our elbow node elbow.SetPos(new Vector3(0, -2, 0)); //Translate the elbow down 2 on the y axis forearm = new MeshNode(cylinder); //Assign a cylinder to our forearm node forearm.SetPos(new Vector3(0, -1, 0)); //Translate the forearm down 1 on the y axis wrist = new MeshNode(sphere); //Assign a sphere for the wrist node wrist.SetPos(new Vector3(0, -2, 0)); //Translate the wrist down 2 on the y axis hand = new MeshNode(box); //Assign the box to the hand node hand.SetPos(new Vector3(0, -0.7f, 0)); //Translate the hand down 0.7 (half the height of the box) on the y axis shoulder.AddChild(arm); //The shoulder is the root of this scene, in our case. It is the parent shoulder.AddChild(elbow); //of both the arm and the elbow elbow.AddChild(forearm); //The elbow is the parent of the forearm and wrist elbow.AddChild(wrist); wrist.AddChild(hand); //The wrist is the parent of the hand shoulder.SetPos(new Vector3(0, 5, 0)); //This call effectively translates the entire arm up 5 on the y axis }
public override void LoadContent(ContentManager content, GraphicsDevice g) { base.LoadContent(content, g); //Set up our camera and primitive renderer cam = new ThirdPersonCamera(targetPos, 5.0f, 0.2f); primBatch = new PrimitiveBatch(g); //Initialize our PrimitiveBatch MeshBuilder mb = new MeshBuilder(g); Mesh triangle;// = mb.CreateSphere(0.3f, 15, 15); mb.Begin(); // mb.AddTriangle(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(1, 0, 0), true); // mb.AddTriangle(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(1, 0, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(0, 1), true); mb.AddQuad(Vector3.Zero, new Vector3(1, 1, 0), new Vector3(2, 1, 0), new Vector3(1, 0, 0), true, new Vector2(0, 0), new Vector2(1, 1), new Vector2(2, 1), new Vector2(1, 0)); triangle = mb.End(); triangle.Texture = content.Load<Texture2D>("Cube"); target = new MeshNode(triangle); target.SetPos(targetPos); }
public override void LoadContent(ContentManager content, GraphicsDevice g) { base.LoadContent(content, g); primBatch = new PrimitiveBatch(Device); cam = new FirstPersonCamera(0.5f, 10); cam.Pos = new Vector3(3, 3, 13); MeshBuilder mb = new MeshBuilder(Device); mb.Begin(); mb.AddSphere(radius, 20, 20); Mesh sphereMesh = mb.End(); sphere = new MeshNode(sphereMesh); sphere.SetPos(new Vector3(5, 5, 5)); planes = new List<Plane>(); planes.Add(new Plane(Vector3.Right, 0)); planes.Add(new Plane(Vector3.Up, 0)); planes.Add(new Plane(new Vector3(0, 0, 1), 0)); planes.Add(new Plane(Vector3.Left, -10)); planes.Add(new Plane(Vector3.Down, -10)); planes.Add(new Plane(new Vector3(0, 0, -1), -10)); }
public override void LoadContent(ContentManager content, GraphicsDevice g) { base.LoadContent(content, g); primBatch = new PrimitiveBatch(Device); cam = new FirstPersonCamera(0.5f, 10); //cam.Pos = new Vector3(3, 3, 13); Model bodyModel = content.Load<Model>("Models/Body"); Model handleModel = content.Load<Model>("Models/Handle"); Model triggerModel = content.Load<Model>("Models/Trigger"); crosshair = content.Load<Texture2D>("Crosshair"); fire = content.Load<SoundEffect>("fire_silenced"); batch = new SpriteBatch(Device); Mesh bodyMesh = new Mesh(); bodyMesh.Indices = bodyModel.Meshes[0].MeshParts[0].IndexBuffer; bodyMesh.Vertices = bodyModel.Meshes[0].MeshParts[0].VertexBuffer; body = new MeshNode(bodyMesh); Mesh handleMesh = new Mesh(); handleMesh.Indices = handleModel.Meshes[0].MeshParts[0].IndexBuffer; handleMesh.Vertices = handleModel.Meshes[0].MeshParts[0].VertexBuffer; handle = new MeshNode(handleMesh); handle.SetPos(new Vector3(0, 0.13f, 0.477f)); Mesh triggerMesh = new Mesh(); triggerMesh.Indices = triggerModel.Meshes[0].MeshParts[0].IndexBuffer; triggerMesh.Vertices = triggerModel.Meshes[0].MeshParts[0].VertexBuffer; trigger = new MeshNode(triggerMesh); trigger.SetPos(new Vector3(0, 0.033f, -1.561f)); body.AddChild(handle); body.AddChild(trigger); body.SetPos(new Vector3(0, 5, 0)); pickableObjects = new List<MeshNode>(); pickableObjects.Add(body); pickableObjects.Add(handle); pickableObjects.Add(trigger); //Extract triangles bodyTris = GetTriangles(bodyMesh); handleTris = GetTriangles(handleMesh); triggerTris = GetTriangles(triggerMesh); }