Skip to content

Commit

Permalink
Vector3 scalar multiplication implemented by Eigen
Browse files Browse the repository at this point in the history
Add a new eigen() accessor method to BasicVector3 which can be used by the
non-member operators to access the underlying Eigen object.
  • Loading branch information
Matthew Mott committed Apr 27, 2021
1 parent b1ab872 commit 40a187f
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions libs/math/Vector3.h
Expand Up @@ -75,6 +75,12 @@ class BasicVector3
);
}

/// Read-only access to the internal Eigen vector
const Eigen_T& eigen() const { return _v; }

/// Mutable access to the internal Eigen vector
Eigen_T& eigen() { return _v; }

/// Set all 3 components to the provided values.
void set(T x, T y, T z)
{
Expand Down Expand Up @@ -209,8 +215,7 @@ template <
>
BasicVector3<T> operator*(const BasicVector3<T>& v, S s)
{
T factor = static_cast<T>(s);
return BasicVector3<T>(v.x() * factor, v.y() * factor, v.z() * factor);
return BasicVector3<T>(v.eigen() * s);
}

/// Multiply vector components with a scalar and return the result
Expand All @@ -227,7 +232,7 @@ BasicVector3<T> operator*(S s, const BasicVector3<T>& v)
template <typename T, typename S>
BasicVector3<T>& operator*=(BasicVector3<T>& v, S s)
{
v = v * s;
v.eigen() *= s;
return v;
}

Expand Down

0 comments on commit 40a187f

Please sign in to comment.