Biped.cpp
上传用户:gb3593
上传日期:2022-01-07
资源大小:3028k
文件大小:5k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. #include "Biped.h"
  2. #include "BipedDef.h"
  3. Biped::Biped(b2World* w, const b2Vec2& position)
  4. {
  5. m_world = w;
  6. BipedDef def;
  7. b2BodyDef bd;
  8. // create body parts
  9. bd = def.LFootDef;
  10. bd.position += position;
  11. LFoot = w->CreateBody(&bd);
  12. LFoot->CreateFixture(&def.LFootPoly);
  13. LFoot->SetMassFromShapes();
  14. bd = def.RFootDef;
  15. bd.position += position;
  16. RFoot = w->CreateBody(&bd);
  17. RFoot->CreateFixture(&def.RFootPoly);
  18. RFoot->SetMassFromShapes();
  19. bd = def.LCalfDef;
  20. bd.position += position;
  21. LCalf = w->CreateBody(&bd);
  22. LCalf->CreateFixture(&def.LCalfPoly);
  23. LCalf->SetMassFromShapes();
  24. bd = def.RCalfDef;
  25. bd.position += position;
  26. RCalf = w->CreateBody(&bd);
  27. RCalf->CreateFixture(&def.RCalfPoly);
  28. RCalf->SetMassFromShapes();
  29. bd = def.LThighDef;
  30. bd.position += position;
  31. LThigh = w->CreateBody(&bd);
  32. LThigh->CreateFixture(&def.LThighPoly);
  33. LThigh->SetMassFromShapes();
  34. bd = def.RThighDef;
  35. bd.position += position;
  36. RThigh = w->CreateBody(&bd);
  37. RThigh->CreateFixture(&def.RThighPoly);
  38. RThigh->SetMassFromShapes();
  39. bd = def.PelvisDef;
  40. bd.position += position;
  41. Pelvis = w->CreateBody(&bd);
  42. Pelvis->CreateFixture(&def.PelvisPoly);
  43. Pelvis->SetMassFromShapes();
  44. bd = def.StomachDef;
  45. bd.position += position;
  46. Stomach = w->CreateBody(&bd);
  47. Stomach->CreateFixture(&def.StomachPoly);
  48. Stomach->SetMassFromShapes();
  49. bd = def.ChestDef;
  50. bd.position += position;
  51. Chest = w->CreateBody(&bd);
  52. Chest->CreateFixture(&def.ChestPoly);
  53. Chest->SetMassFromShapes();
  54. bd = def.NeckDef;
  55. bd.position += position;
  56. Neck = w->CreateBody(&bd);
  57. Neck->CreateFixture(&def.NeckPoly);
  58. Neck->SetMassFromShapes();
  59. bd = def.HeadDef;
  60. bd.position += position;
  61. Head = w->CreateBody(&bd);
  62. Head->CreateFixture(&def.HeadCirc);
  63. Head->SetMassFromShapes();
  64. bd = def.LUpperArmDef;
  65. bd.position += position;
  66. LUpperArm = w->CreateBody(&bd);
  67. LUpperArm->CreateFixture(&def.LUpperArmPoly);
  68. LUpperArm->SetMassFromShapes();
  69. bd = def.RUpperArmDef;
  70. bd.position += position;
  71. RUpperArm = w->CreateBody(&bd);
  72. RUpperArm->CreateFixture(&def.RUpperArmPoly);
  73. RUpperArm->SetMassFromShapes();
  74. bd = def.LForearmDef;
  75. bd.position += position;
  76. LForearm = w->CreateBody(&bd);
  77. LForearm->CreateFixture(&def.LForearmPoly);
  78. LForearm->SetMassFromShapes();
  79. bd = def.RForearmDef;
  80. bd.position += position;
  81. RForearm = w->CreateBody(&bd);
  82. RForearm->CreateFixture(&def.RForearmPoly);
  83. RForearm->SetMassFromShapes();
  84. bd = def.LHandDef;
  85. bd.position += position;
  86. LHand = w->CreateBody(&bd);
  87. LHand->CreateFixture(&def.LHandPoly);
  88. LHand->SetMassFromShapes();
  89. bd = def.RHandDef;
  90. bd.position += position;
  91. RHand = w->CreateBody(&bd);
  92. RHand->CreateFixture(&def.RHandPoly);
  93. RHand->SetMassFromShapes();
  94. // link body parts
  95. def.LAnkleDef.body1 = LFoot;
  96. def.LAnkleDef.body2 = LCalf;
  97. def.RAnkleDef.body1 = RFoot;
  98. def.RAnkleDef.body2 = RCalf;
  99. def.LKneeDef.body1 = LCalf;
  100. def.LKneeDef.body2 = LThigh;
  101. def.RKneeDef.body1 = RCalf;
  102. def.RKneeDef.body2 = RThigh;
  103. def.LHipDef.body1 = LThigh;
  104. def.LHipDef.body2 = Pelvis;
  105. def.RHipDef.body1 = RThigh;
  106. def.RHipDef.body2 = Pelvis;
  107. def.LowerAbsDef.body1 = Pelvis;
  108. def.LowerAbsDef.body2 = Stomach;
  109. def.UpperAbsDef.body1 = Stomach;
  110. def.UpperAbsDef.body2 = Chest;
  111. def.LowerNeckDef.body1 = Chest;
  112. def.LowerNeckDef.body2 = Neck;
  113. def.UpperNeckDef.body1 = Chest;
  114. def.UpperNeckDef.body2 = Head;
  115. def.LShoulderDef.body1 = Chest;
  116. def.LShoulderDef.body2 = LUpperArm;
  117. def.RShoulderDef.body1 = Chest;
  118. def.RShoulderDef.body2 = RUpperArm;
  119. def.LElbowDef.body1 = LForearm;
  120. def.LElbowDef.body2 = LUpperArm;
  121. def.RElbowDef.body1 = RForearm;
  122. def.RElbowDef.body2 = RUpperArm;
  123. def.LWristDef.body1 = LHand;
  124. def.LWristDef.body2 = LForearm;
  125. def.RWristDef.body1 = RHand;
  126. def.RWristDef.body2 = RForearm;
  127. // create joints
  128. LAnkle = (b2RevoluteJoint*)w->CreateJoint(&def.LAnkleDef);
  129. RAnkle = (b2RevoluteJoint*)w->CreateJoint(&def.RAnkleDef);
  130. LKnee = (b2RevoluteJoint*)w->CreateJoint(&def.LKneeDef);
  131. RKnee = (b2RevoluteJoint*)w->CreateJoint(&def.RKneeDef);
  132. LHip = (b2RevoluteJoint*)w->CreateJoint(&def.LHipDef);
  133. RHip = (b2RevoluteJoint*)w->CreateJoint(&def.RHipDef);
  134. LowerAbs = (b2RevoluteJoint*)w->CreateJoint(&def.LowerAbsDef);
  135. UpperAbs = (b2RevoluteJoint*)w->CreateJoint(&def.UpperAbsDef);
  136. LowerNeck = (b2RevoluteJoint*)w->CreateJoint(&def.LowerNeckDef);
  137. UpperNeck = (b2RevoluteJoint*)w->CreateJoint(&def.UpperNeckDef);
  138. LShoulder = (b2RevoluteJoint*)w->CreateJoint(&def.LShoulderDef);
  139. RShoulder = (b2RevoluteJoint*)w->CreateJoint(&def.RShoulderDef);
  140. LElbow = (b2RevoluteJoint*)w->CreateJoint(&def.LElbowDef);
  141. RElbow = (b2RevoluteJoint*)w->CreateJoint(&def.RElbowDef);
  142. LWrist = (b2RevoluteJoint*)w->CreateJoint(&def.LWristDef);
  143. RWrist = (b2RevoluteJoint*)w->CreateJoint(&def.RWristDef);
  144. }
  145. Biped::~Biped(void)
  146. {
  147. m_world->DestroyBody(LFoot);
  148. m_world->DestroyBody(RFoot);
  149. m_world->DestroyBody(LCalf);
  150. m_world->DestroyBody(RCalf);
  151. m_world->DestroyBody(LThigh);
  152. m_world->DestroyBody(RThigh);
  153. m_world->DestroyBody(Pelvis);
  154. m_world->DestroyBody(Stomach);
  155. m_world->DestroyBody(Chest);
  156. m_world->DestroyBody(Neck);
  157. m_world->DestroyBody(Head);
  158. m_world->DestroyBody(LUpperArm);
  159. m_world->DestroyBody(RUpperArm);
  160. m_world->DestroyBody(LForearm);
  161. m_world->DestroyBody(RForearm);
  162. m_world->DestroyBody(LHand);
  163. m_world->DestroyBody(RHand);
  164. }