You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

128 lines
3.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)
  20. : m_ready(false)
  21. {
  22. m_mesh.Compile("[sc#add afcb110 1 110 -.1]");
  23. vec3 BoxSize = vec3(110.f, 1.f, 110.f);
  24. m_physics.SetShapeToBox(BoxSize);
  25. m_physics.SetMass(.0f);
  26. m_physics.InitBodyToRigid();
  27. m_physics.AddToSimulation(new_sim);
  28. }
  29. PhysicsObject(Simulation* new_sim, float base_mass, const vec3 &base_location)
  30. : m_ready(false)
  31. {
  32. Array<char *> MeshRand;
  33. MeshRand << "[sc#add afcb2 2 2 -.1]";
  34. MeshRand << "[sc#dad afcb2 2 2 -.1]";
  35. MeshRand << "[sc#dda afcb2 2 2 -.1]";
  36. MeshRand << "[sc#daa afcb2 2 2 -.1]";
  37. MeshRand << "[sc#ada afcb2 2 2 -.1]";
  38. MeshRand << "[sc#aad afcb2 2 2 -.1]";
  39. int SphereLimit = MeshRand.Count();
  40. MeshRand << "[sc#add asph16 2 2 2]";
  41. MeshRand << "[sc#dad asph16 2 2 2]";
  42. MeshRand << "[sc#dda asph16 2 2 2]";
  43. MeshRand << "[sc#daa asph16 2 2 2]";
  44. MeshRand << "[sc#ada asph16 2 2 2]";
  45. MeshRand << "[sc#aad asph16 2 2 2]";
  46. int ConeLimit = MeshRand.Count();
  47. MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  48. MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  49. MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  50. MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  51. MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  52. MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
  53. int CylLimit = MeshRand.Count();
  54. MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  55. MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  56. MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  57. MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  58. MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  59. MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
  60. int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1));
  61. m_mesh.Compile(MeshRand[RandValue]);
  62. vec3 BoxSize = vec3(2.0f);
  63. if (RandValue < SphereLimit)
  64. m_physics.SetShapeToBox(BoxSize);
  65. else if (RandValue < ConeLimit)
  66. m_physics.SetShapeToSphere(BoxSize.x);
  67. else if (RandValue < CylLimit)
  68. m_physics.SetShapeToCone(BoxSize.x, BoxSize.y);
  69. else
  70. m_physics.SetShapeToCylinder(BoxSize);
  71. m_physics.SetMass(base_mass);
  72. m_physics.SetBaseTransform(base_location);
  73. m_physics.InitBodyToRigid();
  74. m_physics.AddToSimulation(new_sim);
  75. }
  76. ~PhysicsObject()
  77. {
  78. }
  79. char const *GetName() { return "<PhysicsObject>"; }
  80. protected:
  81. virtual void TickGame(float seconds)
  82. {
  83. WorldEntity::TickGame(seconds);
  84. }
  85. virtual void TickDraw(float seconds)
  86. {
  87. WorldEntity::TickDraw(seconds);
  88. if (!m_ready)
  89. {
  90. m_mesh.MeshConvert();
  91. m_ready = true;
  92. }
  93. m_mesh.Render(m_physics.GetTransform());
  94. }
  95. private:
  96. //Base datas
  97. EasyMesh m_mesh;
  98. EasyPhysics m_physics;
  99. bool m_ready;
  100. };
  101. #endif /* __PHYSICOBJECT_H__ */