Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

157 linhas
4.3 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.SetShapeToBox(BoxSize);
  25. m_physics.SetMass(.0f);
  26. m_physics.SetTransform(base_location, base_rotation);
  27. m_physics.InitBodyToRigid();
  28. m_physics.AddToSimulation(new_sim);
  29. }
  30. PhysicsObject(Simulation* new_sim, float base_mass, const vec3 &base_location)
  31. : m_ready(false), m_should_render(true)
  32. {
  33. Array<char *> MeshRand;
  34. MeshRand << "[sc#add afcb2 2 2 -.1]";
  35. MeshRand << "[sc#dad afcb2 2 2 -.1]";
  36. MeshRand << "[sc#dda afcb2 2 2 -.1]";
  37. MeshRand << "[sc#daa afcb2 2 2 -.1]";
  38. MeshRand << "[sc#ada afcb2 2 2 -.1]";
  39. MeshRand << "[sc#aad afcb2 2 2 -.1]";
  40. int SphereLimit = MeshRand.Count();
  41. MeshRand << "[sc#add asph6 2 2 2]";
  42. MeshRand << "[sc#dad asph6 2 2 2]";
  43. MeshRand << "[sc#dda asph6 2 2 2]";
  44. MeshRand << "[sc#daa asph6 2 2 2]";
  45. MeshRand << "[sc#ada asph6 2 2 2]";
  46. MeshRand << "[sc#aad asph6 2 2 2]";
  47. int ConeLimit = MeshRand.Count();
  48. MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  49. MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  50. MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  51. MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  52. MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  53. MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  54. int CylLimit = MeshRand.Count();
  55. MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  56. MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  57. MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  58. MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  59. MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  60. MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  61. int CapsLimit = MeshRand.Count();
  62. MeshRand << "[sc#add scb#add asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
  63. MeshRand << "[sc#dad scb#dad asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
  64. MeshRand << "[sc#dda scb#dda asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
  65. MeshRand << "[sc#daa scb#daa asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
  66. MeshRand << "[sc#ada scb#ada asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
  67. MeshRand << "[sc#aad scb#aad asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
  68. int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1));
  69. m_mesh.Compile(MeshRand[RandValue]);
  70. vec3 BoxSize = vec3(2.0f);
  71. if (RandValue < SphereLimit)
  72. m_physics.SetShapeToBox(BoxSize);
  73. else if (RandValue < ConeLimit)
  74. m_physics.SetShapeToSphere(BoxSize.x * 2.f);
  75. else if (RandValue < CylLimit)
  76. m_physics.SetShapeToCone(BoxSize.x, BoxSize.y);
  77. else if (RandValue < CapsLimit)
  78. m_physics.SetShapeToCylinder(BoxSize);
  79. else
  80. m_physics.SetShapeToCapsule(BoxSize.x, BoxSize.y);
  81. m_physics.SetMass(base_mass);
  82. m_physics.SetTransform(base_location);
  83. m_physics.InitBodyToRigid();
  84. m_physics.AddToSimulation(new_sim);
  85. }
  86. void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)))
  87. {
  88. m_physics.SetTransform(base_location, base_rotation);
  89. }
  90. lol::mat4 GetTransform()
  91. {
  92. return m_physics.GetTransform();
  93. }
  94. void SetRender(bool should_render)
  95. {
  96. m_should_render = should_render;
  97. }
  98. ~PhysicsObject()
  99. {
  100. }
  101. char const *GetName() { return "<PhysicsObject>"; }
  102. protected:
  103. virtual void TickGame(float seconds)
  104. {
  105. WorldEntity::TickGame(seconds);
  106. }
  107. virtual void TickDraw(float seconds)
  108. {
  109. WorldEntity::TickDraw(seconds);
  110. if (!m_ready)
  111. {
  112. m_mesh.MeshConvert();
  113. m_ready = true;
  114. }
  115. if (m_should_render)
  116. m_mesh.Render(m_physics.GetTransform());
  117. }
  118. private:
  119. //Base datas
  120. EasyMesh m_mesh;
  121. EasyPhysics m_physics;
  122. bool m_ready;
  123. bool m_should_render;
  124. };
  125. #endif /* __PHYSICOBJECT_H__ */