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 | |
---|
9 | /* FIXME: this file is pure crap; it's only a test. */ |
---|
10 | |
---|
11 | #if !defined __PHYSICOBJECT_H__ |
---|
12 | #define __PHYSICOBJECT_H__ |
---|
13 | |
---|
14 | #include "core.h"
|
---|
15 | #include "easymesh/easymesh.h" |
---|
16 | #include "Physics/EasyPhysics.h" |
---|
17 | |
---|
18 | using namespace lol;
|
---|
19 | using namespace lol::phys;
|
---|
20 | |
---|
21 | class PhysicsObject : public WorldEntity |
---|
22 | { |
---|
23 | public: |
---|
24 | PhysicsObject(Simulation* new_sim) |
---|
25 | : m_ready(false) |
---|
26 | { |
---|
27 | m_mesh.Compile("[sc#add afcb110 1 110 -.1]"); |
---|
28 | vec3 BoxSize = vec3(110.f, 1.f, 110.f); |
---|
29 | m_physics.SetShapeToBox(BoxSize); |
---|
30 | m_physics.SetMass(.0f); |
---|
31 | m_physics.InitBodyToRigid(); |
---|
32 | m_physics.AddToSimulation(new_sim); |
---|
33 | } |
---|
34 | |
---|
35 | PhysicsObject(Simulation* new_sim, float base_mass, const vec3 &base_location) |
---|
36 | : m_ready(false) |
---|
37 | { |
---|
38 | Array<char *> MeshRand; |
---|
39 |
|
---|
40 | MeshRand << "[sc#add afcb2 2 2 -.1]";
|
---|
41 | MeshRand << "[sc#dad afcb2 2 2 -.1]";
|
---|
42 | MeshRand << "[sc#dda afcb2 2 2 -.1]";
|
---|
43 | MeshRand << "[sc#daa afcb2 2 2 -.1]";
|
---|
44 | MeshRand << "[sc#ada afcb2 2 2 -.1]";
|
---|
45 | MeshRand << "[sc#aad afcb2 2 2 -.1]"; |
---|
46 | |
---|
47 | int SphereLimit = MeshRand.Count(); |
---|
48 | |
---|
49 | MeshRand << "[sc#add asph16 2 2 2]";
|
---|
50 | MeshRand << "[sc#dad asph16 2 2 2]";
|
---|
51 | MeshRand << "[sc#dda asph16 2 2 2]";
|
---|
52 | MeshRand << "[sc#daa asph16 2 2 2]";
|
---|
53 | MeshRand << "[sc#ada asph16 2 2 2]";
|
---|
54 | MeshRand << "[sc#aad asph16 2 2 2]"; |
---|
55 | |
---|
56 | |
---|
57 | int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1)); |
---|
58 | |
---|
59 | m_mesh.Compile(MeshRand[RandValue]); |
---|
60 | vec3 BoxSize = vec3(2.0f); |
---|
61 | if (RandValue >= SphereLimit) |
---|
62 | m_physics.SetShapeToSphere(BoxSize.x); |
---|
63 | else |
---|
64 | m_physics.SetShapeToBox(BoxSize); |
---|
65 | m_physics.SetMass(base_mass); |
---|
66 | m_physics.SetBaseTransform(base_location); |
---|
67 | m_physics.InitBodyToRigid(); |
---|
68 | m_physics.AddToSimulation(new_sim); |
---|
69 | } |
---|
70 | |
---|
71 | ~PhysicsObject() |
---|
72 | { |
---|
73 | } |
---|
74 | |
---|
75 | char const *GetName() { return "<PhysicsObject>"; } |
---|
76 | |
---|
77 | protected: |
---|
78 | virtual void TickGame(float seconds) |
---|
79 | { |
---|
80 | WorldEntity::TickGame(seconds); |
---|
81 | } |
---|
82 | |
---|
83 | virtual void TickDraw(float seconds) |
---|
84 | { |
---|
85 | WorldEntity::TickDraw(seconds); |
---|
86 | |
---|
87 | if (!m_ready) |
---|
88 | { |
---|
89 | m_mesh.MeshConvert(); |
---|
90 | m_ready = true; |
---|
91 | } |
---|
92 | |
---|
93 | m_mesh.Render(m_physics.GetTransform()); |
---|
94 | } |
---|
95 | |
---|
96 | private: |
---|
97 | //Base datas |
---|
98 | EasyMesh m_mesh; |
---|
99 | EasyPhysics m_physics; |
---|
100 | |
---|
101 | bool m_ready; |
---|
102 | }; |
---|
103 | |
---|
104 | #endif /* __PHYSICOBJECT_H__ */ |
---|
105 | |
---|