25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

91 lines
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. m_physics.SetShapeToBox(vec3(110.f, 1.f, 110.f));
  24. m_physics.SetMass(.0f);
  25. m_physics.InitBodyToRigid();
  26. m_physics.AddToSimulation(new_sim);
  27. }
  28. PhysicsObject(Simulation* new_sim, float base_mass, vec3 &base_location)
  29. : m_ready(false)
  30. {
  31. Array<char *> MeshRand;
  32. MeshRand << "[sc#add afcb2 2 2 -.1]";
  33. MeshRand << "[sc#dad afcb2 2 2 -.1]";
  34. MeshRand << "[sc#dda afcb2 2 2 -.1]";
  35. MeshRand << "[sc#daa afcb2 2 2 -.1]";
  36. MeshRand << "[sc#ada afcb2 2 2 -.1]";
  37. MeshRand << "[sc#aad afcb2 2 2 -.1]";
  38. int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1));
  39. m_mesh.Compile(MeshRand[RandValue]);
  40. m_physics.SetShapeToBox(vec3(2.0f));
  41. m_physics.SetMass(base_mass);
  42. m_physics.SetBaseTransform(base_location);
  43. m_physics.InitBodyToRigid();
  44. m_physics.AddToSimulation(new_sim);
  45. }
  46. ~PhysicsObject()
  47. {
  48. }
  49. char const *GetName() { return "<PhysicsObject>"; }
  50. protected:
  51. virtual void TickGame(float seconds)
  52. {
  53. WorldEntity::TickGame(seconds);
  54. }
  55. virtual void TickDraw(float seconds)
  56. {
  57. WorldEntity::TickDraw(seconds);
  58. if (!m_ready)
  59. {
  60. m_mesh.MeshConvert();
  61. m_ready = true;
  62. }
  63. m_mesh.Render(m_physics.GetTransform());
  64. }
  65. private:
  66. //Base datas
  67. EasyMesh m_mesh;
  68. EasyPhysics m_physics;
  69. bool m_ready;
  70. };
  71. #endif /* __PHYSICOBJECT_H__ */