Skip to content
Snippets Groups Projects
Commit d4ff0c47 authored by Yoel's avatar Yoel
Browse files

Added new scalar-product so it can be used s*v and v*s. Also slight extra...

Added new scalar-product so it can be used s*v and v*s. Also slight extra constraint in normalization
parent d945526f
No related branches found
No related tags found
No related merge requests found
......@@ -93,6 +93,9 @@ bool Vec3::operator!=(const Vec3& rhs) const {
Vec3 Vec3::normalize() const {
Vec3 x(*this);
float l = x.length();
if (l == 0) {
return x;
}
return Vec3(x[0] / l, x[1] / l, x[2] / l);
}
float Vec3::length() const {
......@@ -123,4 +126,8 @@ std::ostream& operator<<(std::ostream& os, const util::Vec3& rhs) {
os << "(" << rhs[0] << " ," << rhs[1] << " ," << rhs[2] << ")";
return os;
}
Vec3 operator*(float s, const Vec3& rhs) {
return rhs * s;
}
} // namespace util
\ No newline at end of file
......@@ -20,6 +20,7 @@ class Vec3 {
Vec3 operator+(const Vec3& rhs) const;
Vec3 operator*(const Vec3& rhs) const;
Vec3 operator*(float s) const;
friend Vec3 operator*(float s, const Vec3& rhs);
Vec3 operator/(const Vec3& rhs) const;
Vec3 operator/(const float div) const;
void operator-=(const Vec3& rhs);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment