VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bulletUtil.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2024 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
10 
11 #pragma once
12 
14 #include <btBulletCollisionCommon.h>
15 #include <geometry/point.h>
16 #include <geometry/surface.h>
18 #include <matrix/vlVector.h>
19 #include <list>
21 #include <tbb/spin_rw_mutex.h>
23 
25 
26 #include <boost/optional.hpp>
27 
28 #include <LinearMath/btTransform.h>
29 #include <LinearMath/btMatrix3x3.h>
30 
31 #include <osg/Matrix>
32 #include <osg/Vec3>
33 
34 class DtChord;
35 class DtSphere;
36 class DtLocalVertexList;
39 class Coordinate_System;
40 
41 #define LONG_FUDGE_FACTOR 1e-6
42 #define SETNORTH(u,n) (u).setNorth((n))
43 #define SETEAST(u,e) (u).setEast((e))
44 #define SETUP(u,upp) (u).setUp((upp))
45 
46 
47 typedef std::list< std::shared_ptr<btCollisionObject> > DtCollisionObjectList;
48 
50  : public std::enable_shared_from_this<DtCollisionObjectInterface>
51 {
52 public:
53  typedef std::vector< std::shared_ptr<makVrv::DtDynamicTerrainFeature> > DynamicFeatures;
54 
56  virtual ~DtCollisionObjectInterface();
57 
59  virtual std::shared_ptr<btCollisionShape> bulletCollisionShape() const = 0;
60 
62  virtual const btTransform& worldTransform() const = 0;
63 
66  virtual bool buildBvh() = 0;
67 
68  virtual bool isBvhBuilt() const = 0;
69 
71  virtual bool enabled() const = 0;
72 
74  virtual unsigned int numberOfTriangles() const = 0;
75 
77  virtual double radius() const = 0;
78 
80  virtual DtSurface triangleSurface(unsigned int triangleIndex) const = 0;
81 
83  virtual DynamicFeatures dynamicFeatures() const = 0;
84 };
85 
89 {
90 public:
92  const DtDegMinSec& refLatitude,
93  const DtDegMinSec& refLongitude,
94  int standardOffsets,
95  DtUtmReferencePoint* refPoint,
96  long zone = 0,
97  bool setUseDynamicSceneOrigin = false,
98  double dynamicSceneOriginDeadband = 0.0,
99  double scaleFactor = 0.9996);
100 
102  virtual ~DtSerializableUtmCS_ext() override;
103  ;
104 
105 protected:
106  void init2RefLatLon(const DtDegMinSec& refLatitude,
107  const DtDegMinSec& refLongitude, int standardOffsets, long zone,
108  bool setUseDynamicSceneOrigin, double dynamicSceneOriginDeadband,
109  double scaleFactor, DtUtmReferencePoint* refPoint);;
110 
111  DtUtmReferencePoint* myUtemRefPoint;
112 };
113 
115 
116 inline btVector3 DtPoint2btVector3(const DtPoint& p) { return btVector3(p.x(), p.y(), p.z()); }
117 inline btVector3 DtVector2btVector3(const DtVector& v) { return btVector3(v.x(), v.y(), v.z()); }
118 inline DtPoint btVector32DtPoint(const btVector3& v) { return DtPoint(v.x(), v.y(), v.z()); }
119 inline DtVector btVector32DtVector(const btVector3& v) { return DtVector(v.x(), v.y(), v.z()); }
120 
121 DtDcm DT_DLL_vantageTerrainImplementation btMatrix2DtDcm(const btMatrix3x3& m);
122 
123 bool DT_DLL_vantageTerrainImplementation btVectorIsZero(const btVector3& v);
125 
130  const DtChord& chord,
131  const DtSphere& sphere);
132 
136  const DtSphere& sphere1,
137  const DtSphere& sphere2);
138 
145  const Coordinate_System&,
146  const DtLocalVertexList& shape,
147  const DtSphere& sphere);
148 
153  const Coordinate_System&,
155  const DtSphere& sphere);
156 
159  : public btCollisionWorld::RayResultCallback
160 {
164  {
165  explicit RayResultRecord(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace);
166 
170  const btVector3& rayFromWorld, const btVector3& rayToWorld) const;
171 
172  std::shared_ptr<const DtCollisionObjectInterface> object;
174  btVector3 normal;
175  boost::optional<btTransform> normalTransform;
177  };
178 
179  explicit DtBulletRayResultCallback(
180  DtIntersectionRecord::DtIntersectionType irtFlag, short int filterMask);
181 
183  virtual bool needsCollision(btBroadphaseProxy* proxy0) const override;
184 
185  bool dataAvailable() const { return myDataAvailable; }
186 
187 protected:
189  mutable bool myDataAvailable;
190 };
191 
196 {
198  DtIntersectionRecord::DtIntersectionType irtFlag, short int filterMask);
199 
200  virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace) override;
201 
202  std::vector<RayResultRecord> myRecords;
203 };
204 
208 {
210  DtIntersectionRecord::DtIntersectionType irtFlag, short int filterMask);
211 
212  virtual btScalar addSingleResult(
213  btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace) override;
214 
215  boost::optional<RayResultRecord> myResult;
216 };
217 
221 {
222  explicit DtIntersectionExistsCallback(short int filterMask);
223 
224  virtual bool needsCollision(btBroadphaseProxy* proxy0) const override;
225 
226  virtual btScalar addSingleResult(
227  btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace) override;
228 };
229 
234  const DtVector& rayDirectionNonNormalized,
235  const DtSphere& sphere,
236  double& t);
237 
239 
240 void getBasisAndOrigin(osg::Matrix& matrix, btMatrix3x3& basisA, btVector3& origin, osg::Vec3d& scale, bool& scaled);
241 
Only records whether there was a hit or not, bails out of future calculations once it finds one...
Definition: bulletUtil.h:219
const double & x() const
Definition: point.h:188
std::vector< std::shared_ptr< makVrv::DtDynamicTerrainFeature > > DynamicFeatures
Definition: bulletUtil.h:53
NOTE: This entire class is deprecated, in favor of Dt3dChord.
Definition: chord.h:40
DtVrfChordIntersectionRecord represents a list of DtChordIntersectRecords. This is useful for followi...
Definition: vrfChordIntersectRecordList.h:31
Definition: sphere.h:22
bool myDataAvailable
Definition: bulletUtil.h:189
btScalar intersectionTime
Definition: bulletUtil.h:173
void getBasisAndOrigin(osg::Matrix &matrix, btMatrix3x3 &basisA, btVector3 &origin, osg::Vec3d &scale, bool &scaled)
void init2RefLatLon(const DtDegMinSec &refLatitude, const DtDegMinSec &refLongitude, int standardOffsets, long zone, bool setUseDynamicSceneOrigin, double dynamicSceneOriginDeadband, double scaleFactor, DtUtmReferencePoint *refPoint)
voidpf uLong int origin
Definition: ioapi.h:42
btVector3 DtVector2btVector3(const DtVector &v)
Utilities for using Bullet in MAK products.
Definition: bulletUtil.h:117
bool DT_DLL_vantageTerrainImplementation shapeSphereVolumetricIntersect(const Coordinate_System &, const DtLocalVertexList &shape, const DtSphere &sphere)
Note that this function treats the shape as if it is in two dimensions (all tests ignore height for t...
bool dataAvailable() const
Definition: bulletUtil.h:185
boost::optional< RayResultRecord > myResult
Definition: bulletUtil.h:215
bool DT_DLL_vantageTerrainImplementation sphereSphereVolumetricIntersect(const DtSphere &sphere1, const DtSphere &sphere2)
Overwriting the makTerrain toolkit function to support UTM in the southern hemisphere so that the ref...
Definition: bulletUtil.h:88
Definition: surface.h:181
boost::optional< btTransform > normalTransform
Definition: bulletUtil.h:175
int triangleIndex
Definition: bulletUtil.h:176
bool DT_DLL_vantageTerrainImplementation DtIntersectRaySphere2(const DtPoint &rayStartPoint, const DtVector &rayDirectionNonNormalized, const DtSphere &sphere, double &t)
Almost the same function DtIntersectRaySphere in makTerrainToolkit But removing a few lines of code s...
Only records the closest hit.
Definition: bulletUtil.h:206
Definition: coordSystem.h:54
DtDcm DT_DLL_vantageTerrainImplementation btMatrix2DtDcm(const btMatrix3x3 &m)
Utilities for using Bullet in MAK products.
std::shared_ptr< DtTerrainPagingGeometry > DtTerrainPagingGeometryPtr
Definition: terrainPagingGeometry.h:46
DtPoint btVector32DtPoint(const btVector3 &v)
Utilities for using Bullet in MAK products.
Definition: bulletUtil.h:118
Definition: serializableUtmCS.h:22
DtVector btVector32DtVector(const btVector3 &v)
Utilities for using Bullet in MAK products.
Definition: bulletUtil.h:119
DtSerializableUtmCS_ext(const DtDegMinSec &refLatitude, const DtDegMinSec &refLongitude, int standardOffsets, DtUtmReferencePoint *refPoint, long zone=0, bool setUseDynamicSceneOrigin=false, double dynamicSceneOriginDeadband=0.0, double scaleFactor=0.9996)
The DtCoordinateSystem is used to manage the current coordinate system of the scene.
Definition: DtCoordinateSystem.h:40
const double & y() const
Definition: point.h:198
Definition: bulletUtil.h:49
Definition: vrfChordIntersectionRecord.h:19
const DtIntersectionRecord::DtIntersectionType myIrtFlag
Definition: bulletUtil.h:188
Base class for bullet callbacks which implements needsCollision.
Definition: bulletUtil.h:158
Extended version of bullet&#39;s RayResultCallback which records all the hits along the ray instead of on...
Definition: bulletUtil.h:194
bool DT_DLL_vantageTerrainImplementation geometrySphereVolumetricIntersect(const Coordinate_System &, DtTerrainPagingGeometryPtr geometry, const DtSphere &sphere)
std::list< std::shared_ptr< btCollisionObject > > DtCollisionObjectList
Definition: bulletUtil.h:47
Holds hit results so that data we need from them can be computed after mutex has been released...
Definition: bulletUtil.h:163
#define DT_DLL_vantageTerrainImplementation
This file is used to determine how to build.
Definition: vantageTerrainImplementationDefines.h:28
virtual ~DtSerializableUtmCS_ext() override
Destructor.
btVector3 normal
Definition: bulletUtil.h:174
bool DT_DLL_vantageTerrainImplementation btVectorIsZero(const btVector3 &v)
Utilities for using Bullet in MAK products.
bool DT_DLL_vantageTerrainImplementation chordSphereVolumetricIntersect(const DtChord &chord, const DtSphere &sphere)
const double & z() const
Definition: point.h:208
std::vector< RayResultRecord > myRecords
Definition: bulletUtil.h:202
Coordinate_System * createVrfCoordinateSystem(const makVrv::DtCoordinateSystem &coodSysIn)
class DtLocalVertexList:
Definition: localVertexList.h:20
std::shared_ptr< const DtCollisionObjectInterface > object
Definition: bulletUtil.h:172
btVector3 DtPoint2btVector3(const DtPoint &p)
Utilities for using Bullet in MAK products.
Definition: bulletUtil.h:116
Definition: point.h:34
DtUtmReferencePoint * myUtemRefPoint
Definition: bulletUtil.h:109
virtual bool needsCollision(btBroadphaseProxy *proxy0) const override
Builds BVH and checks to see if object is enabled.
DtIntersectionType
Definition: intersectionRecord.h:41
virtual long zone() const

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)