btConvexHullShape reutilization

johnvillar
Posts: 8
Joined: Thu May 03, 2012 10:56 pm

btConvexHullShape reutilization

Post by johnvillar »

Hi all, i'm currently integrating bullet on my game engine for android and i would like to know if anyone can tell me how can i reuse a btConvexHullShape on multiple rigid bodies? I'm currently trying to implement "gibs" and have already solved most collision problems, but if i reuse a convex hull on a different rigid body the previous body dissapears in place of the new one. I create each subsequent new rigid body with the "localCreateRigidBody" found on the samples, i'm doing something wrong?
User avatar
jarno
Posts: 57
Joined: Tue Mar 16, 2010 1:42 am

Re: btConvexHullShape reutilization

Post by jarno »

As long as the local scaling and margin of the convex hull shape remains the same, I see no reason why it shouldn't work.
johnvillar
Posts: 8
Joined: Thu May 03, 2012 10:56 pm

Re: btConvexHullShape reutilization

Post by johnvillar »

That's weird. I will post some code this monday when i'm back to the office to show you exactly what i'm doing. I'm trying to understand Bullet and C++ in one step so maybe i'm doing something stupid and don't realize it. :)
johnvillar
Posts: 8
Joined: Thu May 03, 2012 10:56 pm

Re: btConvexHullShape reutilization

Post by johnvillar »

Check the code if you can:

http://pae.st/c2L2/

The first two class functions are for creating the convex shape (very suboptimal) and the last two functions are for the JNI Interface with the java side in Android.

Code: Select all

// Class functions
BulletEngine::crearShapeConvexoTriMesh
BulletEngine::insertarDynamicDesdeShape

// JNI Calls
Java_com_contimita_utils_BulletNdk_crearShapeConvexoTriMesh
Java_com_contimita_utils_BulletNdk_insertarDynamicConShape
As you can see, my engine"revolves around one Bullet instance globally visible to the C++ code, and has some functions for the java side to call and interact with Bullet.

The problem is that when i insert a dynamic rigid body with the previously constructed convex hull, the previous rigid body gets overwritten somehow and it disapears.
johnvillar
Posts: 8
Joined: Thu May 03, 2012 10:56 pm

Re: btConvexHullShape reutilization

Post by johnvillar »

Here's a link to a Youtube video of the problem.

http://www.youtube.com/watch?v=ROK1gd643n4
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: btConvexHullShape reutilization

Post by Typhontaur »

I, for example, for each models, including gibs, create a new btConvexHullShape.
until the gibs have a life (including collisions), then free the resources.
here the demo

you tried to do it this way? (sorry 4 engrish)
johnvillar
Posts: 8
Joined: Thu May 03, 2012 10:56 pm

Re: btConvexHullShape reutilization

Post by johnvillar »

I'm aiming at something like that. But the problem is that with each new instance of a RigidBody that uses the shape the previous rigid body ceases to exist (or render in the same place, as far as i've seen)
johnvillar
Posts: 8
Joined: Thu May 03, 2012 10:56 pm

Re: btConvexHullShape reutilization

Post by johnvillar »

Btw, here's how i obtain the transformation matrix for my geometry in the render pipeline.

http://pae.st/hBj8/

Is that the right way?
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: btConvexHullShape reutilization

Post by Typhontaur »

I also use opengl, so here's the code ... does not seem different...

Code: Select all

inline void C_Math::Matrix4_Copy (const mat4_t in, mat4_t out)
{
	out[ 0] = in[ 0];
	out[ 1] = in[ 1];
	out[ 2] = in[ 2];
	out[ 3] = in[ 3];
	out[ 4] = in[ 4];
	out[ 5] = in[ 5];
	out[ 6] = in[ 6];
	out[ 7] = in[ 7];
	out[ 8] = in[ 8];
	out[ 9] = in[ 9];
	out[10] = in[10];
	out[11] = in[11];
	out[12] = in[12];
	out[13] = in[13];
	out[14] = in[14];
	out[15] = in[15];
}
and this is the definition of the matrix:
typedef float mat4_t[16];
johnvillar
Posts: 8
Joined: Thu May 03, 2012 10:56 pm

Re: btConvexHullShape reutilization

Post by johnvillar »

Was just reading your previous post, and i'm trying to use only ONE convex hull for type of gib, that means i'm reutilizing one ConvexHull with different rigid bodies.

Maybe that isn't possible :(
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: btConvexHullShape reutilization

Post by Typhontaur »

mhmmm...
I do:
if the model is already listed, then resume it.
So I have the old btConvexHullShape.
otherwise create a new stuff for the new model.

I am sorry being unable to express, english is not my language ...
I have trouble with google ... sorry :twisted:
User avatar
jarno
Posts: 57
Joined: Tue Mar 16, 2010 1:42 am

Re: btConvexHullShape reutilization

Post by jarno »

Maybe you have a mixup between an object index and a collision shape pointer?
I see that for obtenerMatrizRigidBody() you use sim as an index into the object array, while in Java_com_contimita_utils_BulletNdk_insertarDynamicConShape() sim is a collision shape pointer.

If the objects are actually appearing at the same place, instead of disappearing, that would suggest a problem with the motion state. The motion state has nothing to do with the collision shape.

---JvdL---
johnvillar
Posts: 8
Joined: Thu May 03, 2012 10:56 pm

Re: btConvexHullShape reutilization

Post by johnvillar »

Thanks all... it was just an stupid bug on my part :-D

This library rocks!
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: btConvexHullShape reutilization

Post by Typhontaur »

johnvillar wrote:Thanks all... it was just an stupid bug on my part :-D

This library rocks!
Goood! :lol:

Yeah! Bullet is a....Bomb! :mrgreen: