setScale() in SphereCollisionShape

Hey guys,

I have been experimenting with the physics of sphere-like objects for a while now.

What I need
I need a scaled sphere collisionshape that can be added to a CompoundCollisionShape.
For example the sphere is 6 meters in x-direction, 2 in y-direction and 4 in z-direction.

The Problem
When I do

shape.setScale(new Vector3f(6,2,4));

it doesn´t affect the Sphere the way I want it:
It is scaled, but its scaled 6 times in EVERY direction, not just the x-direction.
The debugging mesh and the physics behavior match perfectly until now.

If you look in the docs, you will find:

setScale public void setScale(Vector3f scale)

WARNING - CompoundCollisionShape scaling has no effect.

So apparently you have to watch out if you use the CompoundCollisionShape.

But even if you try without CompoundCollisionShape, if you scale a simple Sphere and look at the results

  1. The debugging mesh is scaled properly, it is some stretche</span>d sphere-thing.
  2. The actual behavior of the physics show that the sphere hasn´t been scaled properly at all! It still behaves as a normal sphere, stretched by the factor 6 in every direction!
    .

My Questions
1. The physics debugging wireframe doesn´t match the actual behavior at all if you do

shape.setScale(new Vector3f(6,2,4));

Am I doing something wrong or does this need to be fixed?

2. Is there a way to get a properly strechted sphere?
And, of course, can I use it with CompoundCollisionShape?

Thanks for your answers in advance

I think I have to correct myself a bit:
When you scale a simple Sphere by 6, 2 and 4 it is not scaled at all.
But this still is a problem…

My Code basically is simply like this:
[java]
//…
SphereCollisionShape testShape = new SphereCollisionShape(1);
testShape.setScale(new Vector3f(5,12,20));
RigidBodyControl phyControl = new RigidBodyControl(testShape,mass);
//…
[/java]

I don’t think you can deform it like that and still call it a sphere :slight_smile: Usually spheres are used because they are fast to check collisions with. If they are non-uniformly scaled they aren’t as fast anymore. Here are the shapes in bullet

http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Shapes

maybe you can find another shape that is good enough for your use case.

Yeah, it´s not a sphere…
it was just the only way to describe it :slight_smile:

I guess you can approximate any shape through boxes, but there is the methode setScale() and
the debug shape even gets changed through it.

I know spheres are easy to calculate since you only have to calculate the distance to the center of the sphere, but
scaled spheres shouldn´t be that big of a deal…

Calculating if a point is within a scaled sphere for example is fairly easy. You just scale the coordinates of the point accordingly and do the real calculation as usual.
It should still be WAY faster than a bunch of boxes.

@m41q said: Yeah, it´s not a sphere... it was just the only way to describe it :)

I guess you can approximate any shape through boxes, but there is the methode setScale() and
the debug shape even gets changed through it.

I know spheres are easy to calculate since you only have to calculate the distance to the center of the sphere, but
scaled spheres shouldn´t be that big of a deal…

Calculating if a point is within a scaled sphere for example is fairly easy. You just scale the coordinates of the point accordingly and do the real calculation as usual.
It should still be WAY faster than a bunch of boxes.

…except you have to rotate the radials into the same frame. You don’t have to do this with spheres but you do have to do it with ellipsoids.

Yes, it’s faster than a bunch of boxes. It’s also way slower than plain spheres.

<cite>@pspeed said:</cite> ...except you have to rotate the radials into the same frame.

Yep, you´re right, the rotation has to be done as well of course.

So… can you do this with jME or respectively jBullet?

I mean, the method is there…

by the way, it´s the same for the cylinder:

When you do
[java]
CylinderCollisionShape testShape = new CylinderCollisionShape(new Vector3f(10,1,5),0);
[/java]
the cylinder has a width of 10 meters and is 1 meter broad, but the 5 meters are not taken care of.
setScale() has no effect at all (at least I couldn´t find one).

But this time, at least the debugging shape is accurate (it´s like the cylinder actually is, not how I want him to be).
I have to admit, scaling cylinders is not one of the features I really need, but I just wanted to mention it.

So the question is still there: Can you scale spheres?

yes you can scale spheres, but only the first argument is used, the rest are ignored. This is so that all collisionshapes can have the same interface. You seem to be going round in circles (pun intended)

Aaaand I guess the same is true for cylinders.
Well… thats not very good…
But I guess it´s not jME´s fault, but rather JBullet´s for not implementing it.

Anyways, thanks for the clarification!
Maybe someone could write a little note in the Javadoc of SphereCollisionShape and CylinderCollisionShape.