ScummVM API documentation
dgCollisionHeightField.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __DGCOLLIION_HEIGHT_FIELD__
23 #define __DGCOLLIION_HEIGHT_FIELD__
24 
25 #include "dgCollision.h"
26 #include "dgCollisionMesh.h"
27 
29 typedef dgFloat32(*dgCollisionHeightFieldRayCastCallback)(const dgBody *const body, const dgCollisionHeightField *const heightFieldCollision, dgFloat32 interception, dgInt32 row, dgInt32 col, dgVector *const normal, int faceId, void *const usedData);
30 
31 
33 public:
34  dgCollisionHeightField(dgWorld *const world, dgInt32 width, dgInt32 height, dgInt32 contructionMode,
35  const dgUnsigned16 *const elevationMap, const dgInt8 *const atributeMap, dgFloat32 horizontalScale, dgFloat32 vertcalScale);
36 
37  dgCollisionHeightField(dgWorld *const world, dgDeserialize deserialization, void *const userData);
38 
39  virtual ~dgCollisionHeightField(void);
40 
41  void SetCollisionRayCastCallback(dgCollisionHeightFieldRayCastCallback rayCastCallback);
42  dgCollisionHeightFieldRayCastCallback GetDebugRayCastCallback() const {
43  return m_userRayCastCallback;
44  }
45 
46 
47 private:
48 
49  void AllocateVertex(dgWorld *const world, dgInt32 thread) const;
50  void CalculateMinExtend2d(const dgVector &p0, const dgVector &p1, dgVector &boxP0, dgVector &boxP1) const;
51  void CalculateMinExtend3d(const dgVector &p0, const dgVector &p1, dgVector &boxP0, dgVector &boxP1) const;
52  dgFloat32 RayCastCell(const dgFastRayTest &ray, dgInt32 xIndex0, dgInt32 zIndex0, dgVector &normalOut) const;
53  dgFloat32 RayCastCellSimd(const dgFastRayTest &ray, dgInt32 xIndex0, dgInt32 zIndex0, dgVector &normalOut) const;
54 
55  virtual void Serialize(dgSerialize callback, void *const userData) const;
56  virtual dgFloat32 RayCast(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
57  virtual dgFloat32 RayCastSimd(const dgVector &localP0, const dgVector &localP1, dgContactPoint &contactOut, OnRayPrecastAction preFilter, const dgBody *const body, void *const userData) const;
58  virtual void GetCollidingFaces(dgPolygonMeshDesc *const data) const;
59  virtual void GetCollidingFacesSimd(dgPolygonMeshDesc *const data) const;
60 
61  virtual void GetCollisionInfo(dgCollisionInfo *info) const;
62  void DebugCollision(const dgMatrix &matrixPtr, OnDebugCollisionMeshCallback callback, void *const userData) const;
63 
64  void GetVertexListIndexList(const dgVector &p0, const dgVector &p1, dgGetVertexListIndexList &data) const;
65 
66  void GetLocalAABB(const dgVector &p0, const dgVector &p1, dgVector &boxP0, dgVector &boxP1) const;
67 
68 
69  dgInt32 m_width;
70  dgInt32 m_height;
71  dgInt32 m_diagonalMode;
72  dgInt8 *m_atributeMap;
73  dgUnsigned16 *m_elevationMap;
74  dgFloat32 m_verticalScale;
75  dgFloat32 m_horizontalScale;
76 // dgFloat32 m_verticalScaleInv;
77  dgFloat32 m_horizontalScaleInv;
78  dgCollisionHeightFieldRayCastCallback m_userRayCastCallback;
79 
80  dgVector m_minBox;
81  dgVector m_maxBox;
82 
83  struct dgPerIntanceData {
84  dgWorld *m_world;
85  dgInt32 m_refCount;
86  dgInt32 m_vertexCount[DG_MAXIMUN_THREADS];
87  dgVector *m_vertex[DG_MAXIMUN_THREADS];
88  };
89 
90  dgPerIntanceData *m_instanceData;
91  friend class dgCollisionCompound;
92 };
93 
94 
95 #endif
Definition: dgIntersections.h:35
Definition: dgCollision.h:73
Definition: dgBody.h:85
Definition: dgCollisionMesh.h:39
Definition: dgVector.h:86
Definition: dgContact.h:88
Definition: dgCollisionMesh.h:101
Definition: dgCollisionMesh.h:90
Definition: dgCollisionHeightField.h:32
Definition: dgMatrix.h:41
Definition: dgWorld.h:118
Definition: dgCollisionCompound.h:31