示例#1
0
    // Use this for initialization
    void Start()
    {
        pointLight          = new PointLightParam();
        pointLight.position = transform.position;
        pointLight.color    = Color.yellow;
        pointLight.range    = 0.5f;

        LightManager lm = Camera.main.GetComponent <LightManager>();

        lm.AddPointLight(pointLight);
    }
示例#2
0
    protected override void Start()
    {
        base.Start();
        pointLight          = new PointLightParam();
        pointLight.position = transform.position;
        pointLight.color    = Color.white * 0.5f;
        pointLight.range    = 3.0f;

        LightManager lm = Camera.main.GetComponent <LightManager>();

        lm.AddPointLight(pointLight);
    }
        /// <summary>
        /// Called when the GameComponent needs to be updated. Override this method with component-specific update code.
        /// </summary>
        /// <param name="gameTime">Time elapsed since the last call to Update</param>
        public override void Update(GameTime gameTime)
        {
            float dt = gameTime.ElapsedGameTime.Milliseconds / 1000.0f;

            KeyboardState keyboardState = Keyboard.GetState();
            MouseState    mouseState    = Mouse.GetState();

            // Toggle shadow rendering on and off
            if (keyboardState.IsKeyDown(Keys.T) && lastKeyboardState.IsKeyUp(Keys.T))
            {
                ShadowRenderer.Enabled = !ShadowRenderer.Enabled;
            }

            // Switch through shadowmap filtering techniques
            if (keyboardState.IsKeyDown(Keys.G) && lastKeyboardState.IsKeyUp(Keys.G))
            {
                shadowRenderer.ShadowFilteringType = (ShadowFilteringType)((((int)shadowRenderer.ShadowFilteringType) + 1) % 4);
            }

            // Move the camera with keyboard and mouse input
            float cameraMoveAmount   = 50.0f * dt;
            float cameraRotateAmount = 0.25f * dt;
            float modelRotateAmount  = 0.5f * dt;

            if (keyboardState.IsKeyDown(Keys.W))
            {
                camera.Position += camera.WorldMatrix.Forward * cameraMoveAmount;
            }
            if (keyboardState.IsKeyDown(Keys.S))
            {
                camera.Position += camera.WorldMatrix.Backward * cameraMoveAmount;
            }
            if (keyboardState.IsKeyDown(Keys.A))
            {
                camera.Position += camera.WorldMatrix.Left * cameraMoveAmount;
            }
            if (keyboardState.IsKeyDown(Keys.D))
            {
                camera.Position += camera.WorldMatrix.Right * cameraMoveAmount;
            }
            if (keyboardState.IsKeyDown(Keys.Q))
            {
                camera.Position += camera.WorldMatrix.Up * cameraMoveAmount;
            }
            if (keyboardState.IsKeyDown(Keys.E))
            {
                camera.Position += camera.WorldMatrix.Down * cameraMoveAmount;
            }
            if (keyboardState.IsKeyDown(Keys.D1))
            {
                shadowRenderer.ShadowFilteringType = ShadowFilteringType.PCF2x2;
            }
            if (keyboardState.IsKeyDown(Keys.D2))
            {
                shadowRenderer.ShadowFilteringType = ShadowFilteringType.PCF3x3;
            }
            if (keyboardState.IsKeyDown(Keys.D3))
            {
                shadowRenderer.ShadowFilteringType = ShadowFilteringType.PCF5x5;
            }
            if (keyboardState.IsKeyDown(Keys.D4))
            {
                shadowRenderer.ShadowFilteringType = ShadowFilteringType.PCF7x7;
            }

            if (keyboardState.IsKeyDown(Keys.Space))
            {
                LightManager.AddPointLight(new Lights.PointLight(camera.Position, Color.Yellow.ToVector3(), 50f, 1));
            }

            if (keyboardState.IsKeyDown(Keys.PageDown))
            {
                skyRenderer.Theta -= 0.4f * dt;
            }

            if (lastMouseX == -1)
            {
                lastMouseX = mouseState.X;
            }
            if (lastMouseY == -1)
            {
                lastMouseY = mouseState.Y;
            }

            int mouseMoveX = mouseState.X - lastMouseX;
            int mouseMoveY = mouseState.Y - lastMouseY;

            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                camera.YRotation -= cameraRotateAmount * mouseMoveX;
                camera.XRotation -= cameraRotateAmount * mouseMoveY;
            }

            SkyRenderer.Parameters.LightDirection = new Vector4(LightManager.Light.Direction, 1);
            SkyRenderer.Parameters.LightColor     = new Vector4(LightManager.Light.Color, 1);
            skyRenderer.Update(gameTime);

            Game.Window.Title = String.Format("X:{0} = Y:{1} = Z:{2}", camera.Position.X, camera.Position.Y, camera.Position.Z);

            lastMouseX        = mouseState.X;
            lastMouseY        = mouseState.Y;
            lastKeyboardState = keyboardState;

            base.Update(gameTime);
        }
示例#4
0
        public void Main(string[] args)
        {
            using (AgateSetup setup = new AgateSetup(args))
            {
                setup.AskUser = true;
                setup.Initialize(true, false, false);
                if (setup.WasCanceled)
                {
                    return;
                }

                LightingTestForm frm = new LightingTestForm();
                frm.Show();

                DisplayWindow wnd = new DisplayWindow(CreateWindowParams.FromControl(frm.agateRenderTarget1));

                Surface image = new Surface("jellybean.png");
                Surface ball  = new Surface("ball.png");
                Point   ballPt;
                double  time = 0;

                image.SetScale(2.0, 2.0);
                ball.DisplayAlignment = OriginAlignment.Center;

                LightManager lights = new LightManager();
                lights.Enabled = true;
                lights.AddPointLight(new Vector3(0, 0, -1), Color.White);
                lights.AddPointLight(new Vector3(0, 0, -1), Color.Yellow);

                Display.VSync = false;

                //lights[0].Ambient = Color.White;
                lights[1].AttenuationConstant  = 0.01f;
                lights[1].AttenuationQuadratic = 5e-7f;

                Mouse.MouseMove += delegate(InputEventArgs e)
                {
                    lights[1].Position =
                        new Vector3(e.MousePosition.X, e.MousePosition.Y, -1);
                };

                while (frm.Visible == true)
                {
                    if (frm.chkMoveLight.Checked)
                    {
                        time += Display.DeltaTime / 1000.0;
                    }


                    ballPt = new Point((int)(120 + 110 * Math.Cos(time)),
                                       (int)(120 + 110 * Math.Sin(time)));

                    lights[0].Position = new Vector3(ballPt.X, ballPt.Y, -1);
                    lights[0].Ambient  = Color.FromArgb(frm.btnAmbient.BackColor.ToArgb());
                    lights[0].Diffuse  = Color.FromArgb(frm.btnDiffuse.BackColor.ToArgb());

                    image.RotationAngleDegrees = (double)frm.nudAngle.Value;

                    Display.BeginFrame();
                    Display.Clear(Color.DarkRed);

                    lights.Enabled = frm.enableLightingCheck.Checked;
                    lights.DoLighting();

                    if (frm.chkSurfaceGradient.Checked)
                    {
                        Gradient g = new Gradient(Color.Red, Color.Blue, Color.Cyan, Color.Green);

                        image.ColorGradient = g;
                    }
                    else
                    {
                        image.Color = Color.White;
                    }

                    image.TesselateFactor = (int)frm.nudTess.Value;

                    image.Draw(50, 50);

                    image.Draw(50 + image.DisplayWidth, 50);
                    image.Draw(50, 50 + image.DisplayHeight);

                    ball.Draw(ballPt);

                    Display.EndFrame();
                    Core.KeepAlive();

                    frm.lblFPS.Text = "FPS: " + Display.FramesPerSecond.ToString("0.00");
                }
            }
        }