![]() |
ezEngine
Release 25.03
|
A class that represents a mathematical plane. More...
#include <Plane.h>
Public Types | |
using | ComponentType = Type |
Public Member Functions | |
EZ_DECLARE_POD_TYPE () | |
ezPlaneTemplate () | |
Default constructor. Does not initialize the plane. | |
ezVec4Template< Type > | GetAsVec4 () const |
Returns an ezVec4 with the plane normal in x,y,z and the negative distance in w. | |
ezResult | SetFromPoints (const ezVec3Template< Type > &v1, const ezVec3Template< Type > &v2, const ezVec3Template< Type > &v3) |
Creates the plane-equation from three points on the plane. | |
ezResult | SetFromPoints (const ezVec3Template< Type > *const pVertices) |
Creates the plane-equation from three points on the plane, given as an array. | |
ezResult | SetFromPoints (const ezVec3Template< Type > *const pVertices, ezUInt32 uiMaxVertices) |
Creates the plane-equation from a set of unreliable points lying on the same plane. Some points might be equal or too close to each other for the typical algorithm. Returns false, if no reliable set of points could be found. Does try to create a plane anyway. More... | |
ezResult | SetFromDirections (const ezVec3Template< Type > &vTangent1, const ezVec3Template< Type > &vTangent2, const ezVec3Template< Type > &vPointOnPlane) |
Creates a plane from two direction vectors that span the plane, and one point on it. | |
Type | GetDistanceTo (const ezVec3Template< Type > &vPoint) const |
Returns the distance of the point to the plane. | |
Type | GetMinimumDistanceTo (const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const |
Returns the minimum distance that any of the given points had to the plane. More... | |
Type | GetMinimumDistanceTo (const ezBoundingBoxTemplate< Type > &box) const |
Returns the minimum distance between given box and a plane. | |
Type | GetMaximumDistanceTo (const ezBoundingBoxTemplate< Type > &box) const |
Returns the maximum distance between given box and a plane. | |
void | GetMinMaxDistanceTo (Type &out_fMin, Type &out_fMax, const ezVec3Template< Type > *pPoints, ezUInt32 uiNumPoints, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const |
Returns the minimum and maximum distance that any of the given points had to the plane. More... | |
ezPositionOnPlane::Enum | GetPointPosition (const ezVec3Template< Type > &vPoint) const |
Returns on which side of the plane the point lies. | |
ezPositionOnPlane::Enum | GetPointPosition (const ezVec3Template< Type > &vPoint, Type fPlaneHalfWidth) const |
Returns on which side of the plane the point lies. | |
ezPositionOnPlane::Enum | GetObjectPosition (const ezVec3Template< Type > *const pPoints, ezUInt32 uiVertices) const |
Returns on which side of the plane the set of points lies. Might be on both sides. | |
ezPositionOnPlane::Enum | GetObjectPosition (const ezVec3Template< Type > *const pPoints, ezUInt32 uiVertices, Type fPlaneHalfWidth) const |
Returns on which side of the plane the set of points lies. Might be on both sides. | |
ezPositionOnPlane::Enum | GetObjectPosition (const ezBoundingSphereTemplate< Type > &sphere) const |
Returns on which side of the plane the sphere is located. | |
ezPositionOnPlane::Enum | GetObjectPosition (const ezBoundingBoxTemplate< Type > &box) const |
Returns on which side of the plane the box is located. | |
const ezVec3Template< Type > | ProjectOntoPlane (const ezVec3Template< Type > &vPoint) const |
Projects a point onto a plane (along the planes normal). | |
const ezVec3Template< Type > | Mirror (const ezVec3Template< Type > &vPoint) const |
Returns the mirrored point. E.g. on the other side of the plane, at the same distance. | |
const ezVec3Template< Type > | GetCoplanarDirection (const ezVec3Template< Type > &vDirection) const |
Take the given direction vector and returns a modified one that is coplanar to the plane. | |
bool | IsIdentical (const ezPlaneTemplate< Type > &rhs) const |
Checks whether this plane and the other are identical. | |
bool | IsEqual (const ezPlaneTemplate< Type > &rhs, Type fEpsilon=ezMath::DefaultEpsilon< Type >()) const |
Checks whether this plane and the other are equal within some threshold. | |
bool | IsValid () const |
Checks whether the plane has valid values (not NaN, normalized normal). | |
bool | IsNaN () const |
Checks whether any component is NaN. | |
bool | IsFinite () const |
Checks whether any component is Infinity. | |
void | Transform (const ezMat3Template< Type > &m) |
Transforms the plane with the given matrix. | |
void | Transform (const ezMat4Template< Type > &m) |
Transforms the plane with the given matrix. | |
void | Flip () |
Negates Normal/Distance to switch which side of the plane is front and back. | |
bool | FlipIfNecessary (const ezVec3Template< Type > &vPoint, bool bPlaneShouldFacePoint=true) |
Negates Normal/Distance to switch which side of the plane is front and back. Returns true, if the plane had to be flipped. | |
bool | GetRayIntersection (const ezVec3Template< Type > &vRayStartPos, const ezVec3Template< Type > &vRayDir, Type *out_pIntersectionDinstance=nullptr, ezVec3Template< Type > *out_pIntersection=nullptr) const |
Returns true, if the ray hit the plane. The intersection time describes at which multiple of the ray direction the ray hit the plane. More... | |
bool | GetRayIntersectionBiDirectional (const ezVec3Template< Type > &vRayStartPos, const ezVec3Template< Type > &vRayDir, Type *out_pIntersectionDistance=nullptr, ezVec3Template< Type > *out_pIntersection=nullptr) const |
Returns true, if the ray intersects the plane. Intersection time and point are stored in the out-parameters. Allows for intersections at negative times (shooting into the opposite direction). | |
bool | GetLineSegmentIntersection (const ezVec3Template< Type > &vLineStartPos, const ezVec3Template< Type > &vLineEndPos, Type *out_pHitFraction=nullptr, ezVec3Template< Type > *out_pIntersection=nullptr) const |
Returns true, if there is any intersection with the plane between the line's start and end position. Returns the fraction along the line and the actual intersection point. | |
Static Public Member Functions | |
static ezPlaneTemplate< Type > | MakeInvalid () |
Returns an invalid plane with a zero normal. | |
static ezPlaneTemplate< Type > | MakeFromNormalAndPoint (const ezVec3Template< Type > &vNormal, const ezVec3Template< Type > &vPointOnPlane) |
Creates a plane from a normal and a point on the plane. More... | |
static ezPlaneTemplate< Type > | MakeFromPoints (const ezVec3Template< Type > &v1, const ezVec3Template< Type > &v2, const ezVec3Template< Type > &v3) |
Creates a plane from three points. More... | |
static ezResult | GetPlanesIntersectionPoint (const ezPlaneTemplate< Type > &p0, const ezPlaneTemplate< Type > &p1, const ezPlaneTemplate< Type > &p2, ezVec3Template< Type > &out_vResult) |
Computes the one point where all three planes intersect. Returns EZ_FAILURE if no such point exists. | |
static ezResult | FindSupportPoints (const ezVec3Template< Type > *const pVertices, ezInt32 iMaxVertices, ezInt32 &out_i1, ezInt32 &out_i2, ezInt32 &out_i3) |
Returns three points from an unreliable set of points, that reliably form a plane. Returns false, if there are none. | |
Public Attributes | |
ezVec3Template< Type > | m_vNormal |
Type | m_fNegDistance |
A class that represents a mathematical plane.
Type ezPlaneTemplate< Type >::GetMinimumDistanceTo | ( | const ezVec3Template< Type > * | pPoints, |
ezUInt32 | uiNumPoints, | ||
ezUInt32 | uiStride = sizeof(ezVec3Template<Type>) |
||
) | const |
Returns the minimum distance that any of the given points had to the plane.
'Minimum' means the (non-absolute) distance of a point to the plane. So a point behind the plane will always have a 'lower distance' than a point in front of the plane, even if that is closer to the plane's surface.
void ezPlaneTemplate< Type >::GetMinMaxDistanceTo | ( | Type & | out_fMin, |
Type & | out_fMax, | ||
const ezVec3Template< Type > * | pPoints, | ||
ezUInt32 | uiNumPoints, | ||
ezUInt32 | uiStride = sizeof(ezVec3Template<Type>) |
||
) | const |
Returns the minimum and maximum distance that any of the given points had to the plane.
'Minimum' (and 'maximum') means the (non-absolute) distance of a point to the plane. So a point behind the plane will always have a 'lower distance' than a point in front of the plane, even if that is closer to the plane's surface.
bool ezPlaneTemplate< Type >::GetRayIntersection | ( | const ezVec3Template< Type > & | vRayStartPos, |
const ezVec3Template< Type > & | vRayDir, | ||
Type * | out_pIntersectionDinstance = nullptr , |
||
ezVec3Template< Type > * | out_pIntersection = nullptr |
||
) | const |
Returns true, if the ray hit the plane. The intersection time describes at which multiple of the ray direction the ray hit the plane.
An intersection will be reported regardless of whether the ray starts 'behind' or 'in front of' the plane, as long as it points at it. vRayDir does not need to be normalized.
out_vIntersection = vRayStartPos + out_fIntersection * vRayDir
Intersections with out_fIntersection less than zero will be discarded and not reported as intersections. If such intersections are desired, use GetRayIntersectionBiDirectional instead.
|
static |
Creates a plane from a normal and a point on the plane.
|
static |
Creates a plane from three points.
ezResult ezPlaneTemplate< Type >::SetFromPoints | ( | const ezVec3Template< Type > *const | pVertices, |
ezUInt32 | uiMaxVertices | ||
) |
Creates the plane-equation from a set of unreliable points lying on the same plane. Some points might be equal or too close to each other for the typical algorithm. Returns false, if no reliable set of points could be found. Does try to create a plane anyway.
The given vertices can be partially equal or lie on the same line. The algorithm will try to find 3 vertices, that form a plane, and deduce the normal from them. This algorithm is much slower, than all the other methods, so only use it, when you know, that your data can contain such configurations.