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); }
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(); //get a list of predifined colours in the 'Color' structure using reflection //avoid doing this sort of thing at runtime! PropertyInfo[] colours = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.Public); // get all the static properties Random random = new Random(); int lightCount = 12; //geometry for a light (shared for each light) IDraw lightGeometry = null; for (int i = 0; i < lightCount; i++) { //start with white. Color colour = Color.White; //try and pick a random colour from the list, using reflection to get the value of the property try { //pick a random field info object (a reflected colour property) var randomColourField = colours[random.Next(colours.Length)]; //try and get it's value object colourObject = randomColourField.GetValue(null, null); if (colourObject is Color) colour = (Color)colourObject; } catch { //this shouldn't fail, but always be careful with reflection... //typically this would be handled correctly, but here, just stick with white. } float angle = (float)i / (float)lightCount * (float)Math.PI * 2; Vector3 position = new Vector3((float)Math.Sin(angle) * (diskRadius + 1), (float)Math.Cos(angle) * (diskRadius + 1), 4); float intensity = 1; //interface to the light about to be created IMaterialPointLight light = null; //create the point light light = lights.CreatePointLight(position, intensity, colour, colour); light.SourceRadius = 5; //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(position, lightGeometry, colour); //add the light geometry to the screen drawToScreen.Add(lightSourceDrawer); } //add the actor actor = new Tutorials.Tutorial_11.Actor(this.Content, this.lights); drawToScreen.Add(actor); //create the ground disk GroundDisk ground = new GroundDisk(this.Content, lights, diskRadius); //then add it to the screen drawToScreen.Add(ground); }