XNA--camera, lights and effects

      XNA makes it simple to deal with a camera, lights, and special effects, but you do need to know the basics about these to create even a simple 3D game. After all, without a camera and lights, how can you see what was constructed in your 3D scene.

      XNA’s BasicEffect class fulfills all your needs for not only basic games, but also for some complex games. This class offers properties and methods that let youdefine the final details to render your 3D scene. The following are some of the most important properties of this class:

              • View: The view matrix, which defines the camera position and direction. Usually created using Matrix.CreateLookAt.
              • Projection: The projection matrix that’s used tomap the 3D scene coordinates to screen coordinates. Usually created throughMatrix.CreatePerspective, Matrix.CreateOrthographic, or a similar method.
              • World: The world matrix, which is used to apply transformations to all objects in the 3D scene.
              • LightingEnabled: If False, the scene is rendered using a base light that illuminates all sides of all objects equally. If True, the light properties of BasicEffect will be used to light the scene.
              • AmbientLightColor: Defines the color of the ambient light, which illuminates all sides of all objects equally. It’s used only when rendering if LightingEnabled is set to True.

              • DirectionalLight0, DirectionalLight1, and DirectionalLight2: Define up to three directional lights used by the effect when rendering. Each directional light is defined by its specular color (color of the light that will have a perfect, mirror-like reflection), its diffuse color (color of the light that will be reflected diffusely), and the light direction. These properties are used only if LightingEnabled is set to True.
               • FogColor, FogStart, and FogEnd: Let you define “fog” for the scene, so objects in the fog range appear to be seen through a dense smoke. You can specify the fog color, along with the distance in which the fog begins and ends.

//Set object and camera info
            effect.World = worldRotation * worldTranslation * worldRotation;
            effect.View = camera.view;
            effect.Projection = camera.projection;
            effect.Texture = texture;
            effect.TextureEnabled = true;
// Begin effect and draw for each pass
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                //GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>
                    (PrimitiveType.TriangleStrip, verts, 0, 2);
            }








你可能感兴趣的:(properties,Class,each,Matrix,methods,distance)