How Does Collision Detection work in JMonkeyEngine 3.5

In Java3D 1.5 and above, you have the Bounds collisions representation and detection system:

javax.media.j3d.Shape3D
Constructor:
Shape3D()
methods:
Bounds getCollisionBounds()

javax.media.j3d.Bounds
methods:
abstract boolean intersect(Bounds boundsObject)
abstract boolean intersect(Bounds [] boundsObjects)

Every physical virtual world object is some kind of Shape3D. A Bounds object can be perfectly calculated and obtained for every Shape3D. Now, these Bounds objects are just an invisible perimeter object of the original Shape3D, virtual world object. If Bounds break past each other’s barriers at collision, you can test for that being true or false.

A desired movement, being in two (2) or three (3) dimensions, is usually from the barycentre (“centre of gravity point”) or a surface or a 3D object. This movement is either a vector length motion in the direction and length of that vector. However that vector’s length can be broken down into a finite number of units, being pixel unit lengths. If you want a surface or 3D object to turn, in 2D or 3D space, by degrees or radians, then degrees and radian amount turning can also be broken down into the smallest finite unit, which for turns too is pixel units.

All this is fantastic, because just before you move or turn an object, at the smallest degree possible,
you can leave the Shape3D alone, and move the Bounds. You then do an intersection test with every other proximity relevant Bounds object, from all other such Shapes, like the ground, floor or any other Shape3D (Bounds) objects. This test will return true or false, and will not throw any exceptions. If you get a false, that there is an intersection, you then know that you can’t keep up moving or turning any more pixel units, and that your primary object, or otherwise, must stop then due to obstruction.

Now this is how you can do things in Java3D. But I now wish to use JMonkeyEngine 3.5. I have only been told it has a ray casting system. I was really hoping that it would also have a Bounds pre motion collision system, because that is must easier, and sensible to perceive, from my point of view.

Does JMonkeyEngine have a Bounds intersection system for collision detection? If not, what does it have,
and how is that applied on the motion or turning of an object in relation to other objects, no matter where the two (relative proximity) objects are, or what their surfaces are like, to the smallest resolution possible, which I still believe is the pixel unit? Can someone please respond with an addressal answer to my one bigger question here, please?

1 Like

This is even easier than I expected. In JMonkeyEngine 3.5, you just need to add the RigidBodyControl
to the sceneModel, at which point presumably, RigidbodyControl is updated and treated when
motion from it leads to an obstruction.

The right collision objects have to be obtained, and all submitted into a CollisionShapeFactory, which seems to automatically get updated when things move in relation to one another. Is the latter true? Can someone add anything useful to this point?

This might seem to imply that the first, moving object is stopped before intersersecting with a second object, along its previous path of motion before collision. Is this also true? Can someone add anything useful to this point?

There are two general ways to do collisions:

First is with a full physics system, where you attach physics objects like RigidBodyControl to the BulletAppState like the wiki link above shows. The physics system will handle everything and you can register listeners to listen for collisions.

The second is with jme classes that implement the Collidable interface, such as Ray, a BoundingSphere, or a BoundingBox. These will tend to be cheaper for most things and can be done an an as-needed basis.

Here’s the basic tutorial for using a ray; there is unfortunately not any good tutorial showing how to use BoundingVolumes (i.e. BoundingSphere and BoundingBox) but here are also the links to their javadoc:

https://javadoc.jmonkeyengine.org/v3.3.0-beta2/com/jme3/math/Ray.html
https://javadoc.jmonkeyengine.org/v3.3.0-beta2/com/jme3/bounding/BoundingSphere.html
https://javadoc.jmonkeyengine.org/v3.3.0-beta1/com/jme3/bounding/BoundingBox.html

And in regards to :

Jmonkey Spatial objects will have a BoundingVolume as their bounds, and should work very similar to what you are expecting. For most regular spatials, a bounding box will be auto-generated to match the size of the mesh, and I also believe the boundingbox will always have an identity rotation, so colliding with a complex mesh’s boundingbox will not give mesh-accurate collisions.
https://javadoc.jmonkeyengine.org/v3.3.0-beta1/com/jme3/scene/Spatial.html#getWorldBound--

3 Likes

You are quite right. In terms of JME3, what I have had in mind is a
com.jme3.bounding.BoundingVolume.

In Java3D, 3 dimensional objects are either a Shape3D or an OrientedShape3D.

Can someone please reply, telling me what the equivalent of a JME3 “Shape3D” is,
that I can call a method on, to directly obtain its BoundingVolume, please?

Spatial, which has this method.

The javadoc should be able to answer most of your questions like this. And if you’re unsure what basic classes to look for in the javadoc, then you would benefit greatly from at least looking through the intro tutorials in the JME wik (linked at the top of the forum page where you see “documnetation”) to understand what they do. Then you will at least become familiar with frequently used basic JME classes like Spatial, Node, Gemoetry, etc.

1 Like

But a Spatial only seems to be a node for the nodetree. What is the class name for any kind
of one 3D object, with vertices, flat surfaces, and curved surfaces somewhere through 3D empty space, with the equivalent of Materials and Textures on and associated with it, in JME3?

A Geometry.

Geometry and Node both extend Spatial. Geometry has a material, and Node is used for attaching other spatials to it.

1 Like

Is there any other aggregation of a Geometry, that can be transformed, applied to, and acted upon, perhaps before something which straddles two concepts, like a Spatial does? Does JMonkeyEngine3 have a direct equivalent to Java3D’s Shape3D, that (in JMonkey) encapsulates a Geometry, certainly before something that is even more general again, in the way a Spatial is?

Java3d did a bunch of things in a really silly way because it was the only way it would work at the time. 80% of renderers were software renderers… they had to do a lot of really dumb stuff just to make things work at all.

Technology has moved on. You would do well to erase as much of Java3D’s silliness from your brain as possible and concentrate on what you are actually trying to achieve.

You will probably get better responses if you rephrase your question with respect to what you actually want to do and not trying to find direct parallels to the super-crazy things that Java3D did.

Because you won’t find them. It’s like trying to ask about the horse shit catcher on a modern electric car.

2 Likes