aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/star_control/fvector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic/star_control/fvector.cpp')
-rw-r--r--engines/titanic/star_control/fvector.cpp60
1 files changed, 55 insertions, 5 deletions
diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp
index d880a134f5..4fd17bf883 100644
--- a/engines/titanic/star_control/fvector.cpp
+++ b/engines/titanic/star_control/fvector.cpp
@@ -21,16 +21,11 @@
*/
#include "titanic/star_control/fvector.h"
-#include "titanic/star_control/dvector.h"
#include "titanic/star_control/fpose.h"
-//#include "common/algorithm.h"
//#include "common/textconsole.h"
namespace Titanic {
-FVector::FVector(const DVector &src) : _x(src._x), _y(src._y), _z(src._z) {
-}
-
FVector FVector::swapComponents() const {
return FVector(
(ABS(_x - _y) < 0.00001 && ABS(_y - _z) < 0.00001 &&
@@ -48,6 +43,16 @@ FVector FVector::crossProduct(const FVector &src) const {
);
}
+void FVector::rotVectAxisY(float angleDeg) {
+ float sinVal = sin(angleDeg * Deg2Rad);
+ float cosVal = cos(angleDeg * Deg2Rad);
+ float x = cosVal * _x - sinVal * _z;
+ float z = cosVal * _z + sinVal * _x;
+
+ _x = x;
+ _z = z;
+}
+
bool FVector::normalize(float & hyp) {
hyp = sqrt(_x * _x + _y * _y + _z * _z);
if (hyp==0) {
@@ -73,6 +78,23 @@ FVector FVector::addAndNormalize(const FVector &v) const {
return tempV;
}
+FVector FVector::getAnglesAsVect() const {
+ FVector vector = *this;
+ FVector dest;
+
+ if (!vector.normalize(dest._x)) {
+ // Makes this vector have magnitude=1, put the scale amount in dest._x,
+ // but if it is unsuccessful, crash
+ assert(dest._x);
+ }
+
+ dest._y = acos(vector._y); // radian distance/angle that this vector's y component is from the +y axis,
+ // result is restricted to [0,pi]
+ dest._z = atan2(vector._x,vector._z); // result is restricted to [-pi,pi]
+
+ return dest;
+}
+
float FVector::getDistance(const FVector &src) const {
float xd = src._x - _x;
float yd = src._y - _y;
@@ -89,6 +111,34 @@ FVector FVector::MatProdRowVect(const FPose &pose) const {
return v;
}
+FPose FVector::getFrameTransform(const FVector &v) {
+ FPose matrix1, matrix2, matrix3, matrix4;
+
+ FVector vector1 = getAnglesAsVect();
+ matrix1.setRotationMatrix(X_AXIS, vector1._y * Rad2Deg);
+ matrix2.setRotationMatrix(Y_AXIS, vector1._z * Rad2Deg);
+ fposeProd(matrix1,matrix2,matrix3);
+ matrix4 = matrix3.inverseTransform();
+
+ vector1 = v.getAnglesAsVect();
+ matrix1.setRotationMatrix(X_AXIS, vector1._y * Rad2Deg);
+ matrix2.setRotationMatrix(Y_AXIS, vector1._z * Rad2Deg);
+ fposeProd(matrix1,matrix2,matrix3);
+ fposeProd(matrix4,matrix3,matrix1);
+
+ return matrix1;
+}
+
+FPose FVector::formRotXY() const {
+ FVector v1 = getAnglesAsVect();
+ FPose m1, m2;
+ m1.setRotationMatrix(X_AXIS, v1._y * Rad2Deg);
+ m2.setRotationMatrix(Y_AXIS, v1._z * Rad2Deg);
+ FPose m3;
+ fposeProd(m1,m2,m3);
+ return m3;
+}
+
Common::String FVector::toString() const {
return Common::String::format("(%.3f,%.3f,%.3f)", _x, _y, _z);
}