Blender  V2.93
rb_bullet_api.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation
17  * All rights reserved.
18  */
19 
25 /*
26  * Bullet Continuous Collision Detection and Physics Library
27  * Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
28  *
29  * This software is provided 'as-is', without any express or implied warranty. In no event will the
30  * authors be held liable for any damages arising from the use of this software. Permission is
31  * granted to anyone to use this software for any purpose, including commercial applications, and
32  * to alter it and redistribute it freely, subject to the following restrictions:
33  *
34  * 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
35  * original software. If you use this software in a product, an acknowledgment in the product
36  * documentation would be appreciated but is not required.
37  * 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
38  * being the original software.
39  * 3. This notice may not be removed or altered from any source distribution.
40  */
41 
42 /* This file defines the "RigidBody interface" for the
43  * Bullet Physics Engine. This API is designed to be used
44  * from C-code in Blender as part of the Rigid Body simulation
45  * system.
46  *
47  * It is based on the Bullet C-API, but is heavily modified to
48  * give access to more data types and to offer a nicer interface.
49  *
50  * -- Joshua Leung, June 2010
51  */
52 
53 #include <errno.h>
54 #include <stdio.h>
55 
56 #include "RBI_api.h"
57 
58 #include "btBulletDynamicsCommon.h"
59 
61 #include "LinearMath/btMatrix3x3.h"
62 #include "LinearMath/btScalar.h"
63 #include "LinearMath/btTransform.h"
64 #include "LinearMath/btVector3.h"
65 
69 
77 };
78 struct rbRigidBody {
81 };
82 
83 struct rbVert {
85 };
86 struct rbTri {
87  int v0, v1, v2;
88 };
89 
90 struct rbMeshData {
96 };
97 
103 };
104 
106  virtual bool needBroadphaseCollision(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const
107  {
108  rbRigidBody *rb0 = (rbRigidBody *)((btRigidBody *)proxy0->m_clientObject)->getUserPointer();
109  rbRigidBody *rb1 = (rbRigidBody *)((btRigidBody *)proxy1->m_clientObject)->getUserPointer();
110 
111  bool collides;
112  collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
113  collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
114  collides = collides && (rb0->col_groups & rb1->col_groups);
115 
116  return collides;
117  }
118 };
119 
120 static inline void copy_v3_btvec3(float vec[3], const btVector3 &btvec)
121 {
122  vec[0] = (float)btvec[0];
123  vec[1] = (float)btvec[1];
124  vec[2] = (float)btvec[2];
125 }
126 static inline void copy_quat_btquat(float quat[4], const btQuaternion &btquat)
127 {
128  quat[0] = btquat.getW();
129  quat[1] = btquat.getX();
130  quat[2] = btquat.getY();
131  quat[3] = btquat.getZ();
132 }
133 
134 /* ********************************** */
135 /* Dynamics World Methods */
136 
137 /* Setup ---------------------------- */
138 
139 rbDynamicsWorld *RB_dworld_new(const float gravity[3])
140 {
142 
143  /* collision detection/handling */
144  world->collisionConfiguration = new btDefaultCollisionConfiguration();
145 
146  world->dispatcher = new btCollisionDispatcher(world->collisionConfiguration);
148 
149  world->pairCache = new btDbvtBroadphase();
150 
151  world->filterCallback = new rbFilterCallback();
152  world->pairCache->getOverlappingPairCache()->setOverlapFilterCallback(world->filterCallback);
153 
154  /* constraint solving */
155  world->constraintSolver = new btSequentialImpulseConstraintSolver();
156 
157  /* world */
158  world->dynamicsWorld = new btDiscreteDynamicsWorld(
159  world->dispatcher, world->pairCache, world->constraintSolver, world->collisionConfiguration);
160 
161  RB_dworld_set_gravity(world, gravity);
162 
163  return world;
164 }
165 
167 {
168  /* bullet doesn't like if we free these in a different order */
169  delete world->dynamicsWorld;
170  delete world->constraintSolver;
171  delete world->pairCache;
172  delete world->dispatcher;
173  delete world->collisionConfiguration;
174  delete world->filterCallback;
175  delete world;
176 }
177 
178 /* Settings ------------------------- */
179 
180 /* Gravity */
182 {
183  copy_v3_btvec3(g_out, world->dynamicsWorld->getGravity());
184 }
185 
186 void RB_dworld_set_gravity(rbDynamicsWorld *world, const float g_in[3])
187 {
188  world->dynamicsWorld->setGravity(btVector3(g_in[0], g_in[1], g_in[2]));
189 }
190 
191 /* Constraint Solver */
192 void RB_dworld_set_solver_iterations(rbDynamicsWorld *world, int num_solver_iterations)
193 {
194  btContactSolverInfo &info = world->dynamicsWorld->getSolverInfo();
195 
196  info.m_numIterations = num_solver_iterations;
197 }
198 
199 /* Split Impulse */
201 {
202  btContactSolverInfo &info = world->dynamicsWorld->getSolverInfo();
203 
204  info.m_splitImpulse = split_impulse;
205 }
206 
207 /* Simulation ----------------------- */
208 
210  float timeStep,
211  int maxSubSteps,
212  float timeSubStep)
213 {
214  world->dynamicsWorld->stepSimulation(timeStep, maxSubSteps, timeSubStep);
215 }
216 
217 /* Export -------------------------- */
218 
226 void RB_dworld_export(rbDynamicsWorld *world, const char *filename)
227 {
228  // create a large enough buffer. There is no method to pre-calculate the buffer size yet.
229  int maxSerializeBufferSize = 1024 * 1024 * 5;
230 
231  btDefaultSerializer *serializer = new btDefaultSerializer(maxSerializeBufferSize);
232  world->dynamicsWorld->serialize(serializer);
233 
234  FILE *file = fopen(filename, "wb");
235  if (file) {
236  fwrite(serializer->getBufferPointer(), serializer->getCurrentBufferSize(), 1, file);
237  fclose(file);
238  }
239  else {
240  fprintf(stderr, "RB_dworld_export: %s\n", strerror(errno));
241  }
242 }
243 
244 /* ********************************** */
245 /* Rigid Body Methods */
246 
247 /* Setup ---------------------------- */
248 
249 void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *object, int col_groups)
250 {
251  btRigidBody *body = object->body;
252  object->col_groups = col_groups;
253 
254  world->dynamicsWorld->addRigidBody(body);
255 }
256 
258 {
259  btRigidBody *body = object->body;
260 
261  world->dynamicsWorld->removeRigidBody(body);
262 }
263 
264 /* Collision detection */
265 
267  rbRigidBody *object,
268  const float loc_start[3],
269  const float loc_end[3],
270  float v_location[3],
271  float v_hitpoint[3],
272  float v_normal[3],
273  int *r_hit)
274 {
275  btRigidBody *body = object->body;
276  btCollisionShape *collisionShape = body->getCollisionShape();
277  /* only convex shapes are supported, but user can specify a non convex shape */
278  if (collisionShape->isConvex()) {
280  btVector3(loc_start[0], loc_start[1], loc_start[2]),
281  btVector3(loc_end[0], loc_end[1], loc_end[2]));
282 
283  btQuaternion obRot = body->getWorldTransform().getRotation();
284 
285  btTransform rayFromTrans;
286  rayFromTrans.setIdentity();
287  rayFromTrans.setRotation(obRot);
288  rayFromTrans.setOrigin(btVector3(loc_start[0], loc_start[1], loc_start[2]));
289 
290  btTransform rayToTrans;
291  rayToTrans.setIdentity();
292  rayToTrans.setRotation(obRot);
293  rayToTrans.setOrigin(btVector3(loc_end[0], loc_end[1], loc_end[2]));
294 
295  world->dynamicsWorld->convexSweepTest(
296  (btConvexShape *)collisionShape, rayFromTrans, rayToTrans, result, 0);
297 
298  if (result.hasHit()) {
299  *r_hit = 1;
300 
301  v_location[0] = result.m_convexFromWorld[0] +
302  (result.m_convexToWorld[0] - result.m_convexFromWorld[0]) *
303  result.m_closestHitFraction;
304  v_location[1] = result.m_convexFromWorld[1] +
305  (result.m_convexToWorld[1] - result.m_convexFromWorld[1]) *
306  result.m_closestHitFraction;
307  v_location[2] = result.m_convexFromWorld[2] +
308  (result.m_convexToWorld[2] - result.m_convexFromWorld[2]) *
309  result.m_closestHitFraction;
310 
311  v_hitpoint[0] = result.m_hitPointWorld[0];
312  v_hitpoint[1] = result.m_hitPointWorld[1];
313  v_hitpoint[2] = result.m_hitPointWorld[2];
314 
315  v_normal[0] = result.m_hitNormalWorld[0];
316  v_normal[1] = result.m_hitNormalWorld[1];
317  v_normal[2] = result.m_hitNormalWorld[2];
318  }
319  else {
320  *r_hit = 0;
321  }
322  }
323  else {
324  /* we need to return a value if user passes non convex body, to report */
325  *r_hit = -2;
326  }
327 }
328 
329 /* ............ */
330 
331 rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4])
332 {
333  rbRigidBody *object = new rbRigidBody;
334  /* current transform */
335  btTransform trans;
336  trans.setIdentity();
337  trans.setOrigin(btVector3(loc[0], loc[1], loc[2]));
338  trans.setRotation(btQuaternion(rot[1], rot[2], rot[3], rot[0]));
339 
340  /* create motionstate, which is necessary for interpolation (includes reverse playback) */
341  btDefaultMotionState *motionState = new btDefaultMotionState(trans);
342 
343  /* make rigidbody */
344  btRigidBody::btRigidBodyConstructionInfo rbInfo(1.0f, motionState, shape->cshape);
345 
346  object->body = new btRigidBody(rbInfo);
347 
348  object->body->setUserPointer(object);
349 
350  return object;
351 }
352 
354 {
355  btRigidBody *body = object->body;
356 
357  /* motion state */
358  btMotionState *ms = body->getMotionState();
359 
360  delete ms;
361 
362  /* collision shape is done elsewhere... */
363 
364  /* body itself */
365 
366  /* manually remove constraint refs of the rigid body, normally this happens when removing
367  * constraints from the world
368  * but since we delete everything when the world is rebult, we need to do it manually here */
369  for (int i = body->getNumConstraintRefs() - 1; i >= 0; i--) {
370  btTypedConstraint *con = body->getConstraintRef(i);
371  body->removeConstraintRef(con);
372  }
373 
374  delete body;
375  delete object;
376 }
377 
378 /* Settings ------------------------- */
379 
381 {
382  btRigidBody *body = object->body;
383 
384  /* set new collision shape */
385  body->setCollisionShape(shape->cshape);
386 
387  /* recalculate inertia, since that depends on the collision shape... */
388  RB_body_set_mass(object, RB_body_get_mass(object));
389 }
390 
391 /* ............ */
392 
394 {
395  btRigidBody *body = object->body;
396 
397  /* there isn't really a mass setting, but rather 'inverse mass'
398  * which we convert back to mass by taking the reciprocal again
399  */
400  float value = (float)body->getInvMass();
401 
402  if (value) {
403  value = 1.0f / value;
404  }
405 
406  return value;
407 }
408 
409 void RB_body_set_mass(rbRigidBody *object, float value)
410 {
411  btRigidBody *body = object->body;
412  btVector3 localInertia(0, 0, 0);
413 
414  /* calculate new inertia if non-zero mass */
415  if (value) {
416  btCollisionShape *shape = body->getCollisionShape();
417  shape->calculateLocalInertia(value, localInertia);
418  }
419 
420  btVector3 minAabb, maxAabb;
421  btTransform ident;
422  ident.setIdentity();
423  body->getCollisionShape()->getAabb(ident, minAabb, maxAabb);
424  body->setMassProps(value, localInertia);
425  body->updateInertiaTensor();
426 }
427 
429 {
430  btRigidBody *body = object->body;
431  return body->getFriction();
432 }
433 
434 void RB_body_set_friction(rbRigidBody *object, float value)
435 {
436  btRigidBody *body = object->body;
437  body->setFriction(value);
438 }
439 
441 {
442  btRigidBody *body = object->body;
443  return body->getRestitution();
444 }
445 
446 void RB_body_set_restitution(rbRigidBody *object, float value)
447 {
448  btRigidBody *body = object->body;
449  body->setRestitution(value);
450 }
451 
453 {
454  btRigidBody *body = object->body;
455  return body->getLinearDamping();
456 }
457 
458 void RB_body_set_linear_damping(rbRigidBody *object, float value)
459 {
460  RB_body_set_damping(object, value, RB_body_get_linear_damping(object));
461 }
462 
464 {
465  btRigidBody *body = object->body;
466  return body->getAngularDamping();
467 }
468 
469 void RB_body_set_angular_damping(rbRigidBody *object, float value)
470 {
471  RB_body_set_damping(object, RB_body_get_linear_damping(object), value);
472 }
473 
474 void RB_body_set_damping(rbRigidBody *object, float linear, float angular)
475 {
476  btRigidBody *body = object->body;
477  body->setDamping(linear, angular);
478 }
479 
481 {
482  btRigidBody *body = object->body;
483  return body->getLinearSleepingThreshold();
484 }
485 
487 {
489 }
490 
492 {
493  btRigidBody *body = object->body;
494  return body->getAngularSleepingThreshold();
495 }
496 
498 {
500 }
501 
502 void RB_body_set_sleep_thresh(rbRigidBody *object, float linear, float angular)
503 {
504  btRigidBody *body = object->body;
505  body->setSleepingThresholds(linear, angular);
506 }
507 
508 /* ............ */
509 
510 void RB_body_get_linear_velocity(rbRigidBody *object, float v_out[3])
511 {
512  btRigidBody *body = object->body;
513 
514  copy_v3_btvec3(v_out, body->getLinearVelocity());
515 }
516 
517 void RB_body_set_linear_velocity(rbRigidBody *object, const float v_in[3])
518 {
519  btRigidBody *body = object->body;
520 
521  body->setLinearVelocity(btVector3(v_in[0], v_in[1], v_in[2]));
522 }
523 
524 void RB_body_get_angular_velocity(rbRigidBody *object, float v_out[3])
525 {
526  btRigidBody *body = object->body;
527 
528  copy_v3_btvec3(v_out, body->getAngularVelocity());
529 }
530 
531 void RB_body_set_angular_velocity(rbRigidBody *object, const float v_in[3])
532 {
533  btRigidBody *body = object->body;
534 
535  body->setAngularVelocity(btVector3(v_in[0], v_in[1], v_in[2]));
536 }
537 
538 void RB_body_set_linear_factor(rbRigidBody *object, float x, float y, float z)
539 {
540  btRigidBody *body = object->body;
541  body->setLinearFactor(btVector3(x, y, z));
542 }
543 
544 void RB_body_set_angular_factor(rbRigidBody *object, float x, float y, float z)
545 {
546  btRigidBody *body = object->body;
547  body->setAngularFactor(btVector3(x, y, z));
548 }
549 
550 /* ............ */
551 
552 void RB_body_set_kinematic_state(rbRigidBody *object, int kinematic)
553 {
554  btRigidBody *body = object->body;
555  if (kinematic) {
556  body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
557  }
558  else {
559  body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT);
560  }
561 }
562 
563 /* ............ */
564 
565 void RB_body_set_activation_state(rbRigidBody *object, int use_deactivation)
566 {
567  btRigidBody *body = object->body;
568  if (use_deactivation) {
569  body->forceActivationState(ACTIVE_TAG);
570  }
571  else {
572  body->setActivationState(DISABLE_DEACTIVATION);
573  }
574 }
576 {
577  btRigidBody *body = object->body;
578  body->setActivationState(ACTIVE_TAG);
579 }
581 {
582  btRigidBody *body = object->body;
583  body->setActivationState(ISLAND_SLEEPING);
584 }
585 
586 /* ............ */
587 
588 /* Simulation ----------------------- */
589 
590 /* The transform matrices Blender uses are OpenGL-style matrices,
591  * while Bullet uses the Right-Handed coordinate system style instead.
592  */
593 
594 void RB_body_get_transform_matrix(rbRigidBody *object, float m_out[4][4])
595 {
596  btRigidBody *body = object->body;
597  btMotionState *ms = body->getMotionState();
598 
599  btTransform trans;
600  ms->getWorldTransform(trans);
601 
602  trans.getOpenGLMatrix((btScalar *)m_out);
603 }
604 
605 void RB_body_set_loc_rot(rbRigidBody *object, const float loc[3], const float rot[4])
606 {
607  btRigidBody *body = object->body;
608  btMotionState *ms = body->getMotionState();
609 
610  /* set transform matrix */
611  btTransform trans;
612  trans.setIdentity();
613  trans.setOrigin(btVector3(loc[0], loc[1], loc[2]));
614  trans.setRotation(btQuaternion(rot[1], rot[2], rot[3], rot[0]));
615 
616  ms->setWorldTransform(trans);
617 }
618 
619 void RB_body_set_scale(rbRigidBody *object, const float scale[3])
620 {
621  btRigidBody *body = object->body;
622 
623  /* apply scaling factor from matrix above to the collision shape */
624  btCollisionShape *cshape = body->getCollisionShape();
625  if (cshape) {
626  cshape->setLocalScaling(btVector3(scale[0], scale[1], scale[2]));
627 
628  /* GIimpact shapes have to be updated to take scaling into account */
629  if (cshape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE) {
630  ((btGImpactMeshShape *)cshape)->updateBound();
631  }
632  }
633 }
634 
635 /* ............ */
636 /* Read-only state info about status of simulation */
637 
638 void RB_body_get_position(rbRigidBody *object, float v_out[3])
639 {
640  btRigidBody *body = object->body;
641 
642  copy_v3_btvec3(v_out, body->getWorldTransform().getOrigin());
643 }
644 
645 void RB_body_get_orientation(rbRigidBody *object, float v_out[4])
646 {
647  btRigidBody *body = object->body;
648 
649  copy_quat_btquat(v_out, body->getWorldTransform().getRotation());
650 }
651 
652 void RB_body_get_scale(rbRigidBody *object, float v_out[3])
653 {
654  btRigidBody *body = object->body;
655 
656  btCollisionShape *cshape = body->getCollisionShape();
657  /* The body should have a collision shape when we try to set the scale. */
658  btAssert(cshape);
659  copy_v3_btvec3(v_out, cshape->getLocalScaling());
660 }
661 
662 /* ............ */
663 /* Overrides for simulation */
664 
665 void RB_body_apply_central_force(rbRigidBody *object, const float v_in[3])
666 {
667  btRigidBody *body = object->body;
668 
669  body->applyCentralForce(btVector3(v_in[0], v_in[1], v_in[2]));
670 }
671 
672 /* ********************************** */
673 /* Collision Shape Methods */
674 
675 /* Setup (Standard Shapes) ----------- */
676 
677 rbCollisionShape *RB_shape_new_box(float x, float y, float z)
678 {
679  rbCollisionShape *shape = new rbCollisionShape;
680  shape->cshape = new btBoxShape(btVector3(x, y, z));
681  shape->mesh = NULL;
682  shape->compoundChilds = 0;
683  shape->compoundChildShapes = NULL;
684  return shape;
685 }
686 
688 {
689  rbCollisionShape *shape = new rbCollisionShape;
690  shape->cshape = new btSphereShape(radius);
691  shape->mesh = NULL;
692  shape->compoundChilds = 0;
693  shape->compoundChildShapes = NULL;
694  return shape;
695 }
696 
698 {
699  rbCollisionShape *shape = new rbCollisionShape;
700  shape->cshape = new btCapsuleShapeZ(radius, height);
701  shape->mesh = NULL;
702  shape->compoundChilds = 0;
703  shape->compoundChildShapes = NULL;
704  return shape;
705 }
706 
708 {
709  rbCollisionShape *shape = new rbCollisionShape;
710  shape->cshape = new btConeShapeZ(radius, height);
711  shape->mesh = NULL;
712  shape->compoundChilds = 0;
713  shape->compoundChildShapes = NULL;
714  return shape;
715 }
716 
718 {
719  rbCollisionShape *shape = new rbCollisionShape;
720  shape->cshape = new btCylinderShapeZ(btVector3(radius, radius, height));
721  shape->mesh = NULL;
722  shape->compoundChilds = 0;
723  shape->compoundChildShapes = NULL;
724  return shape;
725 }
726 
727 /* Setup (Convex Hull) ------------ */
728 
730  float *verts, int stride, int count, float margin, bool *can_embed)
731 {
732  btConvexHullComputer hull_computer = btConvexHullComputer();
733 
734  // try to embed the margin, if that fails don't shrink the hull
735  if (hull_computer.compute(verts, stride, count, margin, 0.0f) < 0.0f) {
736  hull_computer.compute(verts, stride, count, 0.0f, 0.0f);
737  *can_embed = false;
738  }
739 
740  rbCollisionShape *shape = new rbCollisionShape;
741  btConvexHullShape *hull_shape = new btConvexHullShape(&(hull_computer.vertices[0].getX()),
742  hull_computer.vertices.size());
743 
744  shape->cshape = hull_shape;
745  shape->mesh = NULL;
746  shape->compoundChilds = 0;
747  shape->compoundChildShapes = NULL;
748  return shape;
749 }
750 
751 /* Setup (Triangle Mesh) ---------- */
752 
753 /* Need to call RB_trimesh_finish() after creating triangle mesh and adding vertices and triangles
754  */
755 
756 rbMeshData *RB_trimesh_data_new(int num_tris, int num_verts)
757 {
758  rbMeshData *mesh = new rbMeshData;
759  mesh->vertices = new rbVert[num_verts];
760  mesh->triangles = new rbTri[num_tris];
761  mesh->num_vertices = num_verts;
762  mesh->num_triangles = num_tris;
763 
764  return mesh;
765 }
766 
768 {
769  delete mesh->index_array;
770  delete[] mesh->vertices;
771  delete[] mesh->triangles;
772  delete mesh;
773 }
774 
775 void RB_trimesh_add_vertices(rbMeshData *mesh, float *vertices, int num_verts, int vert_stride)
776 {
777  for (int i = 0; i < num_verts; i++) {
778  float *vert = (float *)(((char *)vertices + i * vert_stride));
779  mesh->vertices[i].x = vert[0];
780  mesh->vertices[i].y = vert[1];
781  mesh->vertices[i].z = vert[2];
782  }
783 }
784 void RB_trimesh_add_triangle_indices(rbMeshData *mesh, int num, int index0, int index1, int index2)
785 {
786  mesh->triangles[num].v0 = index0;
787  mesh->triangles[num].v1 = index1;
788  mesh->triangles[num].v2 = index2;
789 }
790 
792 {
794  (int *)mesh->triangles,
795  sizeof(rbTri),
796  mesh->num_vertices,
797  (btScalar *)mesh->vertices,
798  sizeof(rbVert));
799 }
800 
802 {
803  rbCollisionShape *shape = new rbCollisionShape;
804 
805  /* triangle-mesh we create is a BVH wrapper for triangle mesh data (for faster lookups) */
806  // RB_TODO perhaps we need to allow saving out this for performance when rebuilding?
807  btBvhTriangleMeshShape *unscaledShape = new btBvhTriangleMeshShape(
808  mesh->index_array, true, true);
809 
810  shape->cshape = new btScaledBvhTriangleMeshShape(unscaledShape, btVector3(1.0f, 1.0f, 1.0f));
811  shape->mesh = mesh;
812  shape->compoundChilds = 0;
813  shape->compoundChildShapes = NULL;
814  return shape;
815 }
816 
818  float *vertices,
819  int num_verts,
820  int vert_stride,
821  float min[3],
822  float max[3])
823 {
824  if (shape->mesh == NULL || num_verts != shape->mesh->num_vertices) {
825  return;
826  }
827 
828  for (int i = 0; i < num_verts; i++) {
829  float *vert = (float *)(((char *)vertices + i * vert_stride));
830  shape->mesh->vertices[i].x = vert[0];
831  shape->mesh->vertices[i].y = vert[1];
832  shape->mesh->vertices[i].z = vert[2];
833  }
834 
835  if (shape->cshape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) {
837  btBvhTriangleMeshShape *mesh_shape = scaled_shape->getChildShape();
838  mesh_shape->refitTree(btVector3(min[0], min[1], min[2]), btVector3(max[0], max[1], max[2]));
839  }
840  else if (shape->cshape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE) {
841  btGImpactMeshShape *mesh_shape = (btGImpactMeshShape *)shape->cshape;
842  mesh_shape->updateBound();
843  }
844 }
845 
847 {
848  rbCollisionShape *shape = new rbCollisionShape;
849 
850  btGImpactMeshShape *gimpactShape = new btGImpactMeshShape(mesh->index_array);
851  gimpactShape->updateBound(); // TODO: add this to the update collision margin call?
852 
853  shape->cshape = gimpactShape;
854  shape->mesh = mesh;
855  shape->compoundChilds = 0;
856  shape->compoundChildShapes = NULL;
857  return shape;
858 }
859 
860 /* Compound Shape ---------------- */
861 
863 {
864  rbCollisionShape *shape = new rbCollisionShape;
865  btCompoundShape *compoundShape = new btCompoundShape();
866 
867  shape->cshape = compoundShape;
868  shape->mesh = NULL;
869  shape->compoundChilds = 0;
870  shape->compoundChildShapes = NULL;
871  return shape;
872 }
873 
875  rbCollisionShape *shape,
876  const float loc[3],
877  const float rot[4])
878 {
879  /* set transform matrix */
880  btTransform trans;
881  trans.setIdentity();
882  trans.setOrigin(btVector3(loc[0], loc[1], loc[2]));
883  trans.setRotation(btQuaternion(rot[1], rot[2], rot[3], rot[0]));
884 
885  btCompoundShape *compoundShape = (btCompoundShape *)(parentShape->cshape);
886  compoundShape->addChildShape(trans, shape->cshape);
887 
888  /* Store shapes for deletion later */
889  parentShape->compoundChildShapes = (rbCollisionShape **)(realloc(
890  parentShape->compoundChildShapes,
891  sizeof(rbCollisionShape *) * (++parentShape->compoundChilds)));
892  parentShape->compoundChildShapes[parentShape->compoundChilds - 1] = shape;
893 }
894 
895 /* Cleanup --------------------------- */
896 
898 {
899  if (shape->cshape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) {
900  btBvhTriangleMeshShape *child_shape =
901  ((btScaledBvhTriangleMeshShape *)shape->cshape)->getChildShape();
902 
903  delete child_shape;
904  }
905  if (shape->mesh) {
907  }
908  delete shape->cshape;
909 
910  /* Delete compound child shapes if there are any */
911  for (int i = 0; i < shape->compoundChilds; i++) {
913  }
914  if (shape->compoundChildShapes != NULL) {
915  free(shape->compoundChildShapes);
916  }
917 
918  delete shape;
919 }
920 
921 /* Settings --------------------------- */
922 
924 {
925  return shape->cshape->getMargin();
926 }
927 
928 void RB_shape_set_margin(rbCollisionShape *shape, float value)
929 {
930  shape->cshape->setMargin(value);
931 }
932 
933 /* ********************************** */
934 /* Constraints */
935 
936 /* Setup ----------------------------- */
937 
938 void RB_dworld_add_constraint(rbDynamicsWorld *world, rbConstraint *con, int disable_collisions)
939 {
940  btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint *>(con);
941 
942  world->dynamicsWorld->addConstraint(constraint, disable_collisions);
943 }
944 
946 {
947  btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint *>(con);
948 
949  world->dynamicsWorld->removeConstraint(constraint);
950 }
951 
952 /* ............ */
953 
954 static void make_constraint_transforms(btTransform &transform1,
955  btTransform &transform2,
956  btRigidBody *body1,
957  btRigidBody *body2,
958  float pivot[3],
959  float orn[4])
960 {
961  btTransform pivot_transform = btTransform();
962  pivot_transform.setIdentity();
963  pivot_transform.setOrigin(btVector3(pivot[0], pivot[1], pivot[2]));
964  pivot_transform.setRotation(btQuaternion(orn[1], orn[2], orn[3], orn[0]));
965 
966  transform1 = body1->getWorldTransform().inverse() * pivot_transform;
967  transform2 = body2->getWorldTransform().inverse() * pivot_transform;
968 }
969 
971 {
972  btRigidBody *body1 = rb1->body;
973  btRigidBody *body2 = rb2->body;
974 
975  btVector3 pivot1 = body1->getWorldTransform().inverse() *
976  btVector3(pivot[0], pivot[1], pivot[2]);
977  btVector3 pivot2 = body2->getWorldTransform().inverse() *
978  btVector3(pivot[0], pivot[1], pivot[2]);
979 
980  btTypedConstraint *con = new btPoint2PointConstraint(*body1, *body2, pivot1, pivot2);
981 
982  return (rbConstraint *)con;
983 }
984 
986  float orn[4],
987  rbRigidBody *rb1,
988  rbRigidBody *rb2)
989 {
990  btRigidBody *body1 = rb1->body;
991  btRigidBody *body2 = rb2->body;
992  btTransform transform1;
993  btTransform transform2;
994 
995  make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn);
996 
997  btFixedConstraint *con = new btFixedConstraint(*body1, *body2, transform1, transform2);
998 
999  return (rbConstraint *)con;
1000 }
1001 
1003  float orn[4],
1004  rbRigidBody *rb1,
1005  rbRigidBody *rb2)
1006 {
1007  btRigidBody *body1 = rb1->body;
1008  btRigidBody *body2 = rb2->body;
1009  btTransform transform1;
1010  btTransform transform2;
1011 
1012  make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn);
1013 
1014  btHingeConstraint *con = new btHingeConstraint(*body1, *body2, transform1, transform2);
1015 
1016  return (rbConstraint *)con;
1017 }
1018 
1020  float orn[4],
1021  rbRigidBody *rb1,
1022  rbRigidBody *rb2)
1023 {
1024  btRigidBody *body1 = rb1->body;
1025  btRigidBody *body2 = rb2->body;
1026  btTransform transform1;
1027  btTransform transform2;
1028 
1029  make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn);
1030 
1031  btSliderConstraint *con = new btSliderConstraint(*body1, *body2, transform1, transform2, true);
1032 
1033  return (rbConstraint *)con;
1034 }
1035 
1037  float orn[4],
1038  rbRigidBody *rb1,
1039  rbRigidBody *rb2)
1040 {
1041  btRigidBody *body1 = rb1->body;
1042  btRigidBody *body2 = rb2->body;
1043  btTransform transform1;
1044  btTransform transform2;
1045 
1046  make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn);
1047 
1048  btSliderConstraint *con = new btSliderConstraint(*body1, *body2, transform1, transform2, true);
1049  con->setUpperAngLimit(-1.0f); // unlock rotation axis
1050 
1051  return (rbConstraint *)con;
1052 }
1053 
1055  float orn[4],
1056  rbRigidBody *rb1,
1057  rbRigidBody *rb2)
1058 {
1059  btRigidBody *body1 = rb1->body;
1060  btRigidBody *body2 = rb2->body;
1061  btTransform transform1;
1062  btTransform transform2;
1063 
1064  make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn);
1065 
1067  *body1, *body2, transform1, transform2, true);
1068 
1069  return (rbConstraint *)con;
1070 }
1071 
1073  float orn[4],
1074  rbRigidBody *rb1,
1075  rbRigidBody *rb2)
1076 {
1077  btRigidBody *body1 = rb1->body;
1078  btRigidBody *body2 = rb2->body;
1079  btTransform transform1;
1080  btTransform transform2;
1081 
1082  make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn);
1083 
1085  *body1, *body2, transform1, transform2, true);
1086 
1087  return (rbConstraint *)con;
1088 }
1089 
1091  float orn[4],
1092  rbRigidBody *rb1,
1093  rbRigidBody *rb2)
1094 {
1095  btRigidBody *body1 = rb1->body;
1096  btRigidBody *body2 = rb2->body;
1097  btTransform transform1;
1098  btTransform transform2;
1099 
1100  make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn);
1101 
1103  *body1, *body2, transform1, transform2);
1104 
1105  return (rbConstraint *)con;
1106 }
1107 
1109  float orn[4],
1110  rbRigidBody *rb1,
1111  rbRigidBody *rb2)
1112 {
1113  btRigidBody *body1 = rb1->body;
1114  btRigidBody *body2 = rb2->body;
1115  btTransform transform1;
1116  btTransform transform2;
1117 
1118  make_constraint_transforms(transform1, transform2, body1, body2, pivot, orn);
1119 
1121  *body1, *body2, transform1, transform2, true);
1122 
1123  /* unlock constraint axes */
1124  for (int i = 0; i < 6; i++) {
1125  con->setLimit(i, 0.0f, -1.0f);
1126  }
1127  /* unlock motor axes */
1128  con->getTranslationalLimitMotor()->m_upperLimit.setValue(-1.0f, -1.0f, -1.0f);
1129 
1130  return (rbConstraint *)con;
1131 }
1132 
1133 /* Cleanup ----------------------------- */
1134 
1136 {
1137  btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint *>(con);
1138  delete constraint;
1139 }
1140 
1141 /* Settings ------------------------- */
1142 
1144 {
1145  btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint *>(con);
1146 
1147  constraint->setEnabled(enabled);
1148 }
1149 
1150 void RB_constraint_set_limits_hinge(rbConstraint *con, float lower, float upper)
1151 {
1152  btHingeConstraint *constraint = reinterpret_cast<btHingeConstraint *>(con);
1153 
1154  // RB_TODO expose these
1155  float softness = 0.9f;
1156  float bias_factor = 0.3f;
1157  float relaxation_factor = 1.0f;
1158 
1159  constraint->setLimit(lower, upper, softness, bias_factor, relaxation_factor);
1160 }
1161 
1162 void RB_constraint_set_limits_slider(rbConstraint *con, float lower, float upper)
1163 {
1164  btSliderConstraint *constraint = reinterpret_cast<btSliderConstraint *>(con);
1165 
1166  constraint->setLowerLinLimit(lower);
1167  constraint->setUpperLinLimit(upper);
1168 }
1169 
1171  rbConstraint *con, float lin_lower, float lin_upper, float ang_lower, float ang_upper)
1172 {
1173  btSliderConstraint *constraint = reinterpret_cast<btSliderConstraint *>(con);
1174 
1175  constraint->setLowerLinLimit(lin_lower);
1176  constraint->setUpperLinLimit(lin_upper);
1177  constraint->setLowerAngLimit(ang_lower);
1178  constraint->setUpperAngLimit(ang_upper);
1179 }
1180 
1181 void RB_constraint_set_limits_6dof(rbConstraint *con, int axis, float lower, float upper)
1182 {
1183  btGeneric6DofConstraint *constraint = reinterpret_cast<btGeneric6DofConstraint *>(con);
1184 
1185  constraint->setLimit(axis, lower, upper);
1186 }
1187 
1188 void RB_constraint_set_limits_6dof_spring2(rbConstraint *con, int axis, float lower, float upper)
1189 {
1190  btGeneric6DofSpring2Constraint *constraint = reinterpret_cast<btGeneric6DofSpring2Constraint *>(
1191  con);
1192 
1193  constraint->setLimit(axis, lower, upper);
1194 }
1195 
1196 void RB_constraint_set_stiffness_6dof_spring(rbConstraint *con, int axis, float stiffness)
1197 {
1198  btGeneric6DofSpringConstraint *constraint = reinterpret_cast<btGeneric6DofSpringConstraint *>(
1199  con);
1200 
1201  constraint->setStiffness(axis, stiffness);
1202 }
1203 
1204 void RB_constraint_set_damping_6dof_spring(rbConstraint *con, int axis, float damping)
1205 {
1206  btGeneric6DofSpringConstraint *constraint = reinterpret_cast<btGeneric6DofSpringConstraint *>(
1207  con);
1208 
1209  // invert damping range so that 0 = no damping
1210  damping = (damping > 1.0f) ? 0.0f : 1.0f - damping;
1211 
1212  constraint->setDamping(axis, damping);
1213 }
1214 
1215 void RB_constraint_set_spring_6dof_spring(rbConstraint *con, int axis, int enable)
1216 {
1217  btGeneric6DofSpringConstraint *constraint = reinterpret_cast<btGeneric6DofSpringConstraint *>(
1218  con);
1219 
1220  constraint->enableSpring(axis, enable);
1221 }
1222 
1224 {
1225  btGeneric6DofSpringConstraint *constraint = reinterpret_cast<btGeneric6DofSpringConstraint *>(
1226  con);
1227 
1228  constraint->setEquilibriumPoint();
1229 }
1230 
1231 void RB_constraint_set_stiffness_6dof_spring2(rbConstraint *con, int axis, float stiffness)
1232 {
1233  btGeneric6DofSpring2Constraint *constraint = reinterpret_cast<btGeneric6DofSpring2Constraint *>(
1234  con);
1235 
1236  constraint->setStiffness(axis, stiffness);
1237 }
1238 
1239 void RB_constraint_set_damping_6dof_spring2(rbConstraint *con, int axis, float damping)
1240 {
1241  btGeneric6DofSpring2Constraint *constraint = reinterpret_cast<btGeneric6DofSpring2Constraint *>(
1242  con);
1243 
1244  constraint->setDamping(axis, damping);
1245 }
1246 
1247 void RB_constraint_set_spring_6dof_spring2(rbConstraint *con, int axis, int enable)
1248 {
1249  btGeneric6DofSpring2Constraint *constraint = reinterpret_cast<btGeneric6DofSpring2Constraint *>(
1250  con);
1251 
1252  constraint->enableSpring(axis, enable);
1253 }
1254 
1256 {
1257  btGeneric6DofSpring2Constraint *constraint = reinterpret_cast<btGeneric6DofSpring2Constraint *>(
1258  con);
1259 
1260  constraint->setEquilibriumPoint();
1261 }
1262 
1263 void RB_constraint_set_solver_iterations(rbConstraint *con, int num_solver_iterations)
1264 {
1265  btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint *>(con);
1266 
1267  constraint->setOverrideNumSolverIterations(num_solver_iterations);
1268 }
1269 
1271 {
1272  btTypedConstraint *constraint = reinterpret_cast<btTypedConstraint *>(con);
1273 
1274  constraint->setBreakingImpulseThreshold(threshold);
1275 }
1276 
1277 void RB_constraint_set_enable_motor(rbConstraint *con, int enable_lin, int enable_ang)
1278 {
1279  btGeneric6DofConstraint *constraint = reinterpret_cast<btGeneric6DofConstraint *>(con);
1280 
1281  constraint->getTranslationalLimitMotor()->m_enableMotor[0] = enable_lin;
1282  constraint->getRotationalLimitMotor(0)->m_enableMotor = enable_ang;
1283 }
1284 
1286  float max_impulse_lin,
1287  float max_impulse_ang)
1288 {
1289  btGeneric6DofConstraint *constraint = reinterpret_cast<btGeneric6DofConstraint *>(con);
1290 
1291  constraint->getTranslationalLimitMotor()->m_maxMotorForce.setX(max_impulse_lin);
1292  constraint->getRotationalLimitMotor(0)->m_maxMotorForce = max_impulse_ang;
1293 }
1294 
1296  float velocity_lin,
1297  float velocity_ang)
1298 {
1299  btGeneric6DofConstraint *constraint = reinterpret_cast<btGeneric6DofConstraint *>(con);
1300 
1301  constraint->getTranslationalLimitMotor()->m_targetVelocity.setX(velocity_lin);
1302  constraint->getRotationalLimitMotor(0)->m_targetVelocity = velocity_ang;
1303 }
1304 
1305 /* ********************************** */
typedef float(TangentPoint)[2]
void BLI_kdtree_nd_() free(KDTree *tree)
Definition: kdtree_impl.h:116
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble z
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
Rigid Body API for interfacing with external Physics Engines.
struct rbCollisionShape rbCollisionShape
Definition: RBI_api.h:53
struct rbMeshData rbMeshData
Definition: RBI_api.h:56
struct rbRigidBody rbRigidBody
Definition: RBI_api.h:50
struct rbDynamicsWorld rbDynamicsWorld
Definition: RBI_api.h:47
struct rbConstraint rbConstraint
Definition: RBI_api.h:59
btBoxShape(const btVector3 &boxHalfExtents)
Definition: btBoxShape.cpp:17
@ GIMPACT_SHAPE_PROXYTYPE
Used for GIMPACT Trimesh integration.
@ SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE
btBroadphaseProxy
btBvhTriangleMeshShape(btStridingMeshInterface *meshInterface, bool useQuantizedAabbCompression, bool buildBvh=true)
#define ACTIVE_TAG
#define DISABLE_DEACTIVATION
@ CF_KINEMATIC_OBJECT
void * getUserPointer() const
users can point to their objects, userPointer is not used by Bullet
#define ISLAND_SLEEPING
btCollisionShape
The btCollisionShape class provides an interface for collision shapes that can be shared among btColl...
btCompoundShape(bool enableDynamicAabbTree=true, const int initialChildCapacity=0)
btConvexHullShape(const btScalar *points=0, int numPoints=0, int stride=sizeof(btVector3))
btConvexShape()
not supported on IBM SDK, until we fix the alignment of btVector3
btDefaultMotionState(const btTransform &startTrans=btTransform::getIdentity(), const btTransform &centerOfMassOffset=btTransform::getIdentity())
btDiscreteDynamicsWorld(btDispatcher *dispatcher, btBroadphaseInterface *pairCache, btConstraintSolver *constraintSolver, btCollisionConfiguration *collisionConfiguration)
this btDiscreteDynamicsWorld constructor gets created objects from the user, and will not delete thos...
btGeneric6DofConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
btGeneric6DofSpring2Constraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, RotateOrder rotOrder=RO_XYZ)
btGeneric6DofSpringConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
btHingeConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &pivotInA, const btVector3 &pivotInB, const btVector3 &axisInA, const btVector3 &axisInB, bool useReferenceFrameA=false)
btPoint2PointConstraint(btRigidBody &rbA, btRigidBody &rbB, const btVector3 &pivotInA, const btVector3 &pivotInB)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
#define btAssert(x)
Definition: btScalar.h:295
btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape *childShape, const btVector3 &localScaling)
btSliderConstraint(btRigidBody &rbA, btRigidBody &rbB, const btTransform &frameInA, const btTransform &frameInB, bool useLinearReferenceFrameA)
btSphereShape(btScalar radius)
Definition: btSphereShape.h:29
btTransform
The btTransform class supports rigid transforms with only translation and rotation and no scaling/she...
Definition: btTransform.h:30
btTriangleIndexVertexArray()
btTypedConstraint(btTypedConstraintType type, btRigidBody &rbA)
btVector3
btVector3 can be used to represent 3D points and vectors. It has an un-used w component to suit 16-by...
Definition: btVector3.h:82
SIMD_FORCE_INLINE int size() const
return the number of elements in the array
btConeShapeZ implements a Cone shape, around the Z axis
Definition: btConeShape.h:124
btAlignedObjectArray< btVector3 > vertices
virtual const unsigned char * getBufferPointer() const
Definition: btSerializer.h:564
virtual int getCurrentBufferSize() const
Definition: btSerializer.h:569
static void registerAlgorithm(btCollisionDispatcher *dispatcher)
Use this function for register the algorithm externally.
This class manages a mesh supplied by the btStridingMeshInterface interface.
SIMD_FORCE_INLINE void updateBound()
performs refit operation
virtual void getWorldTransform(btTransform &worldTrans) const =0
virtual void setWorldTransform(const btTransform &worldTrans)=0
The btQuaternion implements quaternion to perform linear algebra rotations in combination with btMatr...
Definition: btQuaternion.h:50
SIMD_FORCE_INLINE const btScalar & getW() const
Definition: btQuaternion.h:614
void setLinearFactor(const btVector3 &linearFactor)
Definition: btRigidBody.h:258
SIMD_FORCE_INLINE const btCollisionShape * getCollisionShape() const
Definition: btRigidBody.h:242
const btVector3 & getAngularVelocity() const
Definition: btRigidBody.h:437
btMotionState * getMotionState()
Definition: btRigidBody.h:549
btScalar getLinearSleepingThreshold() const
Definition: btRigidBody.h:230
void applyCentralForce(const btVector3 &force)
Definition: btRigidBody.h:274
btScalar getInvMass() const
Definition: btRigidBody.h:263
btScalar getAngularDamping() const
Definition: btRigidBody.h:225
int getNumConstraintRefs() const
Definition: btRigidBody.h:598
void removeConstraintRef(btTypedConstraint *c)
void setSleepingThresholds(btScalar linear, btScalar angular)
Definition: btRigidBody.h:299
void setMassProps(btScalar mass, const btVector3 &inertia)
const btVector3 & getLinearVelocity() const
Definition: btRigidBody.h:433
btScalar getAngularSleepingThreshold() const
Definition: btRigidBody.h:235
void setAngularFactor(const btVector3 &angFac)
Definition: btRigidBody.h:568
btScalar getLinearDamping() const
Definition: btRigidBody.h:220
btTypedConstraint * getConstraintRef(int index)
Definition: btRigidBody.h:593
void setAngularVelocity(const btVector3 &ang_vel)
Definition: btRigidBody.h:451
void setDamping(btScalar lin_damping, btScalar ang_damping)
void setLinearVelocity(const btVector3 &lin_vel)
Definition: btRigidBody.h:442
void updateInertiaTensor()
FILE * file
World world
#define rot(x, k)
static float verts[][3]
bool enabled
int count
void RB_constraint_set_max_impulse_motor(rbConstraint *con, float max_impulse_lin, float max_impulse_ang)
float RB_body_get_angular_damping(rbRigidBody *object)
rbConstraint * RB_constraint_new_point(float pivot[3], rbRigidBody *rb1, rbRigidBody *rb2)
float RB_body_get_linear_damping(rbRigidBody *object)
void RB_dworld_set_solver_iterations(rbDynamicsWorld *world, int num_solver_iterations)
void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *object, int col_groups)
void RB_dworld_set_split_impulse(rbDynamicsWorld *world, int split_impulse)
rbCollisionShape * RB_shape_new_convex_hull(float *verts, int stride, int count, float margin, bool *can_embed)
void RB_dworld_delete(rbDynamicsWorld *world)
rbCollisionShape * RB_shape_new_cone(float radius, float height)
rbCollisionShape * RB_shape_new_compound()
void RB_constraint_set_stiffness_6dof_spring(rbConstraint *con, int axis, float stiffness)
void RB_body_set_restitution(rbRigidBody *object, float value)
void RB_body_set_friction(rbRigidBody *object, float value)
void RB_body_set_mass(rbRigidBody *object, float value)
void RB_body_set_activation_state(rbRigidBody *object, int use_deactivation)
rbCollisionShape * RB_shape_new_box(float x, float y, float z)
void RB_dworld_add_constraint(rbDynamicsWorld *world, rbConstraint *con, int disable_collisions)
void RB_constraint_set_damping_6dof_spring(rbConstraint *con, int axis, float damping)
rbConstraint * RB_constraint_new_motor(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
void RB_shape_delete(rbCollisionShape *shape)
void RB_body_delete(rbRigidBody *object)
rbConstraint * RB_constraint_new_piston(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
void RB_body_get_linear_velocity(rbRigidBody *object, float v_out[3])
void RB_constraint_set_enabled(rbConstraint *con, int enabled)
void RB_body_set_angular_sleep_thresh(rbRigidBody *object, float value)
rbConstraint * RB_constraint_new_6dof_spring(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
void RB_constraint_set_stiffness_6dof_spring2(rbConstraint *con, int axis, float stiffness)
static void RB_trimesh_data_delete(rbMeshData *mesh)
void RB_constraint_set_equilibrium_6dof_spring(rbConstraint *con)
void RB_body_apply_central_force(rbRigidBody *object, const float v_in[3])
void RB_constraint_set_limits_slider(rbConstraint *con, float lower, float upper)
void RB_body_set_angular_damping(rbRigidBody *object, float value)
rbCollisionShape * RB_shape_new_sphere(float radius)
void RB_constraint_set_breaking_threshold(rbConstraint *con, float threshold)
void RB_dworld_remove_constraint(rbDynamicsWorld *world, rbConstraint *con)
void RB_dworld_remove_body(rbDynamicsWorld *world, rbRigidBody *object)
rbConstraint * RB_constraint_new_hinge(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
rbConstraint * RB_constraint_new_fixed(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
rbDynamicsWorld * RB_dworld_new(const float gravity[3])
void RB_world_convex_sweep_test(rbDynamicsWorld *world, rbRigidBody *object, const float loc_start[3], const float loc_end[3], float v_location[3], float v_hitpoint[3], float v_normal[3], int *r_hit)
void RB_constraint_set_enable_motor(rbConstraint *con, int enable_lin, int enable_ang)
void RB_body_get_orientation(rbRigidBody *object, float v_out[4])
void RB_body_set_linear_damping(rbRigidBody *object, float value)
void RB_dworld_set_gravity(rbDynamicsWorld *world, const float g_in[3])
void RB_compound_add_child_shape(rbCollisionShape *parentShape, rbCollisionShape *shape, const float loc[3], const float rot[4])
rbCollisionShape * RB_shape_new_gimpact_mesh(rbMeshData *mesh)
void RB_trimesh_add_triangle_indices(rbMeshData *mesh, int num, int index0, int index1, int index2)
void RB_trimesh_add_vertices(rbMeshData *mesh, float *vertices, int num_verts, int vert_stride)
void RB_constraint_set_limits_6dof_spring2(rbConstraint *con, int axis, float lower, float upper)
float RB_body_get_mass(rbRigidBody *object)
void RB_constraint_set_solver_iterations(rbConstraint *con, int num_solver_iterations)
void RB_shape_trimesh_update(rbCollisionShape *shape, float *vertices, int num_verts, int vert_stride, float min[3], float max[3])
void RB_constraint_set_damping_6dof_spring2(rbConstraint *con, int axis, float damping)
void RB_constraint_delete(rbConstraint *con)
void RB_body_set_collision_shape(rbRigidBody *object, rbCollisionShape *shape)
static void copy_quat_btquat(float quat[4], const btQuaternion &btquat)
void RB_body_set_scale(rbRigidBody *object, const float scale[3])
void RB_body_set_damping(rbRigidBody *object, float linear, float angular)
void RB_body_get_angular_velocity(rbRigidBody *object, float v_out[3])
void RB_constraint_set_spring_6dof_spring(rbConstraint *con, int axis, int enable)
void RB_shape_set_margin(rbCollisionShape *shape, float value)
void RB_body_set_linear_sleep_thresh(rbRigidBody *object, float value)
void RB_body_set_linear_velocity(rbRigidBody *object, const float v_in[3])
void RB_body_deactivate(rbRigidBody *object)
rbRigidBody * RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4])
void RB_body_set_kinematic_state(rbRigidBody *object, int kinematic)
void RB_trimesh_finish(rbMeshData *mesh)
void RB_body_get_position(rbRigidBody *object, float v_out[3])
void RB_dworld_export(rbDynamicsWorld *world, const char *filename)
float RB_shape_get_margin(rbCollisionShape *shape)
rbCollisionShape * RB_shape_new_cylinder(float radius, float height)
rbConstraint * RB_constraint_new_6dof_spring2(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
void RB_constraint_set_limits_piston(rbConstraint *con, float lin_lower, float lin_upper, float ang_lower, float ang_upper)
static void copy_v3_btvec3(float vec[3], const btVector3 &btvec)
void RB_dworld_get_gravity(rbDynamicsWorld *world, float g_out[3])
void RB_body_get_transform_matrix(rbRigidBody *object, float m_out[4][4])
void RB_constraint_set_limits_6dof(rbConstraint *con, int axis, float lower, float upper)
void RB_body_set_loc_rot(rbRigidBody *object, const float loc[3], const float rot[4])
void RB_constraint_set_limits_hinge(rbConstraint *con, float lower, float upper)
rbMeshData * RB_trimesh_data_new(int num_tris, int num_verts)
void RB_constraint_set_target_velocity_motor(rbConstraint *con, float velocity_lin, float velocity_ang)
float RB_body_get_friction(rbRigidBody *object)
rbCollisionShape * RB_shape_new_trimesh(rbMeshData *mesh)
void RB_body_set_angular_velocity(rbRigidBody *object, const float v_in[3])
static void make_constraint_transforms(btTransform &transform1, btTransform &transform2, btRigidBody *body1, btRigidBody *body2, float pivot[3], float orn[4])
void RB_body_activate(rbRigidBody *object)
void RB_body_set_linear_factor(rbRigidBody *object, float x, float y, float z)
void RB_body_set_sleep_thresh(rbRigidBody *object, float linear, float angular)
rbConstraint * RB_constraint_new_slider(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
void RB_dworld_step_simulation(rbDynamicsWorld *world, float timeStep, int maxSubSteps, float timeSubStep)
void RB_constraint_set_equilibrium_6dof_spring2(rbConstraint *con)
float RB_body_get_linear_sleep_thresh(rbRigidBody *object)
void RB_body_get_scale(rbRigidBody *object, float v_out[3])
rbConstraint * RB_constraint_new_6dof(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
void RB_constraint_set_spring_6dof_spring2(rbConstraint *con, int axis, int enable)
rbCollisionShape * RB_shape_new_capsule(float radius, float height)
void RB_body_set_angular_factor(rbRigidBody *object, float x, float y, float z)
float RB_body_get_angular_sleep_thresh(rbRigidBody *object)
float RB_body_get_restitution(rbRigidBody *object)
#define min(a, b)
Definition: sort.c:51
size_t num_triangles() const
Definition: mesh.h:92
rbCollisionShape ** compoundChildShapes
btCollisionShape * cshape
rbMeshData * mesh
btBroadphaseInterface * pairCache
btConstraintSolver * constraintSolver
btDefaultCollisionConfiguration * collisionConfiguration
btDiscreteDynamicsWorld * dynamicsWorld
btOverlapFilterCallback * filterCallback
btDispatcher * dispatcher
virtual bool needBroadphaseCollision(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const
rbVert * vertices
rbTri * triangles
btTriangleIndexVertexArray * index_array
btRigidBody * body
btScalar y
btScalar x
btScalar z
float max