hkpConvexListUtils.h
上传用户:yisoukefu
上传日期:2020-08-09
资源大小:39506k
文件大小:7k
源码类别:

其他游戏

开发平台:

Visual C++

  1. /* 
  2.  * 
  3.  * Confidential Information of Telekinesys Research Limited (t/a Havok). Not for disclosure or distribution without Havok's
  4.  * prior written consent. This software contains code, techniques and know-how which is confidential and proprietary to Havok.
  5.  * Level 2 and Level 3 source code contains trade secrets of Havok. Havok Software (C) Copyright 1999-2009 Telekinesys Research Limited t/a Havok. All Rights Reserved. Use of this software is subject to the terms of an end user license agreement.
  6.  * 
  7.  */
  8. #ifndef HK_COLLIDE2_CONVEX_LIST_SHARED_HELPERS_H
  9. #define HK_COLLIDE2_CONVEX_LIST_SHARED_HELPERS_H
  10. #include <Physics/Collide/Shape/Compound/Collection/hkpShapeCollection.h>
  11. #include <Physics/Collide/Shape/Misc/ConvexList/hkpConvexListShape.h>
  12. // File info: this file is shared by the hkpConvexListAgent & hkConvexListAgent3
  13. // C4701: local variable 'output' may be used without having been initialized
  14. # pragma warning(push)
  15. # pragma warning(disable: 4701)
  16. struct hkpProcessCollisionOutputBackup
  17. {
  18. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( HK_MEMORY_CLASS_COLLIDE, hkpProcessCollisionOutputBackup );
  19. hkpProcessCollisionOutputBackup( const hkpProcessCollisionOutput& output )
  20. {
  21. m_firstPoint = output.m_firstFreeContactPoint;
  22. m_toi = output.m_toi;
  23. #if defined(HK_1N_MACHINE_SUPPORTS_WELDING)
  24. if ( output.m_potentialContacts )
  25. {
  26. m_weldingInformation = *output.m_potentialContacts;
  27. }
  28. #endif
  29. }
  30. inline void rollbackOutput( const hkpCdBody& bodyA, const hkpCdBody& bodyB, hkpProcessCollisionOutput& output, hkpContactMgr* mgr )
  31. {
  32. if ( output.m_toi.m_time != m_toi.m_time )
  33. {
  34. mgr->removeToi( *output.m_constraintOwner.val(), output.m_toi.m_properties );
  35. output.m_toi = m_toi;
  36. }
  37. output.m_firstFreeContactPoint = m_firstPoint;
  38. #if defined(HK_1N_MACHINE_SUPPORTS_WELDING)
  39. if ( output.m_potentialContacts )
  40. {
  41. *output.m_potentialContacts = m_weldingInformation;
  42. }
  43. #endif
  44. }
  45. hkpProcessCdPoint* m_firstPoint;
  46. hkpProcessCollisionOutput::PotentialInfo m_weldingInformation;
  47. hkpProcessCollisionOutput::ToiInfo m_toi;
  48. };
  49. class hkpMapPointsToSubShapeContactMgr : public hkpContactMgr
  50. {
  51. public:
  52. hkpMapPointsToSubShapeContactMgr( hkpContactMgr* mgr ): hkpContactMgr( hkpContactMgr::TYPE_CONVEX_LIST_CONTACT_MGR )
  53. {
  54. m_contactMgr = mgr;
  55. m_invalidPointHit = false;
  56. }
  57. hkContactPointId addContactPointImpl( const hkpCdBody& a, const hkpCdBody& b, const hkpProcessCollisionInput& input, hkpProcessCollisionOutput& output, const hkpGskCache* contactCache, hkContactPoint& cp )
  58. {
  59. const hkpCdBody* aMod = &a;
  60. const hkpCdBody* bMod = &b;
  61. hkpCdBody aTemp;
  62. hkpCdBody bTemp;
  63. if (a.getShape()->getType() == HK_SHAPE_CONVEX_LIST )
  64. {
  65. int shapeKey = ( 0xff00 & contactCache->m_vertices[0] ) >> 8;
  66. for (int i = 1; i < contactCache->m_dimA; ++i)
  67. {
  68. int shapeKey2 = ( 0xff00 & contactCache->m_vertices[i] ) >> 8;
  69. if ( shapeKey2 != shapeKey )
  70. {
  71. m_invalidPointHit = true;
  72. return HK_INVALID_CONTACT_POINT;
  73. }
  74. }
  75. hkpShapeCollection::ShapeBuffer buffer;
  76. const hkpShape* childShape = static_cast<const hkpConvexListShape*>(a.getShape())->getChildShape(shapeKey, buffer);
  77. new (&aTemp) hkpCdBody(&a);
  78. aTemp.setShape( childShape, shapeKey );
  79. aMod = &aTemp;
  80. }
  81. if (b.getShape()->getType() == HK_SHAPE_CONVEX_LIST )
  82. {
  83. int shapeKey = (0xff00 & contactCache->m_vertices[contactCache->m_dimA]) >> 8;
  84. for (int i = contactCache->m_dimA + 1; i < contactCache->m_dimA + contactCache->m_dimB; ++i)
  85. {
  86. int shapeKey2 = (0xff00 & contactCache->m_vertices[i]) >> 8;
  87. if ( shapeKey2 != shapeKey )
  88. {
  89. m_invalidPointHit = true;
  90. return HK_INVALID_CONTACT_POINT;
  91. }
  92. }
  93. hkpShapeCollection::ShapeBuffer buffer;
  94. const hkpShape* childShape = static_cast<const hkpConvexListShape*>(b.getShape())->getChildShape(shapeKey, buffer);
  95. new (&bTemp) hkpCdBody(&b);
  96. bTemp.setShape( childShape, shapeKey );
  97. bMod = &bTemp;
  98. }
  99. return m_contactMgr->addContactPoint( *aMod, *bMod, input, output, contactCache, cp );
  100. }
  101. hkResult reserveContactPointsImpl( int numPoints )
  102. {
  103. return m_contactMgr->reserveContactPoints( numPoints );
  104. }
  105. void removeContactPointImpl( hkContactPointId cpId, hkCollisionConstraintOwner& constraintOwner )
  106. {
  107. m_contactMgr->removeContactPoint( cpId, constraintOwner );
  108. }
  109. void processContactImpl( const hkpCollidable& a, const hkpCollidable& b, const hkpProcessCollisionInput& input, hkpProcessCollisionData& collisionData )
  110. {
  111. m_contactMgr->processContact( a, b, input, collisionData );
  112. }
  113. void cleanup()
  114. {
  115. m_contactMgr->cleanup();
  116. }
  117. ToiAccept addToiImpl( const hkpCdBody& a, const hkpCdBody& b, const hkpProcessCollisionInput& input, hkpProcessCollisionOutput& output, hkTime toi, hkContactPoint& cp, const hkpGskCache* gskCache, hkReal& projectedVelocity, hkpContactPointProperties& propertiesOut )
  118. {
  119. const hkpCdBody* aMod = &a;
  120. const hkpCdBody* bMod = &b;
  121. hkpCdBody aTemp;
  122. hkpCdBody bTemp;
  123. if (a.getShape()->getType() == HK_SHAPE_CONVEX_LIST )
  124. {
  125. int shapeKey = ( 0xff00 & gskCache->m_vertices[0] ) >> 8;
  126. for (int i = 1; i < gskCache->m_dimA; ++i)
  127. {
  128. int shapeKey2 = ( 0xff00 & gskCache->m_vertices[i] ) >> 8;
  129. if ( shapeKey2 != shapeKey )
  130. {
  131. m_invalidPointHit = true;
  132. return TOI_REJECT;
  133. }
  134. }
  135. hkpShapeCollection::ShapeBuffer buffer;
  136. const hkpShape* childShape = static_cast<const hkpConvexListShape*>(a.getShape())->getChildShape(shapeKey, buffer);
  137. new (&aTemp) hkpCdBody(&a);
  138. aTemp.setShape( childShape, shapeKey );
  139. aMod = &aTemp;
  140. }
  141. if (b.getShape()->getType() == HK_SHAPE_CONVEX_LIST )
  142. {
  143. int shapeKey = ( 0xff00 & gskCache->m_vertices[gskCache->m_dimA] ) >> 8;
  144. for (int i = gskCache->m_dimA + 1; i < gskCache->m_dimA + gskCache->m_dimB; ++i)
  145. {
  146. int shapeKey2 = ( 0xff00 & gskCache->m_vertices[i] ) >> 8;
  147. if ( shapeKey2 != shapeKey )
  148. {
  149. m_invalidPointHit = true;
  150. return TOI_REJECT;
  151. }
  152. }
  153. hkpShapeCollection::ShapeBuffer buffer;
  154. const hkpShape* childShape = static_cast<const hkpConvexListShape*>(b.getShape())->getChildShape(shapeKey, buffer);
  155. new (&bTemp) hkpCdBody(&b);
  156. bTemp.setShape( childShape, shapeKey );
  157. bMod = &bTemp;
  158. }
  159. return m_contactMgr->addToi( *aMod, *bMod, input, output, toi, cp, gskCache, projectedVelocity, propertiesOut );
  160. }
  161. void removeToiImpl( class hkCollisionConstraintOwner& constraintOwner, hkpContactPointProperties& properties )
  162. {
  163. m_contactMgr->removeToi( constraintOwner, properties );
  164. }
  165. public:
  166. hkpContactMgr* m_contactMgr;
  167. hkBool m_invalidPointHit;
  168. };
  169. # pragma warning(pop)
  170. #endif // HK_COLLIDE2_CONVEX_LIST_SHARED_HELPERS_H
  171. /*
  172. * Havok SDK - NO SOURCE PC DOWNLOAD, BUILD(#20090216)
  173. * Confidential Information of Havok.  (C) Copyright 1999-2009
  174. * Telekinesys Research Limited t/a Havok. All Rights Reserved. The Havok
  175. * Logo, and the Havok buzzsaw logo are trademarks of Havok.  Title, ownership
  176. * rights, and intellectual property rights in the Havok software remain in
  177. * Havok and/or its suppliers.
  178. * Use of this software for evaluation purposes is subject to and indicates
  179. * acceptance of the End User licence Agreement for this product. A copy of
  180. * the license is included with this software and is also available at www.havok.com/tryhavok.
  181. */