Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
12 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // Orbital
  3. //
  4. // Copyright: (c) 2009-2012 Cdric 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, float base_mass, const vec3 &base_location, int RandValue = -1)
  32. : m_ready(false), m_should_render(true)
  33. {
  34. Array<char const *> MeshRand;
  35. MeshRand << "[sc#add afcb2 2 2 -.1]";
  36. MeshRand << "[sc#dad afcb2 2 2 -.1]";
  37. MeshRand << "[sc#dda afcb2 2 2 -.1]";
  38. MeshRand << "[sc#daa afcb2 2 2 -.1]";
  39. MeshRand << "[sc#ada afcb2 2 2 -.1]";
  40. MeshRand << "[sc#aad afcb2 2 2 -.1]";
  41. int SphereLimit = MeshRand.Count();
  42. MeshRand << "[sc#add asph6 2 2 2]";
  43. MeshRand << "[sc#dad asph6 2 2 2]";
  44. MeshRand << "[sc#dda asph6 2 2 2]";
  45. MeshRand << "[sc#daa asph6 2 2 2]";
  46. MeshRand << "[sc#ada asph6 2 2 2]";
  47. MeshRand << "[sc#aad asph6 2 2 2]";
  48. int ConeLimit = MeshRand.Count();
  49. MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  50. MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  51. MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  52. MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  53. MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  54. MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  55. int CylLimit = MeshRand.Count();
  56. MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  57. MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  58. MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  59. MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  60. MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  61. MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  62. int CapsLimit = MeshRand.Count();
  63. MeshRand << "[sc#add scb#add acap3 2 1]";
  64. MeshRand << "[sc#dad scb#dad acap3 2 1]";
  65. MeshRand << "[sc#dda scb#dda acap3 2 1]";
  66. MeshRand << "[sc#daa scb#daa acap3 2 1]";
  67. MeshRand << "[sc#ada scb#ada acap3 2 1]";
  68. MeshRand << "[sc#aad scb#aad acap3 2 1]";
  69. switch (RandValue)
  70. {
  71. case 0:
  72. {
  73. RandValue = (int)(lol::RandF() * (SphereLimit - 1));
  74. break;
  75. }
  76. case 1:
  77. {
  78. RandValue = SphereLimit + (int)(lol::RandF() * ((ConeLimit - SphereLimit) - 1));
  79. break;
  80. }
  81. case 2:
  82. {
  83. RandValue = ConeLimit + (int)(lol::RandF() * ((CylLimit - ConeLimit) - 1));
  84. break;
  85. }
  86. case 3:
  87. {
  88. RandValue = CylLimit + (int)(lol::RandF() * ((CapsLimit - CylLimit) - 1));
  89. break;
  90. }
  91. case 4:
  92. {
  93. RandValue = CapsLimit + (int)(lol::RandF() * ((MeshRand.Count() - CapsLimit) - 1));
  94. break;
  95. }
  96. default:
  97. {
  98. RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1));
  99. }
  100. }
  101. m_mesh.Compile(MeshRand[RandValue]);
  102. vec3 BoxSize = vec3(2.0f);
  103. int ColGroup = 1;
  104. if (RandValue < SphereLimit)
  105. {
  106. m_physics.SetShapeToBox(BoxSize);
  107. ColGroup += 0;
  108. }
  109. else if (RandValue < ConeLimit)
  110. {
  111. m_physics.SetShapeToSphere(BoxSize.x * 2.f);
  112. ColGroup += 1;
  113. }
  114. else if (RandValue < CylLimit)
  115. {
  116. m_physics.SetShapeToCone(BoxSize.x, BoxSize.y);
  117. ColGroup += 2;
  118. }
  119. else if (RandValue < CapsLimit)
  120. {
  121. m_physics.SetShapeToCylinder(BoxSize);
  122. ColGroup += 3;
  123. }
  124. else
  125. {
  126. m_physics.SetShapeToCapsule(BoxSize.x, BoxSize.y);
  127. ColGroup += 4;
  128. }
  129. m_physics.SetCollisionChannel(0, 0xFF);
  130. //m_physics.SetCollisionChannel(ColGroup, (1<<ColGroup)|(1));
  131. m_physics.SetMass(base_mass);
  132. m_physics.SetTransform(base_location);
  133. m_physics.InitBodyToRigid();
  134. m_physics.AddToSimulation(new_sim);
  135. }
  136. void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)))
  137. {
  138. m_physics.SetTransform(base_location, base_rotation);
  139. }
  140. lol::mat4 GetTransform()
  141. {
  142. return m_physics.GetTransform();
  143. }
  144. void SetRender(bool should_render)
  145. {
  146. m_should_render = should_render;
  147. }
  148. EasyMesh *GetMesh() { return &m_mesh; }
  149. EasyPhysic *GetPhysic() { return &m_physics; }
  150. ~PhysicsObject()
  151. {
  152. }
  153. char const *GetName() { return "<PhysicsObject>"; }
  154. protected:
  155. virtual void TickGame(float seconds)
  156. {
  157. WorldEntity::TickGame(seconds);
  158. }
  159. virtual void TickDraw(float seconds)
  160. {
  161. WorldEntity::TickDraw(seconds);
  162. if (!m_ready)
  163. {
  164. m_mesh.MeshConvert();
  165. m_ready = true;
  166. }
  167. if (m_should_render)
  168. m_mesh.Render(m_physics.GetTransform());
  169. }
  170. private:
  171. //Base datas
  172. EasyMesh m_mesh;
  173. EasyPhysic m_physics;
  174. bool m_ready;
  175. bool m_should_render;
  176. };
  177. #endif /* __PHYSICOBJECT_H__ */