private static void CreateSolarSystemScene(float speed, float orbitDistanceMultiplier, float planetScaleMultiplier, Renderer renderer) { // Create and setup material SimpleMaterial baseMaterial = new SimpleMaterial { VertexShaderPath = "Shaders.fx", VertexShaderEntryPoint = "VS", VertexShaderProfile = "vs_5_0", PixelShaderPath = "Shaders.fx", PixelShaderEntryPoint = "PS", PixelShaderProfile = "ps_5_0", }; baseMaterial.Initialize(renderer.device); baseMaterial.pixelShaderData.LightPos = new Vector4(0, 0, 0, 1); baseMaterial.pixelShaderData.EmissionColor = new Vector4(0.1f, 0.1f, 0.1f, 1); // Load model ModelLoader modelLoader = new ModelLoader(renderer.device); Model sphere = modelLoader.LoadRelative("Assets\\Planets\\sphere.obj"); // Create scene objects // Sun SceneObject sunObject = new SceneObject(); sunObject.model = sphere; SimpleMaterial sunMaterial = baseMaterial.CreateInstanceTyped(); sunMaterial.pixelShaderData.DiffuseColor = new Vector4(0.92f, 0.72f, 0.2f, 1); sunMaterial.pixelShaderData.EmissionColor = new Vector4(0.92f, 0.8f, 0.2f, 1); sunObject.material = sunMaterial; // Mercury CreatePlanet(4f * speed, 0.36f * orbitDistanceMultiplier, 0.38f * planetScaleMultiplier, baseMaterial, new Vector4(0.7f, 0.6f, 0.5f, 1), sphere); // Venus CreatePlanet(1.3f * speed, 0.67f * orbitDistanceMultiplier, 0.95f * planetScaleMultiplier, baseMaterial, new Vector4(0.96f, 0.48f, 0.04f, 1), sphere); // Earth + Moon var earth = CreatePlanet(1f * speed, 0.93f * orbitDistanceMultiplier, 1f * planetScaleMultiplier, baseMaterial, new Vector4(0.2f, 0.2f, 0.8f, 1), sphere); CreatePlanet(1 / 0.1f * speed, 1f * orbitDistanceMultiplier, 0.8f * planetScaleMultiplier, baseMaterial, new Vector4(0.4f, 0.4f, 0.4f, 1), sphere, earth.transform); // Mars CreatePlanet(0.45f * speed, 1.41f * orbitDistanceMultiplier, 0.53f * planetScaleMultiplier, baseMaterial, new Vector4(0.73f, 0.13f, 0.04f, 1), sphere); // Jupiter CreatePlanet(1 / 11.9f * speed, 2.6f * orbitDistanceMultiplier, 11.12f * planetScaleMultiplier, baseMaterial, new Vector4(0.77f, 0.66f, 0.45f, 1), sphere); // Saturn CreatePlanet(1 / 29.5f * speed, 3.7f * orbitDistanceMultiplier, 9.45f * planetScaleMultiplier, baseMaterial, new Vector4(0.68f, 0.54f, 0.36f, 1), sphere); // Uranus CreatePlanet(1 / 84f * speed, 4.4f * orbitDistanceMultiplier, 4.00f * planetScaleMultiplier, baseMaterial, new Vector4(0.55f, 0.83f, 0.97f, 1), sphere); // Neptune CreatePlanet(1 / 165f * speed, 5.2f * orbitDistanceMultiplier, 3.88f * planetScaleMultiplier, baseMaterial, new Vector4(0.38f, 0.50f, 0.83f, 1), sphere); }
private static SceneObject CreatePlanet(float orbitRotationSpeed, float orbitDistance, float planetScale, SimpleMaterial baseMaterial, Vector4 planetColor, Model model, Transform parentTransform = null) { SceneObject planetRoot = new SceneObject(); SimpleTransformAnimationComponent animationComponent = new SimpleTransformAnimationComponent() { RotationSpeed = new Vector3(orbitRotationSpeed, 0, 0), }; planetRoot.AddComponent(animationComponent); planetRoot.animationComponent = animationComponent; planetRoot.transform.parent = parentTransform; SceneObject planet = new SceneObject(); planet.model = model; planet.transform.LocalPositionX = orbitDistance; planet.transform.LocalScale = Vector3.One * planetScale; planet.transform.parent = planetRoot.transform; SimpleMaterial planetMaterial = baseMaterial.CreateInstanceTyped(); planetMaterial.pixelShaderData.DiffuseColor = planetColor; planet.material = planetMaterial; return(planet); }