Fixed camera sometimes doing an all-round turn to reach its target
This commit is contained in:
parent
dbcaf5fe90
commit
ff23d1a932
2 changed files with 21 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "CameraDefinition.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "Maths.h"
|
||||
#include "PackStream.h"
|
||||
#include "BoundingBox.h"
|
||||
|
||||
|
@ -249,10 +250,9 @@ bool CameraDefinition::transitionToAnother(const CameraDefinition *wanted, doubl
|
|||
dy = wanted->location.y - location.y;
|
||||
dz = wanted->location.z - location.z;
|
||||
dr = wanted->direction.r - direction.r;
|
||||
// TODO pi-modulo nearest
|
||||
dphi = wanted->direction.phi - direction.phi;
|
||||
dtheta = wanted->direction.theta - direction.theta;
|
||||
droll = wanted->roll - roll;
|
||||
dphi = Maths::modInRange(wanted->direction.phi - direction.phi, -Maths::PI, Maths::PI);
|
||||
dtheta = Maths::modInRange(wanted->direction.theta - direction.theta, -Maths::PI, Maths::PI);
|
||||
droll = Maths::modInRange(wanted->roll - roll, -Maths::PI, Maths::PI);
|
||||
|
||||
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) {
|
||||
|
|
|
@ -42,3 +42,20 @@ TEST(CameraDefinition, getRealDepth) {
|
|||
point = cam.project(Vector3(12.5, 12.0, 58.0));
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue