Esempio n. 1
0
        public void Draw(camera cam, directionalLightSource light)
        {
            transforms = new Matrix[objectModel.Bones.Count];
            objectModel.CopyAbsoluteBoneTransformsTo(transforms);
            int i = 0;

            foreach (ModelMesh mesh in objectModel.Meshes)               // loop through the mesh in the 3d model, drawing each one in turn.
            {
                i++;
                foreach (BasicEffect effect in mesh.Effects)                // This loop then goes through every effect in each mesh.
                {
                    // The following effects allow the object to be drawn in the correct place, with the correct rotation and scale.
                    effect.World  = transforms[mesh.ParentBone.Index];      // begin dealing with transforms to render the object into the game world
                    effect.World *= Matrix.CreateScale(scale);              // scale the mesh to the right size
                    effect.World *= Matrix.CreateRotationX(rotation.X);     // rotate the mesh
                    effect.World *= Matrix.CreateRotationY(rotation.Y);     // rotate the mesh
                    effect.World *= Matrix.CreateRotationZ(rotation.Z);     // rotate the mesh
                    effect.World *= Matrix.CreateTranslation(position);     // position the mesh in the game world

                    // This sets the FOV (Field of View) of the camera. The first parameter is the angle for the FOV, the 2nd is the aspect ratio of your game,
                    // the 3rd is the nearplane distance from the camera and the last paramter is the farplane distance from the camera.
                    effect.Projection = cam.FOVMatrix();

                    // This effect sets the View Matrix, which determines how the camera sees the object.
                    effect.View = cam.LookMatrix();                        // Set the position of the camera and tell it what to look at

                    // the following effects are related to lighting and texture settings, feel free to tweak them to see what happens.
                    effect.LightingEnabled = true;
                    //effect.EnableDefaultLighting();                               // default lighting is 'easymode' lighting, looks nice but isnt custom configured.
                    //effect.Alpha = 50.0f;                                          // amount of transparency
                    effect.AmbientLightColor               = new Vector3(0.25f);    // fills in dark areas with a small amount of light
                    effect.DiffuseColor                    = new Vector3(0.1f);     // Diffuse is the standard colour method
                    effect.DirectionalLight0.Enabled       = true;                  // allows a directional light
                    effect.DirectionalLight0.DiffuseColor  = light.diffuseColor;    // the directional light's main colour
                    effect.DirectionalLight0.SpecularColor = light.specularColor;   // the directional light's colour used for highlights
                    effect.DirectionalLight0.Direction     = light.direction;       // the direction of the light
                    effect.EmissiveColor                   = new Vector3(0.15f);
                    //effect.FogColor = Vector3.Zero;
                    //effect.FogEnabled = false;
                    //effect.PreferPerPixelLighting = true;                         // Makes it shiner and reflects light better
                    //effect.SpecularColor = Vector3.One;
                    //effect.SpecularPower = 200.0f;
                    //effect.Texture = null;
                    //effect.TextureEnabled = true;
                }

                mesh.Draw(); // draw the current mesh using the effects.
            }
        }
Esempio n. 2
0
        public void Draw(camera cam, directionalLightSource light)
        {
            transforms = new Matrix[objectModel.Bones.Count];
            objectModel.CopyAbsoluteBoneTransformsTo(transforms);
            int i = 0;
            foreach (ModelMesh mesh in objectModel.Meshes)               // loop through the mesh in the 3d model, drawing each one in turn.
            {
                i++;
                foreach (BasicEffect effect in mesh.Effects)                // This loop then goes through every effect in each mesh.
                {
                    // The following effects allow the object to be drawn in the correct place, with the correct rotation and scale.
                    effect.World = transforms[mesh.ParentBone.Index];       // begin dealing with transforms to render the object into the game world
                    effect.World *= Matrix.CreateScale(scale);              // scale the mesh to the right size
                    effect.World *= Matrix.CreateRotationX(rotation.X);     // rotate the mesh
                    effect.World *= Matrix.CreateRotationY(rotation.Y);     // rotate the mesh
                    effect.World *= Matrix.CreateRotationZ(rotation.Z);     // rotate the mesh
                    effect.World *= Matrix.CreateTranslation(position);     // position the mesh in the game world
                    
                    // This sets the FOV (Field of View) of the camera. The first parameter is the angle for the FOV, the 2nd is the aspect ratio of your game, 
                    // the 3rd is the nearplane distance from the camera and the last paramter is the farplane distance from the camera.
                    effect.Projection = cam.FOVMatrix();

                    // This effect sets the View Matrix, which determines how the camera sees the object.
                    effect.View = cam.LookMatrix();                        // Set the position of the camera and tell it what to look at

                    // the following effects are related to lighting and texture settings, feel free to tweak them to see what happens.
                    effect.LightingEnabled = true;
                    //effect.EnableDefaultLighting();                               // default lighting is 'easymode' lighting, looks nice but isnt custom configured.
                    //effect.Alpha = 50.0f;                                          // amount of transparency
                    effect.AmbientLightColor = new Vector3(0.25f);                  // fills in dark areas with a small amount of light
                    effect.DiffuseColor = new Vector3(0.1f);                            // Diffuse is the standard colour method
                    effect.DirectionalLight0.Enabled = true;                        // allows a directional light
                    effect.DirectionalLight0.DiffuseColor = light.diffuseColor;     // the directional light's main colour
                    effect.DirectionalLight0.SpecularColor = light.specularColor;   // the directional light's colour used for highlights
                    effect.DirectionalLight0.Direction = light.direction;           // the direction of the light
                    effect.EmissiveColor = new Vector3(0.15f);
                    //effect.FogColor = Vector3.Zero;
                    //effect.FogEnabled = false;
                    //effect.PreferPerPixelLighting = true;                         // Makes it shiner and reflects light better
                    //effect.SpecularColor = Vector3.One;
                    //effect.SpecularPower = 200.0f;
                    //effect.Texture = null;
                    //effect.TextureEnabled = true;
                }

                mesh.Draw(); // draw the current mesh using the effects.
            }
        }