diff options
author | Paul Gilbert | 2017-05-26 21:21:29 -0400 |
---|---|---|
committer | Paul Gilbert | 2017-05-26 21:21:29 -0400 |
commit | 50a6100d27803a070f019aafb816151cb775dfe9 (patch) | |
tree | fd04fb32d218c4f13f0303317e54f7936f273772 /engines | |
parent | f9f835e08092f7dbbc887e2164748bfd9ffcc704 (diff) | |
download | scummvm-rg350-50a6100d27803a070f019aafb816151cb775dfe9.tar.gz scummvm-rg350-50a6100d27803a070f019aafb816151cb775dfe9.tar.bz2 scummvm-rg350-50a6100d27803a070f019aafb816151cb775dfe9.zip |
TITANIC: Simplify FVector addAndNormalize
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/star_control/fvector.cpp | 9 | ||||
-rw-r--r-- | engines/titanic/star_control/fvector.h | 5 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub24.cpp | 28 |
3 files changed, 16 insertions, 26 deletions
diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp index ff07b9bd03..a107ad1ed2 100644 --- a/engines/titanic/star_control/fvector.cpp +++ b/engines/titanic/star_control/fvector.cpp @@ -58,12 +58,11 @@ float FVector::normalize() { return hyp; } -const FVector *FVector::addAndNormalize(FVector &dest, const FVector &v1, const FVector &v2) { - FVector tempVector(v1._x + v2._x, v1._y + v2._y, v1._z + v2._z); - tempVector.normalize(); +FVector FVector::addAndNormalize(const FVector &v) const { + FVector tempV(_x + v._x, _y + v._y, _z + v._z); + tempV.normalize(); - dest = tempVector; - return &dest; + return tempV; } float FVector::getDistance(const FVector &src) const { diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h index a9cb44a19c..fa24fe58c1 100644 --- a/engines/titanic/star_control/fvector.h +++ b/engines/titanic/star_control/fvector.h @@ -64,9 +64,10 @@ public: float normalize(); /** - * Adds two vectors together and then normalizes the result + * Adds the current vector and a passed one together, normalizes them, + * and then returns the resulting vector */ - static const FVector *addAndNormalize(FVector &dest, const FVector &v1, const FVector &v2); + FVector addAndNormalize(const FVector &v) const; /** * Returns the distance between a specified point and this one diff --git a/engines/titanic/star_control/star_control_sub24.cpp b/engines/titanic/star_control/star_control_sub24.cpp index 4ceb82f7fc..cac8850774 100644 --- a/engines/titanic/star_control/star_control_sub24.cpp +++ b/engines/titanic/star_control/star_control_sub24.cpp @@ -57,17 +57,11 @@ void CStarControlSub24::setPath(const FVector &srcV, const FVector &destV, const } if (!flag) { - const FVector *tv; - FVector tempV1, tempV2; - FVector::addAndNormalize(tempV1, row3, _posDelta); - tv = FVector::addAndNormalize(tempV2, row3, tempV1); - tempV1 = *tv; - - tv = FVector::addAndNormalize(tempV2, row3, tempV1); - tempV1 = *tv; - - tv = FVector::addAndNormalize(tempV2, row3, tempV1); - tempV1 = *tv; + FVector tempV1; + tempV1 = row3.addAndNormalize(_posDelta); + tempV1 = row3.addAndNormalize(tempV1); + tempV1 = row3.addAndNormalize(tempV1); + tempV1 = row3.addAndNormalize(tempV1); FMatrix newOrient; newOrient.fn1(tempV1); @@ -81,7 +75,6 @@ void CStarControlSub24::setPath(const FVector &srcV, const FVector &destV, const int CStarControlSub24::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orientation) { FVector v1, v2, v3, v4; - const FVector *tv; if (!_active) return 0; @@ -116,13 +109,10 @@ int CStarControlSub24::proc5(CErrorCode &errorCode, FVector &pos, FMatrix &orien } if (!flag) { - v2.addAndNormalize(v1, v2, v3); - tv = v2.addAndNormalize(v4, v2, v1); - v1 = *tv; - tv = v2.addAndNormalize(v4, v2, v1); - v1 = *tv; - tv = v2.addAndNormalize(v4, v2, v1); - v1 = *tv; + v1 = v2.addAndNormalize(v3); + v1 = v2.addAndNormalize(v1); + v1 = v2.addAndNormalize(v1); + v1 = v2.addAndNormalize(v1); orientation.fn1(v1); v2 = v1; |