1 #ifndef _EPHYSICS_PRIVATE_H
2 #define _EPHYSICS_PRIVATE_H
3 
4 #pragma GCC diagnostic push
5 #pragma GCC system_header
6 
7 #include <BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h>
8 #include <BulletSoftBody/btDefaultSoftBodySolver.h>
9 #include <BulletSoftBody/btSoftRigidDynamicsWorld.h>
10 #include <BulletSoftBody/btSoftBodyHelpers.h>
11 #include <btBulletDynamicsCommon.h>
12 
13 #pragma GCC diagnostic pop
14 
15 #include "EPhysics.h"
16 
17 #ifdef EPHYSICS_LOG_COLOR
18 #undef EPHYSICS_LOG_COLOR
19 #endif
20 #define EPHYSICS_LOG_COLOR EINA_COLOR_BLUE
21 
22 #ifdef ERR
23 # undef ERR
24 #endif
25 #define ERR(...) EINA_LOG_DOM_ERR(_ephysics_log_dom, __VA_ARGS__)
26 
27 #ifdef DBG
28 # undef DBG
29 #endif
30 #define DBG(...) EINA_LOG_DOM_DBG(_ephysics_log_dom, __VA_ARGS__)
31 
32 #ifdef INF
33 # undef INF
34 #endif
35 #define INF(...) EINA_LOG_DOM_INFO(_ephysics_log_dom, __VA_ARGS__)
36 
37 #ifdef WRN
38 # undef WRN
39 #endif
40 #define WRN(...) EINA_LOG_DOM_WARN(_ephysics_log_dom, __VA_ARGS__)
41 
42 #ifdef CRI
43 # undef CRI
44 #endif
45 #define CRI(...) EINA_LOG_DOM_CRIT(_ephysics_log_dom, __VA_ARGS__)
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #define RAD_TO_DEG 57.29582 /* 2 * pi radians == 360 degree */
52 
53 typedef struct _EPhysics_Force EPhysics_Force;
54 typedef struct _EPhysics_Body_Center_Mass EPhysics_Body_Center_Mass;
55 typedef struct _EPhysics_Body_Size EPhysics_Body_Size;
56 typedef struct _EPhysics_Body_Face_Slice EPhysics_Body_Face_Slice;
57 typedef struct _EPhysics_Point EPhysics_Point;
58 typedef struct _EPhysics_Dragging_Data EPhysics_Dragging_Data;
59 
60 typedef enum _EPhysics_Body_Shape
61 {
62   EPHYSICS_BODY_SHAPE_BOX,
63   EPHYSICS_BODY_SHAPE_CUSTOM,
64   EPHYSICS_BODY_SHAPE_CYLINDER,
65   EPHYSICS_BODY_SHAPE_SPHERE,
66   EPHYSICS_BODY_SHAPE_LAST,
67 } EPhysics_Body_Shape;
68 
69 typedef enum _EPhysics_World_Boundary
70 {
71    EPHYSICS_WORLD_BOUNDARY_TOP,
72    EPHYSICS_WORLD_BOUNDARY_BOTTOM,
73    EPHYSICS_WORLD_BOUNDARY_LEFT,
74    EPHYSICS_WORLD_BOUNDARY_RIGHT,
75    EPHYSICS_WORLD_BOUNDARY_FRONT,
76    EPHYSICS_WORLD_BOUNDARY_BACK,
77    EPHYSICS_WORLD_BOUNDARY_LAST
78 } EPhysics_World_Boundary;
79 
80 typedef enum _EPhysics_Body_Type
81 {
82   EPHYSICS_BODY_TYPE_RIGID,
83   EPHYSICS_BODY_TYPE_SOFT,
84   EPHYSICS_BODY_TYPE_CLOTH,
85 } EPhysics_Body_Type;
86 
87 struct _EPhysics_Point {
88      EINA_INLIST;
89      double x;
90      double y;
91      double z;
92 };
93 
94 struct _EPhysics_Force {
95      double x;
96      double y;
97      double z;
98      double torque_x;
99      double torque_y;
100      double torque_z;
101 };
102 
103 struct _EPhysics_Dragging_Data {
104      int triangle;
105      double mass;
106      Eina_Bool dragging:1;
107 };
108 
109 struct _EPhysics_Body_Center_Mass {
110      double x;
111      double y;
112      double z;
113 };
114 
115 struct _EPhysics_Body_Size {
116      Evas_Coord w;
117      Evas_Coord h;
118      Evas_Coord d;
119 };
120 
121 struct _EPhysics_Body_Face_Slice {
122      EPhysics_Body *body;
123      EPhysics_Body_Face face;
124      int slices_cnt;
125      int *points_deform;
126      Eina_List *slices;
127 };
128 
129 // EPhysics_Body is an Eina_Inlist, and Eina_Inslist iterator macros use
130 // offsetof(). Since using offsetof in C++ classes is invalid,
131 // EPhysics_Body must be a POD-type struct.
132 struct _EPhysics_Body {
133      EINA_INLIST;
134      btCollisionShape *collision_shape;
135      btRigidBody *rigid_body;
136      btSoftBody *soft_body;
137      Evas_Object *evas_obj;
138      EPhysics_World *world;
139      int walking;
140      EPhysics_Body_Size size;
141      btScalar scale[3];
142      void *data;
143      Eina_Inlist *callbacks;
144      Eina_List *collision_groups;
145      Eina_List *to_delete;
146      Eina_List *face_objs;
147      EPhysics_Body_Material material;
148      double mass;
149      double density;
150      EPhysics_Force force;
151      EPhysics_Body_Center_Mass cm;
152      Eina_List *faces_slices;
153      EPhysics_Body_Face_Slice *default_face;
154      EPhysics_Body_Type type;
155      EPhysics_Body_Shape shape;
156      int cloth_columns;
157      int cloth_rows;
158      int material_index;
159      int collision_cb;
160      EPhysics_Dragging_Data dragging_data;
161 
162      Eina_Bool active:1;
163      Eina_Bool deleted:1;
164      Eina_Bool light_apply:1;
165      Eina_Bool back_face_culling:1;
166      Eina_Bool clockwise:1;
167      Eina_Bool boundary:1;
168      int bending_constraints;
169      Eina_Bool anchor_hardness;
170 };
171 
172 extern int _ephysics_log_dom;
173 
174 /* Main */
175 void ephysics_dom_count_inc(void);
176 void ephysics_dom_count_dec(void);
177 
178 /* World */
179 int ephysics_world_init(void);
180 int ephysics_world_shutdown(void);
181 Eina_Bool ephysics_world_body_add(EPhysics_World *world, EPhysics_Body *body);
182 Eina_Bool ephysics_world_body_del(EPhysics_World *world, EPhysics_Body *body);
183 Eina_Bool ephysics_world_soft_body_add(EPhysics_World *world, EPhysics_Body *body);
184 void ephysics_world_constraint_add(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint);
185 void ephysics_world_constraint_del(EPhysics_World *world, EPhysics_Constraint *constraint, btGeneric6DofConstraint *bt_constraint);
186 void ephysics_body_world_boundaries_resize(EPhysics_World *world);
187 void ephysics_world_boundary_set(EPhysics_World *world, EPhysics_World_Boundary boundary, EPhysics_Body *body);
188 EPhysics_Body *ephysics_world_boundary_get(const EPhysics_World *world, EPhysics_World_Boundary boundary);
189 Eina_Bool ephysics_world_bodies_outside_autodel_get(const EPhysics_World *world);
190 btSoftBodyWorldInfo *ephysics_world_info_get(const EPhysics_World *world);
191 void ephysics_world_lock_take(EPhysics_World *world);
192 void ephysics_world_lock_release(EPhysics_World *world);
193 Eina_List *ephysics_world_constraints_get(EPhysics_World *world);
194 void ephysics_world_force_update_set(EPhysics_World *world, Eina_Bool force_update);
195 
196 /* Body */
197 Eina_Bool ephysics_body_filter_collision(EPhysics_Body *body0, EPhysics_Body *body1);
198 void ephysics_body_evas_object_update_select(EPhysics_Body *body);
199 void ephysics_orphan_body_del(EPhysics_Body *body);
200 void ephysics_body_contact_processed(EPhysics_Body *body, EPhysics_Body *contact_body, btVector3 position);
201 btRigidBody *ephysics_body_rigid_body_get(const EPhysics_Body *body);
202 btSoftBody *ephysics_body_soft_body_get(const EPhysics_Body *body);
203 void ephysics_body_active_set(EPhysics_Body *body, Eina_Bool active);
204 void ephysics_body_recalc(EPhysics_Body *body, double rate);
205 void ephysics_body_forces_apply(EPhysics_Body *body);
206 void ephysics_body_activate(const EPhysics_Body *body, Eina_Bool activate);
207 void ephysics_body_evas_objects_restack(EPhysics_World *world);
208 void ephysics_body_soft_body_dragging_apply(EPhysics_Body *body);
209 void ephysics_body_soft_body_bending_constraints_generate(EPhysics_Body *body);
210 void ephysics_constraint_body_del(EPhysics_Body *body);
211 
212 /* Camera */
213 EPhysics_Camera *ephysics_camera_add(EPhysics_World *world);
214 void ephysics_camera_del(EPhysics_Camera *camera);
215 void ephysics_camera_moved_set(EPhysics_Camera *camera, Eina_Bool moved);
216 Eina_Bool ephysics_camera_moved_get(const EPhysics_Camera *camera);
217 void ephysics_camera_target_moved(EPhysics_Camera *camera, EPhysics_Body *body);
218 
219 /* Shape */
220 const Eina_Inlist *ephysics_shape_points_get(const EPhysics_Shape *shape);
221 
222 /* Constraint */
223 void ephysics_constraint_recalc(EPhysics_Constraint *constraint, double rate);
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 
229 #endif
230