3es  0.7
3esshape.h
1 //
2 // author: Kazys Stepanas
3 //
4 #ifndef _3ESSHAPE_H_
5 #define _3ESSHAPE_H_
6 
7 #include "3es-core.h"
8 
9 #include "3escolour.h"
10 #include "3esmessages.h"
11 #include "3esv3arg.h"
12 #include "3esquaternionarg.h"
13 
14 #include <cstdint>
15 
16 #ifdef WIN32
17 #pragma warning(push)
18 #pragma warning(disable : 4251)
19 #endif // WIN32
20 
21 namespace tes
22 {
23  class PacketWriter;
24  class Resource;
25 
39  class _3es_coreAPI Shape
40  {
41  public:
42  Shape(uint16_t routingId, uint32_t id = 0);
46  Shape(uint16_t routingId, uint32_t id, uint16_t category);
47  virtual inline ~Shape() {}
48 
49  uint16_t routingId() const;
50 
51  uint32_t id() const;
52  Shape &setId(uint32_t id);
53  uint16_t category() const;
54  Shape &setCategory(uint16_t category);
55 
59  Shape &setWireframe(bool wire);
62  bool isWireframe() const;
63 
67  Shape &setTransparent(bool transparent);
70  bool isTransparent() const;
71 
75  Shape &setTwoSided(bool twoSided);
78  bool isTwoSided() const;
79 
84  Shape &setFlags(uint16_t flags);
87  uint16_t flags() const;
88 
89  Shape &setPosition(const V3Arg &pos);
90  Vector3f position() const;
91 
92  Shape &setPosX(float p);
93  Shape &setPosY(float p);
94  Shape &setPosZ(float p);
95 
96  Shape &setRotation(const QuaternionArg &rot);
97  Quaternionf rotation() const;
98 
99  Shape &setScale(const V3Arg &scale);
100  Vector3f scale() const;
101 
102  Shape &setColour(const Colour &colour);
103  Colour colour() const;
104 
115  virtual void updateFrom(const Shape &other);
116 
123  virtual bool writeCreate(PacketWriter &stream) const;
124 
133  virtual inline int writeData(PacketWriter &stream, unsigned &progressMarker) const { return 0; }
134 
135  bool writeUpdate(PacketWriter &stream) const;
136  bool writeDestroy(PacketWriter &stream) const;
137 
140  virtual inline bool isComplex() const { return false; }
141 
163  virtual int enumerateResources(const Resource **resources, int capacity, int fetchOffset = 0) const;
164 
167  virtual Shape *clone() const;
168 
169  protected:
176  void onClone(Shape *copy) const;
177 
178  void init(uint32_t id, uint16_t cat = 0, uint16_t flags = 0);
179 
180  uint16_t _routingId;
181  CreateMessage _data;
182  };
183 
184 
185  inline Shape::Shape(uint16_t routingId, uint32_t id)
186  : _routingId(routingId)
187  {
188  init(id);
189  }
190 
191 
192  inline Shape::Shape(uint16_t routingId, uint32_t id, uint16_t category)
193  : _routingId(routingId)
194  {
195  init(id, category);
196  }
197 
198 
199  inline void Shape::init(uint32_t id, uint16_t cat, uint16_t flags)
200  {
201  _data.id = id;
202  _data.category = cat;
203  _data.flags = flags;
204  _data.reserved = 0u;
205  _data.attributes.colour = 0xffffffffu;
206  _data.attributes.position[0] = _data.attributes.position[1] = _data.attributes.position[2] = 0;
207  _data.attributes.rotation[0] = _data.attributes.rotation[1] = _data.attributes.rotation[2] = 0;
208  _data.attributes.rotation[3] = _data.attributes.scale[0] = _data.attributes.scale[1] = _data.attributes.scale[2] = 1;
209  }
210 
211 
212  inline uint16_t Shape::routingId() const
213  {
214  return _routingId;
215  }
216 
217 
218  inline uint32_t Shape::id() const
219  {
220  return _data.id;
221  }
222 
223 
224  inline Shape &Shape::setId(uint32_t id)
225  {
226  _data.id = id;
227  return *this;
228  }
229 
230 
231  inline uint16_t Shape::category() const
232  {
233  return _data.category;
234  }
235 
236 
237  inline Shape &Shape::setCategory(uint16_t category)
238  {
239  _data.category = category;
240  return *this;
241  }
242 
243 
244  inline Shape &Shape::setWireframe(bool wire)
245  {
246  _data.flags &= ~OFWire;
247  _data.flags |= OFWire * !!wire;
248  return *this;
249  }
250 
251 
252  inline bool Shape::isWireframe() const
253  {
254  return (_data.flags & OFWire) != 0;
255  }
256 
257 
258  inline Shape &Shape::setTransparent(bool transparent)
259  {
260  _data.flags &= ~OFTransparent;
261  _data.flags |= OFTransparent * !!transparent;
262  return *this;
263  }
264 
265 
266  inline bool Shape::isTransparent() const
267  {
268  return (_data.flags & OFTransparent) != 0;
269  }
270 
271 
272  inline Shape &Shape::setTwoSided(bool twoSided)
273  {
274  _data.flags &= ~OFTwoSided;
275  _data.flags |= OFTwoSided * !!twoSided;
276  return *this;
277  }
278 
279 
280  inline bool Shape::isTwoSided() const
281  {
282  return (_data.flags & OFTwoSided) != 0;
283  }
284 
285 
286  inline Shape &Shape::setFlags(uint16_t flags)
287  {
288  _data.flags = flags;
289  return *this;
290  }
291 
292 
293  inline uint16_t Shape::flags() const
294  {
295  return _data.flags;
296  }
297 
298 
299  inline Shape &Shape::setPosition(const V3Arg &pos)
300  {
301  _data.attributes.position[0] = pos[0];
302  _data.attributes.position[1] = pos[1];
303  _data.attributes.position[2] = pos[2];
304  return *this;
305  }
306 
307 
308  inline Vector3f Shape::position() const
309  {
310  return Vector3f(_data.attributes.position[0], _data.attributes.position[1], _data.attributes.position[2]);
311  }
312 
313 
314  inline Shape &Shape::setPosX(float p)
315  {
316  _data.attributes.position[0] = p;
317  return *this;
318  }
319 
320 
321  inline Shape &Shape::setPosY(float p)
322  {
323  _data.attributes.position[1] = p;
324  return *this;
325  }
326 
327 
328  inline Shape &Shape::setPosZ(float p)
329  {
330  _data.attributes.position[2] = p;
331  return *this;
332  }
333 
334 
335  inline Shape &Shape::setRotation(const QuaternionArg &rot)
336  {
337  _data.attributes.rotation[0] = rot[0];
338  _data.attributes.rotation[1] = rot[1];
339  _data.attributes.rotation[2] = rot[2];
340  _data.attributes.rotation[3] = rot[3];
341  return *this;
342  }
343 
344 
345  inline Quaternionf Shape::rotation() const
346  {
347  return Quaternionf(_data.attributes.rotation[0], _data.attributes.rotation[1], _data.attributes.rotation[2], _data.attributes.rotation[3]);
348  }
349 
350 
351  inline Shape &Shape::setScale(const V3Arg &scale)
352  {
353  _data.attributes.scale[0] = scale[0];
354  _data.attributes.scale[1] = scale[1];
355  _data.attributes.scale[2] = scale[2];
356  return *this;
357  }
358 
359 
360  inline Vector3f Shape::scale() const
361  {
362  return Vector3f(_data.attributes.scale[0], _data.attributes.scale[1], _data.attributes.scale[2]);
363  }
364 
365 
366  inline Shape &Shape::setColour(const Colour &colour)
367  {
368  _data.attributes.colour = colour.c;
369  return *this;
370  }
371 
372 
373  inline Colour Shape::colour() const
374  {
375  return Colour(_data.attributes.colour);
376  }
377 }
378 
379 #ifdef WIN32
380 #pragma warning(pop)
381 #endif // WIN32
382 
383 #endif // _3ESSHAPE_H_
uint32_t colour
Initial object colour.
Definition: 3esmessages.h:355
A base class for encapsulating a shape which is to be represented remotely.
Definition: 3esshape.h:39
A 32-bit integer colour class.
Definition: 3escolour.h:19
float scale[3]
Object scale.
Definition: 3esmessages.h:358
uint16_t flags() const
Retrieve the full set of ObjectFlag values.
Definition: 3esshape.h:293
Shape & setFlags(uint16_t flags)
Set the full set of ObjectFlag values.
Definition: 3esshape.h:286
float position[3]
Object position.
Definition: 3esmessages.h:356
Shape & setTransparent(bool transparent)
Sets the transparent flag value for this shape.
Definition: 3esshape.h:258
virtual int writeData(PacketWriter &stream, unsigned &progressMarker) const
Called only for complex shapes to write additional creation data.
Definition: 3esshape.h:133
uint32_t id
Id of the object to create. Zero for transient objects.
Definition: 3esmessages.h:404
Use a two sided shader.
Definition: 3esmessages.h:95
Definition: 3esbounds.h:13
bool isTwoSided() const
Returns true if the two sided shader flag is set.
Definition: 3esshape.h:280
float rotation[4]
Object rotation (quaternion)
Definition: 3esmessages.h:357
Vector3< float > Vector3f
Defines a single precision vector.
Definition: 3esvector3.h:14
The Resource base class defines an interface for any resource used by Shape objects such as MeshSet...
Definition: 3esresource.h:34
The object supports transparency. Use the colour alpha channel.
Definition: 3esmessages.h:94
uint32_t c
Encoded colour value.
Definition: 3escolour.h:39
bool isTransparent() const
Returns true if the transparent flag is set.
Definition: 3esshape.h:266
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 an object creation message.
Definition: 3esmessages.h:399
uint16_t reserved
Reserved for future use.
Definition: 3esmessages.h:407
uint16_t flags
Flags controlling the appearance and creation of the object.
Definition: 3esmessages.h:406
uint16_t category
Object categorisation. Used to control visibility.
Definition: 3esmessages.h:405
Show the object as a wireframe mesh.
Definition: 3esmessages.h:93
A helper structure used to convert from float or double pointers to Quaternionf arguments.
Definition: 3esquaternionarg.h:14
bool isWireframe() const
Returns true if the wireframe flag is set.
Definition: 3esshape.h:252
virtual bool isComplex() const
Is this a complex shape? Complex shapes have writeData() called.
Definition: 3esshape.h:140
Quaternion< float > Quaternionf
Defines a single precision quaternion.
Definition: 3esquaternion.h:198
ObjectAttributes attributes
Initial transformation and colour.
Definition: 3esmessages.h:408
A utility class for writing payload data to a PacketHeader.
Definition: 3espacketwriter.h:34
Shape & setTwoSided(bool twoSided)
Sets the two sided shader flag value for this shape.
Definition: 3esshape.h:272
Shape & setWireframe(bool wire)
Sets the wireframe flag value for this shape.
Definition: 3esshape.h:244