AGX Dynamics 2.41.3.0
Loading...
Searching...
No Matches
Shape.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19
21
22#include <agx/Vec3.h>
23#include <agx/SPDMatrix3x3.h>
24#include <agx/AffineMatrix4x4.h>
25
29
31
34
35namespace agxTerrain
36{
37 class Terrain;
38}
39
40namespace agx
41{
42 class InternalData;
43}
44
45namespace agxCollide
46{
47 class Geometry;
48 class Space;
49
53
58 {
59 public:
60
62 enum Type {
77 NUM_TYPES
78 };
79
81 static const char* getTypeName(agx::UInt8 type);
82
83 public:
84
88 virtual Shape *clone() const;
89
93 const char* getTypeName() const;
94
98 agx::UInt8 getType() const;
99
103 bool isGroup() const;
104
108 ShapeGroup* asGroup();
109
113 const ShapeGroup* asGroup() const;
114
118 const BoundingAABB& getBoundingVolume() const;
119
124 virtual bool hasSupportFunction() const;
125
130 virtual agx::Vec3 getSupportPoint( const agx::Vec3& supportDirection) const;
131
136 virtual agx::Vec3 getCenter() const;
137
141 virtual agx::Real getVolume() const = 0;
142
148
151 virtual void propagateTransform(const agx::AffineMatrix4x4& transform);
152
157 virtual const BoundingAABB& updateBoundingVolume() = 0;
158
164
170 virtual agx::Real calculateBoundingRadius( BoundingAABB& localAABB ) const;
171
172 agx::Physics::Geometry::ShapePtr getEntity() const;
173
177 Geometry* getGeometry();
178
182 const Geometry* getGeometry() const;
183
185 agx::AffineMatrix4x4 getTransform() const;
186
189
190
194 static BoundingAABB calculateBound(const agx::AffineMatrix4x4& transform, const BoundingAABB& localBound);
195
199 agx::UInt32 getModifiedCount() const;
200
202
203
205 void store( agxStream::OutputArchive& out ) const override;
206 void restore( agxStream::InputArchive& in ) override;
208
209
215 virtual void setRenderData( agxCollide::RenderData *renderData );
216
222 const agxCollide::RenderData* getRenderData( ) const;
223 agxCollide::RenderData* getRenderData();
224
225
226 protected:
227
233 Shape(Type type, agx::Physics::Geometry::ShapePtr entity = agx::Physics::Geometry::ShapeModel::createInstance());
234
239 agx::UInt32 incrementModifiedCount();
240
242 virtual ~Shape();
243
245
246
247 Shape& operator=(const Shape&) = delete;
248
250 void synchronize();
252
253 private:
254 friend class ShapeGroup;
255 friend class Geometry;
256 friend class Space;
257 friend class agxTerrain::Terrain;
258
259 Shape();
260 virtual void setGeometry(Geometry* geometry);
261 virtual void transfer(Space* space);
262
263 virtual void updateGeometryPtr();
264
266 friend class agx::InternalData;
270 agx::Referenced* getInternalData() const;
271
275 void setInternalData( agx::Referenced* data );
277
278 protected:
279
280 void syncronizeShapeIndex();
281
282 agx::Physics::Geometry::ShapeRef m_entity;
283 Geometry* m_geometry;
285 agx::Index m_shapeIndex;
286
287 ShapeGroup* m_parent;
288
289 agx::ref_ptr<agx::Referenced> m_internalData;
290 };
291
292
294
295
296 AGX_DECLARE_POINTER_TYPES(ShapeGroup);
297 class AGXPHYSICS_EXPORT ShapeGroup : public Shape
298 {
299 public:
300 ShapeGroup();
301 virtual Shape *clone() const override;
302
303 void addChild(Shape* shape, const agx::AffineMatrix4x4& transform = agx::AffineMatrix4x4());
304 void removeChild(Shape* shape);
305 void removeChild(size_t index);
306
311 virtual void setRenderData( agxCollide::RenderData *renderData ) override;
312
313
315
316 size_t getNumChildren() const;
317 Shape* getChild(size_t index);
318 const Shape* getChild(size_t index) const;
319 const agx::AffineMatrix4x4& getChildTransform(size_t index) const;
320
326 bool setChildTransform(size_t childIndex, const agx::AffineMatrix4x4& transform);
327
328
329 const ShapeRefVector& getChildren() const;
330 const agx::AffineMatrix4x4Vector& getChildTransforms() const;
331
332 bool replaceChild(size_t childIndex, Shape* newChild, const agx::AffineMatrix4x4& transform = agx::AffineMatrix4x4());
333
334 /* Common shape methods */
335
337 virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override;
338
340 virtual agx::Real getVolume() const override;
341
343 virtual agx::Vec3 getCenter() const override;
344
345 // Computes bounding volume in world coordinate system.
346 virtual const BoundingAABB& updateBoundingVolume() override;
347
348 // Computes bounding volume in local coordinate system.
349 virtual BoundingAABB calculateLocalBound() const override;
350
351 virtual void propagateTransform(const agx::AffineMatrix4x4& transform) override;
352
353 AGXSTREAM_DECLARE_SERIALIZABLE(agxCollide::ShapeGroup);
354
355 protected:
356 virtual ~ShapeGroup();
357
358 private:
359 friend class Geometry;
360
361 // void childUpdated(Shape *child);
362 virtual void updateGeometryPtr() override;
363 virtual void setGeometry(Geometry* geometry) override;
364 virtual void transfer(Space* space) override;
365
366 private:
367 ShapeRefVector m_children;
368 };
369
370 class AGXPHYSICS_EXPORT ShapeIterator
371 {
372 public:
373 ShapeIterator(Geometry* geometry);
374
375 Shape* getShape();
376 const Shape* getShape() const;
377 agx::AffineMatrix4x4 getLocalTransform() const;
378
379 bool isValid() const;
380 void next();
381
382 private:
383 void push(Shape* node, const agx::AffineMatrix4x4& transform);
384
385 private:
386 agx::Vector<Shape*> m_shapes;
388 size_t m_index;
389 };
390
392
393
394 /* Implementation */
395
396 AGX_FORCE_INLINE agx::UInt8 Shape::getType() const
397 {
398 return m_entity.type();
399 }
400 AGX_FORCE_INLINE bool Shape::isGroup() const
401 {
402 return getType() == GROUP;
403 }
404 AGX_FORCE_INLINE ShapeGroup* Shape::asGroup()
405 {
406 agxAssert(this->isGroup());
407 return static_cast<ShapeGroup*>(this);
408 }
409 AGX_FORCE_INLINE const ShapeGroup* Shape::asGroup() const
410 {
411 return const_cast<Shape*>(this)->asGroup();
412 }
413
414 inline agx::Physics::Geometry::ShapePtr Shape::getEntity() const
415 {
416 return m_entity;
417 }
418 AGX_FORCE_INLINE Geometry* Shape::getGeometry()
419 {
420 return m_geometry;
421 }
422 AGX_FORCE_INLINE const Geometry* Shape::getGeometry() const
423 {
424 return m_geometry;
425 }
426 AGX_FORCE_INLINE agx::AffineMatrix4x4 Shape::getTransform() const
427 {
428 return m_entity.transform();
429 }
430
431 AGX_FORCE_INLINE const BoundingAABB& Shape::getBoundingVolume() const
432 {
433 return m_entity.boundingAABB();
434 }
435
436 AGX_FORCE_INLINE BoundingAABB Shape::calculateBound(const agx::AffineMatrix4x4& transform, const BoundingAABB& localBound)
437 {
438 return BoundingAABB(localBound, transform);
439 }
440
441 AGX_FORCE_INLINE size_t ShapeGroup::getNumChildren() const
442 {
443 return m_children.size();
444 }
445 AGX_FORCE_INLINE Shape* ShapeGroup::getChild(size_t index)
446 {
447 return m_children[index];
448 }
449 AGX_FORCE_INLINE const Shape* ShapeGroup::getChild(size_t index) const
450 {
451 return m_children[index];
452 }
453 AGX_FORCE_INLINE const agx::AffineMatrix4x4& ShapeGroup::getChildTransform(size_t index) const
454 {
455 return getEntity().childTransforms()[index];
456 }
457
458 inline agx::Physics::Geometry::ShapeGroupPtr ShapeGroup::getEntity() const
459 {
460 return m_entity;
461 }
462
463 AGX_FORCE_INLINE const ShapeRefVector& ShapeGroup::getChildren() const
464 {
465 return m_children;
466 }
467 AGX_FORCE_INLINE const agx::AffineMatrix4x4Vector& ShapeGroup::getChildTransforms() const
468 {
469 return reinterpret_cast<agx::AffineMatrix4x4Vector&>(getEntity().childTransforms());
470 }
471
473 AGX_FORCE_INLINE agx::UInt32 Shape::getModifiedCount() const
474 {
475 return m_entity.modifiedCount();
476 }
477
478 AGX_FORCE_INLINE agx::UInt32 Shape::incrementModifiedCount()
479 {
480 return ++m_entity.modifiedCount();
481 }
482
483
484 AGX_FORCE_INLINE Shape* ShapeIterator::getShape()
485 {
486 agxAssert(this->isValid());
487 return m_shapes[m_index];
488 }
489
490 AGX_FORCE_INLINE const Shape* ShapeIterator::getShape() const
491 {
492 return const_cast<ShapeIterator*>(this)->getShape();
493 }
494
495 inline agx::AffineMatrix4x4 ShapeIterator::getLocalTransform() const
496 {
497 agxAssert(this->isValid());
498 return m_transforms[m_index];
499 }
500
501 AGX_FORCE_INLINE bool ShapeIterator::isValid() const
502 {
503 return m_index < m_shapes.size();
504 }
505
506 AGX_FORCE_INLINE void ShapeIterator::next()
507 {
508 agxAssert(this->isValid());
509 m_index++;
510 }
511
512 inline bool Shape::hasSupportFunction() const
513 {
514 return false;
515 }
516
517 inline agx::Vec3 Shape::getSupportPoint( const agx::Vec3& ) const
518 {
519 return agx::Vec3(0, 0, 0);
520 }
521
522 inline agx::Vec3 Shape::getCenter() const
523 {
524 return agx::Vec3(0, 0, 0);
525 }
526
527 inline agx::Referenced* Shape::getInternalData() const
528 {
529 return m_internalData;
530 }
531}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:222
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:208
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Class for storing rendering information for a Shape.
Definition: RenderData.h:39
Base class for a shape.
Definition: Shape.h:58
Type
Define the type of a Shape.
Definition: Shape.h:62
virtual Shape * clone() const
Create a clone.
virtual void propagateTransform(const agx::AffineMatrix4x4 &transform)
const char * getTypeName() const
virtual agx::Real calculateBoundingRadius(BoundingAABB &localAABB) const
Calculate the bounding volume (AABB) into localAABB and calculate the bounding radius based on the ne...
virtual BoundingAABB calculateLocalBound() const =0
Calculate the bounding volume in the local coordinate system.
agx::AffineMatrix4x4 getLocalTransform() const
virtual agx::Real getVolume() const =0
Return the volume of the shape.
virtual const BoundingAABB & updateBoundingVolume()=0
Calculate the bounding volume based on the current Shape parameters including transformation.
static const char * getTypeName(agx::UInt8 type)
virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const =0
Calculate the inertia for the shape given a mass.
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:86
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Pointer to a entity instance of type Physics.Geometry.ShapeGroup.
Pointer to a entity instance of type Physics.Geometry.Shape.
Definition: ShapeEntity.h:196
Base class providing referencing counted objects.
Definition: Referenced.h:120
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:49
Vector containing 'raw' data.
Definition: agx/Vector.h:246
#define agxAssert(expr)
Definition: debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_FORCE_INLINE
Definition: macros.h:58
This namespace consists of a set of classes for handling geometric intersection tests including boole...
agx::Vector< agx::ref_ptr< Shape > > ShapeRefVector
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:59
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition: Integer.h:32
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
double Real
Definition: Real.h:42
uint8_t UInt8
Definition: Integer.h:30