diff options
Diffstat (limited to 'intern/rigidbody')
-rw-r--r-- | intern/rigidbody/CMakeLists.txt | 4 | ||||
-rw-r--r-- | intern/rigidbody/RBI_api.h | 6 | ||||
-rw-r--r-- | intern/rigidbody/RBI_hull_api.h | 43 | ||||
-rw-r--r-- | intern/rigidbody/rb_bullet_api.cpp | 10 | ||||
-rw-r--r-- | intern/rigidbody/rb_convex_hull_api.cpp | 83 |
5 files changed, 144 insertions, 2 deletions
diff --git a/intern/rigidbody/CMakeLists.txt b/intern/rigidbody/CMakeLists.txt index 77d88548e1b..91cfc312bd2 100644 --- a/intern/rigidbody/CMakeLists.txt +++ b/intern/rigidbody/CMakeLists.txt @@ -18,6 +18,8 @@ # All rights reserved. # ***** END GPL LICENSE BLOCK ***** +add_definitions(-DBT_USE_DOUBLE_PRECISION) + set(INC . ) @@ -28,7 +30,9 @@ set(INC_SYS set(SRC rb_bullet_api.cpp + rb_convex_hull_api.cpp + RBI_hull_api.h RBI_api.h ) diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h index 07cda49e04b..2e09f8952cb 100644 --- a/intern/rigidbody/RBI_api.h +++ b/intern/rigidbody/RBI_api.h @@ -200,10 +200,12 @@ void RB_body_set_scale(rbRigidBody *body, const float scale[3]); /* ............ */ -/* Get RigidBody's position as vector */ +/* Get RigidBody's position as a vector */ void RB_body_get_position(rbRigidBody *body, float v_out[3]); -/* Get RigidBody's orientation as quaternion */ +/* Get RigidBody's orientation as a quaternion */ void RB_body_get_orientation(rbRigidBody *body, float v_out[4]); +/* Get RigidBody's local scale as a vector */ +void RB_body_get_scale(rbRigidBody *object, float v_out[3]); /* ............ */ diff --git a/intern/rigidbody/RBI_hull_api.h b/intern/rigidbody/RBI_hull_api.h new file mode 100644 index 00000000000..9d2dc5034db --- /dev/null +++ b/intern/rigidbody/RBI_hull_api.h @@ -0,0 +1,43 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation, + * All rights reserved. + */ + +#ifndef __RB_HULL_API_H__ +#define __RB_HULL_API_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct plConvexHull__ { + int unused; +} * plConvexHull; + +plConvexHull plConvexHullCompute(float (*coords)[3], int count); +void plConvexHullDelete(plConvexHull hull); +int plConvexHullNumVertices(plConvexHull hull); +int plConvexHullNumFaces(plConvexHull hull); +void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3], int *original_index); +int plConvexHullGetFaceSize(plConvexHull hull, int n); +void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices); + +#ifdef __cplusplus +} +#endif + +#endif /* __RB_HULL_API_H__ */ diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp index b5814055cf8..daa377a7b55 100644 --- a/intern/rigidbody/rb_bullet_api.cpp +++ b/intern/rigidbody/rb_bullet_api.cpp @@ -649,6 +649,16 @@ void RB_body_get_orientation(rbRigidBody *object, float v_out[4]) copy_quat_btquat(v_out, body->getWorldTransform().getRotation()); } +void RB_body_get_scale(rbRigidBody *object, float v_out[3]) +{ + btRigidBody *body = object->body; + + btCollisionShape *cshape = body->getCollisionShape(); + /* The body should have a collision shape when we try to set the scale. */ + btAssert(cshape); + copy_v3_btvec3(v_out, cshape->getLocalScaling()); +} + /* ............ */ /* Overrides for simulation */ diff --git a/intern/rigidbody/rb_convex_hull_api.cpp b/intern/rigidbody/rb_convex_hull_api.cpp new file mode 100644 index 00000000000..c5893a4c808 --- /dev/null +++ b/intern/rigidbody/rb_convex_hull_api.cpp @@ -0,0 +1,83 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation, + * All rights reserved. + */ + +#include "LinearMath/btConvexHullComputer.h" +#include "RBI_hull_api.h" + +plConvexHull plConvexHullCompute(float (*coords)[3], int count) +{ + btConvexHullComputer *computer = new btConvexHullComputer; + computer->compute(reinterpret_cast<float *>(coords), sizeof(*coords), count, 0, 0); + return reinterpret_cast<plConvexHull>(computer); +} + +void plConvexHullDelete(plConvexHull hull) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + delete computer; +} + +int plConvexHullNumVertices(plConvexHull hull) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + return computer->vertices.size(); +} + +int plConvexHullNumFaces(plConvexHull hull) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + return computer->faces.size(); +} + +void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3], int *original_index) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + const btVector3 &v(computer->vertices[n]); + coords[0] = v[0]; + coords[1] = v[1]; + coords[2] = v[2]; + (*original_index) = computer->original_vertex_index[n]; +} + +int plConvexHullGetFaceSize(plConvexHull hull, int n) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + const btConvexHullComputer::Edge *e_orig, *e; + int count; + + for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0; + count == 0 || e != e_orig; + e = e->getNextEdgeOfFace(), count++) { + ; + } + return count; +} + +void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices) +{ + btConvexHullComputer *computer(reinterpret_cast<btConvexHullComputer *>(hull)); + const btConvexHullComputer::Edge *e_orig, *e; + int count; + + for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0; + count == 0 || e != e_orig; + e = e->getNextEdgeOfFace(), count++) { + vertices[count] = e->getTargetVertex(); + } +} |