Ejemplo n.º 1
0
        protected override void Initialise()
        {
            camera = new Camera3D();

            //create the draw target.
            drawToScreen = new DrawTargetScreen(this, camera);
            //clear to dark blue
            drawToScreen.ClearBuffer.ClearColour = new Color(20, 20, 40);

            //create the light collection
            lights = new MaterialLightCollection();
            //set a dark blue ambient colour
            lights.AmbientLightColour = new Color(40, 40, 80).ToVector3();

            //positions for two lights
            Vector3[] lightPositions = new Vector3[]
            {
                new Vector3(0, 30, 2),
                new Vector3(0, -30, 2)
            };

            //geometry for a light (shared for each light)
            IDraw lightGeometry = null;

            for (int i = 0; i < lightPositions.Length; i++)
            {
                float lightHalfFalloffDistance = 15;
                Color lightColor          = Color.LightYellow;
                Color lightSpecularColour = Color.WhiteSmoke;
                bool  perPixel            = i < 2;    //first two lights are per-pixel

                //interface to the light about to be created
                IMaterialPointLight light = null;

                //create the point light
                light = lights.AddPointLight(perPixel, lightPositions[i], lightHalfFalloffDistance, lightColor, lightSpecularColour);

                //adjust the lighting attenuation model, the constant defaults to 1, which prevents the light being brighter than 1.0 in the falloff equation
                //set to 0.25, the light will get really bright in close (up to 4)
                //(see light.QuadraticAttenuation remarks for an explanation of the falloff model)
                light.ConstantAttenuation = 0.25f;

                //create the light geometry (a sphere)
                if (lightGeometry == null)
                {
                    lightGeometry = new Xen.Ex.Geometry.Sphere(Vector3.One, 8, true, false, false);
                }

                //visually show the light with a light drawer
                IDraw lightSourceDrawer = new LightSourceDrawer(lightPositions[i], lightGeometry, lightColor);

                //add the light geometry to the screen
                drawToScreen.Add(lightSourceDrawer);
            }

            //create the ground disk
            GroundDisk ground = new GroundDisk(this.Content, lights, diskRadius);

            //then add it to the screen
            drawToScreen.Add(ground);
        }
		protected override void Initialise()
		{
			camera = new Camera3D();

			//create the draw target.
			drawToScreen = new DrawTargetScreen(camera);
			//clear to dark blue
			drawToScreen.ClearBuffer.ClearColour = new Color(20, 20, 40);

			//create the light collection
			lights = new MaterialLightCollection();
			//set a dark blue ambient colour
			lights.AmbientLightColour = new Color(40, 40, 80).ToVector3();

			//positions for two lights
			Vector3[] lightPositions = new Vector3[] 
			{ 
				new Vector3(0, 30, 4), 
				new Vector3(0, -30, 4) 
			};

			//geometry for a light (shared for each light)
			IDraw lightGeometry = null;

			for (int i = 0; i < lightPositions.Length; i++)
			{
				float intensity = 2;
				Color lightColor = Color.LightYellow;
				Color lightSpecularColour = Color.WhiteSmoke;

				//interface to the light about to be created
				IMaterialPointLight light = null;

				//create the point light
				light = lights.CreatePointLight(lightPositions[i], intensity, lightColor, lightSpecularColour);
				
				//Adjusting this value controls how quickly the light falloff occurs.
				//A larger value will produce a slower falloff, and result in a softer, brighter light.
				//A smaller value will produce a darker, but sharper light source.
				//Generally, if you reduce this value, increase the intensity to compensate.
				light.SourceRadius = 4;

				//create the light geometry (a sphere)
				if (lightGeometry == null)
					lightGeometry = new Xen.Ex.Geometry.Sphere(Vector3.One, 8, true, false, false);

				//visually show the light with a light drawer
				var lightSourceDrawer = new LightSourceDrawer(lightPositions[i], lightGeometry,lightColor);

				//add the light geometry to the screen
				drawToScreen.Add(lightSourceDrawer);
			}

			//create the ground disk
			var ground = new GroundDisk(this.Content, lights, diskRadius);

			//then add it to the screen
			drawToScreen.Add(ground);
		}