Skip to content

Commit

Permalink
libdeng2|Vector: Added a setLength() method
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 7, 2014
1 parent 75d91de commit e9c4f9c
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doomsday/libdeng2/include/de/core/vector.h
Expand Up @@ -169,6 +169,9 @@ class Vector2
ddouble length() const {
return std::sqrt(ddouble(x*x + y*y));
}
void setLength(ddouble len) {
*this = *this / length() * len;
}
Vector2 normalize() const {
ddouble const len = length();
if(len != 0) {
Expand Down Expand Up @@ -353,6 +356,9 @@ class Vector3 : public Vector2<Type>
inline ddouble length() const {
return std::sqrt(lengthSquared());
}
void setLength(ddouble len) {
*this = *this / length() * len;
}
ddouble lengthSquared() const {
return Vector2<Type>::x*Vector2<Type>::x + Vector2<Type>::y*Vector2<Type>::y + z*z;
}
Expand Down

0 comments on commit e9c4f9c

Please sign in to comment.