Hi,

I'm fairly new to JMEngine. I've been trying to make a sphere collide within a tube. However, since my tube was bounded using setModelBound(new BoundingSphere ()), there is always a collision even when the sphere is the "empty space" of the tube.

Is there anyway to limit the collision detection to say there's a collision when the sphere collides with the surface of the tube?

Thank you for your time.

If I understand it correctly, when you use bounding-accurate collisions you'll always get a collision when the two bounding volumes overlap - even within the 'empty' space instead the geometry. It sounds like you might need to use a triangle accurate collision check instead, so have a look at jmetest.intersection.TestCollisionTree for an example.

Also if its always going to be a sphere colliding within a tube, you could also use straight maths to work out the collision, rather than using the scene graph.

Thanks for the reply!

I looked at the TestCollisionTree, but I'm not quite sure how it will help me. I can't find the point in the code where it allows the the sphere to move inside.

And, what do you mean by the straight math?

Like, where in the code does it show that the collision occurs

Fair enough, it is a bit dotted around. Here are the stripped out important bits :

The important variables :

CollisionResults results;

From the init method :

results = new TriangleCollisionResults();

From the update method :

results.clear();

m.findCollisions(n, results);

In this example m (containing the sphere) and n (containing the crazy shape) are used with the findCollisions method. And because results is an instance of TriangleCollisionResults (rather than BoundingCollisionResults) the framework will do the extra triangle level checks.

I'm not sure what you mean by "allows the the sphere to move inside" - does the sphere start outside of the tube?

Back to the example... still in the update method

if (results.getNumber() > 0) {

...

}

If that returns true you've got a collision in at least one triangle. The rest of the code in there just changes the colour of the crazy shape's collided triangles so you can see it working.

As for the maths bit - its possible to work out if the sphere has collided using the line segment representing the length of the tube, and then taking the distance between that segment and the centre of the sphere. If this distance is less than the radius of the tube plus the radius of the sphere, they must have collided. Hmm on second thoughts its harder than that because that's the maths for a collision with a capsule (a tube with rounded ends) - I'm not sure about a tube with flat ends. I guess its up to you to do some more research if you want to carry on that way.

Maybe try hacking around with that example, change the crazy shape into a tube and see how the sides change colour when the sphere passes through it? Hope that helps.