示例#1
0
        // is called on startup
        public override void Init()
        {
            RC.ClearColor = new float4(1, 1, 1, 1);

            _cubeMesh   = MeshReader.LoadMesh(@"Assets/cube.obj.model");
            _spColor    = MoreShaders.GetDiffuseColorShader(RC);
            _colorParam = _spColor.GetShaderParam("color");
        }
        public GameEntity(String meshPath, RenderContext rc, float posX = 0, float posY = 0, float posZ = 0, float angX = 0, float angY = 0, float angZ = 0)
        {
            _mesh = MeshReader.LoadMesh(meshPath);
            _rc   = rc;

            Position = float4x4.CreateRotationX(angX) *
                       float4x4.CreateRotationY(angY) *
                       float4x4.CreateRotationZ(angZ) *
                       float4x4.CreateTranslation(posX, posY, posZ);

            _shaderProgram = MoreShaders.GetDiffuseColorShader(rc);
            _shaderParam   = _shaderProgram.GetShaderParam("color");
        }
示例#3
0
        // is called on startup
        public override void Init()
        {
            _theColor     = new float4(0.5f, 0.8f, 0, 1);
            RC.ClearColor = new float4(1, 1, 1, 1);

            // initialize the variables
            _meshTea  = MeshReader.LoadMesh(@"Assets/Teapot.obj.model");
            _meshFace = MeshReader.LoadMesh(@"Assets/Face.obj.model");

            _spColor   = MoreShaders.GetShader("simple", RC);
            _spTexture = MoreShaders.GetShader("texture", RC);

            _colorParam   = _spColor.GetShaderParam("vColor");
            _textureParam = _spTexture.GetShaderParam("texture1");

            // load texture
            var imgData = RC.LoadImage("Assets/world_map.jpg");

            _iTex = RC.CreateTexture(imgData);
        }
示例#4
0
        public override void Init()
        {
            _sceneManager = new SceneManager();
            _sceneManager.AttachToContext(RC);

            var spot = new SpotLight(new float3(0, 0, 0), new float3(0, 0, 0), new float4(0.7f, 0.7f, 0.7f, 1),
                                     new float4(0.3f, 0.3f, 0.3f, 1), new float4(0.1f, 0.1f, 0.1f, 1), (float)Math.PI / 8, 0);

            var sphereGeom   = MeshReader.LoadGeometry("Assets/Sphere.obj.model");
            var spaceboxGeom = MeshReader.LoadGeometry("Assets/Spacebox.obj.model");
            var lampGeom     = MeshReader.LoadGeometry("Assets/Lamp.obj.model");

            // main objects
            var worldOrigin = new SceneEntity("WorldOrigin", new MouseAction());

            var cameraholder = new SceneEntity("CameraOwner", new CamScript())
            {
                Transform =
                {
                    GlobalPosition = new float3(0, 0, 10)
                }
            };

            worldOrigin.AddChild(cameraholder);

            _sceneCamera = new Camera(cameraholder);
            _sceneCamera.Resize(Width, Height);

            var root = new SceneEntity("Root1", new MouseAction())
            {
                Transform =
                {
                    GlobalPosition = new float3(0, 0, 0),
                    GlobalScale    = new float3(1, 1, 1)
                }
            };

            var sphere = new SceneEntity("Sphere", new ActionCode(),
                                         new SpecularMaterial(RC, MoreShaders.GetSpecularShader(RC), "Assets/metall.jpg"),
                                         new Renderer(sphereGeom))
            {
                Transform =
                {
                    GlobalPosition = new float3(2,       0, 0),
                    GlobalScale    = new float3(0.5f, 0.5f, 0.5f)
                }
            };

            var cube = new SceneEntity("Sphere2", new ActionCode(),
                                       new BumpMaterial(RC, MoreShaders.GetBumpDiffuseShader(RC), "Assets/metall.jpg", "Assets/normal.jpg"),
                                       new Renderer(sphereGeom))
            {
                Transform =
                {
                    GlobalPosition = new float3(5, 0, 0)
                }
            };

            var light = new SceneEntity("Light", new ActionCode());

            var spaceBox = new SceneEntity("Spacebox",
                                           new DiffuseMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/sky.jpg"),
                                           new Renderer(spaceboxGeom));

            spaceBox.Transform.GlobalScale      = new float3(0.5f, 0.5f, 0.5f);
            spaceBox.Transform.LocalEulerAngles = new float3(-90, 90, 0);

            _sceneManager.AddSceneEntity(worldOrigin);
            _sceneManager.AddSceneEntity(root);
            _sceneManager.AddSceneEntity(sphere);
            _sceneManager.AddSceneEntity(cube);
            _sceneManager.AddSceneEntity(light);
            _sceneManager.AddSceneEntity(spaceBox);

            // LightObject
            var lamp = new SceneEntity("DirLight", new RotateAction(new float3(0, 20, 0)),
                                       new DiffuseMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/metall.jpg"),
                                       new Renderer(lampGeom))
            {
                Transform =
                {
                    GlobalPosition = new float3(0,       0, 0),
                    GlobalScale    = new float3(0.7f, 0.7f, 0.7f)
                }
            };

            light.AddChild(lamp);
            lamp.AddComponent(spot);

            _sceneManager.StartActionCode();

            RC.ClearColor = new float4(1, 0, 0, 1);
        }
示例#5
0
        public override void Init()
        {
            SceneManager.RC = RC;
            SceneEntity _planet;
            // Lights
            DirectionalLight direct = new DirectionalLight(new float3(-500, 1000, 0), new float4(1, 1, 1, 1), new float3(0, 0, 0), 0);

            // Load Geometry

            Geometry planetgeometry = MeshReader.ReadWavefrontObj(new StreamReader(@"Assets/Sphere.obj.model"));
            Geometry spacebox       = MeshReader.ReadWavefrontObj(new StreamReader(@"Assets/spacebox.obj.model"));

            // Setup Empty Objects
            // Null Objects
            SceneEntity _emptyMoon;
            SceneEntity _emptyMercury;
            SceneEntity _emptyVenus;
            SceneEntity _emptyEarth;
            SceneEntity _emptyMars;
            SceneEntity _emptyJupiter;
            SceneEntity _emptySaturn;
            SceneEntity _emptyUranus;
            SceneEntity _emptyNeptun;

            _emptyMoon    = new SceneEntity("emptyPlanetHolder", new MoonAction(_speedearth * 5.0f));
            _emptyMercury = new SceneEntity("emptyPlanetHolder", new PlanetAction(_speedearth * 4.1477f));
            _emptyVenus   = new SceneEntity("emptyPlanetHolder", new PlanetAction(_speedearth * 1.6150f));
            _emptyEarth   = new SceneEntity("emptyPlanetHolder", new PlanetAction(_speedearth));
            _emptyMars    = new SceneEntity("emptyPlanetHolder", new PlanetAction(_speedearth * 0.5320f));
            _emptyJupiter = new SceneEntity("emptyPlanetHolder", new PlanetAction(_speedearth * 0.0833f));
            _emptySaturn  = new SceneEntity("emptyPlanetHolder", new PlanetAction(_speedearth * 0.03476f));
            _emptyUranus  = new SceneEntity("emptyPlanetHolder", new PlanetAction(_speedearth * 0.0119f));
            _emptyNeptun  = new SceneEntity("emptyPlanetHolder", new PlanetAction(_speedearth * 0.0062f));
            SceneManager.Manager.AddSceneEntity(_emptyMoon);
            SceneManager.Manager.AddSceneEntity(_emptyMercury);
            SceneManager.Manager.AddSceneEntity(_emptyVenus);
            SceneManager.Manager.AddSceneEntity(_emptyEarth);
            SceneManager.Manager.AddSceneEntity(_emptyMars);
            SceneManager.Manager.AddSceneEntity(_emptyJupiter);
            SceneManager.Manager.AddSceneEntity(_emptySaturn);
            SceneManager.Manager.AddSceneEntity(_emptyUranus);
            SceneManager.Manager.AddSceneEntity(_emptyNeptun);

            //Setup Camera
            // Scene Camera
            SceneEntity  cameraholder;
            CameraScript camscript;
            SceneEntity  WorldOrigin;

            WorldOrigin = new SceneEntity("WorldOrigin", new RotationScript());
            SceneManager.Manager.AddSceneEntity(WorldOrigin);
            cameraholder = new SceneEntity("CameraOwner", new CameraScript(), WorldOrigin);
            cameraholder.transform.GlobalPosition = new float3(0, 0, 10);
            scenecamera = new Camera(cameraholder);
            scenecamera.Resize(Width, Height);


            // Setup Space Box
            SceneEntity _spaceBox = new SceneEntity("Spacebox", new PlanetMaterial(MoreShaders.GetShader("simpel", RC), "Assets/spaceboxTexture.png"), new Renderer(spacebox));

            SceneManager.Manager.AddSceneEntity(_spaceBox);


            // Setup Earth
            _planet = new SceneEntity("Earth", new PlanetAction(new float3(0, 0.69635f * 365, 0)), _emptyEarth, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/earth.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(2.9f, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.1f, 0.1f, 0.1f);
            _planet.AddComponent(direct);

            //Setup Moon
            //_emptyMoon.transform.LocalPosition = _earth.transform.LocalPosition;
            //_emptyMoonAction = new MoonAction(_speedearth * 5.0f);
            //_emptyMoon.AddComponent(_emptyMoonAction);
            _planet = new SceneEntity("Moon", new PlanetAction(new float3(0, 2.7f, 0)), _emptyMoon, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/moon.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(0.5f, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.05f, 0.05f, 0.05f);


            //SceneManager.Manager.AddSceneEntity(_emptyMoon);
            //_emptyMoon.AddChild(_moon);
            //_emptyMoonAction.Init(_emptyMoon);

            /*
             * _moon = new SceneEntity { name = "Moon" };
             * _emptyMoonAction = new MoonAction(_earth, _speedearth * 5.0f);
             *
             *
             * _moonMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _moonImage = RC.LoadImage("Assets/moon.jpg");
             * _moonIShaderParam = _moonMaterial.sp.GetShaderParam("texture1");
             * _moonITexture = RC.CreateTexture(_moonImage);
             * _moonMaterial.Tex = _moonITexture;
             * _moonMaterial.Textureparam = _moonIShaderParam;
             * _moonRenderer = new Renderer(planetgeometry);
             * _moonRenderer.material = _moonMaterial;
             * _moon.AddComponent(_moonRenderer);
             * _emptyMoon.AddComponent(_emptyMoonAction);
             * _moon.transform.LocalPosition = new float3(0.5f, 0, 0);
             * _moon.transform.LocalScale = new float3(0.05f, 0.05f, 0.05f);
             * SceneManager.Manager.AddSceneEntity(_emptyMoon);
             * _emptyMoon.AddChild(_moon);
             * _emptyMoonAction.Init(_emptyMoon);
             */
            // Setup sun
            _planet = new SceneEntity("Sun", new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/sun.jpg"), new Renderer(planetgeometry));
            _planet.transform.LocalScale = new float3(2, 2, 2);
            SceneManager.Manager.AddSceneEntity(_planet);

            /*
             * _sun = new SceneEntity { name = "Sun" };
             * //_sunAction.Init(_sun);
             * _sunMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _sunImage = RC.LoadImage("Assets/sun.jpg");
             * _sunIShaderParam = _sunMaterial.sp.GetShaderParam("texture1");
             * _sunITexture = RC.CreateTexture(_sunImage);
             * _sunMaterial.Tex = _sunITexture;
             * _sunMaterial.Textureparam = _sunIShaderParam;
             * _sunRenderer = new Renderer(planetgeometry);
             * _sunRenderer.material = _sunMaterial;
             * _sun.AddComponent(_sunRenderer);
             * _sun.transform.LocalPosition = new float3(0,0,0);
             * _sun.transform.LocalScale = new float3(2,2,2);
             * //_earth.AddChild(_sun);
             * SceneManager.Manager.AddSceneEntity(_sun);
             */
            // Setup mercury
            _planet = new SceneEntity("Mercury", new PlanetAction(_speedearth * 6.2234f), _emptyMercury, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/merkur.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(2.35f, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.05f, 0.05f, 0.05f);

            /*
             * _mercury = new SceneEntity { name = "Mercury" };
             * _mercuryAction.Init(_mercury);
             * _mercuryMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _mercuryImage = RC.LoadImage("Assets/merkur.jpg");
             * _mercuryIShaderParam = _mercuryMaterial.sp.GetShaderParam("texture1");
             * _mercuryITexture = RC.CreateTexture(_mercuryImage);
             * _mercuryMaterial.Tex = _mercuryITexture;
             * _mercuryMaterial.Textureparam = _mercuryIShaderParam;
             * _mercuryRenderer = new Renderer(planetgeometry);
             * _mercuryRenderer.material = _mercuryMaterial;
             * _mercury.AddComponent(_mercuryRenderer);
             * _mercury.AddComponent(_mercuryAction);
             * _mercury.transform.LocalPosition = new float3(2.35f, 0, 0);
             * _mercury.transform.LocalScale = new float3(0.05f, 0.05f, 0.05f);
             * //SceneManager.Manager.AddSceneEntity(_mercury);
             * _emptyMercury.AddChild(_mercury);
             */
            // Setup venus
            _planet = new SceneEntity("Venus", new PlanetAction(_speedearth * 1.5021f), _emptyVenus, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/venus.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(2.6f, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.08f, 0.08f, 0.08f);

            /*
             * _venus = new SceneEntity { name = "Venus" };
             * _venusAction.Init(_venus);
             * _venusMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _venusImage = RC.LoadImage("Assets/venus.jpg");
             * _venusIShaderParam = _venusMaterial.sp.GetShaderParam("texture1");
             * _venusITexture = RC.CreateTexture(_venusImage);
             * _venusMaterial.Tex = _venusITexture;
             * _venusMaterial.Textureparam = _venusIShaderParam;
             * _venusRenderer = new Renderer(planetgeometry);
             * _venusRenderer.material = _venusMaterial;
             * _venus.AddComponent(_venusRenderer);
             * _venus.AddComponent(_venusAction);
             * _venus.transform.LocalPosition = new float3(2.6f, 0, 0);
             * _venus.transform.LocalScale = new float3(0.08f, 0.08f, 0.08f);
             * //SceneManager.Manager.AddSceneEntity(_venus);
             * _emptyVenus.AddChild(_venus);*/

            // Setup mars
            _planet = new SceneEntity("Mars", new PlanetAction(_speedearth * 374.125f), _emptyMars, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/mars.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(3.25f, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.07f, 0.07f, 0.07f);

            /*
             * _mars = new SceneEntity { name = "Mars" };
             * _marsAction.Init(_mars);
             * _marsMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _marsImage = RC.LoadImage("Assets/mars.jpg");
             * _marsIShaderParam = _marsMaterial.sp.GetShaderParam("texture1");
             * _marsITexture = RC.CreateTexture(_marsImage);
             * _marsMaterial.Tex = _marsITexture;
             * _marsMaterial.Textureparam = _marsIShaderParam;
             * _marsRenderer = new Renderer(planetgeometry);
             * _marsRenderer.material = _marsMaterial;
             * _mars.AddComponent(_marsRenderer);
             * _mars.AddComponent(_marsAction);
             * _mars.transform.LocalPosition = new float3(3.25f, 0, 0);
             * _mars.transform.LocalScale = new float3(0.07f, 0.07f, 0.07f);
             * //SceneManager.Manager.AddSceneEntity(_mars);
             * _emptyMars.AddChild(_mars);*/

            // Setup jupiter
            _planet = new SceneEntity("Jupiter", new PlanetAction(_speedearth * 882.62f), _emptyJupiter, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/jupiter.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(4, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.4f, 0.4f, 0.4f);

            /*
             * _jupiter = new SceneEntity { name = "Jupiter" };
             * _jupiterAction.Init(_jupiter);
             * _jupiterMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _jupiterImage = RC.LoadImage("Assets/jupiter.jpg");
             * _jupiterIShaderParam = _jupiterMaterial.sp.GetShaderParam("texture1");
             * _jupiterITexture = RC.CreateTexture(_jupiterImage);
             * _jupiterMaterial.Tex = _jupiterITexture;
             * _jupiterMaterial.Textureparam = _jupiterIShaderParam;
             * _jupiterRenderer = new Renderer(planetgeometry);
             * _jupiterRenderer.material = _jupiterMaterial;
             * _jupiter.AddComponent(_jupiterRenderer);
             * _jupiter.AddComponent(_jupiterAction);
             * _jupiter.transform.LocalPosition = new float3(4, 0, 0);
             * _jupiter.transform.LocalScale = new float3(0.4f, 0.4f, 0.4f);
             * //SceneManager.Manager.AddSceneEntity(_jupiter);
             * _emptyJupiter.AddChild(_jupiter);
             */
            // Setup saturn
            _planet = new SceneEntity("Saturn", new PlanetAction(_speedearth * 820.61f), _emptySaturn, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/saturn.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(5, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.3f, 0.3f, 0.3f);

            /*_saturn = new SceneEntity { name = "Saturn" };
             * _saturnAction.Init(_saturn);
             * _saturnMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _saturnImage = RC.LoadImage("Assets/saturn.jpg");
             * _saturnIShaderParam = _saturnMaterial.sp.GetShaderParam("texture1");
             * _saturnITexture = RC.CreateTexture(_saturnImage);
             * _saturnMaterial.Tex = _saturnITexture;
             * _saturnMaterial.Textureparam = _saturnIShaderParam;
             * _saturnRenderer = new Renderer(planetgeometry);
             * _saturnRenderer.material = _saturnMaterial;
             * _saturn.AddComponent(_saturnRenderer);
             * _saturn.AddComponent(_saturnAction);
             * _saturn.transform.LocalPosition = new float3(5, 0, 0);
             * _saturn.transform.LocalScale = new float3(0.3f, 0.3f, 0.3f);
             * //SceneManager.Manager.AddSceneEntity(_saturn);
             * _emptySaturn.AddChild(_saturn);*/

            // Setup uranus
            _planet = new SceneEntity("Uranus", new PlanetAction(_speedearth * 509.30f), _emptyUranus, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/uranus.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(6, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.12f, 0.12f, 0.12f);

            /*_uranus = new SceneEntity { name = "Uranus" };
             * _uranusAction.Init(_uranus);
             * _uranusMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _uranusImage = RC.LoadImage("Assets/uranus.jpg");
             * _uranusIShaderParam = _uranusMaterial.sp.GetShaderParam("texture1");
             * _uranusITexture = RC.CreateTexture(_uranusImage);
             * _uranusMaterial.Tex = _uranusITexture;
             * _uranusMaterial.Textureparam = _uranusIShaderParam;
             * _uranusRenderer = new Renderer(planetgeometry);
             * _uranusRenderer.material = _uranusMaterial;
             * _uranus.AddComponent(_uranusRenderer);
             * _uranus.AddComponent(_uranusAction);
             * _uranus.transform.LocalPosition = new float3(6, 0, 0);
             * _uranus.transform.LocalScale = new float3(0.12f, 0.12f, 0.12f);
             * //SceneManager.Manager.AddSceneEntity(_uranus);
             * _emptyUranus.AddChild(_uranus);*/

            // Setup neptun
            _planet = new SceneEntity("Neptun", new PlanetAction(_speedearth * 544.10f), _emptyNeptun, new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC), "Assets/neptune.jpg"), new Renderer(planetgeometry));
            _planet.transform.GlobalPosition = new float3(7, 0, 0);
            _planet.transform.GlobalScale    = new float3(0.14f, 0.14f, 0.14f);

            /*_neptun = new SceneEntity { name = "Neptun" };
             * _neptunAction.Init(_neptun);
             * _neptunMaterial = new PlanetMaterial(MoreShaders.GetShader("diffuse2", RC));
             * _neptunImage = RC.LoadImage("Assets/neptune.jpg");
             * _neptunIShaderParam = _neptunMaterial.sp.GetShaderParam("texture1");
             * _neptunITexture = RC.CreateTexture(_neptunImage);
             * _neptunMaterial.Tex = _neptunITexture;
             * _neptunMaterial.Textureparam = _neptunIShaderParam;
             * _neptunRenderer = new Renderer(planetgeometry);
             * _neptunRenderer.material = _neptunMaterial;
             * _neptun.AddComponent(_neptunRenderer);
             * _neptun.AddComponent(_neptunAction);
             * _neptun.transform.LocalPosition = new float3(7, 0, 0);
             * _neptun.transform.LocalScale = new float3(0.14f, 0.14f, 0.14f);
             * //SceneManager.Manager.AddSceneEntity(_neptun);
             * _emptyNeptun.AddChild(_neptun);*/
            SceneManager.Manager.StartActionCode();
            // Random Rotations
            _emptyEarth.transform.LocalEulerAngles   = new float3(0, 45, 0);
            _emptyMercury.transform.LocalEulerAngles = new float3(0, 55, 0);
            _emptyVenus.transform.LocalEulerAngles   = new float3(0, 335, 0);
            _emptyMars.transform.LocalEulerAngles    = new float3(0, 125, 0);
            _emptyJupiter.transform.LocalEulerAngles = new float3(0, 65, 0);
            _emptySaturn.transform.LocalEulerAngles  = new float3(0, 95, 0);
            _emptyUranus.transform.LocalEulerAngles  = new float3(0, 145, 0);
            _emptyNeptun.transform.LocalEulerAngles  = new float3(0, 245, 0);

            //camrotation.Init(WorldOrigin);
            RC.ClearColor = new float4(1, 0, 0, 1);
        }
示例#6
0
        public override void Init()
        {
            _sceneManager = new SceneManager();
            _sceneManager.AttachToContext(RC);

            // Light
            var direct = new DirectionalLight(new float3(1, 1, 1), new float4(0.7f, 0.7f, 0.7f, 1),
                                              new float4(1f, 1f, 1f, 1), new float4(0.9f, 0.9f, 0.9f, 1),
                                              new float3(0, 0, 0), 0);

            // Load Meshes
            var planetMesh   = MeshReader.LoadMesh(@"Assets/Sphere.obj.model");
            var spaceBoxMesh = MeshReader.LoadMesh(@"Assets/spacebox.obj.model");

            // Setup Empty Objects
            _earthSpeed = new float3(0, 0.69635f, 0);

            var emptyMoon    = new SceneEntity("emptyPlanetHolder", new MoonAction(_earthSpeed * 5.0f));
            var emptyMercury = new SceneEntity("emptyPlanetHolder", new PlanetAction(RC, _earthSpeed * 4.1477f));
            var emptyVenus   = new SceneEntity("emptyPlanetHolder", new PlanetAction(RC, _earthSpeed * 1.6150f));
            var emptyEarth   = new SceneEntity("emptyPlanetHolder", new PlanetAction(RC, _earthSpeed));
            var emptyMars    = new SceneEntity("emptyPlanetHolder", new PlanetAction(RC, _earthSpeed * 0.5320f));
            var emptyJupiter = new SceneEntity("emptyPlanetHolder", new PlanetAction(RC, _earthSpeed * 0.0833f));
            var emptySaturn  = new SceneEntity("emptyPlanetHolder", new PlanetAction(RC, _earthSpeed * 0.03476f));
            var emptyUranus  = new SceneEntity("emptyPlanetHolder", new PlanetAction(RC, _earthSpeed * 0.0119f));
            var emptyNeptun  = new SceneEntity("emptyPlanetHolder", new PlanetAction(RC, _earthSpeed * 0.0062f));

            _sceneManager.AddSceneEntity(emptyMoon);
            _sceneManager.AddSceneEntity(emptyMercury);
            _sceneManager.AddSceneEntity(emptyVenus);
            _sceneManager.AddSceneEntity(emptyEarth);
            _sceneManager.AddSceneEntity(emptyMars);
            _sceneManager.AddSceneEntity(emptyJupiter);
            _sceneManager.AddSceneEntity(emptySaturn);
            _sceneManager.AddSceneEntity(emptyUranus);
            _sceneManager.AddSceneEntity(emptyNeptun);

            // Scene Camera
            var worldOrigin = new SceneEntity("WorldOrigin", new RotationScript());

            _sceneManager.AddSceneEntity(worldOrigin);

            var cameraholder = new SceneEntity("CameraOwner", new CameraScript(RC))
            {
                Transform =
                {
                    GlobalPosition = new float3(0, 0, -10)
                }
            };

            worldOrigin.AddChild(cameraholder);

            _sceneCamera = new Camera(cameraholder);
            _sceneCamera.Resize(Width, Height);

            // Setup Space Box
            var spaceBox = new SceneEntity("Spacebox",
                                           new PlanetMaterial(RC, MoreShaders.GetTextureShader(RC), "Assets/spaceboxTexture.png"),
                                           new Renderer(spaceBoxMesh));

            _sceneManager.AddSceneEntity(spaceBox);

            // Setup Sun
            var planet = new SceneEntity("Sun",
                                         new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/sun.jpg"),
                                         new Renderer(planetMesh))
            {
                Transform = { LocalScale = new float3(2, 2, 2) }
            };

            _sceneManager.AddSceneEntity(planet);

            // Setup Earth
            planet = new SceneEntity("Earth", new PlanetAction(RC, new float3(0, 0.69635f * 365, 0)),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/earth.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(2.9f,    0, 0),
                    GlobalScale    = new float3(0.1f, 0.1f, 0.1f)
                }
            };

            planet.AddComponent(direct);

            emptyEarth.AddChild(planet);

            // Setup Moon
            planet = new SceneEntity("Moon", new PlanetAction(RC, new float3(0, 2.7f, 0)),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/moon.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(0.5f,      0, 0),
                    GlobalScale    = new float3(0.05f, 0.05f, 0.05f)
                }
            };

            emptyMoon.AddChild(planet);

            // Setup Mercury
            planet = new SceneEntity("Mercury", new PlanetAction(RC, _earthSpeed * 6.2234f),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/merkur.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(2.35f,     0, 0),
                    GlobalScale    = new float3(0.05f, 0.05f, 0.05f)
                }
            };

            emptyMercury.AddChild(planet);

            // Setup Venus
            planet = new SceneEntity("Venus", new PlanetAction(RC, _earthSpeed * 1.5021f),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/venus.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(2.6f,      0, 0),
                    GlobalScale    = new float3(0.08f, 0.08f, 0.08f)
                }
            };

            emptyVenus.AddChild(planet);


            // Setup Mars
            planet = new SceneEntity("Mars", new PlanetAction(RC, _earthSpeed * 374.125f),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/mars.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(3.25f,     0, 0),
                    GlobalScale    = new float3(0.07f, 0.07f, 0.07f)
                }
            };

            emptyMars.AddChild(planet);

            // Setup Jupiter
            planet = new SceneEntity("Jupiter", new PlanetAction(RC, _earthSpeed * 882.62f),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/jupiter.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(4,       0, 0),
                    GlobalScale    = new float3(0.4f, 0.4f, 0.4f)
                }
            };

            emptyJupiter.AddChild(planet);

            // Setup Saturn
            planet = new SceneEntity("Saturn", new PlanetAction(RC, _earthSpeed * 820.61f),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/saturn.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(5,       0, 0),
                    GlobalScale    = new float3(0.3f, 0.3f, 0.3f)
                }
            };

            emptySaturn.AddChild(planet);


            // Setup Uranus
            planet = new SceneEntity("Uranus", new PlanetAction(RC, _earthSpeed * 509.30f),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/uranus.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(6,         0, 0),
                    GlobalScale    = new float3(0.12f, 0.12f, 0.12f)
                }
            };

            emptyUranus.AddChild(planet);


            // Setup Neptun
            planet = new SceneEntity("Neptun", new PlanetAction(RC, _earthSpeed * 544.10f),
                                     new PlanetMaterial(RC, MoreShaders.GetDiffuseTextureShader(RC), "Assets/neptune.jpg"),
                                     new Renderer(planetMesh))
            {
                Transform =
                {
                    GlobalPosition = new float3(7,         0, 0),
                    GlobalScale    = new float3(0.14f, 0.14f, 0.14f)
                }
            };

            emptyNeptun.AddChild(planet);

            _sceneManager.StartActionCode();

            // Random Rotations
            emptyEarth.Transform.LocalEulerAngles   = new float3(0, 45, 0);
            emptyMercury.Transform.LocalEulerAngles = new float3(0, 55, 0);
            emptyVenus.Transform.LocalEulerAngles   = new float3(0, 335, 0);
            emptyMars.Transform.LocalEulerAngles    = new float3(0, 125, 0);
            emptyJupiter.Transform.LocalEulerAngles = new float3(0, 65, 0);
            emptySaturn.Transform.LocalEulerAngles  = new float3(0, 95, 0);
            emptyUranus.Transform.LocalEulerAngles  = new float3(0, 145, 0);
            emptyNeptun.Transform.LocalEulerAngles  = new float3(0, 245, 0);

            RC.ClearColor = new float4(1, 0, 0, 1);
        }
示例#7
0
        public override void Init()
        {
            _sceneManager = new SceneManager();
            _sceneManager.AttachToContext(RC);

            var dir = new DirectionalLight(new float3(0, 10, -1), new float4(1, 1, 1, 1), new float4(1, 1, 1, 1),
                                           new float4(1, 1, 1, 1), new float3(0, 0, 0), 0);

            var stativ = new SceneEntity("stativ", new ActionCode())
            {
                Transform =
                {
                    GlobalPosition = new float3(0, 0, 100)
                }
            };

            stativ.AddComponent(dir);

            _sceneManager.AddSceneEntity(stativ);

            _camera = new Camera(stativ);
            _camera.Resize(Width, Height);

            Geometry sohGeo = MeshReader.LoadGeometry("Assets/Sphere.obj.model");

            _sphere = new SceneEntity("sphere", new SphereMaterial(MoreShaders.GetDiffuseColorShader(RC)),
                                      new Renderer(sohGeo));

            _sceneManager.AddSceneEntity(_sphere);

            _channel2 = new Channel <float3>(Lerp.Float3Lerp);
            _channel1 = new Channel <float4>(Lerp.Float4Lerp, new float4(0.5f, 0.5f, 0.5f, 0.5f));

            var key0 = new Keyframe <float4>(0, new float4(1, 0, 1, 1));
            var key1 = new Keyframe <float4>(2, new float4(0.125f, 1, 0.125f, 1));
            var key2 = new Keyframe <float4>(4, new float4(0.250f, 0.75f, 0.250f, 1));
            var key3 = new Keyframe <float4>(6, new float4(0.5f, 0.5f, 0.5f, 1));
            var key4 = new Keyframe <float4>(8, new float4(0.75f, 0.25f, 0.75f, 1));
            var key5 = new Keyframe <float4>(10, new float4(1, 25, 0.125f, 1));
            var key6 = new Keyframe <float4>(0, new float4(0, 1, 0, 1));

            _channel1.AddKeyframe(key0);
            _channel1.AddKeyframe(key1);
            _channel1.AddKeyframe(key2);
            _channel1.AddKeyframe(key3);
            _channel1.AddKeyframe(key4);
            _channel1.AddKeyframe(key5);
            _channel1.AddKeyframe(key6);

            var key40 = new Keyframe <float3>(8, new float3(8, 0, 80));
            var key00 = new Keyframe <float3>(0, new float3(0, 0, 0));
            var key10 = new Keyframe <float3>(2, new float3(1, 2, 20));
            var key20 = new Keyframe <float3>(4, new float3(2, 4, 40));
            var key30 = new Keyframe <float3>(6, new float3(4, 4, 60));
            var key50 = new Keyframe <float3>(12, new float3(0, 4, 60));
            var key60 = new Keyframe <float3>(0, new float3(8, 8, 8));

            _channel2.AddKeyframe(key00);
            _channel2.AddKeyframe(key10);
            _channel2.AddKeyframe(key20);
            _channel2.AddKeyframe(key30);
            _channel2.AddKeyframe(key40);
            _channel2.AddKeyframe(key50);
            _channel2.AddKeyframe(key60);

            _myAnim.AddAnimation(_channel1, RC, "ClearColor");
            _myAnim.AddAnimation(_channel2, _sphere, "Transform.GlobalPosition");
        }