Irrlicht 3D Engine
 
Loading...
Searching...
No Matches
line3d.h
Go to the documentation of this file.
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef __IRR_LINE_3D_H_INCLUDED__
6#define __IRR_LINE_3D_H_INCLUDED__
7
8#include "irrTypes.h"
9#include "vector3d.h"
10
11namespace irr
12{
13namespace core
14{
15
17template <class T>
18class line3d
19{
20 public:
21
23
24 line3d() : start(0,0,0), end(1,1,1) {}
26 line3d(T xa, T ya, T za, T xb, T yb, T zb) : start(xa, ya, za), end(xb, yb, zb) {}
29
30 // operators
31
33 line3d<T>& operator+=(const vector3d<T>& point) { start += point; end += point; return *this; }
34
36 line3d<T>& operator-=(const vector3d<T>& point) { start -= point; end -= point; return *this; }
37
38 bool operator==(const line3d<T>& other) const
39 { return (start==other.start && end==other.end) || (end==other.start && start==other.end);}
40 bool operator!=(const line3d<T>& other) const
41 { return !(start==other.start && end==other.end) || (end==other.start && start==other.end);}
42
43 // functions
45 void setLine(const T& xa, const T& ya, const T& za, const T& xb, const T& yb, const T& zb)
46 {start.set(xa, ya, za); end.set(xb, yb, zb);}
49 {start.set(nstart); end.set(nend);}
51 void setLine(const line3d<T>& line)
52 {start.set(line.start); end.set(line.end);}
53
55
56 T getLength() const { return start.getDistanceFrom(end); }
57
59
60 T getLengthSQ() const { return start.getDistanceFromSQ(end); }
61
63
65 {
66 return (start + end)/(T)2;
67 }
68
70
72 {
73 return end - start;
74 }
75
77
82 {
83 return point.isBetweenPoints(start, end);
84 }
85
87
90 {
92 vector3d<T> v = end - start;
93 T d = (T)v.getLength();
94 v /= d;
95 T t = v.dotProduct(c);
96
97 if (t < (T)0.0)
98 return start;
99 if (t > d)
100 return end;
101
102 v *= t;
103 return start + v;
104 }
105
107
114 {
115 const vector3d<T> q = sorigin - start;
116 T c = q.getLength();
117 T v = q.dotProduct(getVector().normalize());
118 T d = sradius * sradius - (c*c - v*v);
119
120 if (d < 0.0)
121 return false;
122
124 return true;
125 }
126
127 // member variables
128
133};
134
139
140} // end namespace core
141} // end namespace irr
142
143#endif
144
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.h:22
3D line between two points with intersection methods.
Definition line3d.h:19
line3d< T > operator-(const vector3d< T > &point) const
Definition line3d.h:35
bool getIntersectionWithSphere(vector3d< T > sorigin, T sradius, f64 &outdistance) const
Check if the line intersects with a shpere.
Definition line3d.h:113
line3d(T xa, T ya, T za, T xb, T yb, T zb)
Constructor with two points.
Definition line3d.h:26
T getLengthSQ() const
Get squared length of line.
Definition line3d.h:60
vector3d< T > getMiddle() const
Get middle of line.
Definition line3d.h:64
line3d< T > & operator-=(const vector3d< T > &point)
Definition line3d.h:36
void setLine(const line3d< T > &line)
Set this line to new line given as parameter.
Definition line3d.h:51
line3d< T > operator+(const vector3d< T > &point) const
Definition line3d.h:32
vector3d< T > start
Start point of line.
Definition line3d.h:130
vector3d< T > getClosestPoint(const vector3d< T > &point) const
Get the closest point on this line to a point.
Definition line3d.h:89
line3d(const vector3d< T > &start, const vector3d< T > &end)
Constructor with two points as vectors.
Definition line3d.h:28
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
T getLength() const
Get length of line.
Definition line3d.h:56
bool operator!=(const line3d< T > &other) const
Definition line3d.h:40
line3d()
Default constructor.
Definition line3d.h:24
bool isPointBetweenStartAndEnd(const vector3d< T > &point) const
Check if the given point is between start and end of the line.
Definition line3d.h:81
line3d< T > & operator+=(const vector3d< T > &point)
Definition line3d.h:33
vector3d< T > getVector() const
Get vector of line.
Definition line3d.h:71
bool operator==(const line3d< T > &other) const
Definition line3d.h:38
vector3d< T > end
End point of line.
Definition line3d.h:132
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
line3d< f32 > line3df
Typedef for an f32 line.
Definition line3d.h:136
line3d< s32 > line3di
Typedef for an integer line.
Definition line3d.h:138
REALINLINE f32 squareroot(const f32 f)
Definition irrMath.h:471
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
double f64
64 bit floating point variable.
Definition irrTypes.h:108