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 EasyPhysic 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 | #include <bullet/BulletCollision/CollisionDispatch/btGhostObject.h>
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | namespace lol |
---|
28 | { |
---|
29 | |
---|
30 | namespace phys |
---|
31 | { |
---|
32 | |
---|
33 | class EasyPhysic |
---|
34 | { |
---|
35 | |
---|
36 | friend class EasyConstraint;
|
---|
37 |
|
---|
38 | #ifdef HAVE_PHYS_USE_BULLET
|
---|
39 |
|
---|
40 | public:
|
---|
41 | EasyPhysic(); |
---|
42 | ~EasyPhysic(); |
---|
43 | |
---|
44 | virtual void SetShapeToBox(lol::vec3& box_size); |
---|
45 | virtual void SetShapeToSphere(float radius); |
---|
46 | virtual void SetShapeToCone(float radius, float height); |
---|
47 | virtual void SetShapeToCylinder(lol::vec3& cyl_size); |
---|
48 | virtual void SetShapeToCapsule(float radius, float height); |
---|
49 | |
---|
50 | virtual bool CanChangeCollisionChannel() { return (m_rigid_body == NULL); } |
---|
51 | virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))); |
---|
52 | virtual void SetMass(float mass); |
---|
53 | virtual void InitBodyToRigid(bool ZeroMassIsKinematic=false); |
---|
54 | virtual void InitBodyToGhost(); |
---|
55 | virtual void AddToSimulation(class Simulation* current_simulation);
|
---|
56 | virtual void RemoveFromSimulation(class Simulation* current_simulation);
|
---|
57 | virtual mat4 GetTransform(); |
---|
58 | |
---|
59 | protected:
|
---|
60 | virtual void SetLocalInertia(float mass); |
---|
61 | virtual void SetShapeTo(btCollisionShape* collision_shape); |
---|
62 | |
---|
63 | virtual btGhostObject* GetGhostObject(); |
---|
64 |
|
---|
65 | btCollisionObject* m_collision_object;
|
---|
66 |
|
---|
67 | btGhostObject* m_ghost_object;
|
---|
68 |
|
---|
69 | btRigidBody* m_rigid_body;
|
---|
70 | btVector3 m_local_inertia;
|
---|
71 |
|
---|
72 | btCollisionShape* m_collision_shape;
|
---|
73 | btConvexShape* m_convex_shape;
|
---|
74 | btMotionState* m_motion_state;
|
---|
75 |
|
---|
76 | #else // NO PHYSIC IMPLEMENTATION
|
---|
77 |
|
---|
78 | public: |
---|
79 | EasyPhysic() { } |
---|
80 | |
---|
81 | virtual void SetShapeToBox(lol::vec3& BoxSize) { } |
---|
82 | virtual void SetShapeToSphere(float radius) { } |
---|
83 | virtual void SetShapeToCone(float radius, float height) { } |
---|
84 | virtual void SetShapeToCylinder(lol::vec3& cyl_size) { } |
---|
85 | virtual void SetShapeToCapsule(float radius, float height) { } |
---|
86 | |
---|
87 | virtual bool CanChangeCollisionChannel() { return true; } |
---|
88 | virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation=lol::quat(lol::mat4(1.0f))) { } |
---|
89 | virtual void SetMass(float mass) { } |
---|
90 | virtual void InitBodyToRigid() { } |
---|
91 | virtual void InitBodyToGhost() { } |
---|
92 | virtual void AddToSimulation(class Simulation* current_simulation) { }
|
---|
93 | virtual void RemoveFromSimulation(class Simulation* current_simulation) { }
|
---|
94 | virtual mat4 GetTransform() { return mat4(1.0f); } |
---|
95 | |
---|
96 | virtual void InitBodyToGhost() { } |
---|
97 | |
---|
98 | #endif // PHYSIC IMPLEMENTATION |
---|
99 |
|
---|
100 | public: |
---|
101 | //Sets the collision Group & Mask. |
---|
102 | //Mask can change at runtime, not group ! |
---|
103 | virtual bool SetCollisionChannel(int NewGroup, int NewMask) |
---|
104 | { |
---|
105 | if (CanChangeCollisionChannel()) |
---|
106 | { |
---|
107 | m_collision_group = (1<<NewGroup); |
---|
108 | m_collision_mask = NewMask; |
---|
109 | return true; |
---|
110 | } |
---|
111 | return false; |
---|
112 | } |
---|
113 | int GetCollisionGroup() { return m_collision_group; } |
---|
114 | int GetCollisionMask() { return m_collision_mask; } |
---|
115 |
|
---|
116 | protected:
|
---|
117 | lol::mat4 m_local_to_world;
|
---|
118 | float m_mass;
|
---|
119 | int m_collision_group;
|
---|
120 | int m_collision_mask;
|
---|
121 | }; |
---|
122 | |
---|
123 | } /* namespace phys */ |
---|
124 | |
---|
125 | } /* namespace lol */ |
---|
126 | |
---|
127 | #endif /* __EASYPHYSICS_EASYPHYSICS_H__ */ |
---|
128 | |
---|