~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to intern/rigidbody/RBI_api.h

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software Foundation,
 
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 * The Original Code is Copyright (C) 2013 Blender Foundation,
 
19
 * All rights reserved.
 
20
 *
 
21
 * The Original Code is: all of this file.
 
22
 *
 
23
 * Contributor(s): Joshua Leung, Sergej Reich
 
24
 *
 
25
 * ***** END GPL LICENSE BLOCK *****
 
26
 */
 
27
 
 
28
/** \file RBI_api.h
 
29
 *  \ingroup RigidBody
 
30
 *  \brief Rigid Body API for interfacing with external Physics Engines
 
31
 */
 
32
 
 
33
#ifndef __RB_API_H__
 
34
#define __RB_API_H__
 
35
 
 
36
#ifdef __cplusplus
 
37
extern "C" {
 
38
#endif
 
39
 
 
40
/* API Notes:
 
41
 * Currently, this API is optimised for Bullet RigidBodies, and doesn't
 
42
 * take into account other Physics Engines. Some tweaking may be necessary
 
43
 * to allow other systems to be used, in particular there may be references
 
44
 * to datatypes that aren't used here...
 
45
 *
 
46
 * -- Joshua Leung (22 June 2010)
 
47
 */
 
48
 
 
49
/* ********************************** */
 
50
/* Partial Type Defines - Aliases for the type of data we store */
 
51
 
 
52
// ----------
 
53
 
 
54
/* Dynamics World */
 
55
typedef struct rbDynamicsWorld rbDynamicsWorld;
 
56
 
 
57
/* Rigid Body */
 
58
typedef struct rbRigidBody rbRigidBody;
 
59
 
 
60
/* Collision Shape */
 
61
typedef struct rbCollisionShape rbCollisionShape;
 
62
 
 
63
/* Mesh Data (for Collision Shapes of Meshes) */
 
64
typedef struct rbMeshData rbMeshData;
 
65
 
 
66
/* Constraint */
 
67
typedef struct rbConstraint rbConstraint;
 
68
 
 
69
/* ********************************** */
 
70
/* Dynamics World Methods */
 
71
 
 
72
/* Setup ---------------------------- */
 
73
 
 
74
/* Create a new dynamics world instance */
 
75
// TODO: add args to set the type of constraint solvers, etc.
 
76
extern rbDynamicsWorld *RB_dworld_new(const float gravity[3]);
 
77
 
 
78
/* Delete the given dynamics world, and free any extra data it may require */
 
79
extern void RB_dworld_delete(rbDynamicsWorld *world);
 
80
 
 
81
/* Settings ------------------------- */
 
82
 
 
83
/* Gravity */
 
84
extern void RB_dworld_get_gravity(rbDynamicsWorld *world, float g_out[3]);
 
85
extern void RB_dworld_set_gravity(rbDynamicsWorld *world, const float g_in[3]);
 
86
 
 
87
/* Constraint Solver */
 
88
extern void RB_dworld_set_solver_iterations(rbDynamicsWorld *world, int num_solver_iterations);
 
89
/* Split Impulse */
 
90
extern void RB_dworld_set_split_impulse(rbDynamicsWorld *world, int split_impulse);
 
91
 
 
92
/* Simulation ----------------------- */
 
93
 
 
94
/* Step the simulation by the desired amount (in seconds) with extra controls on substep sizes and maximum substeps */
 
95
extern void RB_dworld_step_simulation(rbDynamicsWorld *world, float timeStep, int maxSubSteps, float timeSubStep);
 
96
 
 
97
/* Export -------------------------- */
 
98
 
 
99
/* Exports the dynamics world to physics simulator's serialisation format */
 
100
void RB_dworld_export(rbDynamicsWorld *world, const char *filename);
 
101
 
 
102
/* ********************************** */
 
103
/* Rigid Body Methods */
 
104
 
 
105
/* Setup ---------------------------- */
 
106
 
 
107
/* Add RigidBody to dynamics world */
 
108
extern void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *body, int col_groups);
 
109
 
 
110
/* Remove RigidBody from dynamics world */
 
111
extern void RB_dworld_remove_body(rbDynamicsWorld *world, rbRigidBody *body);
 
112
 
 
113
/* ............ */
 
114
 
 
115
/* Create new RigidBody instance */
 
116
extern rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4]);
 
117
 
 
118
/* Delete the given RigidBody instance */
 
119
extern void RB_body_delete(rbRigidBody *body);
 
120
 
 
121
/* Settings ------------------------- */
 
122
 
 
123
/* 'Type' */
 
124
extern void RB_body_set_type(rbRigidBody *body, int type, float mass);
 
125
 
 
126
/* ............ */
 
127
 
 
128
/* Collision Shape */
 
129
extern void RB_body_set_collision_shape(rbRigidBody *body, rbCollisionShape *shape);
 
130
 
 
131
/* ............ */
 
132
 
 
133
/* Mass */
 
134
extern float RB_body_get_mass(rbRigidBody *body);
 
135
extern void RB_body_set_mass(rbRigidBody *body, float value);
 
136
 
 
137
/* Friction */
 
138
extern float RB_body_get_friction(rbRigidBody *body);
 
139
extern void RB_body_set_friction(rbRigidBody *body, float value);
 
140
 
 
141
/* Restitution */
 
142
extern float RB_body_get_restitution(rbRigidBody *body);
 
143
extern void RB_body_set_restitution(rbRigidBody *body, float value);
 
144
 
 
145
/* Damping */
 
146
extern float RB_body_get_linear_damping(rbRigidBody *body);
 
147
extern void RB_body_set_linear_damping(rbRigidBody *body, float value);
 
148
 
 
149
extern float RB_body_get_angular_damping(rbRigidBody *body);
 
150
extern void RB_body_set_angular_damping(rbRigidBody *body, float value);
 
151
 
 
152
extern void RB_body_set_damping(rbRigidBody *object, float linear, float angular);
 
153
 
 
154
/* Sleeping Thresholds */
 
155
extern float RB_body_get_linear_sleep_thresh(rbRigidBody *body);
 
156
extern void RB_body_set_linear_sleep_thresh(rbRigidBody *body, float value);
 
157
 
 
158
extern float RB_body_get_angular_sleep_thresh(rbRigidBody *body);
 
159
extern void RB_body_set_angular_sleep_thresh(rbRigidBody *body, float value);
 
160
 
 
161
extern void RB_body_set_sleep_thresh(rbRigidBody *body, float linear, float angular);
 
162
 
 
163
/* Linear Velocity */
 
164
extern void RB_body_get_linear_velocity(rbRigidBody *body, float v_out[3]);
 
165
extern void RB_body_set_linear_velocity(rbRigidBody *body, const float v_in[3]);
 
166
 
 
167
/* Angular Velocity */
 
168
extern void RB_body_get_angular_velocity(rbRigidBody *body, float v_out[3]);
 
169
extern void RB_body_set_angular_velocity(rbRigidBody *body, const float v_in[3]);
 
170
 
 
171
/* Linear/Angular Factor, used to lock translation/roation axes */
 
172
extern void RB_body_set_linear_factor(rbRigidBody *object, float x, float y, float z);
 
173
extern void RB_body_set_angular_factor(rbRigidBody *object, float x, float y, float z);
 
174
 
 
175
/* Kinematic State */
 
176
extern void RB_body_set_kinematic_state(rbRigidBody *body, int kinematic);
 
177
 
 
178
/* RigidBody Interface - Rigid Body Activation States */
 
179
extern int RB_body_get_activation_state(rbRigidBody *body);
 
180
extern void RB_body_set_activation_state(rbRigidBody *body, int use_deactivation);
 
181
extern void RB_body_activate(rbRigidBody *body);
 
182
extern void RB_body_deactivate(rbRigidBody *body);
 
183
 
 
184
 
 
185
/* Simulation ----------------------- */
 
186
 
 
187
/* Get current transform matrix of RigidBody to use in Blender (OpenGL format) */
 
188
extern void RB_body_get_transform_matrix(rbRigidBody *body, float m_out[4][4]);
 
189
 
 
190
/* Set RigidBody's location and rotation */
 
191
extern void RB_body_set_loc_rot(rbRigidBody *body, const float loc[3], const float rot[4]);
 
192
/* Set RigidBody's local scaling */
 
193
extern void RB_body_set_scale(rbRigidBody *body, const float scale[3]);
 
194
 
 
195
/* ............ */
 
196
 
 
197
/* Get RigidBody's position as vector */
 
198
void RB_body_get_position(rbRigidBody *body, float v_out[3]);
 
199
/* Get RigidBody's orientation as quaternion */
 
200
void RB_body_get_orientation(rbRigidBody *body, float v_out[4]);
 
201
 
 
202
/* ............ */
 
203
 
 
204
extern void RB_body_apply_central_force(rbRigidBody *body, const float v_in[3]);
 
205
 
 
206
/* ********************************** */
 
207
/* Collision Shape Methods */
 
208
 
 
209
/* Setup (Standard Shapes) ----------- */
 
210
 
 
211
extern rbCollisionShape *RB_shape_new_box(float x, float y, float z);
 
212
extern rbCollisionShape *RB_shape_new_sphere(float radius);
 
213
extern rbCollisionShape *RB_shape_new_capsule(float radius, float height);
 
214
extern rbCollisionShape *RB_shape_new_cone(float radius, float height);
 
215
extern rbCollisionShape *RB_shape_new_cylinder(float radius, float height);
 
216
 
 
217
/* Setup (Convex Hull) ------------ */
 
218
 
 
219
extern rbCollisionShape *RB_shape_new_convex_hull(float *verts, int stride, int count, float margin, bool *can_embed);
 
220
 
 
221
/* Setup (Triangle Mesh) ---------- */
 
222
 
 
223
/* 1 */
 
224
extern rbMeshData *RB_trimesh_data_new(void);
 
225
extern void RB_trimesh_add_triangle(rbMeshData *mesh, const float v1[3], const float v2[3], const float v3[3]);
 
226
/* 2a - Triangle Meshes */
 
227
extern rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh);
 
228
/* 2b - GImpact Meshes */
 
229
extern rbCollisionShape *RB_shape_new_gimpact_mesh(rbMeshData *mesh);
 
230
 
 
231
 
 
232
/* Cleanup --------------------------- */
 
233
 
 
234
extern void RB_shape_delete(rbCollisionShape *shape);
 
235
 
 
236
/* Settings --------------------------- */
 
237
 
 
238
/* Collision Margin */
 
239
extern float RB_shape_get_margin(rbCollisionShape *shape);
 
240
extern void RB_shape_set_margin(rbCollisionShape *shape, float value);
 
241
 
 
242
/* ********************************** */
 
243
/* Constraints */
 
244
 
 
245
/* Setup ----------------------------- */
 
246
 
 
247
/* Add Rigid Body Constraint to simulation world */
 
248
extern void RB_dworld_add_constraint(rbDynamicsWorld *world, rbConstraint *con, int disable_collisions);
 
249
 
 
250
/* Remove Rigid Body Constraint from simulation world */
 
251
extern void RB_dworld_remove_constraint(rbDynamicsWorld *world, rbConstraint *con);
 
252
 
 
253
extern rbConstraint *RB_constraint_new_point(float pivot[3], rbRigidBody *rb1, rbRigidBody *rb2);
 
254
extern rbConstraint *RB_constraint_new_fixed(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2);
 
255
extern rbConstraint *RB_constraint_new_hinge(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2);
 
256
extern rbConstraint *RB_constraint_new_slider(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2);
 
257
extern rbConstraint *RB_constraint_new_piston(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2);
 
258
extern rbConstraint *RB_constraint_new_6dof(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2);
 
259
extern rbConstraint *RB_constraint_new_6dof_spring(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2);
 
260
 
 
261
/* ............ */
 
262
 
 
263
/* Cleanup --------------------------- */
 
264
 
 
265
extern void RB_constraint_delete(rbConstraint *con);
 
266
 
 
267
/* Settings --------------------------- */
 
268
 
 
269
/* Enable or disable constraint */
 
270
extern void RB_constraint_set_enabled(rbConstraint *con, int enabled);
 
271
 
 
272
/* Limits */
 
273
#define RB_LIMIT_LIN_X 0
 
274
#define RB_LIMIT_LIN_Y 1
 
275
#define RB_LIMIT_LIN_Z 2
 
276
#define RB_LIMIT_ANG_X 3
 
277
#define RB_LIMIT_ANG_Y 4
 
278
#define RB_LIMIT_ANG_Z 5
 
279
/* Bullet uses the following convention:
 
280
 * - lower limit == upper limit -> axis is locked
 
281
 * - lower limit > upper limit -> axis is free
 
282
 * - lower limit < upper limit -> axis is limited in given range
 
283
 */
 
284
extern void RB_constraint_set_limits_hinge(rbConstraint *con, float lower, float upper);
 
285
extern void RB_constraint_set_limits_slider(rbConstraint *con, float lower, float upper);
 
286
extern void RB_constraint_set_limits_piston(rbConstraint *con, float lin_lower, float lin_upper, float ang_lower, float ang_upper);
 
287
extern void RB_constraint_set_limits_6dof(rbConstraint *con, int axis, float lower, float upper);
 
288
 
 
289
/* 6dof spring specific */
 
290
extern void RB_constraint_set_stiffness_6dof_spring(rbConstraint *con, int axis, float stiffness);
 
291
extern void RB_constraint_set_damping_6dof_spring(rbConstraint *con, int axis, float damping);
 
292
extern void RB_constraint_set_spring_6dof_spring(rbConstraint *con, int axis, int enable);
 
293
extern void RB_constraint_set_equilibrium_6dof_spring(rbConstraint *con);
 
294
 
 
295
/* Set number of constraint solver iterations made per step, this overrided world setting
 
296
 * To use default set it to -1 */
 
297
extern void RB_constraint_set_solver_iterations(rbConstraint *con, int num_solver_iterations);
 
298
 
 
299
/* Set breaking impulse threshold, if constraint shouldn't break it can be set to FLT_MAX */
 
300
extern void RB_constraint_set_breaking_threshold(rbConstraint *con, float threshold);
 
301
 
 
302
/* ********************************** */
 
303
 
 
304
#ifdef __cplusplus
 
305
}
 
306
#endif
 
307
 
 
308
#endif /* __RB_API_H__ */
 
309