void TestToVectorSystem(const AngleToVectorSystem system, const int zero_axis, const int ninety_axis, const int ignored_axis) { // Angle zero should translate to the zero axis. const vec3 zero = Angle(0.0f).ToVectorSystem(system); EXPECT_NEAR(zero[zero_axis], 1.0f, kUnitVectorPrecision); EXPECT_NEAR(zero[ninety_axis], 0.0f, kUnitVectorPrecision); EXPECT_NEAR(zero[ignored_axis], 0.0f, kUnitVectorPrecision); // Angle 180 should translate to the negative zero axis. const vec3 minus_zero = Angle(kPi).ToVectorSystem(system); EXPECT_NEAR(minus_zero[zero_axis], -1.0f, kUnitVectorPrecision); EXPECT_NEAR(minus_zero[ninety_axis], 0.0f, kUnitVectorPrecision); EXPECT_NEAR(minus_zero[ignored_axis], 0.0f, kUnitVectorPrecision); // Angle 90 should translate to the 90 axis. const vec3 ninety = Angle(kHalfPi).ToVectorSystem(system); EXPECT_NEAR(ninety[zero_axis], 0.0f, kUnitVectorPrecision); EXPECT_NEAR(ninety[ninety_axis], 1.0f, kUnitVectorPrecision); EXPECT_NEAR(ninety[ignored_axis], 0.0f, kUnitVectorPrecision); // Angle -90 should translate to the -90 axis. const vec3 minus_ninety = Angle(-kHalfPi).ToVectorSystem(system); EXPECT_NEAR(minus_ninety[zero_axis], 0.0f, kUnitVectorPrecision); EXPECT_NEAR(minus_ninety[ninety_axis], -1.0f, kUnitVectorPrecision); EXPECT_NEAR(minus_ninety[ignored_axis], 0.0f, kUnitVectorPrecision); // Angle 45 should translate to a unit vector between the 0 and 90 axes. const vec3 forty_five = Angle(kQuarterPi).ToVectorSystem(system); const float one_over_root_two = 1.0f / sqrt(2.0f); EXPECT_NEAR(forty_five[zero_axis], one_over_root_two, kUnitVectorPrecision); EXPECT_NEAR(forty_five[ninety_axis], one_over_root_two, kUnitVectorPrecision); EXPECT_NEAR(forty_five[ignored_axis], 0.0f, kUnitVectorPrecision); }
static void UpdateCamera(fplbase::InputSystem* input, Camera* camera) { const fplbase::InputPointer& pointer = input->get_pointers()[0]; if (!pointer.used) return; // Update latitude and longitude: left mouse drag. if (input->GetButton(fplbase::K_POINTER1).is_down() && pointer.mousedelta != mathfu::kZeros2i) { const float lat = camera->latitude.ToRadians() + pointer.mousedelta.y * kLatitudeSensitivity; camera->latitude = Angle(mathfu::Clamp(lat, -kMaxLatitude, kMaxLatitude)); camera->longitude += Angle(pointer.mousedelta.x * kLongitudeSensitivity); } // Update distance: right mouse drag. // (Unfortunately, InputSystem doesn't support scroll wheels yet) if (input->GetButton(fplbase::K_POINTER3).is_down() && pointer.mousedelta != mathfu::kZeros2i) { const float dist = camera->distance + (pointer.mousedelta.x + pointer.mousedelta.y) * kDistanceSensitivity; camera->distance = std::max(dist, camera->z_near); } // Update target: middle mouse drag. if (input->GetButton(fplbase::K_POINTER2).is_down() && pointer.mousedelta != mathfu::kZeros2i) { const vec3 right = CameraRight(*camera); const vec3 up = VectorSystemUp(camera->coordinate_system); const vec2 dist = kTargetSensitivity * vec2(pointer.mousedelta); camera->target += dist[0] * right + dist[1] * up; } }
virtual void SetUp() { above_pi_ = MinutelyDifferentFloat(kPi, 1); below_pi_ = MinutelyDifferentFloat(kPi, -1); above_negative_pi_ = MinutelyDifferentFloat(-kPi, -1); below_negative_pi_ = MinutelyDifferentFloat(-kPi, 1); half_pi_ = Angle(kHalfPi); }
// Unary negate should send pi to pi, because -pi is not in range. TEST_F(AngleTests, NegatePi) { const Angle a = Angle(kPi); const Angle negative_a = -a; EXPECT_FLOAT_EQ(negative_a.ToRadians(), kPi); }
// Unary negate should change the sign. TEST_F(AngleTests, Negate) { const Angle a = Angle(kHalfPi); EXPECT_FLOAT_EQ(-a.ToRadians(), -kHalfPi); }