AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Shape.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. 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#ifndef AGXCOLLIDE_SHAPE_H
18#define AGXCOLLIDE_SHAPE_H
19
20
22
23#include <agx/Vec3.h>
24#include <agx/SPDMatrix3x3.h>
25#include <agx/AffineMatrix4x4.h>
26
30
32
35
36namespace agxTerrain
37{
38 class Terrain;
39}
40
41namespace agxCollide
42{
43 class Geometry;
44 class Space;
45
49
54 {
55 public:
56
75
77 static const char* getTypeName(agx::UInt8 type);
78
79 public:
80
84 virtual Shape *clone() const;
85
89 const char* getTypeName() const;
90
94 agx::UInt8 getType() const;
95
99 bool isGroup() const;
100
104 ShapeGroup* asGroup();
105
109 const ShapeGroup* asGroup() const;
110
114 const BoundingAABB& getBoundingVolume() const;
115
120 virtual bool hasSupportFunction() const;
121
126 virtual agx::Vec3 getSupportPoint( const agx::Vec3& supportDirection) const;
127
132 virtual agx::Vec3 getCenter() const;
133
137 virtual agx::Real getVolume() const = 0;
138
144
147 virtual void propagateTransform(const agx::AffineMatrix4x4& transform);
148
153 virtual const BoundingAABB& updateBoundingVolume() = 0;
154
160
166 virtual agx::Real calculateBoundingRadius( BoundingAABB& localAABB ) const;
167
168 agx::Physics::Geometry::ShapePtr getEntity() const;
169
173 Geometry* getGeometry();
174
178 const Geometry* getGeometry() const;
179
181 agx::AffineMatrix4x4 getTransform() const;
182
185
186
190 static BoundingAABB calculateBound(const agx::AffineMatrix4x4& transform, const BoundingAABB& localBound);
191
195 agx::UInt32 getModifiedCount() const;
196
198
199
201 void store( agxStream::OutputArchive& out ) const override;
202 void restore( agxStream::InputArchive& in ) override;
204
205
211 virtual void setRenderData( agxCollide::RenderData *renderData );
212
218 const agxCollide::RenderData* getRenderData( ) const;
219 agxCollide::RenderData* getRenderData();
220
221
222 protected:
223
229 Shape(Type type, agx::Physics::Geometry::ShapePtr entity = agx::Physics::Geometry::ShapeModel::createInstance());
230
235 agx::UInt32 incrementModifiedCount();
236
238 virtual ~Shape();
239
241
242
243 Shape& operator=(const Shape&) = delete;
244
246 void synchronize();
248
249 private:
250 friend class ShapeGroup;
251 friend class Geometry;
252 friend class Space;
253 friend class agxTerrain::Terrain;
254
255 Shape();
256 virtual void setGeometry(Geometry* geometry);
257 virtual void transfer(Space* space);
258
259 virtual void updateGeometryPtr();
260
261
262 protected:
263
264 void syncronizeShapeIndex();
265
266 agx::Physics::Geometry::ShapeRef m_entity;
267 Geometry* m_geometry;
269 agx::Index m_shapeIndex;
270
271 ShapeGroup* m_parent;
272 };
273
274
276
277
278 AGX_DECLARE_POINTER_TYPES(ShapeGroup);
279 class AGXPHYSICS_EXPORT ShapeGroup : public Shape
280 {
281 public:
282 ShapeGroup();
283 virtual Shape *clone() const override;
284
285 void addChild(Shape* shape, const agx::AffineMatrix4x4& transform = agx::AffineMatrix4x4());
286 void removeChild(Shape* shape);
287 void removeChild(size_t index);
288
293 virtual void setRenderData( agxCollide::RenderData *renderData ) override;
294
295
297
298 size_t getNumChildren() const;
299 Shape* getChild(size_t index);
300 const Shape* getChild(size_t index) const;
301 const agx::AffineMatrix4x4& getChildTransform(size_t index) const;
302
308 bool setChildTransform(size_t childIndex, const agx::AffineMatrix4x4& transform);
309
310
311 const ShapeRefVector& getChildren() const;
312 const agx::AffineMatrix4x4Vector& getChildTransforms() const;
313
314 bool replaceChild(size_t childIndex, Shape* newChild, const agx::AffineMatrix4x4& transform = agx::AffineMatrix4x4());
315
316 /* Common shape methods */
317
319 virtual agx::SPDMatrix3x3 calculateInertia(agx::Real mass) const override;
320
322 virtual agx::Real getVolume() const override;
323
325 virtual agx::Vec3 getCenter() const override;
326
327 // Computes bounding volume in world coordinate system.
328 virtual const BoundingAABB& updateBoundingVolume() override;
329
330 // Computes bounding volume in local coordinate system.
331 virtual BoundingAABB calculateLocalBound() const override;
332
333 virtual void propagateTransform(const agx::AffineMatrix4x4& transform) override;
334
335 AGXSTREAM_DECLARE_SERIALIZABLE(agxCollide::ShapeGroup);
336
337 protected:
338 virtual ~ShapeGroup();
339
340 private:
341 friend class Geometry;
342
343 // void childUpdated(Shape *child);
344 virtual void updateGeometryPtr() override;
345 virtual void setGeometry(Geometry* geometry) override;
346 virtual void transfer(Space* space) override;
347
348 private:
349 ShapeRefVector m_children;
350 };
351
352 class AGXPHYSICS_EXPORT ShapeIterator
353 {
354 public:
355 ShapeIterator(Geometry* geometry);
356
357 Shape* getShape();
358 const Shape* getShape() const;
359 agx::AffineMatrix4x4 getLocalTransform() const;
360
361 bool isValid() const;
362 void next();
363
364 private:
365 void push(Shape* node, const agx::AffineMatrix4x4& transform);
366
367 private:
368 agx::Vector<Shape*> m_shapes;
370 size_t m_index;
371 };
372
374
375
376 /* Implementation */
377
378 AGX_FORCE_INLINE agx::UInt8 Shape::getType() const
379 {
380 return m_entity.type();
381 }
382 AGX_FORCE_INLINE bool Shape::isGroup() const
383 {
384 return getType() == GROUP;
385 }
386 AGX_FORCE_INLINE ShapeGroup* Shape::asGroup()
387 {
388 agxAssert(this->isGroup());
389 return static_cast<ShapeGroup*>(this);
390 }
391 AGX_FORCE_INLINE const ShapeGroup* Shape::asGroup() const
392 {
393 return const_cast<Shape*>(this)->asGroup();
394 }
395
396 inline agx::Physics::Geometry::ShapePtr Shape::getEntity() const
397 {
398 return m_entity;
399 }
400 AGX_FORCE_INLINE Geometry* Shape::getGeometry()
401 {
402 return m_geometry;
403 }
404 AGX_FORCE_INLINE const Geometry* Shape::getGeometry() const
405 {
406 return m_geometry;
407 }
408 AGX_FORCE_INLINE agx::AffineMatrix4x4 Shape::getTransform() const
409 {
410 return m_entity.transform();
411 }
412
413 AGX_FORCE_INLINE const BoundingAABB& Shape::getBoundingVolume() const
414 {
415 return m_entity.boundingAABB();
416 }
417
418 AGX_FORCE_INLINE BoundingAABB Shape::calculateBound(const agx::AffineMatrix4x4& transform, const BoundingAABB& localBound)
419 {
420 return BoundingAABB(localBound, transform);
421 }
422
423 AGX_FORCE_INLINE size_t ShapeGroup::getNumChildren() const
424 {
425 return m_children.size();
426 }
427 AGX_FORCE_INLINE Shape* ShapeGroup::getChild(size_t index)
428 {
429 return m_children[index];
430 }
431 AGX_FORCE_INLINE const Shape* ShapeGroup::getChild(size_t index) const
432 {
433 return m_children[index];
434 }
435 AGX_FORCE_INLINE const agx::AffineMatrix4x4& ShapeGroup::getChildTransform(size_t index) const
436 {
437 return getEntity().childTransforms()[index];
438 }
439
440 inline agx::Physics::Geometry::ShapeGroupPtr ShapeGroup::getEntity() const
441 {
442 return m_entity;
443 }
444
445 AGX_FORCE_INLINE const ShapeRefVector& ShapeGroup::getChildren() const
446 {
447 return m_children;
448 }
449 AGX_FORCE_INLINE const agx::AffineMatrix4x4Vector& ShapeGroup::getChildTransforms() const
450 {
451 return reinterpret_cast<agx::AffineMatrix4x4Vector&>(getEntity().childTransforms());
452 }
453
455 AGX_FORCE_INLINE agx::UInt32 Shape::getModifiedCount() const
456 {
457 return m_entity.modifiedCount();
458 }
459
460 AGX_FORCE_INLINE agx::UInt32 Shape::incrementModifiedCount()
461 {
462 return ++m_entity.modifiedCount();
463 }
464
465
466 AGX_FORCE_INLINE Shape* ShapeIterator::getShape()
467 {
468 agxAssert(this->isValid());
469 return m_shapes[m_index];
470 }
471
472 AGX_FORCE_INLINE const Shape* ShapeIterator::getShape() const
473 {
474 return const_cast<ShapeIterator*>(this)->getShape();
475 }
476
477 inline agx::AffineMatrix4x4 ShapeIterator::getLocalTransform() const
478 {
479 agxAssert(this->isValid());
480 return m_transforms[m_index];
481 }
482
483 AGX_FORCE_INLINE bool ShapeIterator::isValid() const
484 {
485 return m_index < m_shapes.size();
486 }
487
488 AGX_FORCE_INLINE void ShapeIterator::next()
489 {
490 agxAssert(this->isValid());
491 m_index++;
492 }
493
494 inline bool Shape::hasSupportFunction() const
495 {
496 return false;
497 }
498
499 inline agx::Vec3 Shape::getSupportPoint( const agx::Vec3& ) const
500 {
501 return agx::Vec3(0, 0, 0);
502 }
503
504 inline agx::Vec3 Shape::getCenter() const
505 {
506 return agx::Vec3(0, 0, 0);
507 }
508
509}
510#endif
#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...
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition agx/Vector.h:34
Axis aligned bounding box implementation.
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:54
Type
Define the type of a Shape.
Definition Shape.h:58
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:82
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Pointer to a entity instance of type Physics.Geometry.ShapeGroup.
Pointer to a entity instance of type Physics.Geometry.Shape.
Base class providing referencing counted objects.
Definition Referenced.h:120
Specialized type of matrices for holding symmetric positive definite matrices.
Vector containing 'raw' data.
Definition agx/Vector.h:246
#define agxAssert(expr)
Definition debug.h:143
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
#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