Ejemplo n.º 1
0
void RigidCollisionObjectBullet::reload_shapes() {

	if (mainShape && mainShape->isCompound()) {
		// Destroy compound
		bulletdelete(mainShape);
	}

	mainShape = NULL;

	ShapeWrapper *shpWrapper;
	const int shape_count = shapes.size();

	// Reset shape if required
	if (force_shape_reset) {
		for (int i(0); i < shape_count; ++i) {
			shpWrapper = &shapes.write[i];
			bulletdelete(shpWrapper->bt_shape);
		}
		force_shape_reset = false;
	}

	const btVector3 body_scale(get_bt_body_scale());

	// Try to optimize by not using compound
	if (1 == shape_count) {
		shpWrapper = &shapes.write[0];
		if (shpWrapper->transform.getOrigin().isZero() && shpWrapper->transform.getBasis() == shpWrapper->transform.getBasis().getIdentity()) {
			shpWrapper->claim_bt_shape(body_scale);
			mainShape = shpWrapper->bt_shape;
			main_shape_changed();
			return;
		}
	}

	// Optimization not possible use a compound shape
	btCompoundShape *compoundShape = bulletnew(btCompoundShape(enableDynamicAabbTree, shape_count));

	for (int i(0); i < shape_count; ++i) {
		shpWrapper = &shapes.write[i];
		shpWrapper->claim_bt_shape(body_scale);
		btTransform scaled_shape_transform(shpWrapper->transform);
		scaled_shape_transform.getOrigin() *= body_scale;
		compoundShape->addChildShape(scaled_shape_transform, shpWrapper->bt_shape);
	}

	compoundShape->recalculateLocalAabb();
	mainShape = compoundShape;
	main_shape_changed();
}
Ejemplo n.º 2
0
RigidBodyBullet::~RigidBodyBullet() {
	bulletdelete(godotMotionState);

	if (force_integration_callback)
		memdelete(force_integration_callback);

	destroy_kinematic_utilities();
}
Ejemplo n.º 3
0
void RigidBodyBullet::KinematicUtilities::just_delete_shapes(int new_size) {
	for (int i = shapes.size() - 1; 0 <= i; --i) {
		if (shapes[i].shape) {
			bulletdelete(shapes.write[i].shape);
		}
	}
	shapes.resize(new_size);
}
Ejemplo n.º 4
0
void RigidCollisionObjectBullet::internal_shape_destroy(int p_index, bool p_permanentlyFromThisBody) {
	ShapeWrapper &shp = shapes.write[p_index];
	shp.shape->remove_owner(this, p_permanentlyFromThisBody);
	if (shp.bt_shape == mainShape) {
		mainShape = NULL;
	}
	bulletdelete(shp.bt_shape);
}
Ejemplo n.º 5
0
void RigidCollisionObjectBullet::shape_changed(int p_shape_index) {
	ShapeWrapper &shp = shapes.write[p_shape_index];
	if (shp.bt_shape == mainShape) {
		mainShape = NULL;
	}
	bulletdelete(shp.bt_shape);
	reload_shapes();
}
Ejemplo n.º 6
0
void BulletPhysicsServer::free(RID p_rid) {
	if (shape_owner.owns(p_rid)) {

		ShapeBullet *shape = shape_owner.get(p_rid);

		// Notify the shape is configured
		for (Map<ShapeOwnerBullet *, int>::Element *element = shape->get_owners().front(); element; element = element->next()) {
			static_cast<ShapeOwnerBullet *>(element->key())->remove_shape(shape);
		}

		shape_owner.free(p_rid);
		bulletdelete(shape);
	} else if (rigid_body_owner.owns(p_rid)) {

		RigidBodyBullet *body = rigid_body_owner.get(p_rid);

		body->set_space(NULL);

		body->remove_all_shapes(true);

		rigid_body_owner.free(p_rid);
		bulletdelete(body);

	} else if (soft_body_owner.owns(p_rid)) {

		SoftBodyBullet *body = soft_body_owner.get(p_rid);

		body->set_space(NULL);

		soft_body_owner.free(p_rid);
		bulletdelete(body);

	} else if (area_owner.owns(p_rid)) {

		AreaBullet *area = area_owner.get(p_rid);

		area->set_space(NULL);

		area->remove_all_shapes(true);

		area_owner.free(p_rid);
		bulletdelete(area);

	} else if (joint_owner.owns(p_rid)) {

		JointBullet *joint = joint_owner.get(p_rid);
		joint->destroy_internal_constraint();
		joint_owner.free(p_rid);
		bulletdelete(joint);

	} else if (space_owner.owns(p_rid)) {

		SpaceBullet *space = space_owner.get(p_rid);

		space->remove_all_collision_objects();

		space_set_active(p_rid, false);
		space_owner.free(p_rid);
		bulletdelete(space);
	} else {

		ERR_EXPLAIN("Invalid ID");
		ERR_FAIL();
	}
}
Ejemplo n.º 7
0
SoftBodyBullet::~SoftBodyBullet() {
	bulletdelete(soft_body_shape_data);
}
Ejemplo n.º 8
0
void SoftBodyBullet::set_body_shape_data(SoftShapeData *p_soft_shape_data, SoftShapeType p_type) {
	bulletdelete(soft_body_shape_data);
	soft_body_shape_data = p_soft_shape_data;
	soft_shape_type = p_type;
}
Ejemplo n.º 9
0
RigidCollisionObjectBullet::~RigidCollisionObjectBullet() {
	remove_all_shapes(true, true);
	if (mainShape && mainShape->isCompound()) {
		bulletdelete(mainShape);
	}
}
Ejemplo n.º 10
0
void CollisionObjectBullet::destroyBulletCollisionObject() {
	bulletdelete(bt_collision_object);
}