mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
mathutil: override plane.normalize() to be meaningful for planes
Now it only divides by the length of the normal, rather than also adding in the square of the w component.
This commit is contained in:
parent
c634c455fd
commit
d081b4d420
@ -137,6 +137,37 @@ dist_to_plane(const FLOATNAME(LPoint3) &point) const {
|
|||||||
return (_v(0) * point[0] + _v(1) * point[1] + _v(2) * point[2] + _v(3));
|
return (_v(0) * point[0] + _v(1) * point[1] + _v(2) * point[2] + _v(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes the plane in place. Returns true if the plane was normalized,
|
||||||
|
* false if the plane had a zero-length normal vector.
|
||||||
|
*/
|
||||||
|
INLINE_MATHUTIL bool FLOATNAME(LPlane)::
|
||||||
|
normalize() {
|
||||||
|
FLOATTYPE l2 = get_normal().length_squared();
|
||||||
|
if (l2 == (FLOATTYPE)0.0f) {
|
||||||
|
return false;
|
||||||
|
|
||||||
|
} else if (!IS_THRESHOLD_EQUAL(l2, 1.0f, NEARLY_ZERO(FLOATTYPE) * NEARLY_ZERO(FLOATTYPE))) {
|
||||||
|
(*this) /= csqrt(l2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalizes the plane and returns the normalized plane as a copy. If the
|
||||||
|
* plane's normal was a zero-length vector, the same plane is returned.
|
||||||
|
*/
|
||||||
|
INLINE_MATHUTIL FLOATNAME(LPlane) FLOATNAME(LPlane)::
|
||||||
|
normalized() const {
|
||||||
|
FLOATTYPE l2 = get_normal().length_squared();
|
||||||
|
if (l2 != (FLOATTYPE)0.0f) {
|
||||||
|
return (*this) / csqrt(l2);
|
||||||
|
} else {
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the point within the plane nearest to the indicated point in space.
|
* Returns the point within the plane nearest to the indicated point in space.
|
||||||
*/
|
*/
|
||||||
|
@ -39,6 +39,9 @@ PUBLISHED:
|
|||||||
FLOATNAME(LPoint3) get_point() const;
|
FLOATNAME(LPoint3) get_point() const;
|
||||||
|
|
||||||
INLINE_MATHUTIL FLOATTYPE dist_to_plane(const FLOATNAME(LPoint3) &point) const;
|
INLINE_MATHUTIL FLOATTYPE dist_to_plane(const FLOATNAME(LPoint3) &point) const;
|
||||||
|
|
||||||
|
INLINE_MATHUTIL bool normalize();
|
||||||
|
INLINE_MATHUTIL FLOATNAME(LPlane) normalized() const;
|
||||||
INLINE_MATHUTIL FLOATNAME(LPoint3) project(const FLOATNAME(LPoint3) &point) const;
|
INLINE_MATHUTIL FLOATNAME(LPoint3) project(const FLOATNAME(LPoint3) &point) const;
|
||||||
INLINE_MATHUTIL void flip();
|
INLINE_MATHUTIL void flip();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user