Exemplo n.º 1
0
        //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
        }
Exemplo n.º 2
0
        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);
        }