ezEngine  Milestone 7
ezPlaneTemplate< Type > Class Template Reference

A class that represents a mathematical plane. More...

#include <Plane.h>

Public Types

typedef Type ComponentType
 

Public Member Functions

 EZ_DECLARE_POD_TYPE ()
 
 ezPlaneTemplate ()
 Default constructor. Does not initialize the plane.
 
 ezPlaneTemplate (const ezVec3Template< Type > &vNormal, const ezVec3Template< Type > &vPointOnPlane)
 Creates the plane-equation from a normal and a point on the plane.
 
 ezPlaneTemplate (const ezVec3Template< Type > &v1, const ezVec3Template< Type > &v2, const ezVec3Template< Type > &v3)
 Creates the plane-equation from three points on the plane.
 
 ezPlaneTemplate (const ezVec3Template< Type > *const pVertices)
 Creates the plane-equation from three points on the plane, given as an array.
 
 ezPlaneTemplate (const ezVec3Template< Type > *const pVertices, ezUInt32 iMaxVertices)
 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.
 
void SetFromNormalAndPoint (const ezVec3Template< Type > &vNormal, const ezVec3Template< Type > &vPointOnPlane)
 Creates the plane-equation from a normal and a point on the plane.
 
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 iMaxVertices)
 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.
 
void SetInvalid ()
 Sets the plane to an invalid state (all zero).
 
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...
 
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 vPoints, ezUInt32 iVertices) 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 vPoints, ezUInt32 iVertices, 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::BasicType< Type >::DefaultEpsilon()) 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, or infinite, normalized normal).
 
bool IsNaN () const
 Checks whether any component is NaN.
 
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_fIntersection=nullptr, ezVec3Template< Type > *out_vIntersection=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_fIntersection=nullptr, ezVec3Template< Type > *out_vIntersection=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_fHitFraction=nullptr, ezVec3Template< Type > *out_vIntersection=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 ezResult GetPlanesIntersectionPoint (const ezPlaneTemplate< Type > &p0, const ezPlaneTemplate< Type > &p1, const ezPlaneTemplate< Type > &p2, ezVec3Template< Type > &out_Result)
 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_v1, ezInt32 &out_v2, ezInt32 &out_v3)
 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
 

Detailed Description

template<typename Type>
class ezPlaneTemplate< Type >

A class that represents a mathematical plane.

Member Function Documentation

template<typename Type>
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.

template<typename Type>
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.

template<typename Type>
bool ezPlaneTemplate< Type >::GetRayIntersection ( const ezVec3Template< Type > &  vRayStartPos,
const ezVec3Template< Type > &  vRayDir,
Type *  out_fIntersection = nullptr,
ezVec3Template< Type > *  out_vIntersection = 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.

template<typename Type>
ezResult ezPlaneTemplate< Type >::SetFromPoints ( const ezVec3Template< Type > *const  pVertices,
ezUInt32  iMaxVertices 
)

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.


The documentation for this class was generated from the following files: