Skip to content

Commit

Permalink
TITANIC: Simplify FVector addAndNormalize
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 27, 2017
1 parent f9f835e commit 50a6100
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
9 changes: 4 additions & 5 deletions engines/titanic/star_control/fvector.cpp
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions engines/titanic/star_control/fvector.h
Expand Up @@ -64,9 +64,10 @@ class FVector {
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
Expand Down
28 changes: 9 additions & 19 deletions engines/titanic/star_control/star_control_sub24.cpp
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 50a6100

Please sign in to comment.