Vector4 +, -, negation, and *
+, -, and negation were easy. Multiplication is wacky because the Matrix class does it. So, to do binary * (not *=) I needed to dynamic_cast the resulting Matrix<4,1> to a Vector4&&.
This commit is contained in:
parent
a3d51f7cf3
commit
b41cdb7186
2 changed files with 94 additions and 0 deletions
|
@ -78,6 +78,9 @@ Vector4::Z()
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::Z --
|
||||
*/
|
||||
const Double&
|
||||
Vector4::Z()
|
||||
const
|
||||
|
@ -86,6 +89,73 @@ Vector4::Z()
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator* --
|
||||
*/
|
||||
Vector4
|
||||
Vector4::operator*(const Double& rhs)
|
||||
const
|
||||
{
|
||||
return dynamic_cast<Vector4&&>(*this * rhs);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator+ --
|
||||
*/
|
||||
Vector4
|
||||
Vector4::operator+(const Vector4& rhs)
|
||||
const
|
||||
{
|
||||
return Vector4(*this) += rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator+= --
|
||||
*/
|
||||
Vector4&
|
||||
Vector4::operator+=(const Vector4& rhs)
|
||||
{
|
||||
mData[0] += rhs.mData[0];
|
||||
mData[1] += rhs.mData[1];
|
||||
mData[2] += rhs.mData[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator- --
|
||||
*/
|
||||
Vector4
|
||||
Vector4::operator-(const Vector4& rhs)
|
||||
const
|
||||
{
|
||||
return Vector4(*this) -= rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator-= --
|
||||
*/
|
||||
Vector4&
|
||||
Vector4::operator-=(const Vector4& rhs)
|
||||
{
|
||||
return *this += -rhs;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::operator- --
|
||||
*/
|
||||
Vector4
|
||||
Vector4::operator-()
|
||||
const
|
||||
{
|
||||
return Vector4(-X(), -Y(), -Z());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::Vector4::Length2 --
|
||||
*/
|
||||
|
@ -146,6 +216,17 @@ Vector4::Normalize()
|
|||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* charles::basics::operator* --
|
||||
*/
|
||||
Vector4
|
||||
operator*(const Double& lhs,
|
||||
const Vector4& rhs)
|
||||
{
|
||||
return rhs * lhs;
|
||||
}
|
||||
|
||||
} /* namespace basics */
|
||||
} /* namespace charles */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue