Beispiel #1
0
        /// <summary>
        /// Given a scene, render all the objects in the scene.
        /// </summary>
        /// <param name="scene">Scene to be rendered</param>
        /// <param name="camera">Camera object</param>
        public void Draw(Scene scene, GameObject camera)
        {
            List<GameObject> objects = scene.Visible();

            game.GraphicsDevice.Clear(Color.Black);

            Matrix worldMatrix = Matrix.Identity;
            Matrix cameraMatrix = camera.position.matrix();
            Matrix objectMatrix;

            foreach (GameObject obj in objects)
            {
                objectMatrix = worldMatrix * obj.position.matrix();
                RenderObject(obj, cameraMatrix, objectMatrix);
            }
        }
Beispiel #2
0
        protected override void LoadContent()
        {
            scene = new Scene();

            arrow = new GameObject();
            arrow.model = contentManager.Load<Model>("Models/Arrow");
            arrow.position = new Coords(0, 0, -50);

            scene.Add(arrow);

            camera = new GameObject();
            camera.position = new Coords(0, 0, 0);

            audio.MusicTrack("AdaptiveTest");

            base.LoadContent();
        }
Beispiel #3
0
        /// <summary>
        /// Render an individual game object
        /// </summary>
        /// <param name="obj">Game object to be rendered</param>
        /// <param name="cameraMatrix">Camera view matrix</param>
        /// <param name="objectMatrix">Object position matrix</param>
        public void RenderObject(GameObject obj, Matrix cameraMatrix, Matrix objectMatrix)
        {
            Model model = obj.model;
            Matrix modelMatrix = Matrix.CreateScale(obj.scale) * objectMatrix;
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.World = transforms[mesh.ParentBone.Index] * modelMatrix;
                    effect.View = cameraMatrix;
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(fov, aspect, 1f, 1000f);
                    effect.EnableDefaultLighting();

                    mesh.Draw();
                }
            }
        }