PxScene.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12 
13 
14 #ifndef PX_PHYSICS_NX_SCENE
15 #define PX_PHYSICS_NX_SCENE
16 
21 #include "PxSceneDesc.h"
22 #include "PxSimulationStatistics.h"
23 #include "PxQueryReport.h"
24 #include "PxQueryFiltering.h"
25 #include "PxClient.h"
26 
27 #if PX_USE_PARTICLE_SYSTEM_API
30 #endif
31 
32 #ifndef PX_DOXYGEN
33 namespace physx
34 {
35 #endif
36 
37 class PxRigidStatic;
38 class PxRigidDynamic;
39 class PxConstraint;
40 class PxMaterial;
42 class PxPhysics;
43 class PxBatchQueryDesc;
44 class PxBatchQuery;
45 class PxAggregate;
46 class PxRenderBuffer;
47 class PxVolumeCache;
48 
49 class PxSphereGeometry;
50 class PxBoxGeometry;
52 
53 typedef PxU8 PxDominanceGroup;
54 
55 class PxBaseTask;
56 class PxTaskManager;
57 
65 {
67  void* userData;
69 };
70 
80 {
82  : dominance0(a), dominance1(b) {}
85 };
86 
89 
90 
99 {
100  enum Enum
101  {
106  eRIGID_STATIC = (1 << 0),
107 
112  eRIGID_DYNAMIC = (1 << 1),
113 
114 #if PX_USE_PARTICLE_SYSTEM_API
115 
119  ePARTICLE_SYSTEM = (1 << 2),
120 
125  ePARTICLE_FLUID = (1 << 3),
126 #endif
127 
128 #if PX_USE_CLOTH_API
129 
133  eCLOTH = (1 << 5)
134 #endif
135  };
136 };
137 
145 
146 
148 
151 
171 {
175  PX_INLINE PxQueryCache() : shape(NULL), actor(NULL), faceIndex(0xffffffff) {}
176 
180  PX_INLINE PxQueryCache(PxShape* s, PxU32 findex) : shape(s), actor(NULL), faceIndex(findex) {}
181 
185 };
186 
188 #define PxSceneQueryCache PxQueryCache // PX_DEPRECATED
189 
199 class PxScene
200 {
201  protected:
202 
203  /************************************************************************************************/
204 
208 
209  PxScene(): userData(0) {}
210  virtual ~PxScene() {}
211 
212  public:
213 
225  virtual void release() = 0;
226 
234  virtual void setFlag(PxSceneFlag::Enum flag, bool value) = 0;
235 
243  virtual PxSceneFlags getFlags() const = 0;
244 
245 
256  virtual void setLimits(const PxSceneLimits& limits) = 0;
257 
263  virtual PxSceneLimits getLimits() const = 0;
264 
265 
273  virtual PxPhysics& getPhysics() = 0;
274 
280  virtual PxU32 getTimestamp() const = 0;
281 
282 
284  /************************************************************************************************/
285 
298  virtual void addArticulation(PxArticulation& articulation) = 0;
299 
312  virtual void removeArticulation(PxArticulation& articulation, bool wakeOnLostTouch = true) = 0;
313 
329  virtual void addActor(PxActor& actor) = 0;
330 
349  virtual void addActors(PxActor*const* actors, PxU32 nbActors) = 0;
350 
351 
368  virtual void removeActor(PxActor& actor, bool wakeOnLostTouch = true) = 0;
369 
385  virtual void removeActors(PxActor*const* actors, PxU32 nbActors, bool wakeOnLostTouch = true) = 0;
386 
399  virtual void addAggregate(PxAggregate& aggregate) = 0;
400 
413  virtual void removeAggregate(PxAggregate& aggregate, bool wakeOnLostTouch = true) = 0;
414 
427  virtual void addCollection(const PxCollection& collection) = 0;
429  /************************************************************************************************/
430 
434 
443  virtual PxU32 getNbActors(PxActorTypeFlags types) const = 0;
444 
456  virtual PxU32 getActors(PxActorTypeFlags types, PxActor** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const = 0;
457 
475  virtual const PxActiveTransform*
476  getActiveTransforms(PxU32& nbTransformsOut, PxClientID client = PX_DEFAULT_CLIENT) = 0;
477 
485  virtual PxU32 getNbArticulations() const = 0;
486 
497  virtual PxU32 getArticulations(PxArticulation** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const = 0;
498 
506  virtual PxU32 getNbConstraints() const = 0;
507 
518  virtual PxU32 getConstraints(PxConstraint** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const = 0;
519 
520 
528  virtual PxU32 getNbAggregates() const = 0;
529 
540  virtual PxU32 getAggregates(PxAggregate** userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const = 0;
541 
543  /************************************************************************************************/
544 
548 
599  virtual void setDominanceGroupPair(
600  PxDominanceGroup group1, PxDominanceGroup group2, const PxDominanceGroupPair& dominance) = 0;
601 
607  virtual PxDominanceGroupPair getDominanceGroupPair(PxDominanceGroup group1, PxDominanceGroup group2) const = 0;
608 
610  /************************************************************************************************/
611 
615 
621  virtual PxCpuDispatcher* getCpuDispatcher() const = 0;
622 
630  virtual PxGpuDispatcher* getGpuDispatcher() const = 0;
631 
639  virtual PxSpuDispatcher* getSpuDispatcher() const = 0;
640 
642  /************************************************************************************************/
655  virtual PxClientID createClient() = 0;
656 
671  virtual void setClientBehaviorFlags(PxClientID client, PxClientBehaviorFlags clientBehaviorFlags) = 0;
672 
678  virtual PxClientBehaviorFlags getClientBehaviorFlags(PxClientID client) const = 0;
680 
681 
682  #if PX_USE_CLOTH_API
683 
684  /************************************************************************************************/
685 
701  virtual void setClothInterCollisionDistance(PxF32 distance) = 0;
702 
707  virtual PxF32 getClothInterCollisionDistance() const = 0;
708 
717  virtual void setClothInterCollisionStiffness(PxF32 stiffness) = 0;
722  virtual PxF32 getClothInterCollisionStiffness() const = 0;
723 
732  virtual void setClothInterCollisionNbIterations(PxU32 nbIterations) = 0;
737  virtual PxU32 getClothInterCollisionNbIterations() const = 0;
739 
740  #endif // PX_USE_CLOTH_API
741 
742  /************************************************************************************************/
743 
747 
764  virtual void setSimulationEventCallback(PxSimulationEventCallback* callback, PxClientID client = PX_DEFAULT_CLIENT) = 0;
765 
775  getSimulationEventCallback(PxClientID client = PX_DEFAULT_CLIENT) const = 0;
776 
784  virtual void setContactModifyCallback(PxContactModifyCallback* callback) = 0;
785 
793  virtual void setCCDContactModifyCallback(PxCCDContactModifyCallback* callback) = 0;
794 
802  virtual PxContactModifyCallback*
803  getContactModifyCallback() const = 0;
804 
813  getCCDContactModifyCallback() const = 0;
814 
829  virtual void setBroadPhaseCallback(PxBroadPhaseCallback* callback, PxClientID client = PX_DEFAULT_CLIENT) = 0;
830 
840  virtual PxBroadPhaseCallback* getBroadPhaseCallback(PxClientID client = PX_DEFAULT_CLIENT) const = 0;
841 
843  /************************************************************************************************/
844 
848 
858  virtual const void* getFilterShaderData() const = 0;
859 
867  virtual PxU32 getFilterShaderDataSize() const = 0;
868 
877  getFilterShader() const = 0;
878 
887  getFilterCallback() const = 0;
888 
918  virtual void resetFiltering(PxActor& actor) = 0;
919 
934  virtual void resetFiltering(PxRigidActor& actor, PxShape*const* shapes, PxU32 shapeCount) = 0;
935 
937  /************************************************************************************************/
938 
973  virtual void simulate(PxReal elapsedTime, physx::PxBaseTask* completionTask = NULL,
974  void* scratchMemBlock = 0, PxU32 scratchMemBlockSize = 0, bool controlSimulation = true) = 0;
975 
976 
982  virtual void solve(PxReal elapsedTime, physx::PxBaseTask* completionTask = 0, void* scratchMemBlock = 0,
983  PxU32 scratchMemBlockSize = 0, bool controlSimulation = true) = 0;
984 
990  virtual void collide(PxReal elapsedTime, physx::PxBaseTask* completionTask = 0, void* scratchMemBlock = 0,
991  PxU32 scratchMemBlockSize = 0) = 0;
992 
1004  virtual bool checkResults(bool block = false) = 0;
1005 
1027  virtual bool fetchResults(bool block = false, PxU32* errorState = 0) = 0;
1028 
1033  PX_DEPRECATED virtual void flush(bool sendPendingReports = false) = 0;
1034 
1045  virtual void flushSimulation(bool sendPendingReports = false) = 0;
1046 
1056  virtual void setGravity(const PxVec3& vec) = 0;
1057 
1065  virtual PxVec3 getGravity() const = 0;
1066 
1072  virtual void setBounceThresholdVelocity(const PxReal t) = 0;
1073 
1079  virtual PxReal getBounceThresholdVelocity() const = 0;
1080 
1081 
1090  virtual void setCCDMaxPasses(PxU32 ccdMaxPasses) = 0;
1091 
1100  virtual PxU32 getCCDMaxPasses() const = 0;
1101 
1107  virtual PxReal getContactCorrelationDistance() const = 0;
1108 
1114  virtual PxReal getFrictionOffsetThreshold() const = 0;
1115 
1122  PX_DEPRECATED virtual PxReal getMeshContactMargin() const = 0;
1123 
1128  virtual void setFrictionType(PxFrictionType::Enum frictionType) = 0;
1129 
1134  virtual PxFrictionType::Enum getFrictionType() const = 0;
1135 
1137  /************************************************************************************************/
1138 
1153  virtual bool setVisualizationParameter(PxVisualizationParameter::Enum param, PxReal value) = 0;
1154 
1163  virtual PxReal getVisualizationParameter(PxVisualizationParameter::Enum paramEnum) const = 0;
1164 
1165 
1172  virtual void setVisualizationCullingBox(const PxBounds3& box) = 0;
1173 
1180  virtual const PxBounds3& getVisualizationCullingBox() const = 0;
1181 
1193  virtual const PxRenderBuffer& getRenderBuffer() = 0;
1194 
1204  virtual void getSimulationStatistics(PxSimulationStatistics& stats) const = 0;
1205 
1206 
1208  /************************************************************************************************/
1209 
1213 
1219  virtual PxPruningStructure::Enum getStaticStructure() const = 0;
1220 
1226  virtual PxPruningStructure::Enum getDynamicStructure() const = 0;
1227 
1241  virtual void flushQueryUpdates() = 0;
1242 
1252  virtual PxBatchQuery* createBatchQuery(const PxBatchQueryDesc& desc) = 0;
1253 
1259  virtual PxVolumeCache* createVolumeCache(PxU32 maxStaticShapes = 32, PxU32 maxDynamicShapes = 8) = 0;
1260 
1268  virtual void setDynamicTreeRebuildRateHint(PxU32 dynamicTreeRebuildRateHint) = 0;
1269 
1277  virtual PxU32 getDynamicTreeRebuildRateHint() const = 0;
1278 
1287  virtual void forceDynamicTreeRebuild(bool rebuildStaticStructure, bool rebuildDynamicStructure) = 0;
1288 
1311  virtual bool raycast(
1312  const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
1313  PxRaycastCallback& hitCall, PxHitFlags hitFlags = PxHitFlags(PxHitFlag::eDEFAULT),
1314  const PxQueryFilterData& filterData = PxQueryFilterData(), PxQueryFilterCallback* filterCall = NULL,
1315  const PxQueryCache* cache = NULL) const = 0;
1316 
1344  virtual bool sweep(const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
1345  PxSweepCallback& hitCall, PxHitFlags hitFlags = PxHitFlags(PxHitFlag::eDEFAULT),
1346  const PxQueryFilterData& filterData = PxQueryFilterData(), PxQueryFilterCallback* filterCall = NULL,
1347  const PxQueryCache* cache = NULL, const PxReal inflation = 0.f) const = 0;
1348 
1349 
1369  virtual bool overlap(const PxGeometry& geometry, const PxTransform& pose, PxOverlapCallback& hitCall,
1370  const PxQueryFilterData& filterData = PxQueryFilterData(), PxQueryFilterCallback* filterCall = NULL
1371  ) const = 0;
1372 
1373  //
1374  // DEPRECATED LEGACY FUNCTIONS, please use the new raycast(), overlap() and sweep() APIs instead
1375  //
1377  PX_DEPRECATED PX_INLINE bool raycastAny(
1378  const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
1380  PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL,
1381  PxClientID queryClient = PX_DEFAULT_CLIENT) const
1382  {
1383  PxSceneQueryFilterData fdAny = filterData;
1384  fdAny.flags |= PxQueryFlag::eANY_HIT;
1385  fdAny.clientId = queryClient;
1386  PxRaycastBuffer buf;
1387  raycast(origin, unitDir, distance, buf, PxHitFlags(), fdAny, filterCall, cache);
1388  hit = buf.block;
1389  return buf.hasBlock;
1390  }
1391 
1393  PX_DEPRECATED PX_INLINE bool raycastSingle(
1394  const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
1395  PxSceneQueryFlags outputFlags, PxRaycastHit& hit,
1396  const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
1397  PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL,
1398  PxClientID queryClient = PX_DEFAULT_CLIENT)
1399  {
1400  PxRaycastBuffer buf;
1401  PxQueryFilterData fd1 = filterData; fd1.clientId = queryClient;
1402  raycast(origin, unitDir, distance, buf, outputFlags, fd1, filterCall, cache);
1403  hit = buf.block;
1404  return buf.hasBlock;
1405  }
1406 
1408  PX_DEPRECATED PX_INLINE PxI32 raycastMultiple(
1409  const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
1410  PxSceneQueryFlags outputFlags,
1411  PxRaycastHit* hitBuffer, PxU32 hitBufferSize, bool& blockingHit,
1412  const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
1413  PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL,
1414  PxClientID queryClient = PX_DEFAULT_CLIENT)
1415  {
1416  PxRaycastBuffer buf(hitBuffer, hitBufferSize);
1417  PxQueryFilterData fd1 = filterData; fd1.clientId = queryClient;
1418  raycast(origin, unitDir, distance, buf, outputFlags, fd1, filterCall, cache);
1419  blockingHit = buf.hasBlock;
1420  if (blockingHit)
1421  {
1422  if (buf.nbTouches < hitBufferSize)
1423  {
1424  hitBuffer[buf.nbTouches] = buf.block;
1425  return PxI32(buf.nbTouches+1);
1426  }
1427  else // overflow, drop the last touch
1428  {
1429  hitBuffer[hitBufferSize-1] = buf.block;
1430  return -1;
1431  }
1432  } else
1433  // no block
1434  return (PxI32)buf.nbTouches;
1435  }
1436 
1438  PX_DEPRECATED PX_INLINE bool sweepAny(
1439  const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
1440  PxSceneQueryFlags queryFlags,
1441  PxSceneQueryHit& hit,
1442  const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
1443  PxSceneQueryFilterCallback* filterCall = NULL,
1444  const PxSceneQueryCache* cache = NULL,
1445  PxClientID queryClient = PX_DEFAULT_CLIENT,
1446  const PxReal inflation = 0.f)
1447  {
1448  PxSceneQueryFilterData fdAny = filterData;
1449  fdAny.flags |= PxQueryFlag::eANY_HIT;
1450  fdAny.clientId = queryClient;
1451  PxSweepBuffer buf;
1452  sweep(geometry, pose, unitDir, distance,
1453  buf, queryFlags, fdAny, filterCall, cache, inflation);
1454  hit = buf.block;
1455  return buf.hasBlock;
1456  }
1457 
1459  PX_DEPRECATED PX_INLINE bool sweepSingle(
1460  const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
1461  PxSceneQueryFlags outputFlags,
1462  PxSweepHit& hit,
1463  const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
1464  PxSceneQueryFilterCallback* filterCall = NULL,
1465  const PxSceneQueryCache* cache = NULL,
1466  PxClientID queryClient = PX_DEFAULT_CLIENT, const PxReal inflation=0.f)
1467  {
1468  PxSweepBuffer buf;
1469  PxQueryFilterData fd1 = filterData; fd1.clientId = queryClient;
1470  sweep(geometry, pose, unitDir, distance, buf,
1471  outputFlags, fd1, filterCall, cache, inflation);
1472  hit = buf.block;
1473  return buf.hasBlock;
1474  }
1475 
1478  const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
1479  PxSceneQueryFlags outputFlags, PxSweepHit* hitBuffer, PxU32 hitBufferSize, bool& blockingHit,
1480  const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
1481  PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL,
1482  PxClientID queryClient = PX_DEFAULT_CLIENT, const PxReal inflation = 0.f)
1483  {
1484  PxQueryFilterData fd1 = filterData; fd1.clientId = queryClient;
1485  PxSweepBuffer buf(hitBuffer, hitBufferSize);
1486  sweep(
1487  geometry, pose, unitDir, distance, buf, outputFlags, fd1, filterCall,
1488  cache, inflation);
1489  blockingHit = buf.hasBlock;
1490  if (blockingHit)
1491  {
1492  if (buf.nbTouches < hitBufferSize)
1493  {
1494  hitBuffer[buf.nbTouches] = buf.block;
1495  return PxI32(buf.nbTouches+1);
1496  }
1497  else // overflow, drop the last touch
1498  {
1499  hitBuffer[hitBufferSize-1] = buf.block;
1500  return -1;
1501  }
1502  } else
1503  // no block
1504  return (PxI32)buf.nbTouches;
1505  }
1506 
1508  PX_DEPRECATED PX_INLINE PxI32 overlapMultiple(
1509  const PxGeometry& geometry, const PxTransform& pose,
1510  PxOverlapHit* hitBuffer, PxU32 hitBufferSize,
1511  const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
1512  PxSceneQueryFilterCallback* filterCall = NULL,
1513  PxClientID queryClient = PX_DEFAULT_CLIENT)
1514  {
1515  PxQueryFilterData fd1 = filterData; fd1.clientId = queryClient;
1517  PxOverlapBuffer buf(hitBuffer, hitBufferSize);
1518  overlap(geometry, pose, buf, fd1, filterCall);
1519  if (buf.hasBlock)
1520  {
1521  if (buf.nbTouches < hitBufferSize)
1522  {
1523  hitBuffer[buf.nbTouches] = buf.block;
1524  return PxI32(buf.nbTouches+1);
1525  }
1526  else // overflow, drop the last touch
1527  {
1528  hitBuffer[hitBufferSize-1] = buf.block;
1529  return -1;
1530  }
1531  } else
1532  // no block
1533  return (PxI32)buf.nbTouches;
1534  }
1535 
1537  PX_DEPRECATED PX_INLINE bool overlapAny(
1538  const PxGeometry& geometry, const PxTransform& pose,
1539  PxOverlapHit& hit,
1540  const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
1541  PxSceneQueryFilterCallback* filterCall = NULL,
1542  PxClientID queryClient = PX_DEFAULT_CLIENT)
1543  {
1544  PxSceneQueryFilterData fdAny = filterData;
1545  fdAny.flags |= (PxQueryFlag::eANY_HIT | PxQueryFlag::eNO_BLOCK);
1546  fdAny.clientId = queryClient;
1547  PxOverlapBuffer buf;
1548  overlap(geometry, pose, buf, fdAny, filterCall);
1549  hit = buf.block;
1550  return buf.hasBlock;
1551  }
1552 
1559  virtual PxU32 getSceneQueryStaticTimestamp() const = 0;
1561 
1562  /************************************************************************************************/
1566 
1572  virtual PxBroadPhaseType::Enum getBroadPhaseType() const = 0;
1573 
1580  virtual bool getBroadPhaseCaps(PxBroadPhaseCaps& caps) const = 0;
1581 
1587  virtual PxU32 getNbBroadPhaseRegions() const = 0;
1588 
1597  virtual PxU32 getBroadPhaseRegions(PxBroadPhaseRegionInfo* userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const = 0;
1598 
1615  virtual PxU32 addBroadPhaseRegion(const PxBroadPhaseRegion& region, bool populateRegion=false) = 0;
1616 
1630  virtual bool removeBroadPhaseRegion(PxU32 handle) = 0;
1631 
1633 
1634  /************************************************************************************************/
1635 
1639 
1645  virtual physx::PxTaskManager* getTaskManager() const = 0;
1646 
1647 
1666  virtual void lockRead(const char* file=NULL, PxU32 line=0) = 0;
1667 
1673  virtual void unlockRead() = 0;
1674 
1700  virtual void lockWrite(const char* file=NULL, PxU32 line=0) = 0;
1701 
1707  virtual void unlockWrite() = 0;
1708 
1709 
1723  virtual void setNbContactDataBlocks(PxU32 numBlocks) = 0;
1724 
1725 
1735  virtual PxU32 getNbContactDataBlocksUsed() const = 0;
1736 
1746  virtual PxU32 getMaxNbContactDataBlocksUsed() const = 0;
1747 
1748 
1754  virtual PxU32 getContactReportStreamBufferSize() const = 0;
1755 
1756 
1766  virtual void setSolverBatchSize(PxU32 solverBatchSize) = 0;
1767 
1777  virtual PxU32 getSolverBatchSize() const = 0;
1778 
1779 
1781 
1789  virtual PxReal getWakeCounterResetValue() const = 0;
1790 
1807  virtual void shiftOrigin(const PxVec3& shift) = 0;
1808 
1809  void* userData;
1810 };
1811 
1812 #ifndef PX_DOXYGEN
1813 } // namespace physx
1814 #endif
1815 
1817 #endif


Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com