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

其他游戏

开发平台:

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_CONSTRAINTSOLVER2_SOLVE_H
  9. #define HK_CONSTRAINTSOLVER2_SOLVE_H
  10. #include <Common/Base/hkBase.h>
  11. #include <Physics/ConstraintSolver/Solve/hkpSolverInfo.h>
  12. //#define HK_COMPRESS_SCHEMAS
  13. #if defined HK_COMPRESS_SCHEMAS
  14. # define HK_COMPRESS_SCHEMAS_FLOAT16
  15. #endif
  16. class hkpJacobianSchema;
  17. class hkpVelocityAccumulator;
  18. class hkSpuDmaAccessor;
  19. class hkSpuDmaReader;
  20. class hkpConstraintInstance;
  21. class hkpSolverResults;
  22. struct hkpSolverElemTemp
  23. {
  24. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( HK_MEMORY_CLASS_CONSTRAINT_SOLVER, hkpSolverElemTemp );
  25. union
  26. {
  27. hkReal m_impulseApplied;
  28. hkReal m_usedImpulseFactor;
  29. hkReal m_deltaRhs;
  30. };
  31. };
  32. struct hkpImpulseLimitBreachedElem
  33. {
  34. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( HK_MEMORY_CLASS_CONSTRAINT_SOLVER, hkpImpulseLimitBreachedElem );
  35. HK_ALIGN16(hkUint16   m_type); // set to 0
  36. hkUint16 m_isContact;
  37. hkpConstraintInstance* m_constraintInstance; // this is the value set in hkpConstraintQueryIn.m_constraintInstance
  38. hkpSolverResults*   m_solverResult; // a pointer to the solver results
  39. };
  40. // this class is followed by an array of hkpImpulseLimitBreachedElem
  41. struct hkpImpulseLimitBreachedHeader
  42. {
  43. HK_DECLARE_NONVIRTUAL_CLASS_ALLOCATOR( HK_MEMORY_CLASS_CONSTRAINT_SOLVER, hkpImpulseLimitBreachedHeader );
  44. HK_ALIGN16( int m_numBreached );
  45. // for multi threading this points to the next array
  46. hkpImpulseLimitBreachedHeader* m_next;
  47. inline hkpImpulseLimitBreachedElem& getElem(int index){ return *(hkpImpulseLimitBreachedElem*)hkAddByteOffset(this,index*sizeof(hkpImpulseLimitBreachedElem) + sizeof(hkpImpulseLimitBreachedHeader) ); }
  48. };
  49. class hkpConstraintInstance;
  50. extern "C"  
  51. {
  52. // info pretty much read only, but cannot be shared between threads
  53. hkBool32 HK_CALL hkSolveConstraints( const hkpSolverInfo& info, hkpJacobianSchema *schemas,  hkpVelocityAccumulator * accumulators, hkpSolverElemTemp* temp );
  54. void HK_CALL hkSolveApplyGravityByTheSteps( const hkpSolverInfo& info, hkpVelocityAccumulator* accumulators, hkpVelocityAccumulator* accumulatorsEnd );
  55. hkBool32 HK_CALL hkSolveConstraintsByTheSteps( const hkpSolverInfo& info, int currentSolverStep, int currentSolverMicroStep, const hkpJacobianSchema *schemas,  hkpVelocityAccumulator * accumulators, hkpSolverElemTemp* temp );
  56. int HK_CALL hkSolveIntegrateVelocitiesByTheSteps( const hkpSolverInfo& info, int currentSolverStep, hkpVelocityAccumulator* accumulators, hkpVelocityAccumulator* accumulatorsEnd, hkBool& outSolveFinished );
  57. void HK_CALL hkSolveUpload();
  58. void HK_CALL hkSolveStepJacobians ( const hkpSolverInfo& i, const hkpJacobianSchema *schemas, hkpVelocityAccumulator* accumulators, hkpSolverElemTemp* tmp );
  59. // this function exports the result from the solver into the solver results.
  60. // it also exports the impulse breached constraints within the schemas memory;
  61. void HK_CALL hkExportImpulsesAndRhs( const hkpSolverInfo& i, const hkpSolverElemTemp* temp, const hkpJacobianSchema *schemas, const hkpVelocityAccumulator* accums );
  62. /// Get the violating velocities for some constraints.
  63. /// Contact constraint - returns min( 0.0f, seperatingVelocity ).
  64. /// Bilateral constraint - returns the violating velocity.
  65. /// All the rest return 0.0f.
  66. ///
  67. /// Continues until:
  68. ///  - the constraint is finished by finding the end mark or a new header schema.
  69. ///  - we reach the friction part a contact constraint.
  70.     ///  - we reach maxNumVelocities.
  71. ///
  72. /// Returns the number of velocities calculated.
  73. int HK_CALL hkSolveGetToiViolatingConstraintVelocity( hkpSolverInfo& i, const hkpJacobianSchema *schemas, const hkpVelocityAccumulator* accums, int maxNumVelocities, hkReal* velocitiesOut );
  74. }
  75. #if defined HK_COMPRESS_SCHEMAS
  76. #define HK_SIZE_OF_JACOBIAN_END_SCHEMA 16
  77. #define HK_SIZE_OF_JACOBIAN_HEADER_SCHEMA 16
  78. #define HK_SIZE_OF_JACOBIAN_GOTO_SCHEMA 16
  79. #define HK_SIZE_OF_JACOBIAN_SHIFT_SOLVER_RESULTS_SCHEMA 16
  80. #if defined HK_COMPRESS_SCHEMAS_FLOAT16
  81. # define HK_SIZE_OF_JACOBIAN_1D_BILATERAL_SCHEMA 32
  82. # define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_SCHEMA 16
  83. #define HK_SIZE_OF_JACOBIAN_SINGLE_CONTACT_SCHEMA 32
  84. #define HK_SIZE_OF_JACOBIAN_PAIR_CONTACT_SCHEMA 80 // and can get rid of one more - 64
  85. #else
  86. # define HK_SIZE_OF_JACOBIAN_1D_BILATERAL_SCHEMA 48
  87. # define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_SCHEMA 32
  88. # define HK_SIZE_OF_JACOBIAN_SINGLE_CONTACT_SCHEMA 48
  89. # define HK_SIZE_OF_JACOBIAN_PAIR_CONTACT_SCHEMA 96 //112
  90. #endif
  91. #define HK_SIZE_OF_JACOBIAN_1D_BILATERAL_USER_TAU_SCHEMA 48 //-16
  92. #define HK_SIZE_OF_JACOBIAN_1D_LINEAR_LIMIT_SCHEMA 48 //-16
  93. #define HK_SIZE_OF_JACOBIAN_1D_FRICTION_SCHEMA 48 // -16
  94. #define HK_SIZE_OF_JACOBIAN_1D_LINEAR_MOTOR_SCHEMA 80
  95. #define HK_SIZE_OF_JACOBIAN_1D_PULLEY_SCHEMA 64
  96. #define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_LIMITS_SCHEMA 48
  97. #define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_FRICTION_SCHEMA 48
  98. #define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_MOTOR_SCHEMA 64
  99. #if HK_POINTER_SIZE == 4
  100. #define HK_SIZE_OF_JACOBIAN_2D_FRICTION_SCHEMA 112
  101. #else
  102. #define HK_SIZE_OF_JACOBIAN_2D_FRICTION_SCHEMA 128
  103. #endif
  104. #define HK_SIZE_OF_JACOBIAN_3D_FRICTION_SCHEMA 160
  105. #define HK_SIZE_OF_JACOBIAN_2D_ROLLING_FRICTION_SCHEMA 80
  106. #define HK_SIZE_OF_JACOBIAN_SET_MASS_SCHEMA 32
  107. #define HK_SIZE_OF_JACOBIAN_ADD_VELOCITY_SCHEMA 32
  108. #define HK_SIZE_OF_JACOBIAN_ADD_ANGULAR_VELOCITY_SCHEMA 96
  109. #else // 
  110. #define HK_SIZE_OF_JACOBIAN_END_SCHEMA 16
  111. #if HK_POINTER_SIZE == 4
  112. #define HK_SIZE_OF_JACOBIAN_HEADER_SCHEMA 16
  113. #else
  114. # define HK_SIZE_OF_JACOBIAN_HEADER_SCHEMA 32
  115. #endif
  116. # define HK_SIZE_OF_JACOBIAN_GOTO_SCHEMA 16
  117. #define HK_SIZE_OF_JACOBIAN_SHIFT_SOLVER_RESULTS_SCHEMA 16
  118. #define HK_SIZE_OF_JACOBIAN_1D_BILATERAL_SCHEMA 48
  119. #define HK_SIZE_OF_JACOBIAN_1D_BILATERAL_USER_TAU_SCHEMA 64
  120. #define HK_SIZE_OF_JACOBIAN_1D_LINEAR_LIMIT_SCHEMA 64
  121. #define HK_SIZE_OF_JACOBIAN_1D_FRICTION_SCHEMA 64
  122. #define HK_SIZE_OF_JACOBIAN_1D_LINEAR_MOTOR_SCHEMA 80
  123. #define HK_SIZE_OF_JACOBIAN_1D_PULLEY_SCHEMA 64
  124. #define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_SCHEMA 32
  125. #define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_LIMITS_SCHEMA 48
  126. #define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_FRICTION_SCHEMA 48
  127. #define HK_SIZE_OF_JACOBIAN_1D_ANGULAR_MOTOR_SCHEMA 64
  128. #define HK_SIZE_OF_JACOBIAN_SINGLE_CONTACT_SCHEMA 48
  129. #define HK_SIZE_OF_JACOBIAN_PAIR_CONTACT_SCHEMA 112
  130. #define HK_SIZE_OF_JACOBIAN_2D_FRICTION_SCHEMA 112
  131. #if HK_POINTER_SIZE == 4
  132. #define HK_SIZE_OF_JACOBIAN_3D_FRICTION_SCHEMA 144
  133. #else
  134. #define HK_SIZE_OF_JACOBIAN_3D_FRICTION_SCHEMA 160
  135. #endif
  136. #define HK_SIZE_OF_JACOBIAN_2D_ROLLING_FRICTION_SCHEMA 80
  137. #define HK_SIZE_OF_JACOBIAN_SET_MASS_SCHEMA 32
  138. #define HK_SIZE_OF_JACOBIAN_ADD_VELOCITY_SCHEMA 32
  139. #define HK_SIZE_OF_JACOBIAN_ADD_ANGULAR_VELOCITY_SCHEMA 96
  140. #endif
  141. #define HK_SIZE_OF_JACOBIAN_STIFF_SPRING_CHAIN_SCHEMA 16
  142. #define HK_SIZE_OF_JACOBIAN_BALL_SOCKET_CHAIN_SCHEMA 16
  143. #define HK_SIZE_OF_JACOBIAN_POWERED_CHAIN_SCHEMA  32
  144. #endif // HK_CONSTRAINTSOLVER2_SOLVE_H
  145. /*
  146. * Havok SDK - NO SOURCE PC DOWNLOAD, BUILD(#20090216)
  147. * Confidential Information of Havok.  (C) Copyright 1999-2009
  148. * Telekinesys Research Limited t/a Havok. All Rights Reserved. The Havok
  149. * Logo, and the Havok buzzsaw logo are trademarks of Havok.  Title, ownership
  150. * rights, and intellectual property rights in the Havok software remain in
  151. * Havok and/or its suppliers.
  152. * Use of this software for evaluation purposes is subject to and indicates
  153. * acceptance of the End User licence Agreement for this product. A copy of
  154. * the license is included with this software and is also available at www.havok.com/tryhavok.
  155. */