AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TileSpecification.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
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 
std::pair< Real, Real > RealPair
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:400
agx::Quat getReferenceRotation() const
A TileSpecification determines where in the world a 2D TileId is located and contains utility methods...
agx::VectorPOD< TileModification > TileModificationVector
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...
static AffineMatrix4x4T< Real > translate(const Vec3T< Real > &dv)
Return a matrix which translates according to dv.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
agx::Vec3 convertTilePositionToWorld(agxTerrain::TileId id, agx::Vec2 tilePos) const
Convert a local position in a tile to world coordinates.
agx::Vec3 getTileCenter(agxTerrain::TileId id) const
Return the local center position for tile id in the plane with tiles.
#define AGX_FORCE_INLINE
Definition: Object.h:62
agx::Real getMaximumDepth() const
agx::Vec3 getReferencePoint() const
agx::Real getTileSize() const
The full size of a tile.
agx::Vec2i32 TileId
A TileId is a 2D-coordinate that specifies where a in grid a tile is located.
agx::Vec3 convertWorldCoordinateToTilePosition(agx::Vec3 worldPos) const
Return position in coordinate system defined by the XY-plane with local Z upwards.
#define AGXTERRAIN_EXPORT
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
double Real
Definition: Real.h:42
agx::AffineMatrix4x4 getTileTransform(agxTerrain::TileId id, agx::Real zPos=0) const
Return the transform that can be used to place the tile id correctly.
TileModifications are used to provide a delta for paged terrain changes.
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:101
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:100