3es  0.7
3esarrow.h
1 //
2 // author: Kazys Stepanas
3 //
4 #ifndef _3ESARROW_H_
5 #define _3ESARROW_H_
6 
7 #include "3es-core.h"
8 #include "3esshape.h"
9 
10 namespace tes
11 {
21  class _3es_coreAPI Arrow : public Shape
22  {
23  public:
29  static const Vector3f DefaultDirection;
30 
32  Arrow(uint32_t id = 0u, const V3Arg &origin = V3Arg(0, 0, 0), const V3Arg &dir = DefaultDirection, float length = 1.0f, float radius = 0.025f);
40  Arrow(uint32_t id, uint16_t category, const V3Arg &origin = V3Arg(0, 0, 0), const V3Arg &dir = V3Arg(0, 0, 1), float length = 1.0f, float radius = 0.025f);
41 
45  Arrow &setRadius(float radius);
48  float radius() const;
49 
53  Arrow &setLength(float length);
56  float length() const;
57 
64  Arrow &setOrigin(const V3Arg &origin);
65 
70  Vector3f origin() const;
71 
75  Arrow &setDirection(const V3Arg &direction);
81  Vector3f direction() const;
82  };
83 
84 
85  inline Arrow::Arrow(uint32_t id, const V3Arg &origin, const V3Arg &dir, float length, float radius)
86  : Shape(SIdArrow, id)
87  {
88  setPosition(origin);
89  setDirection(dir);
90  setScale(Vector3f(radius, radius, length));
91  }
92 
93 
94  inline Arrow::Arrow(uint32_t id, uint16_t category, const V3Arg &origin, const V3Arg &dir, float length, float radius)
95  : Shape(SIdArrow, id, category)
96  {
97  setPosition(origin);
98  setDirection(dir);
99  setScale(Vector3f(radius, radius, length));
100  }
101 
102 
104  {
105  Vector3f s = Shape::scale();
106  s.x = s.y = radius;
107  setScale(s);
108  return *this;
109  }
110 
111 
112  inline float Arrow::radius() const
113  {
114  return scale().x;
115  }
116 
117 
119  {
120  Vector3f s = Shape::scale();
121  s.z = length;
122  setScale(s);
123  return *this;
124  }
125 
126 
127  inline float Arrow::length() const
128  {
129  return scale().z;
130  }
131 
132 
134  {
135  setPosition(origin);
136  return *this;
137  }
138 
139 
140  inline Vector3f Arrow::origin() const
141  {
142  return position();
143  }
144 
145 
147  {
148  Quaternionf rot;
149  if (direction.v3.dot(DefaultDirection) > -0.9998f)
150  {
151  rot = Quaternionf(DefaultDirection, direction);
152  }
153  else
154  {
155  rot.setAxisAngle(Vector3f::axisx, float(M_PI));
156  }
157  setRotation(rot);
158  return *this;
159  }
160 
161 
162  inline Vector3f Arrow::direction() const
163  {
164  Quaternionf rot = rotation();
165  return rot * DefaultDirection;
166  }
167 }
168 
169 #endif // _3ESARROW_H_
A base class for encapsulating a shape which is to be represented remotely.
Definition: 3esshape.h:39
Arrow & setOrigin(const V3Arg &origin)
Set the arrow origin.
Definition: 3esarrow.h:133
static const Vector3< T > axisx
The vector (1, 0, 0).
Definition: 3esvector3.h:44
Defines an arrow shape to display.
Definition: 3esarrow.h:21
static const Vector3f DefaultDirection
Default direction used as a reference orientation for packing the rotation.
Definition: 3esarrow.h:29
Arrow & setLength(float length)
Set the arrow length from base to tip.
Definition: 3esarrow.h:118
Definition: 3esbounds.h:13
Vector3< float > Vector3f
Defines a single precision vector.
Definition: 3esvector3.h:14
Quaternion< T > & setAxisAngle(const Vector3< T > &axis, const T &angle)
Sets this quaternion from an axis of rotation and the angle of rotation about that axis (radians)...
Vector3f v3
Vector 3 value.
Definition: 3esv3arg.h:45
Represents a vector in R3.
Definition: 3esvector3.h:14
A helper structure used to convert from float or double pointers to Vector3f arguments.
Definition: 3esv3arg.h:14
Arrow & setRadius(float radius)
Set the arrow radius.
Definition: 3esarrow.h:103
T x
Direct data member access.
Definition: 3esvector3.h:30
float length() const
Get the arrow length from base to tip.
Definition: 3esarrow.h:127
Arrow(uint32_t id=0u, const V3Arg &origin=V3Arg(0, 0, 0), const V3Arg &dir=DefaultDirection, float length=1.0f, float radius=0.025f)
Definition: 3esarrow.h:85
Vector3f origin() const
Get the arrow base position.
Definition: 3esarrow.h:140
Arrow & setDirection(const V3Arg &direction)
Set the arrow direction vector.
Definition: 3esarrow.h:146
Quaternion< float > Quaternionf
Defines a single precision quaternion.
Definition: 3esquaternion.h:198
T dot(const Vector3< T > &other) const
Calculates the dot product of this.other.
Definition: 3esvector3.h:422
Vector3f direction() const
Get the arrow direction vector.
Definition: 3esarrow.h:162
float radius() const
Get the arrow radius.
Definition: 3esarrow.h:112