mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Handle zero-length vectors when normalizing
This commit is contained in:
parent
d91f2c9fd2
commit
9027e5018b
1 changed files with 6 additions and 2 deletions
|
@ -114,11 +114,15 @@ public:
|
||||||
return Vec3(other-(*this)).Length2();
|
return Vec3(other-(*this)).Length2();
|
||||||
}
|
}
|
||||||
Vec3 Normalized() const {
|
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 Normalize() { //returns the previous length, is often useful
|
||||||
float len = Length();
|
float len = Length();
|
||||||
(*this) = (*this)/len;
|
if( len != 0.0f )
|
||||||
|
(*this) = (*this)/len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
float &operator [] (int i) //allow vector[2] = 3 (vector.z=3)
|
float &operator [] (int i) //allow vector[2] = 3 (vector.z=3)
|
||||||
|
|
Loading…
Add table
Reference in a new issue