No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

223 líneas
5.7 KiB

  1. //
  2. // Orbital
  3. //
  4. // Copyright: (c) 2009-2012 Cédric Lecacheur <jordx@free.fr>
  5. // (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
  6. // (c) 2012 Sam Hocevar <sam@hocevar.net>
  7. //
  8. /* FIXME: this file is pure crap; it's only a test. */
  9. #if !defined __PHYSICOBJECT_H__
  10. #define __PHYSICOBJECT_H__
  11. #include "core.h"
  12. #include "easymesh/easymesh.h"
  13. #include "Physics/EasyPhysics.h"
  14. using namespace lol;
  15. using namespace lol::phys;
  16. class PhysicsObject : public WorldEntity
  17. {
  18. public:
  19. PhysicsObject(Simulation* new_sim, const vec3 &base_location, const quat &base_rotation)
  20. : m_ready(false), m_should_render(true)
  21. {
  22. m_mesh.Compile("[sc#ddd afcb60 1 60 -.1]");
  23. vec3 BoxSize = vec3(60.f, 1.f, 60.f);
  24. m_physics.SetCollisionChannel(0, 0xFF);
  25. m_physics.SetShapeToBox(BoxSize);
  26. m_physics.SetMass(.0f);
  27. m_physics.SetTransform(base_location, base_rotation);
  28. m_physics.InitBodyToRigid(true);
  29. m_physics.AddToSimulation(new_sim);
  30. }
  31. PhysicsObject(Simulation* new_sim, const vec3 &base_location, const quat &base_rotation, int dummy)
  32. : m_ready(false), m_should_render(true)
  33. {
  34. m_mesh.Compile("[sc#ddd afcb20 1 20 -.1]");
  35. vec3 BoxSize = vec3(20.f, 1.f, 20.f);
  36. m_physics.SetCollisionChannel(0, 0xFF);
  37. m_physics.SetShapeToBox(BoxSize);
  38. m_physics.SetMass(.0f);
  39. m_physics.SetTransform(base_location, base_rotation);
  40. m_physics.InitBodyToRigid(true);
  41. m_physics.AddToSimulation(new_sim);
  42. }
  43. PhysicsObject(Simulation* new_sim, float base_mass, const vec3 &base_location, int RandValue = -1)
  44. : m_ready(false), m_should_render(true)
  45. {
  46. Array<char const *> MeshRand;
  47. MeshRand << "[sc#add afcb2 2 2 -.1]";
  48. MeshRand << "[sc#dad afcb2 2 2 -.1]";
  49. MeshRand << "[sc#dda afcb2 2 2 -.1]";
  50. MeshRand << "[sc#daa afcb2 2 2 -.1]";
  51. MeshRand << "[sc#ada afcb2 2 2 -.1]";
  52. MeshRand << "[sc#aad afcb2 2 2 -.1]";
  53. int SphereLimit = MeshRand.Count();
  54. MeshRand << "[sc#add asph15 2 2 2]";
  55. MeshRand << "[sc#dad asph15 2 2 2]";
  56. MeshRand << "[sc#dda asph15 2 2 2]";
  57. MeshRand << "[sc#daa asph15 2 2 2]";
  58. MeshRand << "[sc#ada asph15 2 2 2]";
  59. MeshRand << "[sc#aad asph15 2 2 2]";
  60. int ConeLimit = MeshRand.Count();
  61. MeshRand << "[sc#add scb#add ad48 2 0 rx180 ty-1 ac48 2 2 0 0 0]";
  62. MeshRand << "[sc#dad scb#dad ad48 2 0 rx180 ty-1 ac48 2 2 0 0 0]";
  63. MeshRand << "[sc#dda scb#dda ad48 2 0 rx180 ty-1 ac48 2 2 0 0 0]";
  64. MeshRand << "[sc#daa scb#daa ad48 2 0 rx180 ty-1 ac48 2 2 0 0 0]";
  65. MeshRand << "[sc#ada scb#ada ad48 2 0 rx180 ty-1 ac48 2 2 0 0 0]";
  66. MeshRand << "[sc#aad scb#aad ad48 2 0 rx180 ty-1 ac48 2 2 0 0 0]";
  67. int CylLimit = MeshRand.Count();
  68. MeshRand << "[sc#add scb#add ad96 2 0 rx180 ty-1 my ac96 2 2 2 0 0]";
  69. MeshRand << "[sc#dad scb#dad ad96 2 0 rx180 ty-1 my ac96 2 2 2 0 0]";
  70. MeshRand << "[sc#dda scb#dda ad96 2 0 rx180 ty-1 my ac96 2 2 2 0 0]";
  71. MeshRand << "[sc#daa scb#daa ad96 2 0 rx180 ty-1 my ac96 2 2 2 0 0]";
  72. MeshRand << "[sc#ada scb#ada ad96 2 0 rx180 ty-1 my ac96 2 2 2 0 0]";
  73. MeshRand << "[sc#aad scb#aad ad96 2 0 rx180 ty-1 my ac96 2 2 2 0 0]";
  74. int CapsLimit = MeshRand.Count();
  75. MeshRand << "[sc#add scb#add acap21 2 1]";
  76. MeshRand << "[sc#dad scb#dad acap21 2 1]";
  77. MeshRand << "[sc#dda scb#dda acap21 2 1]";
  78. MeshRand << "[sc#daa scb#daa acap21 2 1]";
  79. MeshRand << "[sc#ada scb#ada acap21 2 1]";
  80. MeshRand << "[sc#aad scb#aad acap21 2 1]";
  81. switch (RandValue)
  82. {
  83. case 0:
  84. {
  85. RandValue = (int)(lol::RandF() * (SphereLimit - 1));
  86. break;
  87. }
  88. case 1:
  89. {
  90. RandValue = SphereLimit + (int)(lol::RandF() * ((ConeLimit - SphereLimit) - 1));
  91. break;
  92. }
  93. case 2:
  94. {
  95. RandValue = ConeLimit + (int)(lol::RandF() * ((CylLimit - ConeLimit) - 1));
  96. break;
  97. }
  98. case 3:
  99. {
  100. RandValue = CylLimit + (int)(lol::RandF() * ((CapsLimit - CylLimit) - 1));
  101. break;
  102. }
  103. case 4:
  104. {
  105. RandValue = CapsLimit + (int)(lol::RandF() * ((MeshRand.Count() - CapsLimit) - 1));
  106. break;
  107. }
  108. default:
  109. {
  110. RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1));
  111. }
  112. }
  113. m_mesh.Compile(MeshRand[RandValue]);
  114. vec3 BoxSize = vec3(2.0f);
  115. int ColGroup = 1;
  116. if (RandValue < SphereLimit)
  117. {
  118. m_physics.SetShapeToBox(BoxSize);
  119. ColGroup += 0;
  120. }
  121. else if (RandValue < ConeLimit)
  122. {
  123. m_physics.SetShapeToSphere(BoxSize.x * 2.f);
  124. ColGroup += 1;
  125. }
  126. else if (RandValue < CylLimit)
  127. {
  128. m_physics.SetShapeToCone(BoxSize.x, BoxSize.y);
  129. ColGroup += 2;
  130. }
  131. else if (RandValue < CapsLimit)
  132. {
  133. m_physics.SetShapeToCylinder(BoxSize);
  134. ColGroup += 3;
  135. }
  136. else
  137. {
  138. m_physics.SetShapeToCapsule(BoxSize.x, BoxSize.y);
  139. ColGroup += 4;
  140. }
  141. m_physics.SetCollisionChannel(0, 0xFF);
  142. //m_physics.SetCollisionChannel(ColGroup, (1<<ColGroup)|(1));
  143. m_physics.SetMass(base_mass);
  144. m_physics.SetTransform(base_location);
  145. m_physics.InitBodyToRigid();
  146. m_physics.AddToSimulation(new_sim);
  147. }
  148. void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)))
  149. {
  150. m_physics.SetTransform(base_location, base_rotation);
  151. }
  152. lol::mat4 GetTransform()
  153. {
  154. return m_physics.GetTransform();
  155. }
  156. void SetRender(bool should_render)
  157. {
  158. m_should_render = should_render;
  159. }
  160. EasyMesh *GetMesh() { return &m_mesh; }
  161. EasyPhysic *GetPhysic() { return &m_physics; }
  162. ~PhysicsObject()
  163. {
  164. }
  165. char const *GetName() { return "<PhysicsObject>"; }
  166. protected:
  167. virtual void TickGame(float seconds)
  168. {
  169. WorldEntity::TickGame(seconds);
  170. }
  171. virtual void TickDraw(float seconds)
  172. {
  173. WorldEntity::TickDraw(seconds);
  174. if (!m_ready)
  175. {
  176. m_mesh.MeshConvert();
  177. m_ready = true;
  178. }
  179. if (m_should_render)
  180. m_mesh.Render(m_physics.GetTransform());
  181. }
  182. private:
  183. //Base datas
  184. EasyMesh m_mesh;
  185. EasyPhysic m_physics;
  186. bool m_ready;
  187. bool m_should_render;
  188. };
  189. #endif /* __PHYSICOBJECT_H__ */