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;
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);
#define AGX_DECLARE_POINTER_TYPES(type)
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
The geometry representation used by the collision detection engine.
A HeightField is a collision shape that can be created from a grid structure, like an image.
ContactGenerator * getContactGenerator()
ParticleCoordinateSystem m_dynamicHeightFieldParticleCoordinateSystem
DynamicHeightFieldSimulation()
void setParticleRadius(agx::Real radius)
agx::Real m_particleRadius
ContactGeneratorRef m_contactGenerator
agx::UInt32 m_uniqueParticleId
ParticleCoordinateSystem & getParticleCoordinateSystem()
agx::Real getParticleRadius()
agx::UInt32 getParticleUniqueId() const
void endLocalHeightUpdate()
size_t getLocalX(size_t globalX)
HeightController(agxCollide::HeightField *heightField)
void setHeight(size_t x, size_t y, agx::Real height)
size_t getLocalY(size_t globalY)
bool getLocalHeightUpdate() const
void setEnableLockedBorders(bool lock, bool avalancheMassLoss=true)
agx::Real getHeight(size_t x, size_t y) const
size_t getLocalVectorIndex(size_t globalX, size_t globalY)
bool getEnabledLockedBorders() const
const agxCollide::HeightField * getHeightField() const
void calculateMassProperties()
bool getEnabledAvalancheMassLoss() const
void startLocalHeightUpdate(size_t minX=0, size_t maxX=0, size_t minY=0, size_t maxY=0)
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...
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.
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.
agx::Real findParticleCoordinateHeight(const size_t pcsX, const size_t pcsY, Terrain *terrain)
Calculate the height of a particle position.
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...
ParticleCoordinateSystem()
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...
size_t indexForFCCLattice(size_t pcsX, size_t pcsY, size_t pcsZ, DirectionFCC dir)
hfX, hfY are index in height field.
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 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...
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...
TerrainDebugRenderer(agxModel::Terrain *terrain)
agx::RealVector m_heights
agx::observer_ptr< agxRender::HeightFieldProxy > m_proxy
virtual ~TerrainDebugRenderer()
void render(agxRender::RenderManager *mgr)
Pure virtual method that should implemented to render a derived class during debug rendering.
virtual ~TerrainIterativeProjectedConeFrictionModel()
void addBody(agx::RigidBody *body, const agx::Vec3 &localFrictionDir)
virtual void calculateTangentPlane(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2, const agx::Vec3 &point, const agx::Vec3 &normal, const agx::Real depth, agx::Vec3 &ret_u, agx::Vec3 &ret_v) const override
Calculates friction plane given normal.
RigidBodyObserverVec3PairVector m_bodiesAndDir
TerrainIterativeProjectedConeFrictionModel(agx::FrictionModel::SolveType solveType=agx::FrictionModel::SPLIT)
Default constructor.
Class for managing the rendering of geometries, shapes, rigid bodies, constraints etc.
Inherit from this class and implement the render() method to make it it self during debug rendering.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Derive from this class to implement a listener for simulation step events.
@ POST_STEP
Triggered just AFTER a Dynamics stepForward step is taken.
@ PRE_STEP
Triggered just BEFORE a Dynamics stepForward step is taken.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
@ MAINTAIN_BUFFER
Buffer is maintained (normal stl behavior).
@ SPLIT
First Normal equation is calculated in the DIRECT solver, then in a second pass the normal and the fr...
Iterative Projected Cone Friction (IPC friction) model.
Main material class which acts as a holder of a Surface Material and a Bulk material.
Base class providing referencing counted objects.
The rigid body class, combining a geometric model and a frame of reference.
void clear(ClearPolicy policy=SHRINK_BUFFER_AVERAGED)
Remove all elements, optionally with maintained buffer allocation.
void push_back(const T2 &value)
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
agx::ref_ptr< HeightController > HeightControllerRef
agx::ref_ptr< GeometryContactInfo > GeometryContactInfoRef
agx::ref_ptr< DynamicHeightFieldSimulation > DynamicHeightFieldSimulationRef
agx::Vector< GeometryContactInfoRef > GeometryContactInfoRefVector
agx::Vector< std::pair< agx::RigidBodyObserver, agx::Vec3 > > RigidBodyObserverVec3PairVector
agx::ref_ptr< ContactGenerator > ContactGeneratorRef
AGXCORE_EXPORT const Real Infinity
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)