Exemplo n.º 1
0
        private void CreateDirectionalLight(Assimp.Light light, Spatial spatial)
        {
            DirectionalLight dl = new DirectionalLight();

            dl.Ambient   = ConvertColor(light.ColorAmbient);
            dl.Diffuse   = ConvertColor(light.ColorDiffuse);
            dl.Specular  = ConvertColor(light.ColorSpecular);
            dl.Direction = ConvertVector3(light.Direction);
            spatial.AddLight(dl);
        }
Exemplo n.º 2
0
        private void CreatePointLight(Assimp.Light light, Spatial spatial)
        {
            PointLight pl = new PointLight();

            pl.Constant  = light.AttenuationConstant;
            pl.Linear    = light.AttenuationLinear;
            pl.Quadratic = light.AttenuationQuadratic;
            pl.Ambient   = ConvertColor(light.ColorAmbient);
            pl.Diffuse   = ConvertColor(light.ColorDiffuse);
            pl.Specular  = ConvertColor(light.ColorSpecular);
            pl.Position  = ConvertVector3(light.Position);
            spatial.AddLight(pl);
        }
Exemplo n.º 3
0
        private void CreateSpotLight(Assimp.Light light, Spatial spatial)
        {
            SpotLight sl = new SpotLight();

            sl.Constant  = light.AttenuationConstant;
            sl.Linear    = light.AttenuationLinear;
            sl.Quadratic = light.AttenuationQuadratic;
            sl.Ambient   = ConvertColor(light.ColorAmbient);
            sl.Diffuse   = ConvertColor(light.ColorDiffuse);
            sl.Specular  = ConvertColor(light.ColorSpecular);
            sl.Position  = ConvertVector3(light.Position);
            sl.Direction = ConvertVector3(light.Direction);
            spatial.AddLight(sl);
        }
Exemplo n.º 4
0
        protected override void LoadContent()
        {
            Window.Title = "Input Handling Sample";
            rotateSpeed  = 2.5f;
            speed        = 105.0f;

            Renderer.CurrentCamera.Position = new Vector3(0, 800, 100);
            Renderer.CurrentCamera.LookAt(Vector3.Zero, Vector3.Up);
            Renderer.CurrentCamera.Update();

            //Load our fancy pants racecar
            ModelLoaderParameters mlp = new ModelLoaderParameters();

            mlp.SwapWindingOrder   = true;
            mlp.NormalGeneration   = NormalGeneration.Crease;
            mlp.PreferLitMaterials = true;

            Spatial car = ContentManager.Load <Spatial>("Models//Jeep.dxs", mlp);

            car.SetModelBound(new BoundingBox());
            RootNode.AddChild(car);

            //Create an input layer, this layer will hold all of our controls and input response to the arrow keys, moving the car
            input = new InputLayer();

            //Input layers can be disabled or enabled, so you're able to logically group your inputs together and treat them as one unit.
            //E.g. if you have a screen menu and want the mouse enabled, but for gameplay do not want the mouse enabled.
            //Rather than disabling the whole layer, we'll just disable the first 5 triggers - which are the
            //FPS controls set in BasicApp.
            InputLayer.EnableTrigger(0, false);
            InputLayer.EnableTrigger(1, false);
            InputLayer.EnableTrigger(2, false);
            InputLayer.EnableTrigger(3, false);
            InputLayer.EnableTrigger(4, false);

            //Since we disabled the basicApp's input alyer, lets make sure we can get out of the app
            input.RegisterTrigger(new InputTrigger(new KeyPressedCondition(Keys.Escape, false),
                                                   new InputAction(delegate(GameTime time) {
                Exit();
            })));

            input.RegisterTrigger(new InputTrigger(new KeyPressedCondition(Keys.A, true), new InputAction(
                                                       delegate(GameTime time) {
                car.Rotation *= Quaternion.FromAngleAxis(rotateSpeed * (float)time.ElapsedTimeInSeconds, Vector3.Up);
            }
                                                       )));
            input.RegisterTrigger(new InputTrigger(new KeyPressedCondition(Keys.D, true), new InputAction(
                                                       delegate(GameTime time) {
                car.Rotation *= Quaternion.FromAngleAxis(-rotateSpeed * (float)time.ElapsedTimeInSeconds, Vector3.Up);
            }
                                                       )));

            input.RegisterTrigger(new InputTrigger(new KeyPressedCondition(Keys.W, true), new InputAction(
                                                       delegate(GameTime time) {
                //Usually a good idea to use the world properties, since this may be attached to a node that is moving also
                car.Translation -= car.WorldTransform.GetRotationVector(2) * speed * (float)time.ElapsedTimeInSeconds;
            }
                                                       )));
            input.RegisterTrigger(new InputTrigger(new KeyPressedCondition(Keys.S, true), new InputAction(
                                                       delegate(GameTime time) {
                car.Translation += car.WorldTransform.GetRotationVector(2) * speed * (float)time.ElapsedTimeInSeconds;
            }
                                                       )));

            //Add another point light to the scene
            PointLight pl = new PointLight();

            pl.Attenuate = false;
            pl.Position  = new Vector3(0, 0, 50);
            car.AddLight(pl);
        }