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) 2023 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 #include <boost/shared_ptr.hpp>
28 #include <boost/enable_shared_from_this.hpp>
29 
30 #include <LinearMath/btTransform.h>
31 #include <LinearMath/btMatrix3x3.h>
32 
33 #include <osg/Matrix>
34 #include <osg/Vec3>
35 
36 class DtChord;
37 class DtSphere;
38 class DtLocalVertexList;
41 class Coordinate_System;
42 
43 #define LONG_FUDGE_FACTOR 1e-6
44 #define SETNORTH(u,n) (u).setNorth((n))
45 #define SETEAST(u,e) (u).setEast((e))
46 #define SETUP(u,upp) (u).setUp((upp))
47 
48 
49 typedef std::list< boost::shared_ptr<btCollisionObject> > DtCollisionObjectList;
50 
52  : public boost::enable_shared_from_this<DtCollisionObjectInterface>
53 {
54 public:
55  typedef std::vector< boost::shared_ptr<makVrv::DtDynamicTerrainFeature> > DynamicFeatures;
56 
58  virtual ~DtCollisionObjectInterface();
59 
61  virtual boost::shared_ptr<btCollisionShape> bulletCollisionShape() const = 0;
62 
64  virtual const btTransform& worldTransform() const = 0;
65 
68  virtual bool buildBvh() = 0;
69 
70  virtual bool isBvhBuilt() const = 0;
71 
73  virtual bool enabled() const = 0;
74 
76  virtual unsigned int numberOfTriangles() const = 0;
77 
79  virtual double radius() const = 0;
80 
82  virtual DtSurface triangleSurface(unsigned int triangleIndex) const = 0;
83 
85  virtual DynamicFeatures dynamicFeatures() const = 0;
86 };
87 
91 {
92 public:
94  const DtDegMinSec& refLatitude,
95  const DtDegMinSec& refLongitude,
96  int standardOffsets,
97  DtUtmReferencePoint* refPoint,
98  long zone = 0,
99  bool setUseDynamicSceneOrigin = false,
100  double dynamicSceneOriginDeadband = 0.0,
101  double scaleFactor = 0.9996);
102 
104  virtual ~DtSerializableUtmCS_ext();;
105 
106 protected:
107  void init2RefLatLon(const DtDegMinSec& refLatitude,
108  const DtDegMinSec& refLongitude, int standardOffsets, long zone,
109  bool setUseDynamicSceneOrigin, double dynamicSceneOriginDeadband,
110  double scaleFactor, DtUtmReferencePoint* refPoint);;
111 
112  DtUtmReferencePoint* myUtemRefPoint;
113 };
114 
116 
117 inline btVector3 DtPoint2btVector3(const DtPoint& p) { return btVector3(p.x(), p.y(), p.z()); }
118 inline btVector3 DtVector2btVector3(const DtVector& v) { return btVector3(v.x(), v.y(), v.z()); }
119 inline DtPoint btVector32DtPoint(const btVector3& v) { return DtPoint(v.x(), v.y(), v.z()); }
120 inline DtVector btVector32DtVector(const btVector3& v) { return DtVector(v.x(), v.y(), v.z()); }
121 bool DT_DLL_vantageTerrainImplementation btVectorIsZero(const btVector3& v);
123 
128  const DtChord& chord,
129  const DtSphere& sphere);
130 
134  const DtSphere& sphere1,
135  const DtSphere& sphere2);
136 
143  const Coordinate_System&,
144  const DtLocalVertexList& shape,
145  const DtSphere& sphere);
146 
151  const Coordinate_System&,
153  const DtSphere& sphere);
154 
157  : public btCollisionWorld::RayResultCallback
158 {
162  {
163  explicit RayResultRecord(btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace);
164 
168  const btVector3& rayFromWorld, const btVector3& rayToWorld) const;
169 
170  boost::shared_ptr<const DtCollisionObjectInterface> object;
172  btVector3 normal;
173  boost::optional<btTransform> normalTransform;
175  };
176 
177  explicit DtBulletRayResultCallback(
178  DtIntersectionRecord::DtIntersectionType irtFlag, short int filterMask);
179 
181  virtual bool needsCollision(btBroadphaseProxy* proxy0) const override;
182 
183  bool dataAvailable() const { return myDataAvailable; }
184 
185 protected:
187  mutable bool myDataAvailable;
188 };
189 
194 {
196  DtIntersectionRecord::DtIntersectionType irtFlag, short int filterMask);
197 
198  virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace);
199 
200  std::vector<RayResultRecord> myRecords;
201 };
202 
206 {
208  DtIntersectionRecord::DtIntersectionType irtFlag, short int filterMask);
209 
210  virtual btScalar addSingleResult(
211  btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace);
212 
213  boost::optional<RayResultRecord> myResult;
214 };
215 
219 {
220  explicit DtIntersectionExistsCallback(short int filterMask);
221 
222  virtual bool needsCollision(btBroadphaseProxy* proxy0) const;
223 
224  virtual btScalar addSingleResult(
225  btCollisionWorld::LocalRayResult& rayResult, bool normalInWorldSpace);
226 };
227 
232  const DtVector& rayDirectionNonNormalized,
233  const DtSphere& sphere,
234  double& t);
235 
237 
238 void getBasisAndOrigin(osg::Matrix& matrix, btMatrix3x3& basisA, btVector3& origin, osg::Vec3d& scale, bool& scaled);
239 
Only records whether there was a hit or not, bails out of future calculations once it finds one...
Definition: bulletUtil.h:217
const double & x() const
Definition: point.h:188
NOTE: This entire class is deprecated, in favor of Dt3dChord.
Definition: chord.h:40
DtBoost::shared_ptr< DtTerrainPagingGeometry > DtTerrainPagingGeometryPtr
Definition: terrainPagingGeometry.h:46
DtVrfChordIntersectionRecord represents a list of DtChordIntersectRecords. This is useful for followi...
Definition: vrfChordIntersectRecordList.h:31
Definition: sphere.h:22
bool myDataAvailable
Definition: bulletUtil.h:187
btScalar intersectionTime
Definition: bulletUtil.h:171
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:118
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:183
boost::optional< RayResultRecord > myResult
Definition: bulletUtil.h:213
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:90
Definition: surface.h:181
boost::optional< btTransform > normalTransform
Definition: bulletUtil.h:173
boost::shared_ptr< const DtCollisionObjectInterface > object
Definition: bulletUtil.h:170
int triangleIndex
Definition: bulletUtil.h:174
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...
std::vector< boost::shared_ptr< makVrv::DtDynamicTerrainFeature > > DynamicFeatures
Definition: bulletUtil.h:55
Only records the closest hit.
Definition: bulletUtil.h:204
Definition: coordSystem.h:54
DtPoint btVector32DtPoint(const btVector3 &v)
Utilities for using Bullet in MAK products.
Definition: bulletUtil.h:119
Definition: serializableUtmCS.h:22
DtVector btVector32DtVector(const btVector3 &v)
Utilities for using Bullet in MAK products.
Definition: bulletUtil.h:120
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:51
Definition: vrfChordIntersectionRecord.h:19
const DtIntersectionRecord::DtIntersectionType myIrtFlag
Definition: bulletUtil.h:186
Base class for bullet callbacks which implements needsCollision.
Definition: bulletUtil.h:156
Extended version of bullet&#39;s RayResultCallback which records all the hits along the ray instead of on...
Definition: bulletUtil.h:192
bool DT_DLL_vantageTerrainImplementation geometrySphereVolumetricIntersect(const Coordinate_System &, DtTerrainPagingGeometryPtr geometry, const DtSphere &sphere)
Holds hit results so that data we need from them can be computed after mutex has been released...
Definition: bulletUtil.h:161
#define DT_DLL_vantageTerrainImplementation
This file is used to determine how to build.
Definition: vantageTerrainImplementationDefines.h:28
btVector3 normal
Definition: bulletUtil.h:172
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:200
Coordinate_System * createVrfCoordinateSystem(const makVrv::DtCoordinateSystem &coodSysIn)
class DtLocalVertexList:
Definition: localVertexList.h:20
btVector3 DtPoint2btVector3(const DtPoint &p)
Utilities for using Bullet in MAK products.
Definition: bulletUtil.h:117
virtual ~DtSerializableUtmCS_ext()
Destructor.
std::list< boost::shared_ptr< btCollisionObject > > DtCollisionObjectList
Definition: bulletUtil.h:49
Definition: point.h:34
DtUtmReferencePoint * myUtemRefPoint
Definition: bulletUtil.h:110
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 Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)