CCPhysicsShape.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /****************************************************************************
  2. Copyright (c) 2013-2016 Chukong Technologies Inc.
  3. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CCPHYSICS_SHAPE_H__
  22. #define __CCPHYSICS_SHAPE_H__
  23. #include "base/ccConfig.h"
  24. #if CC_USE_PHYSICS
  25. #include "base/CCRef.h"
  26. #include "math/CCGeometry.h"
  27. struct cpShape;
  28. NS_CC_BEGIN
  29. class PhysicsBody;
  30. typedef struct CC_DLL PhysicsMaterial
  31. {
  32. float density; ///< The density of the object.
  33. float restitution; ///< The bounciness of the physics body.
  34. float friction; ///< The roughness of the surface of a shape.
  35. PhysicsMaterial()
  36. : density(0.0f)
  37. , restitution(0.0f)
  38. , friction(0.0f)
  39. {}
  40. PhysicsMaterial(float aDensity, float aRestitution, float aFriction)
  41. : density(aDensity)
  42. , restitution(aRestitution)
  43. , friction(aFriction)
  44. {}
  45. }PhysicsMaterial;
  46. const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT;
  47. /**
  48. * @addtogroup physics
  49. * @{
  50. * @addtogroup physics_2d
  51. * @{
  52. */
  53. /**
  54. * @brief A shape for body. You do not create PhysicsWorld objects directly, instead, you can view PhysicsBody to see how to create it.
  55. */
  56. class CC_DLL PhysicsShape : public Ref
  57. {
  58. public:
  59. enum class Type
  60. {
  61. UNKNOWN,
  62. CIRCLE,
  63. BOX,
  64. POLYGON,
  65. EDGESEGMENT,
  66. EDGEBOX,
  67. EDGEPOLYGON,
  68. EDGECHAIN,
  69. /** @deprecated Use Type::POLYGON instead. */
  70. POLYGEN = POLYGON,
  71. /** @deprecated Use Type::EDGEPOLYGON instead. */
  72. EDGEPOLYGEN = EDGEPOLYGON,
  73. };
  74. public:
  75. /**
  76. * Get the body that this shape attaches.
  77. *
  78. * @return A PhysicsBody object pointer.
  79. */
  80. PhysicsBody* getBody() const { return _body; }
  81. /**
  82. * Return this shape's type.
  83. *
  84. * @return A Type object.
  85. */
  86. Type getType() const { return _type; }
  87. /**
  88. * Return this shape's area.
  89. *
  90. * @return A float number.
  91. */
  92. float getArea() const { return _area; }
  93. /**
  94. * Get this shape's moment.
  95. *
  96. * @return A float number.
  97. */
  98. float getMoment() const { return _moment; }
  99. /**
  100. * Set this shape's moment.
  101. *
  102. * It will change the body's moment this shape attaches.
  103. *
  104. * @param moment A float number.
  105. */
  106. void setMoment(float moment);
  107. /**
  108. * Set this shape's tag.
  109. *
  110. * @param tag An integer number that identifies a shape object.
  111. */
  112. void setTag(int tag) { _tag = tag; }
  113. /**
  114. * Get this shape's tag.
  115. *
  116. * @return An integer number.
  117. */
  118. int getTag() const { return _tag; }
  119. /**
  120. * Get the mass of this shape.
  121. *
  122. * @return A float number.
  123. */
  124. float getMass() const { return _mass; }
  125. /**
  126. * Set this shape's mass.
  127. *
  128. * It will change the body's mass this shape attaches.
  129. *
  130. * @param mass A float number.
  131. */
  132. void setMass(float mass);
  133. /**
  134. * Get this shape's density.
  135. *
  136. * @return A float number.
  137. */
  138. float getDensity() const { return _material.density; }
  139. /**
  140. * Set this shape's density.
  141. *
  142. * It will change the body's mass this shape attaches.
  143. *
  144. * @param density A float number.
  145. */
  146. void setDensity(float density);
  147. /**
  148. * Get this shape's restitution.
  149. *
  150. * @return A float number.
  151. */
  152. float getRestitution() const { return _material.restitution; }
  153. /**
  154. * Set this shape's restitution.
  155. *
  156. * It will change the shape's elasticity.
  157. *
  158. * @param restitution A float number.
  159. */
  160. void setRestitution(float restitution);
  161. /**
  162. * Get this shape's friction.
  163. *
  164. * @return A float number.
  165. */
  166. float getFriction() const { return _material.friction; }
  167. /**
  168. * Set this shape's friction.
  169. *
  170. * It will change the shape's friction.
  171. *
  172. * @param friction A float number.
  173. */
  174. void setFriction(float friction);
  175. /**
  176. * Get this shape's PhysicsMaterial object.
  177. *
  178. * @return A PhysicsMaterial object reference.
  179. */
  180. const PhysicsMaterial& getMaterial() const { return _material; }
  181. /**
  182. * Set this shape's material.
  183. *
  184. * It will change the shape's mass, elasticity and friction.
  185. *
  186. * @param material A PhysicsMaterial object.
  187. */
  188. void setMaterial(const PhysicsMaterial& material);
  189. bool isSensor() const { return _sensor; }
  190. void setSensor(bool sensor);
  191. /**
  192. * Calculate the default moment value.
  193. *
  194. * This function should be overridden in inherit classes.
  195. * @return A float number, equals 0.0.
  196. */
  197. virtual float calculateDefaultMoment() { return 0.0f; }
  198. /**
  199. * Get this shape's position offset.
  200. *
  201. * This function should be overridden in inherit classes.
  202. * @return A Vec2 object.
  203. */
  204. virtual Vec2 getOffset() { return Vec2::ZERO; }
  205. /**
  206. * Get this shape's center position.
  207. *
  208. * This function should be overridden in inherit classes.
  209. * @return A Vec2 object.
  210. */
  211. virtual Vec2 getCenter() { return getOffset(); }
  212. /**
  213. * Test point is inside this shape or not.
  214. *
  215. * @param point A Vec2 object.
  216. * @return A bool object.
  217. */
  218. bool containsPoint(const Vec2& point) const;
  219. /**
  220. * Move the points to the center.
  221. *
  222. * @param points A Vec2 object pointer.
  223. * @param count An integer number.
  224. * @param center A Vec2 object, default value is Vec2(0,0).
  225. */
  226. static void recenterPoints(Vec2* points, int count, const Vec2& center = Vec2::ZERO);
  227. /**
  228. * Get center of the polygon points.
  229. *
  230. * @param points A Vec2 object pointer.
  231. * @param count An integer number.
  232. * @return A Vec2 object.
  233. */
  234. static Vec2 getPolygonCenter(const Vec2* points, int count);
  235. /** @deprecated use getPolygonCenter() instead */
  236. CC_DEPRECATED_ATTRIBUTE static Vec2 getPolyonCenter(const Vec2* points, int count);
  237. /**
  238. * Set a mask that defines which categories this physics body belongs to.
  239. *
  240. * Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and contactTestBitMask properties, you define which physics bodies interact with each other and when your game is notified of these interactions.
  241. * @param bitmask An integer number, the default value is 0xFFFFFFFF (all bits set).
  242. */
  243. void setCategoryBitmask(int bitmask) { _categoryBitmask = bitmask; }
  244. /**
  245. * Get a mask that defines which categories this physics body belongs to.
  246. *
  247. * @return An integer number.
  248. */
  249. int getCategoryBitmask() const { return _categoryBitmask; }
  250. /**
  251. * A mask that defines which categories of bodies cause intersection notifications with this physics body.
  252. *
  253. * When two bodies share the same space, each body's category mask is tested against the other body's contact mask by performing a logical AND operation. If either comparison results in a non-zero value, an PhysicsContact object is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask for interactions you are interested in.
  254. * @param bitmask An integer number, the default value is 0x00000000 (all bits cleared).
  255. */
  256. void setContactTestBitmask(int bitmask) { _contactTestBitmask = bitmask; }
  257. /**
  258. * Get a mask that defines which categories of bodies cause intersection notifications with this physics body.
  259. *
  260. * @return An integer number.
  261. */
  262. int getContactTestBitmask() const { return _contactTestBitmask; }
  263. /**
  264. * A mask that defines which categories of physics bodies can collide with this physics body.
  265. *
  266. * When two physics bodies contact each other, a collision may occur. This body's collision mask is compared to the other body's category mask by performing a logical AND operation. If the result is a non-zero value, then this body is affected by the collision. Each body independently chooses whether it wants to be affected by the other body. For example, you might use this to avoid collision calculations that would make negligible changes to a body's velocity.
  267. * @param bitmask An integer number, the default value is 0xFFFFFFFF (all bits set).
  268. */
  269. void setCollisionBitmask(int bitmask) { _collisionBitmask = bitmask; }
  270. /**
  271. * Get a mask that defines which categories of physics bodies can collide with this physics body.
  272. *
  273. * @return An integer number.
  274. */
  275. int getCollisionBitmask() const { return _collisionBitmask; }
  276. /**
  277. * Set the group of body.
  278. *
  279. * Collision groups let you specify an integral group index. You can have all fixtures with the same group index always collide (positive index) or never collide (negative index).
  280. * @param group An integer number, it have high priority than bit masks.
  281. */
  282. void setGroup(int group);
  283. /**
  284. * Get the group of body.
  285. *
  286. * @return An integer number.
  287. */
  288. int getGroup() { return _group; }
  289. protected:
  290. void setBody(PhysicsBody* body);
  291. /** calculate the area of this shape */
  292. virtual float calculateArea() { return 0.0f; }
  293. virtual void setScale(float scaleX, float scaleY);
  294. virtual void updateScale();
  295. void addShape(cpShape* shape);
  296. protected:
  297. PhysicsShape();
  298. virtual ~PhysicsShape() = 0;
  299. protected:
  300. PhysicsBody* _body;
  301. std::vector<cpShape*> _cpShapes;
  302. Type _type;
  303. float _area;
  304. float _mass;
  305. float _moment;
  306. bool _sensor;
  307. float _scaleX;
  308. float _scaleY;
  309. float _newScaleX;
  310. float _newScaleY;
  311. PhysicsMaterial _material;
  312. int _tag;
  313. int _categoryBitmask;
  314. int _collisionBitmask;
  315. int _contactTestBitmask;
  316. int _group;
  317. friend class PhysicsWorld;
  318. friend class PhysicsBody;
  319. friend class PhysicsJoint;
  320. friend class PhysicsDebugDraw;
  321. };
  322. /** A circle shape. */
  323. class CC_DLL PhysicsShapeCircle : public PhysicsShape
  324. {
  325. public:
  326. /**
  327. * Creates a PhysicsShapeCircle with specified value.
  328. *
  329. * @param radius A float number, it is the circle's radius.
  330. * @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
  331. * @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
  332. * @return An autoreleased PhysicsShapeCircle object pointer.
  333. */
  334. static PhysicsShapeCircle* create(float radius, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Vec2& offset = Vec2(0, 0));
  335. /**
  336. * Calculate the area of a circle with specified radius.
  337. *
  338. * @param radius A float number
  339. * @return A float number
  340. */
  341. static float calculateArea(float radius);
  342. /**
  343. * Calculate the moment of a circle with specified value.
  344. *
  345. * @param mass A float number
  346. * @param radius A float number
  347. * @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
  348. * @return A float number
  349. */
  350. static float calculateMoment(float mass, float radius, const Vec2& offset = Vec2::ZERO);
  351. /**
  352. * Calculate the moment for a circle.
  353. *
  354. * @return A float number.
  355. */
  356. virtual float calculateDefaultMoment() override;
  357. /**
  358. * Get the circle's radius.
  359. *
  360. * @return A float number.
  361. */
  362. float getRadius() const;
  363. /**
  364. * Get this circle's position offset.
  365. *
  366. * @return A Vec2 object.
  367. */
  368. virtual Vec2 getOffset() override;
  369. protected:
  370. bool init(float radius, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO);
  371. virtual float calculateArea() override;
  372. virtual void updateScale() override;
  373. protected:
  374. PhysicsShapeCircle();
  375. virtual ~PhysicsShapeCircle();
  376. };
  377. /** A polygon shape. */
  378. class CC_DLL PhysicsShapePolygon : public PhysicsShape
  379. {
  380. public:
  381. /**
  382. * Creates a PhysicsShapePolygon with specified value.
  383. *
  384. * @param points A Vec2 object pointer, it is an array of Vec2.
  385. * @param count An integer number, contains the count of the points array.
  386. * @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
  387. * @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
  388. * @return An autoreleased PhysicsShapePolygon object pointer.
  389. */
  390. static PhysicsShapePolygon* create(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO, float radius = 0.0f);
  391. /**
  392. * Calculate the area of a polygon with specified value.
  393. *
  394. * @param points A Vec2 object pointer, it is an array of Vec2.
  395. * @param count An integer number, contains the count of the points array.
  396. * @return A float number.
  397. */
  398. static float calculateArea(const Vec2* points, int count);
  399. /**
  400. * Calculate the moment of a polygon with specified value.
  401. *
  402. * @param mass A float number
  403. * @param points A Vec2 object pointer, it is an array of Vec2.
  404. * @param count An integer number, contains the count of the points array.
  405. * @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
  406. * @return A float number
  407. */
  408. static float calculateMoment(float mass, const Vec2* points, int count, const Vec2& offset = Vec2::ZERO, float radius = 0.0f);
  409. /**
  410. * Calculate the moment for a polygon.
  411. *
  412. * @return A float number.
  413. */
  414. float calculateDefaultMoment() override;
  415. /**
  416. * Get a point of this polygon's points array.
  417. *
  418. * @param i A index of this polygon's points array.
  419. * @return A point value.
  420. */
  421. Vec2 getPoint(int i) const;
  422. /**
  423. * Get this polygon's points array.
  424. *
  425. * @param outPoints A Vec2 array pointer.
  426. */
  427. void getPoints(Vec2* outPoints) const;
  428. /**
  429. * Get this polygon's points array count.
  430. *
  431. * @return An integer number.
  432. */
  433. int getPointsCount() const;
  434. /**
  435. * Get this polygon's center position.
  436. *
  437. * @return A Vec2 object.
  438. */
  439. virtual Vec2 getCenter() override;
  440. protected:
  441. bool init(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO, float radius = 0.0f);
  442. float calculateArea() override;
  443. virtual void updateScale() override;
  444. protected:
  445. PhysicsShapePolygon();
  446. virtual ~PhysicsShapePolygon();
  447. };
  448. /** A box shape. */
  449. class CC_DLL PhysicsShapeBox : public PhysicsShapePolygon
  450. {
  451. public:
  452. /**
  453. * Creates a PhysicsShapeBox with specified value.
  454. *
  455. * @param size Size contains this box's width and height.
  456. * @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
  457. * @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
  458. * @return An autoreleased PhysicsShapeBox object pointer.
  459. */
  460. static PhysicsShapeBox* create(const Size& size, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO, float radius = 0.0f);
  461. /**
  462. * Get this box's width and height.
  463. *
  464. * @return An Size object.
  465. */
  466. Size getSize() const;
  467. /**
  468. * Get this box's position offset.
  469. *
  470. * @return A Vec2 object.
  471. */
  472. virtual Vec2 getOffset() override { return getCenter(); }
  473. protected:
  474. bool init(const Size& size, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, const Vec2& offset = Vec2::ZERO, float radius = 0.0f);
  475. protected:
  476. PhysicsShapeBox();
  477. virtual ~PhysicsShapeBox();
  478. };
  479. /** A segment shape. */
  480. class CC_DLL PhysicsShapeEdgeSegment : public PhysicsShape
  481. {
  482. public:
  483. /**
  484. * Creates a PhysicsShapeEdgeSegment with specified value.
  485. *
  486. * @param a It's the edge's begin position.
  487. * @param b It's the edge's end position.
  488. * @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
  489. * @param border It's a edge's border width.
  490. * @return An autoreleased PhysicsShapeEdgeSegment object pointer.
  491. */
  492. static PhysicsShapeEdgeSegment* create(const Vec2& a, const Vec2& b, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
  493. /**
  494. * Get this edge's begin position.
  495. *
  496. * @return A Vec2 object.
  497. */
  498. Vec2 getPointA() const;
  499. /**
  500. * Get this edge's end position.
  501. *
  502. * @return A Vec2 object.
  503. */
  504. Vec2 getPointB() const;
  505. /**
  506. * Get this edge's center position.
  507. *
  508. * @return A Vec2 object.
  509. */
  510. virtual Vec2 getCenter() override;
  511. protected:
  512. bool init(const Vec2& a, const Vec2& b, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
  513. virtual void updateScale() override;
  514. protected:
  515. PhysicsShapeEdgeSegment();
  516. virtual ~PhysicsShapeEdgeSegment();
  517. friend class PhysicsBody;
  518. };
  519. /** An edge polygon shape. */
  520. class CC_DLL PhysicsShapeEdgePolygon : public PhysicsShape
  521. {
  522. public:
  523. /**
  524. * Creates a PhysicsShapeEdgePolygon with specified value.
  525. *
  526. * @param points A Vec2 object pointer, it contains an array of points.
  527. * @param count An integer number, contains the count of the points array.
  528. * @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
  529. * @param border It's a edge's border width.
  530. * @return An autoreleased PhysicsShapeEdgePolygon object pointer.
  531. */
  532. static PhysicsShapeEdgePolygon* create(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
  533. /**
  534. * Get this polygon's center position.
  535. *
  536. * @return A Vec2 object.
  537. */
  538. virtual Vec2 getCenter() override;
  539. /**
  540. * Get this polygon's points array.
  541. *
  542. * @param outPoints A Vec2 array pointer.
  543. */
  544. void getPoints(Vec2* outPoints) const;
  545. /**
  546. * Get this polygon's points array count.
  547. *
  548. * @return An integer number.
  549. */
  550. int getPointsCount() const;
  551. protected:
  552. bool init(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
  553. virtual void updateScale() override;
  554. protected:
  555. PhysicsShapeEdgePolygon();
  556. virtual ~PhysicsShapeEdgePolygon();
  557. friend class PhysicsBody;
  558. };
  559. /** An edge box shape. */
  560. class CC_DLL PhysicsShapeEdgeBox : public PhysicsShapeEdgePolygon
  561. {
  562. public:
  563. /**
  564. * Creates a PhysicsShapeEdgeBox with specified value.
  565. *
  566. * @param size Size contains this box's width and height.
  567. * @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
  568. * @param border It's a edge's border width.
  569. * @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
  570. * @return An autoreleased PhysicsShapeEdgeBox object pointer.
  571. */
  572. static PhysicsShapeEdgeBox* create(const Size& size, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 0, const Vec2& offset = Vec2::ZERO);
  573. /**
  574. * Get this box's position offset.
  575. *
  576. * @return A Vec2 object.
  577. */
  578. virtual Vec2 getOffset() override { return getCenter(); }
  579. protected:
  580. bool init(const Size& size, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1, const Vec2& offset = Vec2::ZERO);
  581. protected:
  582. PhysicsShapeEdgeBox();
  583. virtual ~PhysicsShapeEdgeBox();
  584. friend class PhysicsBody;
  585. };
  586. /** A chain shape. */
  587. class CC_DLL PhysicsShapeEdgeChain : public PhysicsShape
  588. {
  589. public:
  590. /**
  591. * Creates a PhysicsShapeEdgeChain with specified value.
  592. *
  593. * @param points A Vec2 object pointer, it contains an array of points.
  594. * @param count An integer number, contains the count of the points array.
  595. * @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
  596. * @param border It's a edge's border width.
  597. * @return An autoreleased PhysicsShapeEdgeChain object pointer.
  598. */
  599. static PhysicsShapeEdgeChain* create(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
  600. /**
  601. * Get this chain's center position.
  602. *
  603. * @return A Vec2 object.
  604. */
  605. virtual Vec2 getCenter() override;
  606. /**
  607. * Get this chain's points array.
  608. *
  609. * @param outPoints A Vec2 array pointer.
  610. */
  611. void getPoints(Vec2* outPoints) const;
  612. /**
  613. * Get this chain's points array count.
  614. *
  615. * @return An integer number.
  616. */
  617. int getPointsCount() const;
  618. protected:
  619. bool init(const Vec2* points, int count, const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT, float border = 1);
  620. virtual void updateScale() override;
  621. protected:
  622. PhysicsShapeEdgeChain();
  623. virtual ~PhysicsShapeEdgeChain();
  624. friend class PhysicsBody;
  625. };
  626. /** @} */
  627. /** @} */
  628. NS_CC_END
  629. #endif // CC_USE_PHYSICS
  630. #endif // __CCPHYSICS_FIXTURE_H__