source: trunk/test/Physics/EasyPhysics.h @ 1607

Last change on this file since 1607 was 1607, checked in by touky, 8 years ago

Added walls and better context to the physics.

File size: 2.3 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
5//            (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com>
6//   This program is free software; you can redistribute it and/or
7//   modify it under the terms of the Do What The Fuck You Want To
8//   Public License, Version 2, as published by Sam Hocevar. See
9//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
10//
11
12//
13// The EasyPhysics class
14// ------------------
15//
16
17#if !defined __EASYPHYSICS_EASYPHYSICS_H__
18#define __EASYPHYSICS_EASYPHYSICS_H__
19
20#ifdef HAVE_PHYS_USE_BULLET
21#include "core.h"
22#include <bullet/btBulletDynamicsCommon.h>
23#include <bullet/btBulletCollisionCommon.h>
24#endif
25
26namespace lol
27{
28
29namespace phys
30{
31
32class EasyPhysics
33{
34#ifdef HAVE_PHYS_USE_BULLET
35public:
36        EasyPhysics();
37        ~EasyPhysics();
38
39        void SetShapeToBox(lol::vec3& box_size);
40        void SetShapeToSphere(float radius);
41        void SetShapeToCone(float radius, float height);
42        void SetShapeToCylinder(lol::vec3& cyl_size);
43        void SetShapeToCapsule(float radius, float height);
44
45        void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f)));
46        void SetMass(float mass);
47        void InitBodyToRigid();
48        void AddToSimulation(class Simulation* current_simulation);
49        mat4 GetTransform();
50
51protected:
52        void SetLocalInertia(float mass);
53        void SetShapeTo(btCollisionShape* collision_shape);
54
55        btCollisionObject*                                                      m_collision_object;
56
57        btRigidBody*                                                            m_rigid_body;
58        btScalar                                                                        m_mass;
59        btVector3                                                                       m_local_inertia;
60
61        btCollisionShape*                                                       m_collision_shape;
62        btMotionState*                                                          m_motion_state;
63
64        lol::mat4                                                                       m_local_to_world;
65#else
66public:
67        EasyPhysics() { }
68
69        void SetShapeToBox(lol::vec3& BoxSize) { }
70        void SetShapeToSphere(float radius) { }
71        void SetShapeToCone(float radius, float height) { }
72        void SetShapeToCylinder(lol::vec3& cyl_size) { }
73        void SetShapeToCapsule(float radius, float height) { }
74
75        void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { }
76        void SetMass(float mass) { }
77        void InitBodyToRigid() { }
78        void AddToSimulation(class Simulation* current_simulation) { }
79        mat4 GetTransform() { return mat4(1.0f); }
80#endif
81};
82
83} /* namespace phys */
84
85} /* namespace lol */
86
87#endif /* __EASYPHYSICS_EASYPHYSICS_H__ */
88
Note: See TracBrowser for help on using the repository browser.