voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
triangleVector3.hpp
1 #ifndef TRIANGLEVECTOR3_2_HPP
2 #define TRIANGLEVECTOR3_2_HPP
3 
4 #include "blub/math/vector3.hpp"
5 
6 
7 namespace blub
8 {
9 
11 {
12 public:
14  {
15  positions[0] = vector3(0);
16  positions[1] = vector3(0);
17  positions[2] = vector3(0);
18  }
19  triangleVector3(const vector3& a, const vector3& b, const vector3& c)
20  {
21  positions[0] = a;
22  positions[1] = b;
23  positions[2] = c;
24  }
25 
26  triangleVector3(const vector3& a)
27  {
28  positions[0] = a;
29  positions[1] = a;
30  positions[2] = a;
31  }
32 
33  bool operator == (const triangleVector3 & other) const
34  {
35  return other.positions[0] == positions[0]
36  && other.positions[1] == positions[1]
37  && other.positions[2] == positions[2];
38  }
39 
40  vector3 nearest(vector3 to) const
41  {
42  return positions[nearestId(to)];
43  }
44 
45  uint16 nearestId(vector3 to) const
46  {
47  uint16 nearestId(0);
48  real nearest(positions[0].squaredDistance(to));
49  for (uint16 index = 1; index < 3; ++index)
50  {
51  if (positions[index].squaredDistance(to) < nearest)
52  nearestId = index;
53  }
54  return nearestId;
55  }
56 
57  vector3 getNormal() const
58  {
59  return ((positions[1]-positions[0]).normalisedCopy()).crossProduct((positions[2]-positions[0]).normalisedCopy());
60  }
61 
62  axisAlignedBox getAxisAlignedBoundingBox() const;
63 
64  plane getPlane() const;
65 
66  vector3 midPoint()
67  {
68  return (positions[0] + positions[1] + positions[2]) / 3.0;
69  }
70 
71  vector3 positions[3];
72 };
73 
74 
75 }
76 
77 #endif // TRIANGLEVECTOR3_HPP
Definition: triangleVector3.hpp:10
Definition: vector3.hpp:26
vector3 crossProduct(const vector3 &rkVector) const
Definition: vector3.hpp:478
Definition: axisAlignedBox.hpp:20
Definition: plane.hpp:16
Definition: deadlineTimer.hpp:10