// Translate 2D mouse input into euler angle rotations. private CameraState Look(CameraState state, Action.Look action) { Quaternion localRotation = state.localRotation; Vector2 rotation = action.inputRotation; float time = action.fixedDeltaTime; // inputLook.y rotates the camera around the horizontal axis (with + being up) Vector3 vertLook = rotation.y * time * Vector3.left * settings_.yLookSpeed; Quaternion cameraLookRotation = localRotation * Quaternion.Euler(vertLook); // We have to flip the signs and positions of min/max view angle here because the math // uses the contradictory interpretation of our angles (+/- is down/up). Quaternion clampedRotation = ClampRotationAroundXAxis_(cameraLookRotation, -settings_.maxViewAngle, -settings_.minViewAngle); state.isLooking = true; state.localRotation = clampedRotation; // Debug.Log($"in Look, returning state: {ObjectDumper.Dump(state)}"); return(state); }
public void Should_return_accurate_move_distance_from_move_reducer() { // stub action var mockLookAction = new Action.Look { inputRotation = Vector2.up, fixedDeltaTime = 1.0f }; // stub state condition var mockCameraState = new CameraState { isLooking = false, localRotation = new Quaternion(1f, 1f, 1f, 1f) }; var sut = container_.Resolve <Reducer>(); var result = sut.Reduce(mockCameraState, mockLookAction); Debug.Log(ObjectDumper.Dump(result)); Assert.IsTrue(result.isLooking); // Assert.Equals(result.localRotation, Quaternion.Euler(1f,1f,1f)); }