source: trunk/test/PhysicObject.h @ 1591

Last change on this file since 1591 was 1591, checked in by touky, 11 years ago

Behold the power of LolPhysics !
Added lol::phys::Simulation, lol::phys::EasyPhysics for easy physic uses.
Added PhysicsObject, wich hold EasyMesh & EasyPhysics components so it is easy to use. Easy seems to be the consensus.
BtPhysTest now works with new physics classes.

Known problem for this commit:
Physics is not properly setup.
There might be memory leaks, I don't think I've parsed all new/delete.
A LOT of primitives are not taken into account.

File size: 1.9 KB
Line 
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
18using namespace lol;
19using namespace lol::phys;
20
21class PhysicsObject : public WorldEntity
22{
23public:
24        PhysicsObject(Simulation* new_sim)
25                : m_ready(false)
26        {
27                m_mesh.Compile("[sc#add afcb110 1 110 -.1]");
28                m_physics.SetShapeToBox(vec3(110.f, 1.f, 110.f));
29                m_physics.SetMass(.0f);
30                m_physics.InitBodyToRigid();
31                m_physics.AddToSimulation(new_sim);
32        }
33
34        PhysicsObject(Simulation* new_sim, float base_mass, vec3 &base_location)
35                : m_ready(false)
36        {
37                Array<char *> MeshRand;
38
39                MeshRand << "[sc#add afcb2 2 2 -.1]";
40                MeshRand << "[sc#dad afcb2 2 2 -.1]";
41                MeshRand << "[sc#dda afcb2 2 2 -.1]";
42                MeshRand << "[sc#daa afcb2 2 2 -.1]";
43                MeshRand << "[sc#ada afcb2 2 2 -.1]";
44                MeshRand << "[sc#aad afcb2 2 2 -.1]";
45
46                int RandValue = (int)(lol::RandF() * (MeshRand.Count() - 1));
47
48                m_mesh.Compile(MeshRand[RandValue]);
49                m_physics.SetShapeToBox(vec3(2.0f));
50                m_physics.SetMass(base_mass);
51                m_physics.SetBaseTransform(base_location);
52                m_physics.InitBodyToRigid();
53                m_physics.AddToSimulation(new_sim);
54        }
55
56        ~PhysicsObject()
57        {
58        }
59
60        char const *GetName() { return "<PhysicsObject>"; }
61
62protected:
63        virtual void TickGame(float seconds)
64        {
65                WorldEntity::TickGame(seconds);
66        }
67
68        virtual void TickDraw(float seconds)
69        {
70                WorldEntity::TickDraw(seconds);
71
72                if (!m_ready)
73                {
74                        m_mesh.MeshConvert();
75                        m_ready = true;
76                }
77
78                m_mesh.Render(m_physics.GetTransform());
79        }
80
81private:
82        //Base datas
83        EasyMesh                m_mesh;
84        EasyPhysics             m_physics;
85
86        bool                    m_ready;
87};
88
89#endif /* __PHYSICOBJECT_H__ */
90
Note: See TracBrowser for help on using the repository browser.