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