public void Update(double dt) { if (m_player == null) { return; } var layoutC = m_player.FindComponent <LayoutComponent>(); Debug.Assert(layoutC != null, ""); Matrix headRotTrans = Matrix.Identity; if (m_isEnableHeadRotation) { var gameSys = GameSystem.GetInstance(); switch (gameSys.Config.InputDevice) { case GameConfig.UserInputDevices.MouseKeyboard: break; case GameConfig.UserInputDevices.Pad: { IPadInputSource src = InputSystem.GetInstance().Pad; var thumbDir = src.RightThumbInput.Direction; float magnitude = src.RightThumbInput.NormalizedMagnitude; if (magnitude >= MinimumPadMagnitude) { float maxAngle = 0.9f; m_headRotAngle.X = Math.Min(Math.Max(m_headRotAngle.X + thumbDir.Y * (float)dt, -maxAngle), maxAngle); m_headRotAngle.Y = Math.Min(Math.Max(m_headRotAngle.Y + thumbDir.X * (float)dt, -maxAngle), maxAngle); m_headRotAngle.Z = 0; } else { m_headRotAngle *= 0.9f; } } break; } headRotTrans = Matrix.RotationYawPitchRoll(m_headRotAngle.Y, m_headRotAngle.X, m_headRotAngle.Z); } //var markerC = m_player.FindComponent<ModelMarkerComponent>(); //Debug.Assert(markerC != null, ""); //var mtx = markerC.FindMarkerMatrix(10) * layoutC.Transform; var mtx = headRotTrans * layoutC.Transform * Matrix.Translation(0, 1, 0); Vector3 eye, lookAt, up; eye = mtx.TranslationVector + Vector3.UnitY; lookAt = eye + mtx.Forward * Zoom; up = Vector3.UnitY; m_camera = new DrawSystem.CameraData(eye, lookAt, up); }
/// <summary> /// Update component /// </summary> /// <param name="dT">spend time [sec]</param> public override void Update(double dT) { var cameraSys = CameraSystem.GetInstance(); var drawSys = DrawSystem.GetInstance(); // Calc camera var viewHeadMat = cameraSys.GetCameraData().GetViewMatrix() * drawSys.GetDrawContext().GetHeadMatrix(); viewHeadMat.Invert(); var moveDirection = new Vector3(viewHeadMat.Backward.X, 0, viewHeadMat.Backward.Z); moveDirection.Normalize(); var gameSys = GameSystem.GetInstance(); switch (gameSys.Config.InputDevice) { case GameConfig.UserInputDevices.MouseKeyboard: { IMouseKeyboardInputSource src = InputSystem.GetInstance().MouseKeyboard; var v = Vector3.Zero; if (src.TestKeyState(Keys.W)) { v.Z += PositionFactor; } if (src.TestKeyState(Keys.A)) { v.X -= PositionFactor; } if (src.TestKeyState(Keys.D)) { v.X += PositionFactor; } if (src.TestKeyState(Keys.S)) { v.Z -= PositionFactor; } if (v.X != 0 || v.Z != 0) { float angleY = (float)Math.Atan2(moveDirection.X, moveDirection.Z); v = Vector3.Transform(v, Matrix3x3.RotationY(angleY)); m_behaviorC.RequestMove(v); m_behaviorC.RequestTurn(v); } } break; case GameConfig.UserInputDevices.Pad: { IPadInputSource src = InputSystem.GetInstance().Pad; float angleY = (float)Math.Atan2(moveDirection.X, moveDirection.Z); var thumbDir = src.LeftThumbInput.Direction; float magnitude = src.LeftThumbInput.NormalizedMagnitude; if (magnitude >= MinimumPadMagnitude) { var v = new Vector3(thumbDir.X, 0, thumbDir.Y); v = Vector3.Transform(v, Matrix3x3.RotationY(angleY)); v = v * magnitude; m_behaviorC.RequestMove(v); m_behaviorC.RequestTurn(v); } } break; default: Debug.Fail("unsupported input device type : " + gameSys.Config.InputDevice); break; } }
/// <summary> /// Update component /// </summary> /// <param name="dT">spend time [sec]</param> public override void Update(double dT) { var mapSys = MapSystem.GetInstance(); m_coroutine.Update(dT); if (!m_coroutine.HasCompleted()) { // wait for end of character operation return; } var cameraSys = CameraSystem.GetInstance(); var drawSys = DrawSystem.GetInstance(); var gameSys = GameSystem.GetInstance(); switch (gameSys.Config.InputDevice) { case GameConfig.UserInputDevices.MouseKeyboard: { IMouseKeyboardInputSource src = InputSystem.GetInstance().MouseKeyboard; var v = Vector3.Zero; if (src.TestKeyState(Keys.W)) { v.Z += PositionFactor; } if (src.TestKeyState(Keys.A)) { v.X -= PositionFactor; } if (src.TestKeyState(Keys.D)) { v.X += PositionFactor; } if (src.TestKeyState(Keys.S)) { v.Z -= PositionFactor; } if (v.X != 0 || v.Z != 0) { // @todo } } break; case GameConfig.UserInputDevices.Pad: { IPadInputSource src = InputSystem.GetInstance().Pad; // update move { _InputType inputType = _InputType.None; var thumbDir = src.LeftThumbInput.Direction; float magnitude = src.LeftThumbInput.NormalizedMagnitude; if (magnitude >= MinimumPadMagnitude) { // use pad stick if (thumbDir.Y <= -0.851) { inputType = _InputType.Backward; } else if (thumbDir.Y >= 0.851) { inputType = _InputType.Forward; } else { if (thumbDir.X < 0) { inputType = _InputType.Left; } else { inputType = _InputType.Right; } } } else { // use pad cross key if (src.TestButtonState(InputSystem.PadButtons.Down)) { inputType = _InputType.Backward; } else if (src.TestButtonState(InputSystem.PadButtons.Up)) { inputType = _InputType.Forward; } else if (src.TestButtonState(InputSystem.PadButtons.Left)) { inputType = _InputType.Left; } else if (src.TestButtonState(InputSystem.PadButtons.Right)) { inputType = _InputType.Right; } } #if true switch (inputType) { case _InputType.Forward: { var nextDir = MapLocation.GetForwardDirection(m_currentLocation.Direction); MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir); if (nextLocation.HasValue) { m_currentLocation = nextLocation.Value; var pose = mapSys.GetPose(m_currentLocation); m_coroutine.Start(new _MoveToTask(this, pose.TranslationVector)); // no turn } } break; case _InputType.Backward: { var nextDir = MapLocation.GetBackwardDirection(m_currentLocation.Direction); m_currentLocation.Direction = nextDir; var pose = mapSys.GetPose(m_currentLocation); m_coroutine.Start(new _TurnToTask(this, pose.Forward)); } break; case _InputType.Left: { var nextDir = MapLocation.GetLeftDirection(m_currentLocation.Direction); m_currentLocation.Direction = nextDir; var pose = mapSys.GetPose(m_currentLocation); m_coroutine.Start(new _TurnToTask(this, pose.Forward)); } break; case _InputType.Right: { var nextDir = MapLocation.GetRightDirection(m_currentLocation.Direction); m_currentLocation.Direction = nextDir; var pose = mapSys.GetPose(m_currentLocation); m_coroutine.Start(new _TurnToTask(this, pose.Forward)); } break; } #else switch (inputType) { case _InputType.Forward: { var nextDir = MapLocation.GetForwardDirection(m_currentLocation.Direction); MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir); if (nextLocation.HasValue) { m_currentLocation = nextLocation.Value; var pose = mapSys.GetPose(m_currentLocation); m_coroutine.Start(new _MoveToTask(this, pose.TranslationVector)); // no turn } } break; case _InputType.Backward: { var nextDir = MapLocation.GetBackwardDirection(m_currentLocation.Direction); MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir); if (nextLocation.HasValue) { m_currentLocation = nextLocation.Value; var pose = mapSys.GetPose(m_currentLocation); m_coroutine.Start(Coroutine.Join(new _TurnToTask(this, pose.Forward), new _MoveToTask(this, pose.TranslationVector))); } } break; case _InputType.Left: { var nextDir = MapLocation.GetLeftDirection(m_currentLocation.Direction); MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir); if (nextLocation.HasValue) { m_currentLocation = nextLocation.Value; var pose = mapSys.GetPose(m_currentLocation); m_coroutine.Start(Coroutine.Join(new _TurnToTask(this, pose.Forward), new _MoveToTask(this, pose.TranslationVector))); } } break; case _InputType.Right: { var nextDir = MapLocation.GetRightDirection(m_currentLocation.Direction); MapLocation?nextLocation = mapSys.Walk(m_currentLocation, nextDir); if (nextLocation.HasValue) { m_currentLocation = nextLocation.Value; var pose = mapSys.GetPose(m_currentLocation); m_coroutine.Start(Coroutine.Join(new _TurnToTask(this, pose.Forward), new _MoveToTask(this, pose.TranslationVector))); } } break; } #endif } } break; default: Debug.Fail("unsupported input device type : " + gameSys.Config.InputDevice); break; } }