/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Load saved scene. if (File.Exists(SampleSceneFilePath)) { m_scene = SceneDescription.ReadFromFile(SampleSceneFilePath); } else { // Create a new scene. m_scene = new SceneDescription(); m_scene.Name = "Sample Scene"; // Add some models. m_scene.Add(new SceneDescriptionModelEntry("Sponza", "Models/Sponza/Sponza", Transformation.Identity)); m_scene.Add(new SceneDescriptionModelEntry("Tank1", "Models/tank", Transformation.Identity)); Transformation tank2Transformation = new Transformation(1.0f, Quaternion.Identity, new Vector3(-5, 0, 10)); m_scene.Add(new SceneDescriptionModelEntry("Tank2", "Models/tank", ref tank2Transformation)); Transformation robot1Transformation = new Transformation(1.0f, Quaternion.Identity, new Vector3(5, 3, 10)); m_scene.Add(new SceneDescriptionModelEntry("Robot1", "Models/RobotGame/Yager", ref robot1Transformation)); // Add randomly distributed point lights. { // Point lights Random random = new Random(); for (int i = 0; i < 200; ++i) { Vector3 position = new Vector3( ( float )random.NextDouble() * 200.0f - 100.0f, ( float )random.NextDouble() * 150.0f, ( float )random.NextDouble() * 100.0f - 50.0f); Vector3 diffuseColor = new Vector3( ( float )random.NextDouble(), ( float )random.NextDouble(), ( float )random.NextDouble()); float specularPower = ( float )random.NextDouble() * 10.0f; float attenuationDistance = 10.0f + ( float )random.NextDouble() * 190.0f; float attenuationDistanceExponent = 1.0f + ( float )random.NextDouble() * 99.0f; m_scene.Add(SceneDescriptionLightEntry.CreatePointLight(string.Format("PointLight{0}", i), position, diffuseColor, specularPower, attenuationDistance, attenuationDistanceExponent)); } // Spot lights #if false random = new Random(random.Next()); for (int i = 0; i < 20; ++i) { Vector3 position = new Vector3( ( float )random.NextDouble() * 200.0f - 100.0f, ( float )random.NextDouble() * 150.0f, ( float )random.NextDouble() * 100.0f - 50.0f); Vector3 direction = new Vector3( ( float )random.NextDouble() * 2.0f - 1.0f, ( float )random.NextDouble() * 2.0f - 1.0f, ( float )random.NextDouble() * 2.0f - 1.0f); Vector3 diffuseColor = new Vector3( ( float )random.NextDouble(), ( float )random.NextDouble(), ( float )random.NextDouble()); float specularPower = ( float )random.NextDouble() * 100.0f; float attenuationDistance = ( float )random.NextDouble() * 200.0f; float attenuationDistanceExponent = 100.0f; float attenuationInnerAngle = ( float )random.NextDouble() * MathHelper.PiOver4; float attenuationOuterAngle = attenuationInnerAngle + ( float )random.NextDouble() * MathHelper.PiOver4; float attenuationAngleExponent = 1.0f + ( float )random.NextDouble() * 19.0f; m_scene.Add( string.Format("SpotLight{0}", i), SceneDescriptionLightEntry.CreateSpotLight(position, direction, diffuseColor, specularPower, attenuationDistance, attenuationDistanceExponent, attenuationInnerAngle, attenuationOuterAngle, attenuationAngleExponent)); } #endif } // Add a direction light. m_scene.Add(SceneDescriptionLightEntry.CreateDirectionalLight("SkyLight", new Vector3(0, -1, 0), new Vector3(0.2f, 0.2f, 0.2f), 1.0f)); } base.Initialize(); }