Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btCompoundShape not working with dynamic aabb tree enabled #4673

Open
Fewnity opened this issue Nov 21, 2024 · 0 comments
Open

btCompoundShape not working with dynamic aabb tree enabled #4673

Fewnity opened this issue Nov 21, 2024 · 0 comments

Comments

@Fewnity
Copy link

Fewnity commented Nov 21, 2024

I noticed something weird with compound shapes, on PC, PlayStation Portable, PlayStation Vita I don't have any problem with compound shapes, but on PlayStation 3 it's not working well. (Using GCC 7.2 C++17 with the open source sdk, none of the PS3 specific code of bullet is used, PS3 defines used by bullet are no defined in my case, I'm not using the SPU).

Everything works fine when I'm doing this

compoundShape = new btCompoundShape(false);

but collisions are buggy with this instead

compoundShape = new btCompoundShape();

When I add children to the compound shape, looks like only the first (or last idk) added shape is affected by collisions, but other shapes do not collide with other objects of the scene.

Here is a sample, on PC the final Y position of the cube is 2, but on PS3 the final Y position is 1.

btDefaultCollisionConfiguration collisionConfig;
btCollisionDispatcher dispatcher(&collisionConfig);
btDbvtBroadphase broadphase;
btSequentialImpulseConstraintSolver solver;
btDiscreteDynamicsWorld world(&dispatcher, &broadphase, &solver, &collisionConfig);
world.setGravity(btVector3(0, -9.81, 0));

// Static ground
btCollisionShape* groundShape = new btBoxShape(btVector3(1, 1, 1));
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, 0, 0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
world.addRigidBody(groundRigidBody);

btCompoundShape* compoundShape = new btCompoundShape();

// Add shapes to the compound shape
for (int i = 0; i < 2; ++i) {
	btBoxShape* box = new btBoxShape(btVector3(1, 1, 1));
	btTransform transform;
	transform.setIdentity();
	transform.setOrigin(btVector3(0, 1-i, 0));
	compoundShape->addChildShape(transform, box);
}

btDefaultMotionState* compoundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 10, 0)));
btScalar mass = 5.0;
btVector3 inertia(0, 0, 0);
compoundShape->calculateLocalInertia(mass, inertia);
btRigidBody::btRigidBodyConstructionInfo compoundRigidBodyCI(mass, compoundMotionState, compoundShape, inertia);
btRigidBody* compoundRigidBody = new btRigidBody(compoundRigidBodyCI);
world.addRigidBody(compoundRigidBody);

// Simulation
for (int i = 0; i < 300; i++) 
{
	world.stepSimulation(1.f / 60.f, 10);

	btTransform transform;
	compoundRigidBody->getMotionState()->getWorldTransform(transform);
	std::cout << "Step " << i << ": Position = "
		<< transform.getOrigin().getX() << ", "
		<< transform.getOrigin().getY() << ", "
		<< transform.getOrigin().getZ() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant