PolyPhysicsScreenEntity.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 ScreenEntity;
  25. /**
  26. * A 2D Physics enabled screen entity.
  27. */
  28. class _PolyExport PhysicsScreenEntity {
  29. public:
  30. PhysicsScreenEntity(ScreenEntity *entity, b2World *world, Number worldScale, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation);
  31. ~PhysicsScreenEntity();
  32. /**
  33. * Returns the screen entity associated with this physics entity.
  34. */
  35. ScreenEntity *getScreenEntity();
  36. /**
  37. * Applies torque to the physics entity
  38. */
  39. void applyTorque(Number torque);
  40. /**
  41. * Applies force to the physics entity
  42. */
  43. void applyForce(Vector2 force);
  44. void setTransform(Vector2 pos, Number angle);
  45. void Update();
  46. /**
  47. * Rectangular physics entity
  48. */
  49. static const int ENTITY_RECT = 1;
  50. /**
  51. * Circular physics entity
  52. */
  53. static const int ENTITY_CIRCLE = 2;
  54. /**
  55. * Mesh entity.
  56. */
  57. static const int ENTITY_MESH = 3;
  58. b2Fixture *fixture;
  59. b2Body* body;
  60. b2Shape *shape;
  61. bool collisionOnly;
  62. protected:
  63. Number worldScale;
  64. Vector2 lastPosition;
  65. Number lastRotation;
  66. ScreenEntity *screenEntity;
  67. };
  68. }