add LVecBase3::project, etc., suggested by nik

This commit is contained in:
David Rose 2009-04-10 18:32:38 +00:00
parent 18e5f0c723
commit 12cc0232fc
18 changed files with 212 additions and 92 deletions

View File

@ -185,6 +185,18 @@ operator / (FLOATTYPE scalar) const {
return FLOATNAME(LPoint2)(FLOATNAME(LVecBase2)::operator / (scalar));
}
////////////////////////////////////////////////////////////////////
// Function: LPoint2::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
project(const FLOATNAME(LVecBase2) &onto) const {
return FLOATNAME(LVecBase2)::project(onto);
}
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: LPoint2::python_repr

View File

@ -46,6 +46,7 @@ PUBLISHED:
INLINE_LINMATH FLOATNAME(LPoint2) operator * (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LPoint2) project(const FLOATNAME(LVecBase2) &onto) const;
#ifdef HAVE_PYTHON
INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;

View File

@ -218,6 +218,18 @@ cross(const FLOATNAME(LVecBase3) &other) const {
return FLOATNAME(LVecBase3)::cross(other);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LPoint3) FLOATNAME(LPoint3)::
project(const FLOATNAME(LVecBase3) &onto) const {
return FLOATNAME(LVecBase3)::project(onto);
}
////////////////////////////////////////////////////////////////////
// Function: LPoint3::operator * scalar
// Access: Public

View File

@ -55,6 +55,7 @@ PUBLISHED:
operator - (const FLOATNAME(LVector3) &other) const;
INLINE_LINMATH FLOATNAME(LPoint3) cross(const FLOATNAME(LVecBase3) &other) const;
INLINE_LINMATH FLOATNAME(LPoint3) project(const FLOATNAME(LVecBase3) &onto) const;
INLINE_LINMATH FLOATNAME(LPoint3) operator * (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LPoint3) operator / (FLOATTYPE scalar) const;

View File

@ -205,6 +205,18 @@ operator / (FLOATTYPE scalar) const {
return FLOATNAME(LPoint4)(FLOATNAME(LVecBase4)::operator / (scalar));
}
////////////////////////////////////////////////////////////////////
// Function: LPoint4::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
project(const FLOATNAME(LVecBase4) &onto) const {
return FLOATNAME(LVecBase4)::project(onto);
}
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: LPoint4::python_repr

View File

@ -47,6 +47,7 @@ PUBLISHED:
INLINE_LINMATH FLOATNAME(LPoint4) operator * (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LPoint4) project(const FLOATNAME(LVecBase4) &onto) const;
#ifdef HAVE_PYTHON
INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;

View File

@ -364,6 +364,49 @@ set(FLOATTYPE x, FLOATTYPE y) {
_v.v._1 = y;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::length
// Access: Public
// Description: Returns the length of the vector, by the Pythagorean
// theorem.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2)::
length() const {
return csqrt((*this).dot(*this));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::length_squared
// Access: Public
// Description: Returns the square of the vector's length, cheap and
// easy.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase2)::
length_squared() const {
return (*this).dot(*this);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::normalize
// Access: Public
// Description: Normalizes the vector in place. Returns true if the
// vector was normalized, false if it was a zero-length
// vector.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LVecBase2)::
normalize() {
FLOATTYPE l2 = length_squared();
if (l2 == (FLOATTYPE)0.0f) {
set(0.0f, 0.0f);
return false;
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) {
(*this) /= csqrt(l2);
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::dot
// Access: Public
@ -375,6 +418,18 @@ dot(const FLOATNAME(LVecBase2) &other) const {
return _v.v._0 * other._v.v._0 + _v.v._1 * other._v.v._1;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase2) FLOATNAME(LVecBase2)::
project(const FLOATNAME(LVecBase2) &onto) const {
return onto * (dot(onto) / onto.length_squared());
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase2::operator <
// Access: Public

View File

@ -78,7 +78,12 @@ PUBLISHED:
INLINE_LINMATH void fill(FLOATTYPE fill_value);
INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y);
INLINE_LINMATH FLOATTYPE length() const;
INLINE_LINMATH FLOATTYPE length_squared() const;
INLINE_LINMATH bool normalize();
INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase2) &other) const;
INLINE_LINMATH FLOATNAME(LVecBase2) project(const FLOATNAME(LVecBase2) &onto) const;
INLINE_LINMATH bool operator < (const FLOATNAME(LVecBase2) &other) const;
INLINE_LINMATH bool operator == (const FLOATNAME(LVecBase2) &other) const;

View File

@ -511,6 +511,18 @@ cross(const FLOATNAME(LVecBase3) &other) const {
_v.v._0 * other._v.v._1 - other._v.v._0 * _v.v._1);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase3) FLOATNAME(LVecBase3)::
project(const FLOATNAME(LVecBase3) &onto) const {
return onto * (dot(onto) / onto.length_squared());
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase3::operator <
// Access: Published

View File

@ -89,6 +89,7 @@ PUBLISHED:
INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase3) &other) const;
INLINE_LINMATH FLOATNAME(LVecBase3) cross(const FLOATNAME(LVecBase3) &other) const;
INLINE_LINMATH FLOATNAME(LVecBase3) project(const FLOATNAME(LVecBase3) &onto) const;
INLINE_LINMATH bool operator < (const FLOATNAME(LVecBase3) &other) const;
INLINE_LINMATH bool operator == (const FLOATNAME(LVecBase3) &other) const;

View File

@ -454,6 +454,49 @@ set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w) {
_v.v._3 = w;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::length
// Access: Public
// Description: Returns the length of the vector, by the Pythagorean
// theorem.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
length() const {
return csqrt((*this).dot(*this));
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::length_squared
// Access: Public
// Description: Returns the square of the vector's length, cheap and
// easy.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase4)::
length_squared() const {
return (*this).dot(*this);
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::normalize
// Access: Public
// Description: Normalizes the vector in place. Returns true if the
// vector was normalized, false if it was a zero-length
// vector.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LVecBase4)::
normalize() {
FLOATTYPE l2 = length_squared();
if (l2 == (FLOATTYPE)0.0f) {
set(0.0f, 0.0f, 0.0f, 0.0f);
return false;
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) {
(*this) /= csqrt(l2);
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::dot
// Access: Public
@ -467,6 +510,18 @@ dot(const FLOATNAME(LVecBase4) &other) const {
_v.v._2 * other._v.v._2 + _v.v._3 * other._v.v._3;
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVecBase4) FLOATNAME(LVecBase4)::
project(const FLOATNAME(LVecBase4) &onto) const {
return onto * (dot(onto) / onto.length_squared());
}
////////////////////////////////////////////////////////////////////
// Function: LVecBase4::operator <
// Access: Public

View File

@ -83,7 +83,12 @@ PUBLISHED:
INLINE_LINMATH void fill(FLOATTYPE fill_value);
INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z, FLOATTYPE w);
INLINE_LINMATH FLOATTYPE length() const;
INLINE_LINMATH FLOATTYPE length_squared() const;
INLINE_LINMATH bool normalize();
INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase4) &other) const;
INLINE_LINMATH FLOATNAME(LVecBase4) project(const FLOATNAME(LVecBase4) &onto) const;
INLINE_LINMATH bool operator < (const FLOATNAME(LVecBase4) &other) const;
INLINE_LINMATH bool operator == (const FLOATNAME(LVecBase4) &other) const;

View File

@ -154,49 +154,6 @@ operator - (const FLOATNAME(LVector2) &other) const {
return FLOATNAME(LVecBase2)::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LVector2::length
// Access: Public
// Description: Returns the length of the vector, by the Pythagorean
// theorem.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2)::
length() const {
return csqrt((*this).dot(*this));
}
////////////////////////////////////////////////////////////////////
// Function: LVector2::length_squared
// Access: Public
// Description: Returns the square of the vector's length, cheap and
// easy.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector2)::
length_squared() const {
return (*this).dot(*this);
}
////////////////////////////////////////////////////////////////////
// Function: LVector2::normalize
// Access: Public
// Description: Normalizes the vector in place. Returns true if the
// vector was normalized, false if it was a zero-length
// vector.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LVector2)::
normalize() {
FLOATTYPE l2 = length_squared();
if (l2 == (FLOATTYPE)0.0f) {
set(0.0f, 0.0f);
return false;
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) {
(*this) /= csqrt(l2);
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: LVector2::operator * scalar
// Access: Public
@ -218,6 +175,18 @@ operator / (FLOATTYPE scalar) const {
return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (recip_scalar));
}
////////////////////////////////////////////////////////////////////
// Function: LVector2::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector2) FLOATNAME(LVector2)::
project(const FLOATNAME(LVecBase2) &onto) const {
return FLOATNAME(LVecBase2)::project(onto);
}
////////////////////////////////////////////////////////////////////
// Function: LVector2::signed_angle_rad
// Access: Published

View File

@ -37,12 +37,10 @@ PUBLISHED:
INLINE_LINMATH FLOATNAME(LVecBase2) operator - (const FLOATNAME(LVecBase2) &other) const;
INLINE_LINMATH FLOATNAME(LVector2) operator - (const FLOATNAME(LVector2) &other) const;
INLINE_LINMATH FLOATTYPE length() const;
INLINE_LINMATH FLOATTYPE length_squared() const;
INLINE_LINMATH bool normalize();
INLINE_LINMATH FLOATNAME(LVector2) operator * (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LVector2) project(const FLOATNAME(LVecBase2) &onto) const;
INLINE_LINMATH FLOATTYPE signed_angle_rad(const FLOATNAME(LVector2) &other) const;
INLINE_LINMATH FLOATTYPE signed_angle_deg(const FLOATNAME(LVector2) &other) const;

View File

@ -208,6 +208,18 @@ cross(const FLOATNAME(LVecBase3) &other) const {
return FLOATNAME(LVecBase3)::cross(other);
}
////////////////////////////////////////////////////////////////////
// Function: LVector3::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector3) FLOATNAME(LVector3)::
project(const FLOATNAME(LVecBase3) &onto) const {
return FLOATNAME(LVecBase3)::project(onto);
}
////////////////////////////////////////////////////////////////////
// Function: LVector::angle_rad
// Access: Published

View File

@ -49,6 +49,7 @@ PUBLISHED:
INLINE_LINMATH FLOATNAME(LVector3) operator - (const FLOATNAME(LVector3) &other) const;
INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const;
INLINE_LINMATH FLOATNAME(LVector3) project(const FLOATNAME(LVecBase3) &onto) const;
INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const;
INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const;

View File

@ -175,49 +175,6 @@ operator - (const FLOATNAME(LVector4) &other) const {
return FLOATNAME(LVecBase4)::operator - (other);
}
////////////////////////////////////////////////////////////////////
// Function: LVector4::length
// Access: Public
// Description: Returns the length of the vector, by the Pythagorean
// theorem.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector4)::
length() const {
return csqrt((*this).dot(*this));
}
////////////////////////////////////////////////////////////////////
// Function: LVector4::length_squared
// Access: Public
// Description: Returns the square of the vector's length, cheap and
// easy.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector4)::
length_squared() const {
return (*this).dot(*this);
}
////////////////////////////////////////////////////////////////////
// Function: LVector4::normalize
// Access: Public
// Description: Normalizes the vector in place. Returns true if the
// vector was normalized, false if it was a zero-length
// vector.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH bool FLOATNAME(LVector4)::
normalize() {
FLOATTYPE l2 = length_squared();
if (l2 == (FLOATTYPE)0.0f) {
set(0.0f, 0.0f, 0.0f, 0.0f);
return false;
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) {
(*this) /= csqrt(l2);
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: LVector4::operator * scalar
// Access: Public
@ -239,6 +196,18 @@ operator / (FLOATTYPE scalar) const {
return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (recip_scalar));
}
////////////////////////////////////////////////////////////////////
// Function: LVector4::project
// Access: Published
// Description: Returns a new vector representing the projection of
// this vector onto another one. The resulting vector
// will be a scalar multiple of onto.
////////////////////////////////////////////////////////////////////
INLINE_LINMATH FLOATNAME(LVector4) FLOATNAME(LVector4)::
project(const FLOATNAME(LVecBase4) &onto) const {
return FLOATNAME(LVecBase4)::project(onto);
}
#ifdef HAVE_PYTHON
////////////////////////////////////////////////////////////////////
// Function: LVector4::python_repr

View File

@ -39,12 +39,11 @@ PUBLISHED:
INLINE_LINMATH FLOATNAME(LVecBase4) operator - (const FLOATNAME(LVecBase4) &other) const;
INLINE_LINMATH FLOATNAME(LVector4) operator - (const FLOATNAME(LVector4) &other) const;
INLINE_LINMATH FLOATTYPE length() const;
INLINE_LINMATH FLOATTYPE length_squared() const;
INLINE_LINMATH bool normalize();
INLINE_LINMATH FLOATNAME(LVector4) operator * (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const;
INLINE_LINMATH FLOATNAME(LVector4) project(const FLOATNAME(LVecBase4) &onto) const;
#ifdef HAVE_PYTHON
INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
#endif