CUGL 2.3
Cornell University Game Library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cugl::Plane Class Reference

#include <CUPlane.h>

Public Types

enum class  Side { INCIDENT , BACK , FRONT }
 

Public Member Functions

 Plane ()
 
 Plane (const Vec3 normal, float dist=0)
 
 Plane (const Vec3 normal, const Vec3 point)
 
 Plane (const Vec3 point1, const Vec3 point2, const Vec3 point3)
 
 Plane (float a, float b, float c, float d)
 
 Plane (const Plane &plane)
 
 ~Plane ()
 
Planeoperator= (const Plane &plane)
 
Planeoperator= (const Vec3 normal)
 
Planeset (const Vec3 normal, float dist=0)
 
Planeset (const Vec3 normal, const Vec3 point)
 
Planeset (const Vec3 point1, const Vec3 point2, const Vec3 point3)
 
Planeset (float a, float b, float c, float d)
 
Planeset (const Plane &plane)
 
Planemultiply (const Mat4 &mat)
 
Planeoperator*= (const Mat4 &mat)
 
const Plane operator* (const Mat4 &mat) const
 
float distance (const Vec3 point) const
 
float getIntersection (const Ray &ray) const
 
bool contains (const Vec3 point, float variance=CU_MATH_EPSILON) const
 
Side sideOf (const Vec3 point) const
 
Side sideOf (float x, float y, float z) const
 
bool isFrontFacing (const Vec3 direction) const
 
bool operator== (const Plane &p) const
 
bool operator!= (const Plane &p) const
 
bool equals (const Plane &p, float variance=CU_MATH_EPSILON) const
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 

Static Public Member Functions

static Planemultiply (const Plane &plane, const Mat4 &mat, Plane *dst)
 
static float intersection (const Plane &plane, const Ray &ray)
 

Public Attributes

Vec3 normal
 
float offset
 

Static Public Attributes

static const Plane XY
 
static const Plane XZ
 
static const Plane YZ
 

Detailed Description

This class ia a plane defined via a normal and the distance from the origin.

The normal must be a unit vector. However, we allow direct access to the normal and do not check this invariant.

Member Enumeration Documentation

◆ Side

enum class cugl::Plane::Side
strong

This enum specifies on which side a point lies respective to the plane.

Enumerator
INCIDENT 

The point is on the plane

BACK 

The point is on the side opposite the normal

FRONT 

The point is on the side with the normal

Constructor & Destructor Documentation

◆ Plane() [1/6]

cugl::Plane::Plane ( )
inline

Creates the XY plane.

◆ Plane() [2/6]

cugl::Plane::Plane ( const Vec3  normal,
float  dist = 0 
)
inline

Creates a new plane with the given normal and distance to the origin.

Parameters
normalThe plane normal
distThe distance to the origin

◆ Plane() [3/6]

cugl::Plane::Plane ( const Vec3  normal,
const Vec3  point 
)
inline

Creates a new plane based on the normal and a point on the plane.

Parameters
normalThe normal
pointThe point on the plane

◆ Plane() [4/6]

cugl::Plane::Plane ( const Vec3  point1,
const Vec3  point2,
const Vec3  point3 
)
inline

Creates a new plane containing the three given points.

The normal is calculated via a cross product between (point1-point2)x(point2-point3)

Parameters
point1The first point
point2The second point
point3The third point

◆ Plane() [5/6]

cugl::Plane::Plane ( float  a,
float  b,
float  c,
float  d 
)
inline

Creates a new plane from the given equation coefficients.

The equation of the plane is ax + by + cz = d.

Parameters
aThe x coefficient
bThe y coefficient
cThe z coefficient
dThe constant factor

◆ Plane() [6/6]

cugl::Plane::Plane ( const Plane plane)
inline

Creates a copy of the given plane.

Parameters
planeThe plane to copy,

◆ ~Plane()

cugl::Plane::~Plane ( )
inline

Destroys this plane, releasing all resources

Member Function Documentation

◆ contains()

bool cugl::Plane::contains ( const Vec3  point,
float  variance = CU_MATH_EPSILON 
) const
inline

Returns true if this plane contains the given point within tolerance.

The tolerance bounds the point distance.

Parameters
pointThe point to check
varianceThe comparison tolerance.
Returns
true if this plane contains the given point within tolerance.

◆ distance()

float cugl::Plane::distance ( const Vec3  point) const
inline

Return the signed distance between the plane and the given point.

The distance is signed, so that a point on the same side as the normal will have positive distance, while a point on the back side will have negative distance.

Returns
the signed distance between the plane and the given point.

◆ equals()

bool cugl::Plane::equals ( const Plane p,
float  variance = CU_MATH_EPSILON 
) const
inline

Returns true if the planes are within tolerance of each other.

The tolerance bounds the normal and distance separately.

Parameters
pThe plane to compare against.
varianceThe comparison tolerance.
Returns
true if the rays are within tolerance of each other.

◆ getIntersection()

float cugl::Plane::getIntersection ( const Ray ray) const
inline

Returns the intersection parameter of the ray with this plane.

If the value is negative, the intersection is in the reverse direction of the ray.

Parameters
rayThe ray to check
Returns
the intersection of the ray with this plane.

◆ intersection()

static float cugl::Plane::intersection ( const Plane plane,
const Ray ray 
)
static

Computes the intersection paramter the ray with the plane.

If the value is negative, the intersection is in the reverse direction of the ray.

Parameters
planeThe plane to check
rayThe ray to check
Returns
the intersection paramter the ray with the plane.

◆ isFrontFacing()

bool cugl::Plane::isFrontFacing ( const Vec3  direction) const
inline

Returns whether the plane is facing the direction vector.

In this method, you should think of the direction vector as the direction a camera looks in. This method will return true if the front side of the plane determined by its normal faces the camera.

Parameters
directionThe direction
Returns
whether the plane is facing the direction vector.

◆ multiply() [1/2]

Plane & cugl::Plane::multiply ( const Mat4 mat)
inline

Multiplies this plane by the given matrix.

The multiplication transforms the plane. That is, if point p is on the original plane, p*M is on the newly created plane. To transform a plane by a matrix, we mutliply the vector (a,b,c,d) by the inverse of mat, where ax + by + cz = d is the equation of the plane.

Parameters
matThe transform matrix
Returns
A reference to this (modified) Plane for chaining.

◆ multiply() [2/2]

static Plane * cugl::Plane::multiply ( const Plane plane,
const Mat4 mat,
Plane dst 
)
static

Multiplies the plane by the given matrix and assigns it to dst.

The multiplication transforms the plane. That is, if point p is on the original plane, p*M is on the newly created plane. To transform a plane by a matrix, we mutliply the vector (a,b,c,d) by the inverse of mat, where ax + by + cz = d is the equation of the plane.

Parameters
planeThe plane to transform
matThe transform matrix
dstA plane to store the result in
Returns
A reference to dst for chaining

◆ operator std::string()

cugl::Plane::operator std::string ( ) const
inline

Cast from Ray to a string.

◆ operator!=()

bool cugl::Plane::operator!= ( const Plane p) const
inline

Returns true if this plane is not equal to the given plane.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
pThe plane to compare against.
Returns
True if this plane is not equal to the given plane.

◆ operator*()

const Plane cugl::Plane::operator* ( const Mat4 mat) const
inline

Return a copy of this plane transformed by the given matrix.

The multiplication transforms the plane. That is, if point p is on the original plane, p*M is on the newly created plane. To transform a plane by a matrix, we mutliply the vector (a,b,c,d) by the inverse of mat, where ax + by + cz = d is the equation of the plane.

Parameters
matThe transform matrix
Returns
a copy of this plane transformed by the given matrix.

◆ operator*=()

Plane & cugl::Plane::operator*= ( const Mat4 mat)
inline

Multiplies this plane by the given matrix.

The multiplication transforms the plane. That is, if point p is on the original plane, p*M is on the newly created plane. To transform a plane by a matrix, we mutliply the vector (a,b,c,d) by the inverse of mat, where ax + by + cz = d is the equation of the plane.

Parameters
matThe transform matrix
Returns
A reference to this (modified) Plane for chaining.

◆ operator=() [1/2]

Plane & cugl::Plane::operator= ( const Plane plane)
inline

Sets this plane to be a copy of the given plane.

Parameters
planeThe plane to copy,
Returns
A reference to this (modified) Plane for chaining.

◆ operator=() [2/2]

Plane & cugl::Plane::operator= ( const Vec3  normal)
inline

Sets this plane to have the given normal.

After assignment, this plane will intersect the origin.

Parameters
normalThe plane normal
Returns
A reference to this (modified) Plane for chaining.

◆ operator==()

bool cugl::Plane::operator== ( const Plane p) const
inline

Returns true if this plane is equal to the given plane.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
pThe plane to compare against.
Returns
True if this plane is equal to the given plane.

◆ set() [1/5]

Plane & cugl::Plane::set ( const Plane plane)
inline

Sets this plane to be a copy of the given plane.

Parameters
planeThe plane to copy,
Returns
A reference to this (modified) Plane for chaining.

◆ set() [2/5]

Plane & cugl::Plane::set ( const Vec3  normal,
const Vec3  point 
)

Sets this plane to have the given normal and contain the given point.

Parameters
normalThe normal
pointThe point on the plane
Returns
A reference to this (modified) Plane for chaining.

◆ set() [3/5]

Plane & cugl::Plane::set ( const Vec3  normal,
float  dist = 0 
)

Sets this plane to have the given normal and distance to the origin.

Parameters
normalThe plane normal
distThe distance to the origin
Returns
A reference to this (modified) Plane for chaining.

◆ set() [4/5]

Plane & cugl::Plane::set ( const Vec3  point1,
const Vec3  point2,
const Vec3  point3 
)

Creates a new plane to one containing the three given points.

The normal is calculated via a cross product between (point1-point2)x(point2-point3)

Parameters
point1The first point
point2The second point
point3The third point
Returns
A reference to this (modified) Plane for chaining.

◆ set() [5/5]

Plane & cugl::Plane::set ( float  a,
float  b,
float  c,
float  d 
)

Sets this plane to have the given equation coefficients.

The equation of the plane is ax + by + cz = d.

Parameters
aThe x coefficient
bThe y coefficient
cThe z coefficient
dThe constant factor

◆ sideOf() [1/2]

Side cugl::Plane::sideOf ( const Vec3  point) const
inline

Returns which side the given point lies relative to normal.

Side::FRONT refers to the side the plane normal points to.

Parameters
pointThe point to check
Returns
which side the given point lies relative to normal.

◆ sideOf() [2/2]

Side cugl::Plane::sideOf ( float  x,
float  y,
float  z 
) const
inline

Returns which side the given point lies relative to normal.

Side::FRONT refers to the side the plane normal points to.

Parameters
xThe x-coordinate of the point
yThe x-coordinate of the point
zThe x-coordinate of the point
Returns
which side the given point lies relative to normal.

◆ toString()

std::string cugl::Plane::toString ( bool  verbose = false) const

Returns a string representation of this plane for debugging purposes.

The plane will be represented by its equation ax+by+cz = d.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this ray for debugging purposes.

Member Data Documentation

◆ normal

Vec3 cugl::Plane::normal

The plane normal (should be a unit vector)

◆ offset

float cugl::Plane::offset

The distance of the plane from the origin

◆ XY

const Plane cugl::Plane::XY
static

The xy plane (normal is z-axis)

◆ XZ

const Plane cugl::Plane::XZ
static

The xz plane (normal is y-axis)

◆ YZ

const Plane cugl::Plane::YZ
static

The yz plane (normal is x-axis)


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