ClassCastException when Colliding with a BillboardNode

Hi guys,

I was getting a ClassCastException when playing with collisions for the first time: I had just a Node & Box collide with a BillBoardNode & Quad. I don't see this mentioned in the formus or bug list, but it's easy to reproduce, and something I'd image would be a typical scenario.



Specifically the exception is:

java.lang.ClassCastException: com.jme.scene.BillboardNode
   at com.jme.scene.TriMesh.findCollisions(TriMesh.java:351)


I believe the cause may be due to the BillBoardNode class overriding SceneElement's getType() and setType() methods to change the meaning of the property entirely to instead mean a type of billboard alignment or rotation. This property override looks suspicious, and maybe it should be refactored to not override SceneElement's type (maybe call it alignmentType or something).

The cast exception occurs in the findCollisions() method where the tested scene object is cast to the Geometry class:


    public void findCollisions(Spatial scene, CollisionResults results) {
        if (this == scene || !isCollidable || !scene.isCollidable()) {
            return;
        }
        if (getWorldBound().intersects(scene.getWorldBound())) {
            if ((scene.getType() & SceneElement.NODE) != 0) {
                Node parent = (Node) scene;
                for (int i = 0; i < parent.getQuantity(); i++) {
                    findCollisions(parent.getChild(i), results);
                }
            } else {
                results.addCollision(this, (Geometry) scene);
            }
        }
    }


If the 'scene' object's type is a SceneElement.NODE then this recursively finds collisions within the node's children. Otherwise it assumes it must be a Geometry and so casts it. If the scene object is a BillBoardNode I think it should also have a type of SceneElement.NODE, but can't for the reasons above and therefore the code attempts to cast a BillboardNode to a Geometry.

Just a noob trying to contribute...
Cheers

Nice find, JM.  This unintended override (yes, bug) came into being when getType was added to Spatial a long time ago (it was part of BillboardNode first…)



I have changed the property name in cvs to alignment, so anyone using a BillboardNode, please switch over to using setAlignment.  Since setType does not override anything, I've left that in but deprecated it.