//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 }