1
0

CCPhysics3D.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /****************************************************************************
  2. Copyright (c) 2015-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #include "physics3d/CCPhysics3D.h"
  21. #if CC_USE_3D_PHYSICS
  22. #if (CC_ENABLE_BULLET_INTEGRATION)
  23. NS_CC_BEGIN
  24. CC_DLL const char* physics3dVersion()
  25. {
  26. #if CC_ENABLE_BULLET_INTEGRATION
  27. return "bullet2.82";
  28. #endif
  29. }
  30. NS_CC_END
  31. cocos2d::Vec3 convertbtVector3ToVec3( const btVector3 &btVec3 )
  32. {
  33. return cocos2d::Vec3(btVec3.x(), btVec3.y(), btVec3.z());
  34. }
  35. btVector3 convertVec3TobtVector3( const cocos2d::Vec3 &vec3 )
  36. {
  37. return btVector3(vec3.x, vec3.y, vec3.z);
  38. }
  39. cocos2d::Mat4 convertbtTransformToMat4( const btTransform &btTrans )
  40. {
  41. cocos2d::Mat4 mat;
  42. auto rot = btTrans.getBasis();
  43. auto row = rot.getRow(0);
  44. mat.m[0] = row.getX();
  45. mat.m[4] = row.getY();
  46. mat.m[8] = row.getZ();
  47. row = rot.getRow(1);
  48. mat.m[1] = row.getX();
  49. mat.m[5] = row.getY();
  50. mat.m[9] = row.getZ();
  51. row = rot.getRow(2);
  52. mat.m[2] = row.getX();
  53. mat.m[6] = row.getY();
  54. mat.m[10] = row.getZ();
  55. row = btTrans.getOrigin();
  56. mat.m[12] = row.getX();
  57. mat.m[13] = row.getY();
  58. mat.m[14] = row.getZ();
  59. return mat;
  60. }
  61. btTransform convertMat4TobtTransform( const cocos2d::Mat4 &mat4 )
  62. {
  63. btTransform btTrans;
  64. btTrans.setFromOpenGLMatrix(mat4.m);
  65. return btTrans;
  66. }
  67. cocos2d::Quaternion convertbtQuatToQuat( const btQuaternion &btQuat )
  68. {
  69. return cocos2d::Quaternion(btQuat.x(), btQuat.y(), btQuat.z(), btQuat.w());
  70. }
  71. btQuaternion convertQuatTobtQuat( const cocos2d::Quaternion &quat )
  72. {
  73. return btQuaternion(quat.x, quat.y, quat.z, quat.w);
  74. }
  75. #endif // CC_ENABLE_BULLET_INTEGRATION
  76. #endif //CC_USE_3D_PHYSICS