AGX Dynamics 2.42.1.1
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 {
78 NUM_TYPES
79 };
80
82 static const char* getTypeName(agx::UInt8 type);
83
84 public:
85
89 virtual Shape *clone() const;
90
94 const char* getTypeName() const;
95
99 agx::UInt8 getType() const;
100
104 bool isGroup() const;
105
109 ShapeGroup* asGroup();
110
114 const ShapeGroup* asGroup() const;
115
119 const BoundingAABB& getBoundingVolume() const;
120
125 virtual bool hasSupportFunction() const;
126
131 virtual agx::Vec3 getSupportPoint( const agx::Vec3& supportDirection) const;
132
137 virtual agx::Vec3 getCenter() const;
138
142 virtual agx::Real getVolume() const = 0;
143
149
152 virtual void propagateTransform(const agx::AffineMatrix4x4& transform);
153
158 virtual const BoundingAABB& updateBoundingVolume() = 0;
159
165
171 virtual agx::Real calculateBoundingRadius( BoundingAABB& localAABB ) const;
172
173 agx::Physics::Geometry::ShapePtr getEntity() const;
174
178 Geometry* getGeometry();
179
183 const Geometry* getGeometry() const;
184
186 agx::AffineMatrix4x4 getTransform() const;
187
190
191
195 static BoundingAABB calculateBound(const agx::AffineMatrix4x4& transform, const BoundingAABB& localBound);
196
200 agx::UInt32 getModifiedCount() const;
201
203
204
206 void store( agxStream::OutputArchive& out ) const override;
207 void restore( agxStream::InputArchive& in ) override;
209
210
216 virtual void setRenderData( agxCollide::RenderData *renderData );
217
226 const agxCollide::RenderData* getRenderData( ) const;
227
236 agxCollide::RenderData* getRenderData();
237
238
239 protected:
240
246 Shape(Type type, agx::Physics::Geometry::ShapePtr entity = agx::Physics::Geometry::ShapeModel::createInstance());
247
252 agx::UInt32 incrementModifiedCount();
253
255 virtual ~Shape();
256
258
259
260 Shape& operator=(const Shape&) = delete;
261
263 void synchronize();
265
266 private:
267 friend class ShapeGroup;
268 friend class Geometry;
269 friend class Space;
270 friend class agxTerrain::Terrain;
271
272 Shape();
273 virtual void setGeometry(Geometry* geometry);
274 virtual void transfer(Space* space);
275
276 virtual void updateGeometryPtr();
277
279 friend class agx::InternalData;
283 agx::Referenced* getInternalData() const;
284
288 void setInternalData( agx::Referenced* data );
290
291 protected:
292
293 void syncronizeShapeIndex();
294
295 agx::Physics::Geometry::ShapeRef m_entity;
296 Geometry* m_geometry;
298 agx::Index m_shapeIndex;
299
300 ShapeGroup* m_parent;
301
302 agx::ref_ptr<agx::Referenced> m_internalData;
303 };
304
305
307
308
309 AGX_DECLARE_POINTER_TYPES(ShapeGroup);
310 class AGXPHYSICS_EXPORT ShapeGroup : public Shape
311 {
312 public:
313 ShapeGroup();
314 virtual Shape *clone() const override;
315
316 void addChild(Shape* shape, const agx::AffineMatrix4x4& transform = agx::AffineMatrix4x4());
317 void removeChild(Shape* shape);
318 void removeChild(size_t index);
319
324 virtual void setRenderData( agxCollide::RenderData *renderData ) override;
325
326
328
329 size_t getNumChildren() const;
330 Shape* getChild(size_t index);
331 const Shape* getChild(size_t index) const;
332 const agx::AffineMatrix4x4& getChildTransform(size_t index) const;
333
339 bool setChildTransform(size_t childIndex, const agx::AffineMatrix4x4& transform);
340
341
342 const ShapeRefVector& getChildren() const;
343 const agx::AffineMatrix4x4Vector& getChildTransforms() const;
344
345 bool replaceChild(size_t childIndex, Shape* newChild, const agx::AffineMatrix4x4& transform = agx::AffineMatrix4x4());
346
347 /* Common shape methods */
348
350 virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override;
351
353 virtual agx::Real getVolume() const override;
354
356 virtual agx::Vec3 getCenter() const override;
357
358 // Computes bounding volume in world coordinate system.
359 virtual const BoundingAABB& updateBoundingVolume() override;
360
361 // Computes bounding volume in local coordinate system.
362 virtual BoundingAABB calculateLocalBound() const override;
363
364 virtual void propagateTransform(const agx::AffineMatrix4x4& transform) override;
365
366 AGXSTREAM_DECLARE_SERIALIZABLE(agxCollide::ShapeGroup);
367
368 protected:
369 virtual ~ShapeGroup();
370
371 private:
372 friend class Geometry;
373
374 // void childUpdated(Shape *child);
375 virtual void updateGeometryPtr() override;
376 virtual void setGeometry(Geometry* geometry) override;
377 virtual void transfer(Space* space) override;
378
379 private:
380 ShapeRefVector m_children;
381 };
382
383 class AGXPHYSICS_EXPORT ShapeIterator
384 {
385 public:
386 ShapeIterator(Geometry* geometry);
387
388 Shape* getShape();
389 const Shape* getShape() const;
390 agx::AffineMatrix4x4 getLocalTransform() const;
391
392 bool isValid() const;
393 void next();
394
395 private:
396 void push(Shape* node, const agx::AffineMatrix4x4& transform);
397
398 private:
399 agx::Vector<Shape*> m_shapes;
401 size_t m_index;
402 };
403
405
406
407 /* Implementation */
408
409 AGX_FORCE_INLINE agx::UInt8 Shape::getType() const
410 {
411 return m_entity.type();
412 }
413 AGX_FORCE_INLINE bool Shape::isGroup() const
414 {
415 return getType() == GROUP;
416 }
417 AGX_FORCE_INLINE ShapeGroup* Shape::asGroup()
418 {
419 agxAssert(this->isGroup());
420 return static_cast<ShapeGroup*>(this);
421 }
422 AGX_FORCE_INLINE const ShapeGroup* Shape::asGroup() const
423 {
424 return const_cast<Shape*>(this)->asGroup();
425 }
426
427 inline agx::Physics::Geometry::ShapePtr Shape::getEntity() const
428 {
429 return m_entity;
430 }
431 AGX_FORCE_INLINE Geometry* Shape::getGeometry()
432 {
433 return m_geometry;
434 }
435 AGX_FORCE_INLINE const Geometry* Shape::getGeometry() const
436 {
437 return m_geometry;
438 }
439 AGX_FORCE_INLINE agx::AffineMatrix4x4 Shape::getTransform() const
440 {
441 return m_entity.transform();
442 }
443
444 AGX_FORCE_INLINE const BoundingAABB& Shape::getBoundingVolume() const
445 {
446 return m_entity.boundingAABB();
447 }
448
449 AGX_FORCE_INLINE BoundingAABB Shape::calculateBound(const agx::AffineMatrix4x4& transform, const BoundingAABB& localBound)
450 {
451 return BoundingAABB(localBound, transform);
452 }
453
454 AGX_FORCE_INLINE size_t ShapeGroup::getNumChildren() const
455 {
456 return m_children.size();
457 }
458 AGX_FORCE_INLINE Shape* ShapeGroup::getChild(size_t index)
459 {
460 return m_children[index];
461 }
462 AGX_FORCE_INLINE const Shape* ShapeGroup::getChild(size_t index) const
463 {
464 return m_children[index];
465 }
466 AGX_FORCE_INLINE const agx::AffineMatrix4x4& ShapeGroup::getChildTransform(size_t index) const
467 {
468 return getEntity().childTransforms()[index];
469 }
470
471 inline agx::Physics::Geometry::ShapeGroupPtr ShapeGroup::getEntity() const
472 {
473 return m_entity;
474 }
475
476 AGX_FORCE_INLINE const ShapeRefVector& ShapeGroup::getChildren() const
477 {
478 return m_children;
479 }
480 AGX_FORCE_INLINE const agx::AffineMatrix4x4Vector& ShapeGroup::getChildTransforms() const
481 {
482 return reinterpret_cast<agx::AffineMatrix4x4Vector&>(getEntity().childTransforms());
483 }
484
486 AGX_FORCE_INLINE agx::UInt32 Shape::getModifiedCount() const
487 {
488 return m_entity.modifiedCount();
489 }
490
491 AGX_FORCE_INLINE agx::UInt32 Shape::incrementModifiedCount()
492 {
493 return ++m_entity.modifiedCount();
494 }
495
496
497 AGX_FORCE_INLINE Shape* ShapeIterator::getShape()
498 {
499 agxAssert(this->isValid());
500 return m_shapes[m_index];
501 }
502
503 AGX_FORCE_INLINE const Shape* ShapeIterator::getShape() const
504 {
505 return const_cast<ShapeIterator*>(this)->getShape();
506 }
507
508 inline agx::AffineMatrix4x4 ShapeIterator::getLocalTransform() const
509 {
510 agxAssert(this->isValid());
511 return m_transforms[m_index];
512 }
513
514 AGX_FORCE_INLINE bool ShapeIterator::isValid() const
515 {
516 return m_index < m_shapes.size();
517 }
518
519 AGX_FORCE_INLINE void ShapeIterator::next()
520 {
521 agxAssert(this->isValid());
522 m_index++;
523 }
524
525 inline bool Shape::hasSupportFunction() const
526 {
527 return false;
528 }
529
530 inline agx::Vec3 Shape::getSupportPoint( const agx::Vec3& ) const
531 {
532 return agx::Vec3(0, 0, 0);
533 }
534
535 inline agx::Vec3 Shape::getCenter() const
536 {
537 return agx::Vec3(0, 0, 0);
538 }
539
540 inline agx::Referenced* Shape::getInternalData() const
541 {
542 return m_internalData;
543 }
544}
#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:221
#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:207
#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:44
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:48
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:41
uint8_t UInt8
Definition: Integer.h:30