3es  0.7
3escylinder.h
1 //
2 // author: Kazys Stepanas
3 //
4 #ifndef _3ESCYLINDER_H_
5 #define _3ESCYLINDER_H_
6 
7 #include "3es-core.h"
8 #include "3esshape.h"
9 
10 namespace tes
11 {
21  class _3es_coreAPI Cylinder : public Shape
22  {
23  public:
29  static const Vector3f DefaultAxis;
30 
32  Cylinder(uint32_t id = 0u, const V3Arg &centre = V3Arg(0, 0, 0), const V3Arg &axis = DefaultAxis, float radius = 1.0f, float length = 1.0f);
40  Cylinder(uint32_t id, uint16_t category, const V3Arg &centre = V3Arg(0, 0, 0), const V3Arg &axis = DefaultAxis, float radius = 1.0f, float length = 1.0f);
41 
45  Cylinder &setRadius(float radius);
48  float radius() const;
49 
53  Cylinder &setLength(float radius);
56  float length() const;
57 
61  Cylinder &setCentre(const V3Arg &centre);
64  Vector3f centre() const;
65 
69  Cylinder &setAxis(const V3Arg &axis);
74  Vector3f axis() const;
75  };
76 
77 
78  inline Cylinder::Cylinder(uint32_t id, const V3Arg &centre, const V3Arg &axis, float radius, float length)
79  : Shape(SIdCylinder, id)
80  {
81  setPosition(centre);
82  setAxis(axis);
83  setScale(Vector3f(radius, radius, length));
84  }
85 
86 
87  inline Cylinder::Cylinder(uint32_t id, uint16_t category, const V3Arg &centre, const V3Arg &axis, float radius, float length)
88  : Shape(SIdCylinder, id, category)
89  {
90  setPosition(centre);
91  setAxis(axis);
92  setScale(Vector3f(radius, radius, length));
93  }
94 
95 
97  {
98  Vector3f s = Shape::scale();
99  s.x = s.y = radius;
100  setScale(s);
101  return *this;
102  }
103 
104 
105  inline float Cylinder::radius() const
106  {
107  return scale().x;
108  }
109 
110 
112  {
113  Vector3f s = Shape::scale();
114  s.z = length;
115  setScale(s);
116  return *this;
117  }
118 
119 
120  inline float Cylinder::length() const
121  {
122  return scale().z;
123  }
124 
125 
127  {
128  setPosition(centre);
129  return *this;
130  }
131 
132 
133  inline Vector3f Cylinder::centre() const
134  {
135  return position();
136  }
137 
138 
140  {
141  Quaternionf rot;
142  if (axis.v3.dot(DefaultAxis) > -0.9998f)
143  {
144  rot = Quaternionf(DefaultAxis, axis);
145  }
146  else
147  {
148  rot.setAxisAngle(Vector3f::axisx, float(M_PI));
149  }
150  setRotation(rot);
151  return *this;
152  }
153 
154 
155  inline Vector3f Cylinder::axis() const
156  {
157  Quaternionf rot = rotation();
158  return rot * DefaultAxis;
159  }
160 }
161 
162 #endif // _3ESCYLINDER_H_
A base class for encapsulating a shape which is to be represented remotely.
Definition: 3esshape.h:39
Vector3f axis() const
Get the cylinder primary axis.
Definition: 3escylinder.h:155
static const Vector3< T > axisx
The vector (1, 0, 0).
Definition: 3esvector3.h:44
Definition: 3esbounds.h:13
Vector3f centre() const
Get the cylinder centre position.
Definition: 3escylinder.h:133
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
float radius() const
Get the cylinder radius.
Definition: 3escylinder.h:105
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
Defines a cylinder shape to display.
Definition: 3escylinder.h:21
Cylinder & setCentre(const V3Arg &centre)
Set the position fo the cylinder centre.
Definition: 3escylinder.h:126
Cylinder & setAxis(const V3Arg &axis)
Set the cylinder primary axis.
Definition: 3escylinder.h:139
T x
Direct data member access.
Definition: 3esvector3.h:30
Quaternion< float > Quaternionf
Defines a single precision quaternion.
Definition: 3esquaternion.h:198
float length() const
Get the cylinder body length.
Definition: 3escylinder.h:120
Cylinder & setRadius(float radius)
Set the cylinder body radius.
Definition: 3escylinder.h:96
Cylinder & setLength(float radius)
Set the cylinder body length.
Definition: 3escylinder.h:111
T dot(const Vector3< T > &other) const
Calculates the dot product of this.other.
Definition: 3esvector3.h:422
static const Vector3f DefaultAxis
Default direction used as a reference orientation for packing the rotation.
Definition: 3escylinder.h:29
Cylinder(uint32_t id=0u, const V3Arg &centre=V3Arg(0, 0, 0), const V3Arg &axis=DefaultAxis, float radius=1.0f, float length=1.0f)
Definition: 3escylinder.h:78