public void Draw(camera3d cam, directionalLightSource light) { if (!visible) { return; // dont render hidden meshes } foreach (ModelMesh mesh in mesh.Meshes) // loop through the mesh in the 3d model, drawing each one in turn. { foreach (BasicEffect effect in mesh.Effects) // This loop then goes through every effect in each mesh. { effect.World = transforms[mesh.ParentBone.Index]; // begin dealing with transforms to render the object into the game world // The following effects allow the object to be drawn in the correct place, with the correct rotation and scale. /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 1 SHOULD BE ENTERED HERE // /////////////////////////////////////////////////////////////////// // the following effects are related to lighting and texture settings, feel free to tweak them to see what happens. effect.LightingEnabled = true; effect.Alpha = Alpha; // 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); } mesh.Draw(); // draw the current mesh using the effects. } }
public void Draw(camera3d cam, directionalLightSource light) { if (!visible) { return; // dont render hidden meshes } foreach (ModelMesh mesh in mesh.Meshes) // loop through the mesh in the 3d model, drawing each one in turn. { foreach (BasicEffect effect in mesh.Effects) // This loop then goes through every effect in each mesh. { effect.World = transforms[mesh.ParentBone.Index]; // begin dealing with transforms to render the object into the game world // The following effects allow the object to be drawn in the correct place, with the correct rotation and scale. /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 1 SHOULD BE ENTERED HERE // /////////////////////////////////////////////////////////////////// /// // world matrix // 1. Scale effect.World *= Matrix.CreateScale(scale); // 2. Rotation effect.World *= Matrix.CreateRotationX(rotation.X); effect.World *= Matrix.CreateRotationY(rotation.Y); effect.World *= Matrix.CreateRotationZ(rotation.Z); // 3. Translation/position effect.World *= Matrix.CreateTranslation(position); // view matrix effect.View = Matrix.CreateLookAt(cam.position, cam.target, Vector3.Up); // projection matrix effect.Projection = Matrix.CreatePerspectiveFieldOfView(cam.fieldOfView, cam.aspectRatio, cam.nearPlane, cam.farPlane); //effect.Projection = Matrix.CreateOrthographic(1600, 900, 1f, 10000f); // the following effects are related to lighting and texture settings, feel free to tweak them to see what happens. effect.LightingEnabled = true; effect.Alpha = Alpha; // 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); } mesh.Draw(); // draw the current mesh using the effects. } }
public void Draw(camera3d cam, directionalLightSource light) { if (!visible) { return; // dont render hidden meshes } foreach (ModelMesh mesh in mesh.Meshes) // loop through the mesh in the 3d model, drawing each one in turn. { foreach (BasicEffect effect in mesh.Effects) // This loop then goes through every effect in each mesh. { effect.World = transforms[mesh.ParentBone.Index]; // begin dealing with transforms to render the object into the game world // The following effects allow the object to be drawn in the correct place, with the correct rotation and scale. /////////////////////////////////////////////////////////////////// // // CODE FOR TASK 1 HAS BEEN ENTERED HERE // /////////////////////////////////////////////////////////////////// /// ----------------------------------------- /// WORLD MATRIX /// ----------------------------------------- //Transform from model space to world space in order - scale, rotation, translation. //1. Scale //Scale our model by multiplying the world matrix by a scale matrix //XNA does this for us using CreateScale effect.World *= Matrix.CreateScale(scale); //2. Rotation //Rotate our model in the game world effect.World *= Matrix.CreateRotationX(rotation.X); //Rotate around the X axis effect.World *= Matrix.CreateRotationY(rotation.Y); //Rotate around the Y axis effect.World *= Matrix.CreateRotationZ(rotation.Z); //Rotate around the Z axis //3. Translation / position //Move our model to the correct place in the game world effect.World *= Matrix.CreateTranslation(position); /// ----------------------------------------- /// VIEW MATRIX /// ----------------------------------------- //This puts the model in relation to where our cam is, and the direction of our cam effect.View = Matrix.CreateLookAt(cam.position, cam.target, Vector3.Up); /// ----------------------------------------- /// PROJECTION MATRIX /// ----------------------------------------- //Projection changes from view space (3D) to screen space (2D) //Can be either orthographic or perspective effect.Projection = Matrix.CreatePerspectiveFieldOfView(cam.fieldOfView, cam.aspectRatio, cam.nearPlane, cam.farPlane); //Orthographic //effect.Projection = Matrix.CreateOrthographic(1600, 900, 1f, 10000f); // the following effects are related to lighting and texture settings, feel free to tweak them to see what happens. effect.LightingEnabled = true; effect.Alpha = Alpha; // 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); } mesh.Draw(); // draw the current mesh using the effects. } }