mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
make normalize() and length() methods on LVecBase3f instead of just LVector3f
This commit is contained in:
parent
0fa44b405c
commit
34e47c5504
@ -81,7 +81,7 @@ cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE_LINMATH FLOATTYPE
|
||||
length(const FLOATNAME(LVector3) &a) {
|
||||
length(const FLOATNAME(LVecBase3) &a) {
|
||||
return a.length();
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ length(const FLOATNAME(LVector3) &a) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
INLINE_LINMATH FLOATNAME(LVector3)
|
||||
normalize(const FLOATNAME(LVector3) &v) {
|
||||
normalize(const FLOATNAME(LVecBase3) &v) {
|
||||
FLOATNAME(LVector3) v1 = v;
|
||||
v1.normalize();
|
||||
return v1;
|
||||
|
@ -48,11 +48,11 @@ cross(const FLOATNAME(LVector3) &a, const FLOATNAME(LVector3) &b);
|
||||
|
||||
// Length of a vector.
|
||||
INLINE_LINMATH FLOATTYPE
|
||||
length(const FLOATNAME(LVector3) &a);
|
||||
length(const FLOATNAME(LVecBase3) &a);
|
||||
|
||||
// A normalized vector.
|
||||
INLINE_LINMATH FLOATNAME(LVector3)
|
||||
normalize(const FLOATNAME(LVector3) &v);
|
||||
normalize(const FLOATNAME(LVecBase3) &v);
|
||||
|
||||
INLINE_LINMATH void
|
||||
generic_write_datagram(Datagram &dest, const FLOATNAME(LVecBase3) &value);
|
||||
|
@ -383,6 +383,49 @@ set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z) {
|
||||
_v.v._2 = z;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase3::length
|
||||
// Access: Published
|
||||
// Description: Returns the length of the vector, by the Pythagorean
|
||||
// theorem.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
|
||||
length() const {
|
||||
return csqrt((*this).dot(*this));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase3::length_squared
|
||||
// Access: Published
|
||||
// Description: Returns the square of the vector's length, cheap and
|
||||
// easy.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE_LINMATH FLOATTYPE FLOATNAME(LVecBase3)::
|
||||
length_squared() const {
|
||||
return (*this).dot(*this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVecBase3::normalize
|
||||
// Access: Published
|
||||
// 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(LVecBase3)::
|
||||
normalize() {
|
||||
FLOATTYPE l2 = length_squared();
|
||||
if (l2 == (FLOATTYPE)0.0f) {
|
||||
set(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: LVecBase3::dot
|
||||
// Access: Published
|
||||
|
@ -78,6 +78,10 @@ PUBLISHED:
|
||||
INLINE_LINMATH void fill(FLOATTYPE fill_value);
|
||||
INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y, FLOATTYPE z);
|
||||
|
||||
INLINE_LINMATH FLOATTYPE length() const;
|
||||
INLINE_LINMATH FLOATTYPE length_squared() const;
|
||||
INLINE_LINMATH bool normalize();
|
||||
|
||||
INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE_LINMATH FLOATNAME(LVecBase3) cross(const FLOATNAME(LVecBase3) &other) const;
|
||||
|
||||
|
@ -169,49 +169,6 @@ operator - (const FLOATNAME(LVector3) &other) const {
|
||||
return FLOATNAME(LVecBase3)::operator - (other);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector3::length
|
||||
// Access: Published
|
||||
// Description: Returns the length of the vector, by the Pythagorean
|
||||
// theorem.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
|
||||
length() const {
|
||||
return csqrt((*this).dot(*this));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector3::length_squared
|
||||
// Access: Published
|
||||
// Description: Returns the square of the vector's length, cheap and
|
||||
// easy.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE_LINMATH FLOATTYPE FLOATNAME(LVector3)::
|
||||
length_squared() const {
|
||||
return (*this).dot(*this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: LVector3::normalize
|
||||
// Access: Published
|
||||
// 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(LVector3)::
|
||||
normalize() {
|
||||
FLOATTYPE l2 = length_squared();
|
||||
if (l2 == (FLOATTYPE)0.0f) {
|
||||
set(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: LVector3::cross
|
||||
// Access: Published
|
||||
|
@ -48,9 +48,6 @@ PUBLISHED:
|
||||
INLINE_LINMATH FLOATNAME(LVecBase3) operator - (const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE_LINMATH FLOATNAME(LVector3) operator - (const FLOATNAME(LVector3) &other) const;
|
||||
|
||||
INLINE_LINMATH FLOATTYPE length() const;
|
||||
INLINE_LINMATH FLOATTYPE length_squared() const;
|
||||
INLINE_LINMATH bool normalize();
|
||||
INLINE_LINMATH FLOATNAME(LVector3) cross(const FLOATNAME(LVecBase3) &other) const;
|
||||
INLINE_LINMATH FLOATTYPE angle_rad(const FLOATNAME(LVector3) &other) const;
|
||||
INLINE_LINMATH FLOATTYPE angle_deg(const FLOATNAME(LVector3) &other) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user