Loading...
Searching...
No Matches
line3d.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_LINE_3D_H_INCLUDED__
#define __IRR_LINE_3D_H_INCLUDED__
#include "irrTypes.h"
#include "vector3d.h"
namespace irr
{
namespace core
{
template <class T>
class line3d
{
public:
line3d() : start(0,0,0), end(1,1,1) {}
line3d(T xa, T ya, T za, T xb, T yb, T zb) : start(xa, ya, za), end(xb, yb, zb) {}
line3d(const vector3d<T>& start, const vector3d<T>& end) : start(start), end(end) {}
// operators
line3d<T> operator+(const vector3d<T>& point) const { return line3d<T>(start + point, end + point); }
line3d<T>& operator+=(const vector3d<T>& point) { start += point; end += point; return *this; }
line3d<T> operator-(const vector3d<T>& point) const { return line3d<T>(start - point, end - point); }
line3d<T>& operator-=(const vector3d<T>& point) { start -= point; end -= point; return *this; }
bool operator==(const line3d<T>& other) const
{ return (start==other.start && end==other.end) || (end==other.start && start==other.end);}
bool operator!=(const line3d<T>& other) const
{ return !(start==other.start && end==other.end) || (end==other.start && start==other.end);}
// functions
void setLine(const T& xa, const T& ya, const T& za, const T& xb, const T& yb, const T& zb)
{start.set(xa, ya, za); end.set(xb, yb, zb);}
void setLine(const vector3d<T>& nstart, const vector3d<T>& nend)
{start.set(nstart); end.set(nend);}
void setLine(const line3d<T>& line)
{start.set(line.start); end.set(line.end);}
T getLength() const { return start.getDistanceFrom(end); }
T getLengthSQ() const { return start.getDistanceFromSQ(end); }
vector3d<T> getMiddle() const
{
return (start + end)/(T)2;
}
vector3d<T> getVector() const
{
return end - start;
}
bool isPointBetweenStartAndEnd(const vector3d<T>& point) const
{
return point.isBetweenPoints(start, end);
}
vector3d<T> getClosestPoint(const vector3d<T>& point) const
{
vector3d<T> c = point - start;
vector3d<T> v = end - start;
T d = (T)v.getLength();
v /= d;
T t = v.dotProduct(c);
if (t < (T)0.0)
return start;
if (t > d)
return end;
v *= t;
return start + v;
}
bool getIntersectionWithSphere(vector3d<T> sorigin, T sradius, f64& outdistance) const
{
const vector3d<T> q = sorigin - start;
T c = q.getLength();
T v = q.dotProduct(getVector().normalize());
T d = sradius * sradius - (c*c - v*v);
if (d < 0.0)
return false;
outdistance = v - core::squareroot ( d );
return true;
}
// member variables
vector3d<T> start;
vector3d<T> end;
};
typedef line3d<f32> line3df;
typedef line3d<s32> line3di;
} // end namespace core
} // end namespace irr
#endif
irr::core::line3d
3D line between two points with intersection methods.
Definition line3d.h:19
irr::core::line3d::operator-
line3d< T > operator-(const vector3d< T > &point) const
Definition line3d.h:35
irr::core::line3d::getIntersectionWithSphere
bool getIntersectionWithSphere(vector3d< T > sorigin, T sradius, f64 &outdistance) const
Check if the line intersects with a shpere.
Definition line3d.h:113
irr::core::line3d::line3d
line3d(T xa, T ya, T za, T xb, T yb, T zb)
Constructor with two points.
Definition line3d.h:26
irr::core::line3d::getLengthSQ
T getLengthSQ() const
Get squared length of line.
Definition line3d.h:60
irr::core::line3d::getMiddle
vector3d< T > getMiddle() const
Get middle of line.
Definition line3d.h:64
irr::core::line3d::operator-=
line3d< T > & operator-=(const vector3d< T > &point)
Definition line3d.h:36
irr::core::line3d::setLine
void setLine(const line3d< T > &line)
Set this line to new line given as parameter.
Definition line3d.h:51
irr::core::line3d::operator+
line3d< T > operator+(const vector3d< T > &point) const
Definition line3d.h:32
irr::core::line3d< f32 >::start
vector3d< f32 > start
Definition line3d.h:130
irr::core::line3d::getClosestPoint
vector3d< T > getClosestPoint(const vector3d< T > &point) const
Get the closest point on this line to a point.
Definition line3d.h:89
irr::core::line3d::line3d
line3d(const vector3d< T > &start, const vector3d< T > &end)
Constructor with two points as vectors.
Definition line3d.h:28
irr::core::line3d::setLine
void setLine(const T &xa, const T &ya, const T &za, const T &xb, const T &yb, const T &zb)
Set this line to a new line going through the two points.
Definition line3d.h:45
irr::core::line3d::getLength
T getLength() const
Get length of line.
Definition line3d.h:56
irr::core::line3d::operator!=
bool operator!=(const line3d< T > &other) const
Definition line3d.h:40
irr::core::line3d::line3d
line3d()
Default constructor.
Definition line3d.h:24
irr::core::line3d::isPointBetweenStartAndEnd
bool isPointBetweenStartAndEnd(const vector3d< T > &point) const
Check if the given point is between start and end of the line.
Definition line3d.h:81
irr::core::line3d::operator+=
line3d< T > & operator+=(const vector3d< T > &point)
Definition line3d.h:33
irr::core::line3d::getVector
vector3d< T > getVector() const
Get vector of line.
Definition line3d.h:71
irr::core::line3d::operator==
bool operator==(const line3d< T > &other) const
Definition line3d.h:38
irr::core::line3d< f32 >::end
vector3d< f32 > end
Definition line3d.h:132
irr::core::line3d::setLine
void setLine(const vector3d< T > &nstart, const vector3d< T > &nend)
Set this line to a new line going through the two points.
Definition line3d.h:48
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
irrTypes.h
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::line3df
line3d< f32 > line3df
Typedef for an f32 line.
Definition line3d.h:136
irr::core::line3di
line3d< s32 > line3di
Typedef for an integer line.
Definition line3d.h:138
irr::core::squareroot
REALINLINE f32 squareroot(const f32 f)
Definition irrMath.h:471
irr
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
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