btBvhTriangleMeshShape does not react to physics

Post Reply
standtall007
Posts: 4
Joined: Tue Jun 14, 2016 4:24 pm

btBvhTriangleMeshShape does not react to physics

Post by standtall007 »

Hi i am new to Bullet Physics and i have been trying to implement it into my game engine.
i have a huge problem, i can render the triangleMesh, but i cannot apply physics to it!

here is the base code i use for the adding and rendering with bullet:

Code: Select all

btRigidBody *addPhysicsMesh(float mass)
	{
		btTriangleMesh *mesh = new btTriangleMesh();

		for (int i = 0; i < m_model->faces; ++i)
		{
			GLuint index0 = 3 * m_model->indices[i];
			GLuint index1 = 3 * m_model->indices[i + 1];
			GLuint index2 = 3 * m_model->indices[i + 2];

			GLfloat *pos0 = m_model->verts[index0];
			GLfloat *pos1 = m_model->verts[index1];
			GLfloat *pos2 = m_model->verts[index2];

			btVector3 v0(pos0[0], pos0[1], pos0[2]);
			btVector3 v1(pos1[0], pos1[1], pos1[2]);
			btVector3 v2(pos2[0], pos2[1], pos2[2]);

			mesh->addTriangle(v0, v1, v2);
		}

		btCollisionShape *shape = new btBvhTriangleMeshShape(mesh, true);

		btTransform t;
		t.setIdentity();
		t.setOrigin(btVector3(m_positionXYZ.x, m_positionXYZ.y, m_positionXYZ.z));

		btDefaultMotionState *motion = new btDefaultMotionState(t);

		btVector3 inertia(0.0f, 0.0f, 0.0f);

		if (mass != 0.0f)
			shape->calculateLocalInertia(mass, inertia);

		btRigidBody::btRigidBodyConstructionInfo info(mass, motion, shape, inertia);
		btRigidBody *body = new btRigidBody(info);
		
		return body;
	}

	void renderPhysicsMesh(btRigidBody *mesh, ShaderProgram shader)
	{
		if (mesh->getCollisionShape()->getShapeType() != TRIANGLE_MESH_SHAPE_PROXYTYPE)
			return;

		btTransform t;

		mesh->getMotionState()->getWorldTransform(t);

		float mat[16];
		t.getOpenGLMatrix(mat);

		glPushMatrix();

		glMultMatrixf(mat);

		m_model->Draw(shader);

		glPopMatrix();
	}
I appreciate all the help i can get, and the only thing the bullet physics won't do at this point is to use the mass and pull a model downwards!
I should also note that i have been setting the world's gravity so it shouldn't be that, but please let me know if the gravity has to be updated all the time, since i am unaware of this.

Thanks for making this physics system open source :)
Last edited by standtall007 on Mon Jun 20, 2016 1:11 pm, edited 1 time in total.
inzombiak
Posts: 16
Joined: Wed Nov 25, 2015 3:34 pm

Re: How come this not working?

Post by inzombiak »

The mass your'e passing isn't 0 by any chance right? Bullet treats a mass of 0 like it is infinite heavy and thus immovable.
standtall007
Posts: 4
Joined: Tue Jun 14, 2016 4:24 pm

Re: How come this not working?

Post by standtall007 »

inzombiak wrote:The mass your'e passing isn't 0 by any chance right? Bullet treats a mass of 0 like it is infinite heavy and thus immovable.
Nope the mass was set to both 1.0f and a wopping 100.0f and neither worked but just how significant is the btRigidBody->setUserPointer(void*)?

i have an example on how i add the objects to the discreteWorld:

Code: Select all

if (k < gameObjects.size())
	{
		body = gameObjects[k]->addPhysicsMesh(0.0f);

		world->addRigidBody(body);
		rigidbodies.push_back(body);

		body->setUserPointer((void*)k);

		k++;
	}
inzombiak
Posts: 16
Joined: Wed Nov 25, 2015 3:34 pm

Re: How come this not working?

Post by inzombiak »

Well in that snippet the mass is 0.
The user pointer isn't a necessity from what I know. It just allows you to bind a pointer (Like one to the object that owns said body) to the btRigidBody. Then when collisions happen or you do a ray cast you can get the object from the btRigidBody.

How is the physics not working? Does the regular Hello World example work? Are tri meshes the only ones that give you issues?
standtall007
Posts: 4
Joined: Tue Jun 14, 2016 4:24 pm

Re: How come this not working?

Post by standtall007 »

inzombiak wrote:Well in that snippet the mass is 0.
The user pointer isn't a necessity from what I know. It just allows you to bind a pointer (Like one to the object that owns said body) to the btRigidBody. Then when collisions happen or you do a ray cast you can get the object from the btRigidBody.

How is the physics not working? Does the regular Hello World example work? Are tri meshes the only ones that give you issues?
To be honest i practically just started to learn Bullet Physics, so i haven't tried any examples yet, instead i tried to follow some tutorials regarding Bullet...
Maybe a dumb move from my point of view :P but i got so much going on with my engine so i have to try and see if i can get things to work!

Regarding how the physics are not working: well it visualizes the model i import (it draws it so that part doesn't contain errors!) but the model(s) imported aren't actually falling downwards when they have a mass higher than 0.0! and they don't either when the mass actually is at 0.0!
inzombiak
Posts: 16
Joined: Wed Nov 25, 2015 3:34 pm

Re: How come this not working?

Post by inzombiak »

Do you add the bodies to the physics world? Is the world set up correctly?

I recommend at least looking at the Hello World example on the wiki.
standtall007
Posts: 4
Joined: Tue Jun 14, 2016 4:24 pm

Re: How come this not working?

Post by standtall007 »

inzombiak wrote:Do you add the bodies to the physics world? Is the world set up correctly?

I recommend at least looking at the Hello World example on the wiki.
I believe that the DynamicWorld is set up correctly but of course i could be wrong.
Thanks for the tip, i will definitely look at the Hello World example, and i will return here if it doesn't work out for me either.

Thanks a lot for your help inzombiak, i really appreciate your help :)

Cheers,
David.
S1L3nCe
Posts: 50
Joined: Thu Mar 24, 2016 10:22 am
Location: France

Re: How come this not working?

Post by S1L3nCe »

Hi,

btBvhTriangleMeshShape is static only, you can't apply physics on it.
You can use btConvexHullShape for create dynamic convex shapes.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: How come this not working?

Post by benelot »

And please go to your first post and edit its title to something more meaningful like "btBvhTriangleMeshShape does not react to physics". This will change the name of the thread, making it easier to help for other people to know what is going on.
Post Reply