aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/star_control/fvector.cpp
diff options
context:
space:
mode:
authorDavid Fioramonti2017-08-19 07:00:39 -0700
committerDavid Fioramonti2017-08-19 08:36:02 -0700
commit24bec379d5f1d59dfac2ff304b8ccbc64f5ae5b2 (patch)
treeb77f40445fbb857ef970312bfc3fb69d4d19b57e /engines/titanic/star_control/fvector.cpp
parent82d0053f8bd472ec598645550825257ddd78d683 (diff)
downloadscummvm-rg350-24bec379d5f1d59dfac2ff304b8ccbc64f5ae5b2.tar.gz
scummvm-rg350-24bec379d5f1d59dfac2ff304b8ccbc64f5ae5b2.tar.bz2
scummvm-rg350-24bec379d5f1d59dfac2ff304b8ccbc64f5ae5b2.zip
TITANIC: Pull assert out of dvector/fvector normalization
Before the normalization function was asserting if it couldn't normalize now the caller can determine what to do with a failed normalization.
Diffstat (limited to 'engines/titanic/star_control/fvector.cpp')
-rw-r--r--engines/titanic/star_control/fvector.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp
index a107ad1ed2..75d30748d2 100644
--- a/engines/titanic/star_control/fvector.cpp
+++ b/engines/titanic/star_control/fvector.cpp
@@ -48,20 +48,25 @@ FVector FVector::crossProduct(const FVector &src) const {
);
}
-float FVector::normalize() {
- float hyp = sqrt(_x * _x + _y * _y + _z * _z);
- assert(hyp);
+bool FVector::normalize(float & hyp) {
+ hyp = sqrt(_x * _x + _y * _y + _z * _z);
+ if (hyp==0) {
+ return false;
+ }
_x *= 1.0 / hyp;
_y *= 1.0 / hyp;
_z *= 1.0 / hyp;
- return hyp;
+ return true;
}
FVector FVector::addAndNormalize(const FVector &v) const {
FVector tempV(_x + v._x, _y + v._y, _z + v._z);
- tempV.normalize();
-
+ float unused_scale=0.0;
+ if (!tempV.normalize(unused_scale)) { // Do the normalization, put the scale amount in unused_scale,
+ // but if it is unsuccessful, crash
+ assert(unused_scale);
+ }
return tempV;
}