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 asph6 2 2 2]";
|
---|
50 | MeshRand << "[sc#dad asph6 2 2 2]";
|
---|
51 | MeshRand << "[sc#dda asph6 2 2 2]";
|
---|
52 | MeshRand << "[sc#daa asph6 2 2 2]";
|
---|
53 | MeshRand << "[sc#ada asph6 2 2 2]";
|
---|
54 | MeshRand << "[sc#aad asph6 2 2 2]"; |
---|
55 | |
---|
56 | int ConeLimit = MeshRand.Count(); |
---|
57 | |
---|
58 | MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
|
---|
59 | MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
|
---|
60 | MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
|
---|
61 | MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
|
---|
62 | MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]";
|
---|
63 | MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 ac16 2 2 0 0 0]"; |
---|
64 | |
---|
65 | int CylLimit = MeshRand.Count(); |
---|
66 | |
---|
67 | MeshRand << "[sc#add scb#add ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
|
---|
68 | MeshRand << "[sc#dad scb#dad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
|
---|
69 | MeshRand << "[sc#dda scb#dda ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
|
---|
70 | MeshRand << "[sc#daa scb#daa ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
|
---|
71 | MeshRand << "[sc#ada scb#ada ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]";
|
---|
72 | MeshRand << "[sc#aad scb#aad ad16 2 0 rx180 ty-1 my ac16 2 2 2 0 0]"; |
---|
73 | |
---|
74 | int CapsLimit = MeshRand.Count(); |
---|
75 | |
---|
76 | MeshRand << "[sc#add scb#add asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
|
---|
77 | MeshRand << "[sc#dad scb#dad asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
|
---|
78 | MeshRand << "[sc#dda scb#dda asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
|
---|
79 | MeshRand << "[sc#daa scb#daa asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
|
---|
80 | MeshRand << "[sc#ada scb#ada asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]";
|
---|
81 | MeshRand << "[sc#aad scb#aad asph6 1 1 1 ty-1 my ac16 2 1 1 0 0]"; |
---|
82 | |
---|
83 | int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1)); |
---|
84 | |
---|
85 | m_mesh.Compile(MeshRand[RandValue]); |
---|
86 | vec3 BoxSize = vec3(2.0f); |
---|
87 | if (RandValue < SphereLimit) |
---|
88 | m_physics.SetShapeToBox(BoxSize); |
---|
89 | else if (RandValue < ConeLimit) |
---|
90 | m_physics.SetShapeToSphere(BoxSize.x * 2.f); |
---|
91 | else if (RandValue < CylLimit) |
---|
92 | m_physics.SetShapeToCone(BoxSize.x, BoxSize.y); |
---|
93 | else if (RandValue < CapsLimit) |
---|
94 | m_physics.SetShapeToCylinder(BoxSize); |
---|
95 | else |
---|
96 | m_physics.SetShapeToCapsule(BoxSize.x, BoxSize.y); |
---|
97 | |
---|
98 | m_physics.SetMass(base_mass); |
---|
99 | m_physics.SetBaseTransform(base_location); |
---|
100 | m_physics.InitBodyToRigid(); |
---|
101 | m_physics.AddToSimulation(new_sim); |
---|
102 | } |
---|
103 | |
---|
104 | ~PhysicsObject() |
---|
105 | { |
---|
106 | } |
---|
107 | |
---|
108 | char const *GetName() { return "<PhysicsObject>"; } |
---|
109 | |
---|
110 | protected: |
---|
111 | virtual void TickGame(float seconds) |
---|
112 | { |
---|
113 | WorldEntity::TickGame(seconds); |
---|
114 | } |
---|
115 | |
---|
116 | virtual void TickDraw(float seconds) |
---|
117 | { |
---|
118 | WorldEntity::TickDraw(seconds); |
---|
119 | |
---|
120 | if (!m_ready) |
---|
121 | { |
---|
122 | m_mesh.MeshConvert(); |
---|
123 | m_ready = true; |
---|
124 | } |
---|
125 | |
---|
126 | m_mesh.Render(m_physics.GetTransform()); |
---|
127 | } |
---|
128 | |
---|
129 | private: |
---|
130 | //Base datas |
---|
131 | EasyMesh m_mesh; |
---|
132 | EasyPhysics m_physics; |
---|
133 | |
---|
134 | bool m_ready; |
---|
135 | }; |
---|
136 | |
---|
137 | #endif /* __PHYSICOBJECT_H__ */ |
---|
138 | |
---|