Fixed camera sometimes doing an all-round turn to reach its target

This commit is contained in:
Michaël Lemaire 2015-12-31 00:36:42 +01:00
parent dbcaf5fe90
commit ff23d1a932
2 changed files with 21 additions and 4 deletions

View file

@ -1,6 +1,7 @@
#include "CameraDefinition.h" #include "CameraDefinition.h"
#include <cmath> #include <cmath>
#include "Maths.h"
#include "PackStream.h" #include "PackStream.h"
#include "BoundingBox.h" #include "BoundingBox.h"
@ -249,10 +250,9 @@ bool CameraDefinition::transitionToAnother(const CameraDefinition *wanted, doubl
dy = wanted->location.y - location.y; dy = wanted->location.y - location.y;
dz = wanted->location.z - location.z; dz = wanted->location.z - location.z;
dr = wanted->direction.r - direction.r; dr = wanted->direction.r - direction.r;
// TODO pi-modulo nearest dphi = Maths::modInRange(wanted->direction.phi - direction.phi, -Maths::PI, Maths::PI);
dphi = wanted->direction.phi - direction.phi; dtheta = Maths::modInRange(wanted->direction.theta - direction.theta, -Maths::PI, Maths::PI);
dtheta = wanted->direction.theta - direction.theta; droll = Maths::modInRange(wanted->roll - roll, -Maths::PI, Maths::PI);
droll = wanted->roll - roll;
if (fabs(dx) < 0.000001 && fabs(dy) < 0.000001 && fabs(dz) < 0.000001 && fabs(dr) < 0.000001 && if (fabs(dx) < 0.000001 && fabs(dy) < 0.000001 && fabs(dz) < 0.000001 && fabs(dr) < 0.000001 &&
fabs(dphi) < 0.000001 && fabs(dtheta) < 0.000001 && fabs(droll) < 0.000001) { fabs(dphi) < 0.000001 && fabs(dtheta) < 0.000001 && fabs(droll) < 0.000001) {

View file

@ -42,3 +42,20 @@ TEST(CameraDefinition, getRealDepth) {
point = cam.project(Vector3(12.5, 12.0, 58.0)); point = cam.project(Vector3(12.5, 12.0, 58.0));
ASSERT_DOUBLE_EQ(cam.getRealDepth(point), 12.5); ASSERT_DOUBLE_EQ(cam.getRealDepth(point), 12.5);
} }
TEST(CameraDefinition, transitionToAnother) {
CameraDefinition cur;
CameraDefinition dest;
cur.setLocationCoords(0.0, 0.0, 0.0);
cur.setTargetCoords(1.0, 0.0, 0.0);
dest.setLocationCoords(2.0, 1.0, 8.0);
dest.setTargetCoords(2.0, 1.0, 9.0);
bool result = cur.transitionToAnother(&dest, 0.5);
EXPECT_TRUE(result);
EXPECT_VECTOR3_COORDS(cur.getLocation(), 1.0, 0.5, 4.0);
EXPECT_VECTOR3_COORDS(cur.getTarget(), 1.70710678118654746, 0.5, 4.70710678118654746);
}