BKE_rigidbody.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /** \file BKE_rigidbody.h
  28. * \ingroup blenkernel
  29. * \brief API for Blender-side Rigid Body stuff
  30. */
  31. #ifndef __BKE_RIGIDBODY_H__
  32. #define __BKE_RIGIDBODY_H__
  33. struct RigidBodyWorld;
  34. struct RigidBodyOb;
  35. struct Scene;
  36. struct Object;
  37. /* -------------- */
  38. /* Memory Management */
  39. void BKE_rigidbody_free_world(struct RigidBodyWorld *rbw);
  40. void BKE_rigidbody_free_object(struct Object *ob);
  41. void BKE_rigidbody_free_constraint(struct Object *ob);
  42. /* ...... */
  43. struct RigidBodyOb *BKE_rigidbody_copy_object(const struct Object *ob);
  44. struct RigidBodyCon *BKE_rigidbody_copy_constraint(const struct Object *ob);
  45. /* Callback format for performing operations on ID-pointers for rigidbody world. */
  46. typedef void (*RigidbodyWorldIDFunc)(struct RigidBodyWorld *rbw, struct ID **idpoin, void *userdata, int cb_flag);
  47. void BKE_rigidbody_world_id_loop(struct RigidBodyWorld *rbw, RigidbodyWorldIDFunc func, void *userdata);
  48. /* -------------- */
  49. /* Setup */
  50. /* create Blender-side settings data - physics objects not initialized yet */
  51. struct RigidBodyWorld *BKE_rigidbody_create_world(struct Scene *scene);
  52. struct RigidBodyOb *BKE_rigidbody_create_object(struct Scene *scene, struct Object *ob, short type);
  53. struct RigidBodyCon *BKE_rigidbody_create_constraint(struct Scene *scene, struct Object *ob, short type);
  54. /* copy */
  55. struct RigidBodyWorld *BKE_rigidbody_world_copy(struct RigidBodyWorld *rbw);
  56. void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw);
  57. /* 'validate' (i.e. make new or replace old) Physics-Engine objects */
  58. void BKE_rigidbody_validate_sim_world(struct Scene *scene, struct RigidBodyWorld *rbw, bool rebuild);
  59. void BKE_rigidbody_calc_volume(struct Object *ob, float *r_vol);
  60. void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_center[3]);
  61. /* -------------- */
  62. /* Utilities */
  63. struct RigidBodyWorld *BKE_rigidbody_get_world(struct Scene *scene);
  64. void BKE_rigidbody_remove_object(struct Scene *scene, struct Object *ob);
  65. void BKE_rigidbody_remove_constraint(struct Scene *scene, struct Object *ob);
  66. /* -------------- */
  67. /* Utility Macros */
  68. /* get mass of Rigid Body Object to supply to RigidBody simulators */
  69. #define RBO_GET_MASS(rbo) \
  70. ((rbo && ((rbo->type == RBO_TYPE_PASSIVE) || (rbo->flag & RBO_FLAG_KINEMATIC) || (rbo->flag & RBO_FLAG_DISABLED))) ? (0.0f) : (rbo->mass))
  71. /* get collision margin for Rigid Body Object, triangle mesh and cone shapes cannot embed margin, convex hull always uses custom margin */
  72. #define RBO_GET_MARGIN(rbo) \
  73. ((rbo->flag & RBO_FLAG_USE_MARGIN || rbo->shape == RB_SHAPE_CONVEXH || rbo->shape == RB_SHAPE_TRIMESH || rbo->shape == RB_SHAPE_CONE) ? (rbo->margin) : (0.04f))
  74. /* -------------- */
  75. /* Simulation */
  76. void BKE_rigidbody_aftertrans_update(struct Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle);
  77. void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime);
  78. bool BKE_rigidbody_check_sim_running(struct RigidBodyWorld *rbw, float ctime);
  79. void BKE_rigidbody_cache_reset(struct RigidBodyWorld *rbw);
  80. void BKE_rigidbody_rebuild_world(struct Scene *scene, float ctime);
  81. void BKE_rigidbody_do_simulation(struct Scene *scene, float ctime);
  82. /* -------------------- */
  83. /* Depsgraph evaluation */
  84. struct EvaluationContext;
  85. void BKE_rigidbody_rebuild_sim(struct EvaluationContext *eval_ctx,
  86. struct Scene *scene);
  87. void BKE_rigidbody_eval_simulation(struct EvaluationContext *eval_ctx,
  88. struct Scene *scene);
  89. void BKE_rigidbody_object_sync_transforms(struct EvaluationContext *eval_ctx,
  90. struct Scene *scene,
  91. struct Object *ob);
  92. #endif /* __BKE_RIGIDBODY_H__ */