Changeset View
Changeset View
Standalone View
Standalone View
intern/rigidbody/rb_bullet_api.cpp
| Show First 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | struct rbDynamicsWorld { | ||||
| btOverlapFilterCallback *filterCallback; | btOverlapFilterCallback *filterCallback; | ||||
| }; | }; | ||||
| struct rbRigidBody { | struct rbRigidBody { | ||||
| btRigidBody *body; | btRigidBody *body; | ||||
| int col_groups; | int col_groups; | ||||
| }; | }; | ||||
| struct rbVert { | struct rbVert { | ||||
| float x, y, z; | btScalar x, y, z; | ||||
| }; | }; | ||||
| struct rbTri { | struct rbTri { | ||||
| int v0, v1, v2; | int v0, v1, v2; | ||||
| }; | }; | ||||
| struct rbMeshData { | struct rbMeshData { | ||||
| btTriangleIndexVertexArray *index_array; | btTriangleIndexVertexArray *index_array; | ||||
| rbVert *vertices; | rbVert *vertices; | ||||
| ▲ Show 20 Lines • Show All 258 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void RB_body_delete(rbRigidBody *object) | void RB_body_delete(rbRigidBody *object) | ||||
| { | { | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| /* motion state */ | /* motion state */ | ||||
| btMotionState *ms = body->getMotionState(); | btMotionState *ms = body->getMotionState(); | ||||
| if (ms) | |||||
| delete ms; | delete ms; | ||||
| /* collision shape is done elsewhere... */ | /* collision shape is done elsewhere... */ | ||||
| /* body itself */ | /* body itself */ | ||||
| /* manually remove constraint refs of the rigid body, normally this happens when removing | /* manually remove constraint refs of the rigid body, normally this happens when removing | ||||
| * constraints from the world | * constraints from the world | ||||
| * but since we delete everything when the world is rebult, we need to do it manually here */ | * but since we delete everything when the world is rebult, we need to do it manually here */ | ||||
| Show All 25 Lines | |||||
| { | { | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| /* there isn't really a mass setting, but rather 'inverse mass' | /* there isn't really a mass setting, but rather 'inverse mass' | ||||
| * which we convert back to mass by taking the reciprocal again | * which we convert back to mass by taking the reciprocal again | ||||
| */ | */ | ||||
| float value = (float)body->getInvMass(); | float value = (float)body->getInvMass(); | ||||
| if (value) | if (value) { | ||||
| value = 1.0f / value; | value = 1.0f / value; | ||||
| } | |||||
| return value; | return value; | ||||
| } | } | ||||
| void RB_body_set_mass(rbRigidBody *object, float value) | void RB_body_set_mass(rbRigidBody *object, float value) | ||||
| { | { | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| btVector3 localInertia(0, 0, 0); | btVector3 localInertia(0, 0, 0); | ||||
| ▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | void RB_body_set_angular_factor(rbRigidBody *object, float x, float y, float z) | ||||
| body->setAngularFactor(btVector3(x, y, z)); | body->setAngularFactor(btVector3(x, y, z)); | ||||
| } | } | ||||
| /* ............ */ | /* ............ */ | ||||
| void RB_body_set_kinematic_state(rbRigidBody *object, int kinematic) | void RB_body_set_kinematic_state(rbRigidBody *object, int kinematic) | ||||
| { | { | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| if (kinematic) | if (kinematic) { | ||||
| body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); | body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); | ||||
| else | } | ||||
| else { | |||||
| body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT); | body->setCollisionFlags(body->getCollisionFlags() & ~btCollisionObject::CF_KINEMATIC_OBJECT); | ||||
| } | } | ||||
| } | |||||
| /* ............ */ | /* ............ */ | ||||
| void RB_body_set_activation_state(rbRigidBody *object, int use_deactivation) | void RB_body_set_activation_state(rbRigidBody *object, int use_deactivation) | ||||
| { | { | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| if (use_deactivation) | if (use_deactivation) { | ||||
| body->forceActivationState(ACTIVE_TAG); | body->forceActivationState(ACTIVE_TAG); | ||||
| else | } | ||||
| else { | |||||
| body->setActivationState(DISABLE_DEACTIVATION); | body->setActivationState(DISABLE_DEACTIVATION); | ||||
| } | } | ||||
| } | |||||
| void RB_body_activate(rbRigidBody *object) | void RB_body_activate(rbRigidBody *object) | ||||
| { | { | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| body->setActivationState(ACTIVE_TAG); | body->setActivationState(ACTIVE_TAG); | ||||
| } | } | ||||
| void RB_body_deactivate(rbRigidBody *object) | void RB_body_deactivate(rbRigidBody *object) | ||||
| { | { | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| Show All 38 Lines | void RB_body_set_scale(rbRigidBody *object, const float scale[3]) | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| /* apply scaling factor from matrix above to the collision shape */ | /* apply scaling factor from matrix above to the collision shape */ | ||||
| btCollisionShape *cshape = body->getCollisionShape(); | btCollisionShape *cshape = body->getCollisionShape(); | ||||
| if (cshape) { | if (cshape) { | ||||
| cshape->setLocalScaling(btVector3(scale[0], scale[1], scale[2])); | cshape->setLocalScaling(btVector3(scale[0], scale[1], scale[2])); | ||||
| /* GIimpact shapes have to be updated to take scaling into account */ | /* GIimpact shapes have to be updated to take scaling into account */ | ||||
| if (cshape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE) | if (cshape->getShapeType() == GIMPACT_SHAPE_PROXYTYPE) { | ||||
| ((btGImpactMeshShape *)cshape)->updateBound(); | ((btGImpactMeshShape *)cshape)->updateBound(); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| /* ............ */ | /* ............ */ | ||||
| /* Read-only state info about status of simulation */ | /* Read-only state info about status of simulation */ | ||||
| void RB_body_get_position(rbRigidBody *object, float v_out[3]) | void RB_body_get_position(rbRigidBody *object, float v_out[3]) | ||||
| { | { | ||||
| btRigidBody *body = object->body; | btRigidBody *body = object->body; | ||||
| ▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| void RB_trimesh_finish(rbMeshData *mesh) | void RB_trimesh_finish(rbMeshData *mesh) | ||||
| { | { | ||||
| mesh->index_array = new btTriangleIndexVertexArray(mesh->num_triangles, | mesh->index_array = new btTriangleIndexVertexArray(mesh->num_triangles, | ||||
| (int *)mesh->triangles, | (int *)mesh->triangles, | ||||
| sizeof(rbTri), | sizeof(rbTri), | ||||
| mesh->num_vertices, | mesh->num_vertices, | ||||
| (float *)mesh->vertices, | (btScalar *)mesh->vertices, | ||||
| sizeof(rbVert)); | sizeof(rbVert)); | ||||
| } | } | ||||
| rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh) | rbCollisionShape *RB_shape_new_trimesh(rbMeshData *mesh) | ||||
| { | { | ||||
| rbCollisionShape *shape = new rbCollisionShape; | rbCollisionShape *shape = new rbCollisionShape; | ||||
| /* triangle-mesh we create is a BVH wrapper for triangle mesh data (for faster lookups) */ | /* triangle-mesh we create is a BVH wrapper for triangle mesh data (for faster lookups) */ | ||||
| Show All 10 Lines | |||||
| void RB_shape_trimesh_update(rbCollisionShape *shape, | void RB_shape_trimesh_update(rbCollisionShape *shape, | ||||
| float *vertices, | float *vertices, | ||||
| int num_verts, | int num_verts, | ||||
| int vert_stride, | int vert_stride, | ||||
| float min[3], | float min[3], | ||||
| float max[3]) | float max[3]) | ||||
| { | { | ||||
| if (shape->mesh == NULL || num_verts != shape->mesh->num_vertices) | if (shape->mesh == NULL || num_verts != shape->mesh->num_vertices) { | ||||
| return; | return; | ||||
| } | |||||
| for (int i = 0; i < num_verts; i++) { | for (int i = 0; i < num_verts; i++) { | ||||
| float *vert = (float *)(((char *)vertices + i * vert_stride)); | float *vert = (float *)(((char *)vertices + i * vert_stride)); | ||||
| shape->mesh->vertices[i].x = vert[0]; | shape->mesh->vertices[i].x = vert[0]; | ||||
| shape->mesh->vertices[i].y = vert[1]; | shape->mesh->vertices[i].y = vert[1]; | ||||
| shape->mesh->vertices[i].z = vert[2]; | shape->mesh->vertices[i].z = vert[2]; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
| /* Cleanup --------------------------- */ | /* Cleanup --------------------------- */ | ||||
| void RB_shape_delete(rbCollisionShape *shape) | void RB_shape_delete(rbCollisionShape *shape) | ||||
| { | { | ||||
| if (shape->cshape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) { | if (shape->cshape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) { | ||||
| btBvhTriangleMeshShape *child_shape = | btBvhTriangleMeshShape *child_shape = | ||||
| ((btScaledBvhTriangleMeshShape *)shape->cshape)->getChildShape(); | ((btScaledBvhTriangleMeshShape *)shape->cshape)->getChildShape(); | ||||
| if (child_shape) | |||||
| delete child_shape; | delete child_shape; | ||||
| } | } | ||||
| if (shape->mesh) | if (shape->mesh) { | ||||
| RB_trimesh_data_delete(shape->mesh); | RB_trimesh_data_delete(shape->mesh); | ||||
| } | |||||
| delete shape->cshape; | delete shape->cshape; | ||||
| /* Delete compound child shapes if there are any */ | /* Delete compound child shapes if there are any */ | ||||
| for (int i = 0; i < shape->compoundChilds; i++) { | for (int i = 0; i < shape->compoundChilds; i++) { | ||||
| RB_shape_delete(shape->compoundChildShapes[i]); | RB_shape_delete(shape->compoundChildShapes[i]); | ||||
| } | } | ||||
| if (shape->compoundChildShapes != NULL) { | if (shape->compoundChildShapes != NULL) { | ||||
| free(shape->compoundChildShapes); | free(shape->compoundChildShapes); | ||||
| ▲ Show 20 Lines • Show All 390 Lines • Show Last 20 Lines | |||||