btTransform and Compound Shape Construction question

aleradish
Posts: 22
Joined: Thu Mar 05, 2009 9:41 pm

btTransform and Compound Shape Construction question

Post by aleradish »

Hi,

I have one Question.. I'm searching to create a method of decomposition of an BoundingVolume in one set of elements in a CompoundObject... For Make that I'm Working with some Shapes and Transforms of these Shapes...

I've noted a thing that I don't understand...

For Example, I want put the child shape in a circonference.
For make that, I create the CompoundShape, for Example B

btCompoundShape* B= new btCompoundShape();

Now, I add the children...

float Step= (2*Math::PI)/NumObjects;
for(int i=0;i<NumObjects){
btCollisionShape* ChildShape=new btSphereShape(3)
btTransform T;
T.setIdentity();
T.setOrigin(btVector3(0,0,Radius));
T.setRotation(new btQuaternion(btVector3(0,1,0),i*Step);
B->AddChildShape(T,ChildShape);
}//Elements inserted

... Now... I will go to make the rayTest of the Scomposed Object; for make that I need the positions of the child Object..

for make that, I wrote:

btVector3* rayStart=btVector3(myCameraPosition);
btVector3* rayEnd=CompoundShape->getChildTransform(i).getOrigin();

Here, is for my a surprise.... the origin is always the same... Why?Is the object in the right place & is the origin the same or the children are in the same point?
How I can make to retrieve the real position?

in OpenGL ,for example if Make that I should see the differences....

if you can... How I can retrieve the child that collide with the ray?...

Thank you so much
Mattg
Posts: 12
Joined: Thu Oct 22, 2009 12:50 am

Re: btTransform and Compound Shape Construction question

Post by Mattg »

You seem to set all child shapes at the same position:

T.setOrigin(btVector3(0,0,Radius));

So as far as I can see it's normal that you get the same origin for all child shapes.
aleradish
Posts: 22
Joined: Thu Mar 05, 2009 9:41 pm

Re: btTransform and Compound Shape Construction question

Post by aleradish »

But, I'm sorry... but the rotation what does mean?
When I make...

btTransform T;
T.setIdentity();
T.setOrigin(0,1,0);
T.setRotation(btQuaternion(btVector(0,1,0),angle);

what does mean this code? the rotation Is only in the place of the object?

Thank you...
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: btTransform and Compound Shape Construction question

Post by Flix »

what does mean this code? the rotation Is only in the place of the object?
Sure, you were adding the same body in btVector3(0,0,radius), each time with a different orientation (rotation in Bullet means body orientation most of the time).

You need to modify the position (origin) of the child transforms as well.

You can try using btSin(...), btCos(...) methods for this, or something like:

Code: Select all

btScalar Step= (2.f*SIMD_PI)/(btScalar)NumObjects;
btCollisionShape* childShape=new [......]; //add it as needed
const btVector3 centerOfMass(0.f,0.f,0.f); // of the compound shape
const btScalar radius = 5.0; //set it as you like
btTransform T;
for(int i=0;i<NumObjects;i++){
T.setIdentity();
T.setRotation(new btQuaternion(btVector3(0,1,0),(btScalar)i*Step); //rotates the transform IN PLACE
T.setOrigin(centerOfMass + T.getBasis().getColumn(2)*radius); //adds the radius in the Z direction
B->AddChildShape(T,ChildShape);
}
I've written this on the fly based on the code you posted, so adjust it a bit to make it work.