17 #ifndef AGXMODEL_TERRAIN_UTILS_H
18 #define AGXMODEL_TERRAIN_UTILS_H
41 class ImpactVolumeData;
52 : m_localHeightUpdate(false), m_lockBorders(false), m_avalancheMassLoss(true), m_heightField(heightField)
55 : m_localHeightUpdate(false), m_lockBorders(false), m_avalancheMassLoss(true), m_heightField(nullptr)
59 m_avalancheMassLoss = avalancheMassLoss;
62 return m_avalancheMassLoss;
68 m_heightField->calculateMassProperties();
70 void setHeight(
size_t x,
size_t y,
agx::Real height );
72 return std::max(globalX, m_minX) - m_minX;
75 return std::max(globalY, m_minY) - m_minY;
78 return (m_maxX - m_minX + 1) * getLocalY(globalY) + getLocalX(globalX);
80 agx::Real getHeight(
size_t x,
size_t y )
const;
81 void startLocalHeightUpdate(
size_t minX = 0,
size_t maxX = 0,
size_t minY = 0,
size_t maxY = 0);
82 void endLocalHeightUpdate();
85 return m_localHeightUpdate;
96 bool m_localHeightUpdate;
98 bool m_avalancheMassLoss;
131 : m_particleResolutionX(1), m_particleResolutionY(1), m_scale(1), m_heightFieldToParticleCoordinateMultiplier(1)
139 enum DirectionFCC {
VERTEX_POS,
POS_X_NEG_Z,
POS_Y_NEG_Z,
NEG_X_NEG_Z,
NEG_Y_NEG_Z,
POS_X_POS_Y,
NEG_X_POS_Y,
NEG_X_NEG_Y,
POS_X_NEG_Y,
POS_X_POS_Z,
POS_Y_POS_Z,
NEG_X_POS_Z,
NEG_Y_POS_Z };
197 size_t m_particleResolutionX;
198 size_t m_particleResolutionY;
202 agx::Real m_heightFieldToParticleCoordinateMultiplier;
218 this->getSimulation()->getSpace()->addGeometryContacts(m_localContacts);
317 : m_geometryContact(gc), m_index(index) {
323 return m_geometry1->getEnable() && m_geometry2->getEnable() && (m_geometry1->getRigidBody() ==
nullptr || m_geometry1->getRigidBody()->getEnable() ) && (m_geometry2->getRigidBody() ==
nullptr || m_geometry2->getRigidBody()->getEnable());
340 m_impactVolumeDataVector.
clear();
344 return m_geometryContact;
347 return m_impactVolumeDataVector;
368 if ( m_heightField ==
nullptr )
370 size_t vectorIndex = m_heightField->getResolutionX() * y + x;
374 return m_tempHeights[vectorIndex];
376 return m_heightField->getHeight(x, y);
381 if ( m_heightField ==
nullptr )
384 if ( m_lockBorders && ( x == 0 || y == 0 || x + 1 >= m_heightField->getResolutionX() || y + 1 >= m_heightField->getResolutionY() ) )
389 m_heightField->setHeight(x, y, height);
405 void initialize(
Terrain* terrain);
agx::Real findFccHeight(agx::Real heightAtVertexPos, agx::Real dX, agx::Real dY, DirectionFCC fccLocalPos)
Calculate height of height field fcc position, given x and y derivatives and the height of the middle...
void setHeight(size_t x, size_t y, agx::Real height)
agx::ref_ptr< GeometryContactInfo > GeometryContactInfoRef
Derive from this class to implement a listener for simulation Step events.
ParticleCoordinateSystem m_dynamicHeightFieldParticleCoordinateSystem
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
void setParticleRadius(agx::Real radius)
Triggered just AFTER a Dynamics stepForward step is taken.
Triggered just BEFORE a Dynamics stepForward step is taken.
HeightController(agxCollide::HeightField *heightField)
agx::Real findParticleCoordinateHeight(const size_t pcsX, const size_t pcsY, Terrain *terrain)
Calculate the height of a particle position.
ParticleCoordinateSystem()
size_t getLocalX(size_t globalX)
virtual ~TerrainDebugRenderer()
void getParentHeightFieldVertex(const size_t &pcsX, const size_t &pcsY, size_t &hfX, size_t &hfY)
To find what hf vertex position For example needed when we need to know which material a particle sho...
#define AGX_DECLARE_POINTER_TYPES(type)
agx::UInt32 getParticleUniqueId() const
agx::Vector< GeometryContactInfoRef > GeometryContactInfoRefVector
bool getEnabledLockedBorders() const
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc...
agx::ref_ptr< HeightController > HeightControllerRef
agx::Real scaleDepth(const agx::Real &depth, const size_t pcsX, const size_t pcsY, const agx::Vec2 &hf2Dpos)
Given the changed height (depth) of a height field vertex, we get the height change at the particle c...
bool getLocalHeightUpdate() const
Base class providing referencing counted objects.
agx::Real getHeight(size_t x, size_t y) const
The geometry representation used by the collision detection engine.
size_t indexForFCCLattice(size_t pcsX, size_t pcsY, size_t pcsZ, DirectionFCC dir)
hfX, hfY are index in height field.
ParticleCoordinateSystem & getParticleCoordinateSystem()
void updateResolution(const agx::Real &particleRadius, const size_t &heightFieldResolutionX, const size_t &heightFieldResolutionY, const agx::Real &scale)
If the particle radius is changed, we must update our resolution for the particle coordinate system...
TerrainDebugRenderer(agxModel::Terrain *terrain)
agx::Vec2 getHeightFieldPosition(const size_t pcsX, const size_t pcsY, const size_t dX=0, const size_t dY=0)
Get 2D position on the height field in length units.
agx::Real getParticleRadius()
agx::Real m_particleRadius
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements, optionally with maintained buffer allocation.
agx::UInt32 m_uniqueParticleId
AGXCORE_EXPORT const Real Infinity
size_t getLocalVectorIndex(size_t globalX, size_t globalY)
Inherit from this class and implement the render() method to make it it self during debug rendering...
The rigid body class, combining a geometric model and a frame of reference.
Main material class which acts as a holder of a Surface Material and a Bulk material.
void setEnableLockedBorders(bool lock, bool avalancheMassLoss=true)
agx::RealVector m_heights
agx::Vector< std::pair< agx::RigidBodyObserver, agx::Vec3 > > RigidBodyObserverVec3PairVector
First Normal equation is calculated in the DIRECT solver, then in a second pass the normal and the fr...
void render(agxRender::RenderManager *mgr)
Pure virtual method that should implemented to render a derived class during debug rendering...
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Iterative Projected Cone Friction (IPC friction) model.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
agx::ref_ptr< ContactGenerator > ContactGeneratorRef
DynamicHeightFieldSimulation()
void collectCloseParticleLowerXYCoordinatesWithHeight(const agxCollide::HeightField *hf, const size_t &hfX, const size_t &hfY, Vec2iHeightDataPairVector &particleCoordinatesWithHeight, Terrain *terrain)
Given one vertex in the height field (that has changed height for example) we get all surrounding par...
void calculateMassProperties()
ContactGenerator * getContactGenerator()
Buffer is maintained (normal stl behavior).
agx::ref_ptr< DynamicHeightFieldSimulation > DynamicHeightFieldSimulationRef
void collectCloseParticleCoordinates(const size_t &hfX, const size_t &hfY, agx::Vec2iVector &particleCoordinates)
Given one vertex in the height field (that has changed height for example) we get all surrounding par...
RigidBodyObserverVec3PairVector m_bodiesAndDir
size_t getLocalY(size_t globalY)
void push_back(const T2 &value)
A HeightField is a collision shape that can be created from a grid structure, like an image...
bool getEnabledAvalancheMassLoss() const
const agxCollide::HeightField * getHeightField() const
agx::Vec3 getHeightFieldPositionFromFCCIndex(size_t fccIndex, const agx::Real minZ, size_t &pcsX, size_t &pcsY)
Translates a position in the imaginary FCC 3 dimensional grid to a world position Returns positions i...
agx::observer_ptr< agxRender::HeightFieldProxy > m_proxy
ContactGeneratorRef m_contactGenerator