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

游戏引擎

开发平台:

Visual C++

  1. /*
  2. * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty.  In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it
  9. * freely, subject to the following restrictions:
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software
  12. * in a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. * 2. Altered source versions must be plainly marked as such, and must not be
  15. * misrepresented as being the original software.
  16. * 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef STATIC_EDGES_H
  19. #define STATIC_EDGES_H
  20. class StaticEdges : public Test
  21. {
  22. public:
  23. StaticEdges()
  24. {
  25. #if 0
  26. {
  27. b2CircleDef sd;
  28. sd.radius = 0.5f;
  29. sd.localPosition.SetZero();
  30. sd.density = 2.0f;
  31. b2BodyDef bd;
  32. bd.position.Set(0.0f, 2.0f);
  33. b2Body* body = m_world->CreateBody(&bd);
  34. body->CreateFixture(&sd);
  35. body->SetMassFromShapes();
  36. }
  37. #endif
  38. {
  39. b2CircleDef sd1;
  40. sd1.radius = 0.5f;
  41. sd1.localPosition.Set(-0.5f, 0.5f);
  42. sd1.density = 2.0f;
  43. b2CircleDef sd2;
  44. sd2.radius = 0.5f;
  45. sd2.localPosition.Set(0.5f, 0.5f);
  46. sd2.density = 0.0f; // massless
  47. for (int i = 0; i < 10; ++i)
  48. {
  49. float32 x = RandomFloat(-0.1f, 0.1f);
  50. b2BodyDef bd;
  51. bd.position.Set(x + 5.0f, 1.05f + 2.5f * i);
  52. bd.angle = RandomFloat(-b2_pi, b2_pi);
  53. b2Body* body = m_world->CreateBody(&bd);
  54. body->CreateFixture(&sd1);
  55. body->CreateFixture(&sd2);
  56. body->SetMassFromShapes();
  57. }
  58. }
  59. {
  60. b2PolygonDef sd1;
  61. sd1.SetAsBox(0.25f, 0.5f);
  62. sd1.density = 2.0f;
  63. b2PolygonDef sd2;
  64. sd2.SetAsBox(0.25f, 0.5f, b2Vec2(0.0f, -0.5f), 0.5f * b2_pi);
  65. sd2.density = 2.0f;
  66. for (int i = 0; i < 10; ++i)
  67. {
  68. float32 x = RandomFloat(-0.1f, 0.1f);
  69. b2BodyDef bd;
  70. bd.position.Set(x - 5.0f, 1.05f + 2.5f * i);
  71. bd.angle = RandomFloat(-b2_pi, b2_pi);
  72. b2Body* body = m_world->CreateBody(&bd);
  73. body->CreateFixture(&sd1);
  74. body->CreateFixture(&sd2);
  75. body->SetMassFromShapes();
  76. }
  77. }
  78. {
  79. b2XForm xf1;
  80. xf1.R.Set(0.3524f * b2_pi);
  81. xf1.position = b2Mul(xf1.R, b2Vec2(1.0f, 0.0f));
  82. b2PolygonDef sd1;
  83. sd1.vertexCount = 3;
  84. sd1.vertices[0] = b2Mul(xf1, b2Vec2(-1.0f, 0.0f));
  85. sd1.vertices[1] = b2Mul(xf1, b2Vec2(1.0f, 0.0f));
  86. sd1.vertices[2] = b2Mul(xf1, b2Vec2(0.0f, 0.5f));
  87. sd1.density = 2.0f;
  88. b2XForm xf2;
  89. xf2.R.Set(-0.3524f * b2_pi);
  90. xf2.position = b2Mul(xf2.R, b2Vec2(-1.0f, 0.0f));
  91. b2PolygonDef sd2;
  92. sd2.vertexCount = 3;
  93. sd2.vertices[0] = b2Mul(xf2, b2Vec2(-1.0f, 0.0f));
  94. sd2.vertices[1] = b2Mul(xf2, b2Vec2(1.0f, 0.0f));
  95. sd2.vertices[2] = b2Mul(xf2, b2Vec2(0.0f, 0.5f));
  96. sd2.density = 2.0f;
  97. for (int32 i = 0; i < 10; ++i)
  98. {
  99. float32 x = RandomFloat(-0.1f, 0.1f);
  100. b2BodyDef bd;
  101. bd.position.Set(x, 2.05f + 2.5f * i);
  102. bd.angle = 0.0f;
  103. b2Body* body = m_world->CreateBody(&bd);
  104. body->CreateFixture(&sd1);
  105. body->CreateFixture(&sd2);
  106. body->SetMassFromShapes();
  107. }
  108. }
  109. {
  110. float32 loop1[] = 
  111. {
  112. 0.063134534f,8.3695248f,
  113. 0.94701801f,9.3165428f,
  114. 0.0f,9.0640047f,
  115. -0.12626907f,10.326695f,
  116. 1.4520943f,11.77879f,
  117. 2.2728432f,10.137292f,
  118. 2.3991123f,11.147444f,
  119. 3.5986685f,10.958041f,
  120. 3.9143411f,7.3593722f,
  121. 4.1668793f,9.4428119f,
  122. 5.4295699f,9.3165428f,
  123. 6.2503189f,8.3063903f,
  124. 6.6922606f,10.137292f,
  125. 4.9876282f,9.8216191f,
  126. 4.7350901f,10.958041f,
  127. 7.2604714f,11.652521f,
  128. 10.732871f,11.147444f,
  129. 10.480333f,10.642368f,
  130. 10.732871f,9.8216191f,
  131. 11.55362f,9.4428119f,
  132. 12.374369f,9.3796773f,
  133. 13.005714f,9.8216191f,
  134. 13.195118f,10.38983f,
  135. 13.005714f,10.768637f,
  136. 12.626907f,10.894906f,
  137. 12.753176f,11.526252f,
  138. 13.573925f,11.715655f,
  139. 14.836616f,11.399982f,
  140. 16.351844f,10.768637f,
  141. 17.867073f,11.399982f,
  142. 17.803939f,10.263561f,
  143. 17.361997f,8.3063903f,
  144. 17.803939f,8.1801212f,
  145. 18.056477f,9.5059464f,
  146. 18.182746f,11.336848f,
  147. 18.561553f,11.210579f,
  148. 18.561553f,9.6322155f,
  149. 18.561553f,7.7381795f,
  150. 18.687822f,5.5284708f,
  151. 19.382302f,5.6547398f,
  152. 19.066629f,8.1801212f,
  153. 19.003495f,10.263561f,
  154. 19.066629f,11.463117f,
  155. 19.887378f,11.841924f,
  156. 20.708127f,11.273713f,
  157. 21.0238f,10.011023f,
  158. 20.708127f,7.2962377f,
  159. 21.086934f,6.2860852f,
  160. 21.150069f,3.7607038f,
  161. 20.392455f,2.5611476f,
  162. 18.624688f,2.5611476f,
  163. 20.771262f,2.1192059f,
  164. 20.771262f,0.22516988f,
  165. 18.624688f,-0.2799064f,
  166. 13.826463f,0.16203534f,
  167. 14.015867f,1.7403987f,
  168. 13.195118f,2.1823404f,
  169. 12.626907f,1.5509951f,
  170. 12.879445f,0.85651522f,
  171. 12.626907f,0.35143895f,
  172. 10.543467f,1.298457f,
  173. 11.490485f,3.9501074f,
  174. 13.889598f,3.6344347f,
  175. 13.889598f,2.9399549f,
  176. 14.584077f,3.8869729f,
  177. 11.932427f,5.2127981f,
  178. 9.7227183f,4.0132419f,
  179. 10.796005f,3.5081657f,
  180. 9.7858528f,3.2556275f,
  181. 10.796005f,2.4980131f,
  182. 7.9549513f,1.7403987f,
  183. 9.6595837f,1.424726f,
  184. 9.217642f,0.66711162f,
  185. 8.270624f,-0.090502792f,
  186. 7.0079333f,0.85651522f,
  187. 6.1240498f,-0.15363733f,
  188. 6.1240498f,3.192493f,
  189. 5.6821081f,2.4348786f,
  190. 4.9876282f,2.1192059f,
  191. 4.1037447f,1.8666678f,
  192. 3.0304576f,1.8666678f,
  193. 2.0834396f,2.245475f,
  194. 1.6414979f,2.6242822f,
  195. 1.3258252f,3.5081657f,
  196. 1.2626907f,0.47770802f,
  197. 0.63134534f,0.035766276f,
  198. 0.063134534f,0.98278429f
  199. };
  200. float32 loop2[] = 
  201. {
  202. 8.270624f,6.1598161f,
  203. 8.270624f,5.3390672f,
  204. 8.7757003f,5.086529f,
  205. 9.4701801f,5.5284708f,
  206. 9.217642f,6.033547f,
  207. 8.7757003f,6.4123542f
  208. };
  209. float32 loop3[] = 
  210. {
  211. -5.0f, 10.0f,
  212. 5.0f, 10.0f,
  213. 5.0f, 0.0f,
  214. -5.0f, 0.0f,
  215. };
  216. b2Vec2 pointLoop1[87];
  217. b2Vec2 pointLoop2[6];
  218. b2Vec2 pointLoop3[4];
  219. for (int32 i = 0; i < 87; i++)
  220. {
  221. pointLoop1[i].Set(loop1[i*2] - 10.0f, loop1[i*2 + 1]);
  222. }
  223. for (int32 i = 0; i < 6; i++)
  224. {
  225. pointLoop2[i].Set(loop2[i*2] - 10.0f, loop2[i*2 + 1]);
  226. }
  227. for (int32 i = 0; i < 4; i++)
  228. {
  229. pointLoop3[i].Set(loop3[i*2], loop3[i*2 + 1]);
  230. }
  231. b2BodyDef bd;
  232. bd.position.Set( 0.0f, 0.0f );
  233. b2Body* body = m_world->CreateBody(&bd);
  234. b2EdgeChainDef edgeDef;
  235. edgeDef.vertexCount = 87;
  236. edgeDef.vertices = pointLoop1;
  237. b2CreateEdgeChain(body, &edgeDef);
  238. edgeDef.vertexCount = 6;
  239. edgeDef.vertices = pointLoop2;
  240. b2CreateEdgeChain(body, &edgeDef);
  241. //edgeDef.vertexCount = 4;
  242. //edgeDef.vertices = pointLoop3;
  243. //b2CreateEdgeChain(body, &edgeDef);
  244. }
  245. }
  246. static Test* Create()
  247. {
  248. return new StaticEdges;
  249. }
  250. };
  251. #endif