mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-17 16:30:30 +02:00
Handle zero-length vectors when normalizing
This commit is contained in:
1 parent
d91f2c9fd2
commit
9027e5018b
1 file changed
+6
-2
+6
-2
@@ -114,11 +114,15 @@ public:
|
||||
return Vec3(other-(*this)).Length2();
|
||||
}
|
||||
Vec3 Normalized() const {
|
||||
return (*this) / Length();
|
||||
float len = Length();
|
||||
if( len == 0.0f)
|
||||
return (*this);
|
||||
return (*this) / len;
|
||||
}
|
||||
float Normalize() { //returns the previous length, is often useful
|
||||
float len = Length();
|
||||
(*this) = (*this)/len;
|
||||
if( len != 0.0f )
|
||||
(*this) = (*this)/len;
|
||||
return len;
|
||||
}
|
||||
float &operator [] (int i) //allow vector[2] = 3 (vector.z=3)
|
||||
|
||||
Reference in new issue
Block a user