Loading...
Searching...
No Matches
plane3d.h
Go to the documentation of this file.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __IRR_PLANE_3D_H_INCLUDED__
#define __IRR_PLANE_3D_H_INCLUDED__
#include "irrMath.h"
#include "vector3d.h"
namespace irr
{
namespace core
{
enum EIntersectionRelation3D
{
ISREL3D_FRONT = 0,
ISREL3D_BACK,
ISREL3D_PLANAR,
ISREL3D_SPANNING,
ISREL3D_CLIPPED
};
template <class T>
class plane3d
{
public:
// Constructors
plane3d(): Normal(0,1,0) { recalculateD(vector3d<T>(0,0,0)); }
plane3d(const vector3d<T>& MPoint, const vector3d<T>& Normal) : Normal(Normal) { recalculateD(MPoint); }
plane3d(T px, T py, T pz, T nx, T ny, T nz) : Normal(nx, ny, nz) { recalculateD(vector3d<T>(px, py, pz)); }
plane3d(const vector3d<T>& point1, const vector3d<T>& point2, const vector3d<T>& point3)
{ setPlane(point1, point2, point3); }
plane3d(const vector3d<T> & normal, const T d) : Normal(normal), D(d) { }
// operators
inline bool operator==(const plane3d<T>& other) const { return (equals(D, other.D) && Normal==other.Normal);}
inline bool operator!=(const plane3d<T>& other) const { return !(*this == other);}
// functions
void setPlane(const vector3d<T>& point, const vector3d<T>& nvector)
{
Normal = nvector;
recalculateD(point);
}
void setPlane(const vector3d<T>& nvect, T d)
{
Normal = nvect;
D = d;
}
void setPlane(const vector3d<T>& point1, const vector3d<T>& point2, const vector3d<T>& point3)
{
// creates the plane from 3 memberpoints
Normal = (point2 - point1).crossProduct(point3 - point1);
Normal.normalize();
recalculateD(point1);
}
bool getIntersectionWithLine(const vector3d<T>& linePoint,
const vector3d<T>& lineVect,
vector3d<T>& outIntersection) const
{
T t2 = Normal.dotProduct(lineVect);
if (t2 == 0)
return false;
T t =- (Normal.dotProduct(linePoint) + D) / t2;
outIntersection = linePoint + (lineVect * t);
return true;
}
f32 getKnownIntersectionWithLine(const vector3d<T>& linePoint1,
const vector3d<T>& linePoint2) const
{
vector3d<T> vect = linePoint2 - linePoint1;
T t2 = (f32)Normal.dotProduct(vect);
return (f32)-((Normal.dotProduct(linePoint1) + D) / t2);
}
bool getIntersectionWithLimitedLine(
const vector3d<T>& linePoint1,
const vector3d<T>& linePoint2,
vector3d<T>& outIntersection) const
{
return (getIntersectionWithLine(linePoint1, linePoint2 - linePoint1, outIntersection) &&
outIntersection.isBetweenPoints(linePoint1, linePoint2));
}
EIntersectionRelation3D classifyPointRelation(const vector3d<T>& point) const
{
const T d = Normal.dotProduct(point) + D;
if (d < -ROUNDING_ERROR_f32)
return ISREL3D_BACK;
if (d > ROUNDING_ERROR_f32)
return ISREL3D_FRONT;
return ISREL3D_PLANAR;
}
void recalculateD(const vector3d<T>& MPoint)
{
D = - MPoint.dotProduct(Normal);
}
vector3d<T> getMemberPoint() const
{
return Normal * -D;
}
bool existsIntersection(const plane3d<T>& other) const
{
vector3d<T> cross = other.Normal.crossProduct(Normal);
return cross.getLength() > core::ROUNDING_ERROR_f32;
}
bool getIntersectionWithPlane(const plane3d<T>& other,
vector3d<T>& outLinePoint,
vector3d<T>& outLineVect) const
{
const T fn00 = Normal.getLength();
const T fn01 = Normal.dotProduct(other.Normal);
const T fn11 = other.Normal.getLength();
const f64 det = fn00*fn11 - fn01*fn01;
if (fabs(det) < ROUNDING_ERROR_f64 )
return false;
const f64 invdet = 1.0 / det;
const f64 fc0 = (fn11*-D + fn01*other.D) * invdet;
const f64 fc1 = (fn00*-other.D + fn01*D) * invdet;
outLineVect = Normal.crossProduct(other.Normal);
outLinePoint = Normal*(T)fc0 + other.Normal*(T)fc1;
return true;
}
bool getIntersectionWithPlanes(const plane3d<T>& o1,
const plane3d<T>& o2, vector3d<T>& outPoint) const
{
vector3d<T> linePoint, lineVect;
if (getIntersectionWithPlane(o1, linePoint, lineVect))
return o2.getIntersectionWithLine(linePoint, lineVect, outPoint);
return false;
}
bool isFrontFacing(const vector3d<T>& lookDirection) const
{
const f32 d = Normal.dotProduct(lookDirection);
return F32_LOWER_EQUAL_0 ( d );
}
T getDistanceTo(const vector3d<T>& point) const
{
return point.dotProduct(Normal) + D;
}
vector3d<T> Normal;
T D;
};
typedef plane3d<f32> plane3df;
typedef plane3d<s32> plane3di;
} // end namespace core
} // end namespace irr
#endif
irr::core::plane3d
Template plane class with some intersection testing methods.
Definition plane3d.h:34
irr::core::plane3d::classifyPointRelation
EIntersectionRelation3D classifyPointRelation(const vector3d< T > &point) const
Classifies the relation of a point to this plane.
Definition plane3d.h:135
irr::core::plane3d::setPlane
void setPlane(const vector3d< T > &nvect, T d)
Definition plane3d.h:64
irr::core::plane3d::getMemberPoint
vector3d< T > getMemberPoint() const
Gets a member point of the plane.
Definition plane3d.h:155
irr::core::plane3d::setPlane
void setPlane(const vector3d< T > &point1, const vector3d< T > &point2, const vector3d< T > &point3)
Definition plane3d.h:70
irr::core::plane3d::plane3d
plane3d(const vector3d< T > &normal, const T d)
Definition plane3d.h:48
irr::core::plane3d::plane3d
plane3d()
Definition plane3d.h:39
irr::core::plane3d::getKnownIntersectionWithLine
f32 getKnownIntersectionWithLine(const vector3d< T > &linePoint1, const vector3d< T > &linePoint2) const
Get percentage of line between two points where an intersection with this plane happens.
Definition plane3d.h:107
irr::core::plane3d::existsIntersection
bool existsIntersection(const plane3d< T > &other) const
Tests if there is an intersection with the other plane.
Definition plane3d.h:162
irr::core::plane3d::recalculateD
void recalculateD(const vector3d< T > &MPoint)
Recalculates the distance from origin by applying a new member point to the plane.
Definition plane3d.h:149
irr::core::plane3d::getIntersectionWithLimitedLine
bool getIntersectionWithLimitedLine(const vector3d< T > &linePoint1, const vector3d< T > &linePoint2, vector3d< T > &outIntersection) const
Get an intersection with a 3d line, limited between two 3d points.
Definition plane3d.h:121
irr::core::plane3d::setPlane
void setPlane(const vector3d< T > &point, const vector3d< T > &nvector)
Definition plane3d.h:58
irr::core::plane3d::plane3d
plane3d(const vector3d< T > &point1, const vector3d< T > &point2, const vector3d< T > &point3)
Definition plane3d.h:45
irr::core::plane3d::plane3d
plane3d(const vector3d< T > &MPoint, const vector3d< T > &Normal)
Definition plane3d.h:41
irr::core::plane3d< f32 >::Normal
vector3d< f32 > Normal
Definition plane3d.h:228
irr::core::plane3d::getIntersectionWithPlanes
bool getIntersectionWithPlanes(const plane3d< T > &o1, const plane3d< T > &o2, vector3d< T > &outPoint) const
Get the intersection point with two other planes if there is one.
Definition plane3d.h:195
irr::core::plane3d::getIntersectionWithPlane
bool getIntersectionWithPlane(const plane3d< T > &other, vector3d< T > &outLinePoint, vector3d< T > &outLineVect) const
Intersects this plane with another.
Definition plane3d.h:173
irr::core::plane3d::getDistanceTo
T getDistanceTo(const vector3d< T > &point) const
Get the distance to a point.
Definition plane3d.h:222
irr::core::plane3d::isFrontFacing
bool isFrontFacing(const vector3d< T > &lookDirection) const
Test if the triangle would be front or backfacing from any point.
Definition plane3d.h:214
irr::core::plane3d::operator==
bool operator==(const plane3d< T > &other) const
Definition plane3d.h:52
irr::core::plane3d::operator!=
bool operator!=(const plane3d< T > &other) const
Definition plane3d.h:54
irr::core::plane3d::getIntersectionWithLine
bool getIntersectionWithLine(const vector3d< T > &linePoint, const vector3d< T > &lineVect, vector3d< T > &outIntersection) const
Get an intersection with a 3d line.
Definition plane3d.h:86
irr::core::plane3d::plane3d
plane3d(T px, T py, T pz, T nx, T ny, T nz)
Definition plane3d.h:43
irr::core::plane3d< f32 >::D
f32 D
Definition plane3d.h:231
irr::core::vector3d
3d vector template class with lots of operators and methods.
Definition vector3d.h:23
irr::core::vector3d::getLength
T getLength() const
Get length of the vector.
Definition vector3d.h:117
irr::core::vector3d::isBetweenPoints
bool isBetweenPoints(const vector3d< T > &begin, const vector3d< T > &end) const
Returns if this vector interpreted as a point is on a line between two other points.
Definition vector3d.h:157
irr::core::vector3d::dotProduct
T dotProduct(const vector3d< T > &other) const
Get the dot product with another vector.
Definition vector3d.h:125
irrMath.h
F32_LOWER_EQUAL_0
#define F32_LOWER_EQUAL_0(n)
Definition irrMath.h:386
irr::core
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
irr::core::ROUNDING_ERROR_f64
const f64 ROUNDING_ERROR_f64
Definition irrMath.h:50
irr::core::EIntersectionRelation3D
EIntersectionRelation3D
Enumeration for intersection relations of 3d objects.
Definition plane3d.h:18
irr::core::ISREL3D_SPANNING
@ ISREL3D_SPANNING
Definition plane3d.h:22
irr::core::ISREL3D_FRONT
@ ISREL3D_FRONT
Definition plane3d.h:19
irr::core::ISREL3D_CLIPPED
@ ISREL3D_CLIPPED
Definition plane3d.h:23
irr::core::ISREL3D_PLANAR
@ ISREL3D_PLANAR
Definition plane3d.h:21
irr::core::ISREL3D_BACK
@ ISREL3D_BACK
Definition plane3d.h:20
irr::core::ROUNDING_ERROR_f32
const f32 ROUNDING_ERROR_f32
Definition irrMath.h:49
irr::core::equals
bool equals(const f64 a, const f64 b, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals b, taking possible rounding errors into account
Definition irrMath.h:185
irr::core::plane3df
plane3d< f32 > plane3df
Typedef for a f32 3d plane.
Definition plane3d.h:236
irr::core::plane3di
plane3d< s32 > plane3di
Typedef for an integer 3d plane.
Definition plane3d.h:239
irr
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
irr::f32
float f32
32 bit floating point variable.
Definition irrTypes.h:104
irr::f64
double f64
64 bit floating point variable.
Definition irrTypes.h:108
vector3d.h
- Irrlicht Engine Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on for Irrlicht 3D Engine by Doxygen 1.15.0