PolyPhysicsScreenEntity.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyVector2.h"
  22. #include "Box2D/Box2D.h"
  23. namespace Polycode {
  24. class Entity;
  25. /**
  26. * A 2D Physics enabled screen entity.
  27. */
  28. class _PolyExport PhysicsScene2DEntity {
  29. public:
  30. PhysicsScene2DEntity() { collisionOnly = false; }
  31. PhysicsScene2DEntity(Entity *entity, b2World *world, Number worldScale, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation, int groupIndex = 0);
  32. virtual ~PhysicsScene2DEntity();
  33. virtual void Update();
  34. /**
  35. * Returns the screen entity associated with this physics entity.
  36. */
  37. Entity *getEntity();
  38. /**
  39. * Applies torque to the physics entity
  40. */
  41. void applyTorque(Number torque);
  42. /**
  43. * Applies force to the physics entity
  44. */
  45. void applyForce(Vector2 force);
  46. /**
  47. * Applies an impulse to the physics entity
  48. */
  49. void applyImpulse(Number fx, Number fy);
  50. /**
  51. * Sets the position and rotation of entity
  52. */
  53. void setTransform(Vector2 pos, Number angle);
  54. /**
  55. * Sets the velocity of the physics entity
  56. */
  57. void setVelocity(Number fx, Number fy);
  58. void setVelocityX( Number fx);
  59. void setVelocityY(Number fy);
  60. /**
  61. * Sets the dampening of the physics entity
  62. */
  63. void setLinearDamping(Number damping);
  64. void setAngularDamping(Number damping);
  65. void setFriction(Number friction);
  66. /**
  67. * Returns dampening information
  68. */
  69. Number getLinearDamping();
  70. Number getAngularDamping();
  71. Number getFriction();
  72. /**
  73. * Sets physics entity density
  74. */
  75. void setDensity(Number density);
  76. Number getDensity();
  77. /**
  78. * Sets collision filtering
  79. * Collision category specifies which bits on a 16 bit field the physics entity belongs to. default is 1 (or "0000000000000001")
  80. * Collision mask specifies which bits the physics entity will collide with. default 65535 (or 0xFFFF, or "1111111111111111", or everything)
  81. * If a physics entity's mask bits don't line up with any of an overlapping entity's category bits, their collisions will be skipped
  82. */
  83. void setCollisionCategory(int categoryBits);
  84. void setCollisionMask(int maskBits);
  85. void setCollisionGroupIndex(int group);
  86. /**
  87. * Gets a specific fixture based on it's index position
  88. */
  89. b2Fixture* getFixture(unsigned short index);
  90. /**
  91. * Gets the last fixture selected (automatically set to last added on creation)
  92. */
  93. b2Fixture* getFixture();
  94. bool getFixedRotation() const;
  95. void setFixedRotation(bool val);
  96. /**
  97. * Rectangular physics entity
  98. */
  99. static const int ENTITY_RECT = 1;
  100. /**
  101. * Circular physics entity
  102. */
  103. static const int ENTITY_CIRCLE = 2;
  104. /**
  105. * Mesh physics entity.
  106. */
  107. static const int ENTITY_MESH = 3;
  108. /**
  109. * Edge phyiscs Entity
  110. */
  111. static const int ENTITY_EDGE = 4;
  112. /**
  113. * Capsule entity.
  114. */
  115. static const int ENTITY_CAPSULE = 5;
  116. /**
  117. * Three vertical circles.
  118. */
  119. static const int ENTITY_TRIPLE_CIRCLE = 6;
  120. b2Body *body;
  121. b2Fixture *fixture;
  122. bool collisionOnly;
  123. protected:
  124. bool fixedRotation;
  125. Number worldScale;
  126. Entity *entity;
  127. };
  128. typedef PhysicsScene2DEntity PhysicsScreenEntity;
  129. }