AGX Dynamics  2.38.0.2
TileSpecification.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agx/config/AGX_USE_AGXTERRAIN.h>
20 #include <agxTerrain/export.h>
21 
22 #include <agx/Integer.h>
23 #include <agx/Vec3.h>
24 #include <agx/Quat.h>
25 #include <agx/AffineMatrix4x4.h>
26 #include <agx/HashFunction.h>
27 
29 
30 #include <utility>
31 
32 namespace agx {
33 
34  typedef std::pair< Real, Real > RealPair;
35 
36 }
37 
38 namespace agxTerrain
39 {
40  class Terrain;
41 
42 
48  typedef agx::Vec2i32 TileId;
49 
50 
55  {
56  public:
59  float height;
60  };
61 
63 
64 
70  {
71  public:
72 
82  TileSpecification( agx::Vec3 refPoint, agx::Quat refRotation,
83  agx::Real tileSize, size_t marginSize,
84  size_t resolution, agx::Real maxDepth );
85 
87 
91  agx::Vec3 getReferencePoint() const;
92 
96  agx::Quat getReferenceRotation() const;
97 
102  agx::Real getTileSize() const;
103 
107  size_t getTileMarginSize() const;
108 
109 
113  size_t getTileResolution() const;
114 
118  agx::Real getMaximumDepth() const;
119 
120 
121 
125  agx::Vec3 convertWorldCoordinateToTilePosition( agx::Vec3 worldPos ) const;
126 
130  agxTerrain::TileId convertWorldCoordinateToTileId( agx::Vec3 worldPos ) const;
131 
138  agx::Vec3 convertTilePositionToWorld( agxTerrain::TileId id, agx::Vec2 tilePos ) const;
139 
140 
147  agx::Vec3 convertTilePositionToWorld( agxTerrain::TileId id, agx::Vec3 tilePos ) const;
148 
149 
153  agx::AffineMatrix4x4 getTileTransform( agxTerrain::TileId id, agx::Real zPos = 0 ) const;
154 
158  agx::AffineMatrix4x4 getTileTransform( agxTerrain::TileId id, agx::Vec3 localOffset ) const;
159 
163  agx::Vec3 getTileCenter( agxTerrain::TileId id ) const;
164 
165  public:
167  void store(agxStream::OutputArchive& out) const;
168  void restore(agxStream::InputArchive& in);
170 
171  private:
172  agx::Vec3 m_referencePoint;
173  agx::Quat m_referenceRotation;
174 
175  agx::Real m_tileSize;
176  size_t m_tileMarginSize;
177  size_t m_tileResolution;
178 
179  agx::Real m_maximumDepth;
180 
181  agx::AffineMatrix4x4 m_gridToWorld;
182  agx::AffineMatrix4x4 m_worldToGrid;
183  };
184 
185 
186 
187 
189  {
190  return m_referencePoint;
191  }
192 
194  {
195  return m_referenceRotation;
196  }
197 
199  {
200  return m_tileSize;
201  }
202 
204  {
205  return m_tileMarginSize;
206  }
207 
209  {
210  return m_tileResolution;
211  }
212 
214  {
215  return m_maximumDepth;
216  }
217 
219  {
220  return convertTilePositionToWorld( id, agx::Vec3( tilePos, 0.0 ) );
221  }
222 
223 
225  {
226  return worldPos * m_worldToGrid;
227  }
228 
229 
230 
232  {
233  agx::Vec3 center = getTileCenter( id );
234  center[2] += zPos;
235 
236  return agx::AffineMatrix4x4::translate( center ) * m_gridToWorld;
237  }
238 
239 
241  {
242  agx::Vec3 center = getTileCenter( id );
243 
244  return agx::AffineMatrix4x4::translate( center + localOffset ) * m_gridToWorld;
245 
246  }
247 }
248 
agxTerrain::TileSpecification::convertTilePositionToWorld
agx::Vec3 convertTilePositionToWorld(agxTerrain::TileId id, agx::Vec2 tilePos) const
Convert a local position in a tile to world coordinates.
Definition: TileSpecification.h:218
agxTerrain::TileModification
TileModifications are used to provide a delta for paged terrain changes.
Definition: TileSpecification.h:54
agxTerrain::Terrain
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:85
agx::Real
double Real
Definition: Real.h:42
HashFunction.h
agxStream::out
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive.
Definition: OutputArchive.h:412
agxTerrain::TileSpecification::getReferencePoint
agx::Vec3 getReferencePoint() const
Definition: TileSpecification.h:188
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:58
agxTerrain::TileSpecification
A TileSpecification determines where in the world a 2D TileId is located and contains utility methods...
Definition: TileSpecification.h:69
agx::AffineMatrix4x4T< Real >::translate
static AffineMatrix4x4T< Real > translate(const Vec3T< Real > &dv)
Return a matrix which translates according to dv.
Definition: AffineMatrix4x4.h:663
agxTerrain::TileSpecification::getTileMarginSize
size_t getTileMarginSize() const
Definition: TileSpecification.h:203
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agx::AffineMatrix4x4T< Real >
agx::RealPair
std::pair< Real, Real > RealPair
Definition: ConstraintImplementation.h:68
agxTerrain::TileSpecification::getTileResolution
size_t getTileResolution() const
Definition: TileSpecification.h:208
agxTerrain::TileSpecification::convertWorldCoordinateToTilePosition
agx::Vec3 convertWorldCoordinateToTilePosition(agx::Vec3 worldPos) const
Return position in coordinate system defined by the XY-plane with local Z upwards.
Definition: TileSpecification.h:224
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxTerrain::TileSpecification::getTileCenter
agx::Vec3 getTileCenter(agxTerrain::TileId id) const
Return the local center position for tile id in the plane with tiles.
agxTerrain::TileModification::tileId
agxTerrain::TileId tileId
Definition: TileSpecification.h:57
agxTerrain::TileSpecification::getTileTransform
agx::AffineMatrix4x4 getTileTransform(agxTerrain::TileId id, agx::Real zPos=0) const
Return the transform that can be used to place the tile id correctly.
Definition: TileSpecification.h:231
agx::VectorPOD< TileModification >
export.h
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agxStream::in
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:399
AffineMatrix4x4.h
agxTerrain::TileModification::vertexIndex
agx::Vec2i32 vertexIndex
Definition: TileSpecification.h:58
agxTerrain::TileSpecification::getMaximumDepth
agx::Real getMaximumDepth() const
Definition: TileSpecification.h:213
Vec3.h
agxTerrain::TileSpecification::getReferenceRotation
agx::Quat getReferenceRotation() const
Definition: TileSpecification.h:193
Integer.h
agx::Vec2T
Definition: Vec2Template.h:30
agxStream::OutputArchive
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
agx::QuatT< Real >
agxStream::InputArchive
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:50
Quat.h
AGXTERRAIN_EXPORT
#define AGXTERRAIN_EXPORT
Definition: agxTerrain/export.h:41
agxTerrain::TileSpecification::getTileSize
agx::Real getTileSize() const
The full size of a tile.
Definition: TileSpecification.h:198
agxTerrain::TileModificationVector
agx::VectorPOD< TileModification > TileModificationVector
Definition: TileSpecification.h:62
agx::Vec3T< Real >
agxTerrain::TileModification::height
float height
Definition: TileSpecification.h:59
agxTerrain::TileId
agx::Vec2i32 TileId
A TileId is a 2D-coordinate that specifies where a in grid a tile is located.
Definition: TileSpecification.h:40
StorageStream.h
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58