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.
 
 
 

93 line
1.9 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 RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1));
  40. m_mesh.Compile(MeshRand[RandValue]);
  41. vec3 BoxSize = vec3(2.0f);
  42. m_physics.SetShapeToBox(BoxSize);
  43. m_physics.SetMass(base_mass);
  44. m_physics.SetBaseTransform(base_location);
  45. m_physics.InitBodyToRigid();
  46. m_physics.AddToSimulation(new_sim);
  47. }
  48. ~PhysicsObject()
  49. {
  50. }
  51. char const *GetName() { return "<PhysicsObject>"; }
  52. protected:
  53. virtual void TickGame(float seconds)
  54. {
  55. WorldEntity::TickGame(seconds);
  56. }
  57. virtual void TickDraw(float seconds)
  58. {
  59. WorldEntity::TickDraw(seconds);
  60. if (!m_ready)
  61. {
  62. m_mesh.MeshConvert();
  63. m_ready = true;
  64. }
  65. m_mesh.Render(m_physics.GetTransform());
  66. }
  67. private:
  68. //Base datas
  69. EasyMesh m_mesh;
  70. EasyPhysics m_physics;
  71. bool m_ready;
  72. };
  73. #endif /* __PHYSICOBJECT_H__ */