void HandleInput(GameTime gameTime) { float time = (float) gameTime.ElapsedGameTime.TotalMilliseconds; lastKeyboardState = currentKeyboardState; lastGamePadState = currentGamePadState; currentKeyboardState = Keyboard.GetState(); currentGamePadState = GamePad.GetState(PlayerIndex.One); rotateDude += currentGamePadState.Triggers.Right * time * 0.2f; rotateDude -= currentGamePadState.Triggers.Left * time * 0.2f; if (currentKeyboardState.IsKeyDown(Keys.Q)) rotateDude -= time * 0.2f; if (currentKeyboardState.IsKeyDown(Keys.E)) rotateDude += time * 0.2f; if (currentKeyboardState.IsKeyUp(Keys.B) && lastKeyboardState.IsKeyDown(Keys.B) || currentGamePadState.IsButtonUp(Buttons.B) && lastGamePadState.IsButtonDown(Buttons.B)) { currentLightCameraType++; if (LightCameraType.Basic < currentLightCameraType) currentLightCameraType = LightCameraType.LiSPSM; } if (currentKeyboardState.IsKeyUp(Keys.Y) && lastKeyboardState.IsKeyDown(Keys.Y) || currentGamePadState.IsButtonUp(Buttons.Y) && lastGamePadState.IsButtonDown(Buttons.Y)) { useCameraFrustumSceneBox = !useCameraFrustumSceneBox; } if (currentKeyboardState.IsKeyUp(Keys.X) && lastKeyboardState.IsKeyDown(Keys.X) || currentGamePadState.IsButtonUp(Buttons.X) && lastGamePadState.IsButtonDown(Buttons.X)) { if (shadowMapForm == ShadowMapForm.Basic) { shadowMapForm = ShadowMapForm.Variance; } else { shadowMapForm = ShadowMapForm.Basic; } } if (currentKeyboardState.IsKeyUp(Keys.K) && lastKeyboardState.IsKeyDown(Keys.K) || currentGamePadState.IsButtonUp(Buttons.RightShoulder) && lastGamePadState.IsButtonDown(Buttons.RightShoulder)) { splitCount++; if (MaxSplitCount < splitCount) splitCount = 1; } if (currentKeyboardState.IsKeyUp(Keys.L) && lastKeyboardState.IsKeyDown(Keys.L) || currentGamePadState.IsButtonUp(Buttons.LeftShoulder) && lastGamePadState.IsButtonDown(Buttons.LeftShoulder)) { currentShadowMapSizeIndex++; if (ShadowMapSizes.Length <= currentShadowMapSizeIndex) currentShadowMapSizeIndex = 0; if (gaussianBlur != null) { gaussianBlur.Dispose(); gaussianBlur = null; } } if (currentKeyboardState.IsKeyDown(Keys.Escape) || currentGamePadState.Buttons.Back == ButtonState.Pressed) { Exit(); } }
public MainGame() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = WindowWidth; graphics.PreferredBackBufferHeight = WindowHeight; camera = new BasicCamera { Position = new Vector3(0, 70, 100), Direction = new Vector3(0, -0.4472136f, -0.8944272f), Fov = MathHelper.PiOver4, AspectRatio = (float) WindowWidth / (float) WindowHeight, NearClipDistance = 1.0f, FarClipDistance = 1000.0f }; cameraFrustum = new BoundingFrustum(Matrix.Identity); corners = new Vector3[8]; // gridModel が半径約 183 であるため、 // これを含むように簡易シーン AABB を決定。 // なお、広大な世界を扱う場合には、表示カメラの視錐台に含まれるオブジェクト、 // および、それらに投影しうるオブジェクトを動的に選択および決定し、 // 適切な最小シーン領域を算出して利用する。 sceneBox = new BoundingBox(new Vector3(-200), new Vector3(200)); useCameraFrustumSceneBox = true; currentLightCameraType = LightCameraType.LiSPSM; basicLightCameraBuilder = new BasicLightCameraBuilder(); uniformLightCameraBuilder = new UniformLightCameraBuilder(); uniformLightCameraBuilder.LightFarClipDistance = lightFar; liSPSMLightCameraBuilder = new LiSPSMLightCameraBuilder(); liSPSMLightCameraBuilder.LightFarClipDistance = lightFar; splitCount = MaxSplitCount; pssm = new PSSM(); pssm.Fov = camera.Fov; pssm.AspectRatio = camera.AspectRatio; pssm.NearClipDistance = camera.NearClipDistance; pssm.FarClipDistance = camera.FarClipDistance; splitDistances = new float[MaxSplitCount + 1]; splitProjections = new Matrix[MaxSplitCount]; shadowMaps = new ShadowMap[MaxSplitCount]; lightViewProjections = new Matrix[MaxSplitCount]; shadowMapForm = ShadowMapForm.Basic; // 単位ベクトル。 lightDirection = new Vector3(0.3333333f, -0.6666667f, -0.6666667f); currentFrustum = new BoundingFrustum(Matrix.Identity); }