Strange collosion behavior

Hello,

its strange, if im trying to check a collision by calling:

[java] rootNode.updateGeometricState();

ship.collideWith(physicsNode, cr);[/java]

im getting the following exception:

[java]com.jme3.collision.UnsupportedCollisionException

at com.jme3.collision.bih.BIHTree.collideWith(BIHTree.java:479)

at com.jme3.scene.Mesh.collideWith(Mesh.java:479)

at com.jme3.scene.Geometry.collideWith(Geometry.java:232)

at com.jme3.scene.Node.collideWith(Node.java:498)

at com.jme3.scene.Node.collideWith(Node.java:498)

at com.jme3.scene.Node.collideWith(Node.java:498)

at com.jme3.scene.Node.collideWith(Node.java:498)

at com.iBoat.ShipSimulation.ShipSimulation.gameModeStep(ShipSimulation.java:450)

at com.iBoat.ShipSimulation.ShipSimulation.simpleUpdate(ShipSimulation.java:382)[/java]



if im using a CollisionGroupListener than the collision are detected before it is visible in the scene.

it is like a rectangle is used for the collision detection, but the physics behavior is right.



and by using a CollisionListener im not getting collosionevents.

You’re doing it wrong, collideWith is collision checking for geometries while CollisionGroupListener is for physics collision.

But why the CollisionGroupListener informs me about a collosion before one happens?



CollisionGroupListener is informed about a collosion.





but the CollisionGroupListener should only be informed by a direct collosion

Because a) the CollisionGroupListener is for making collisions not happen, use PhysicsCollisionListener and b) the display is effectively one frame late to allow multithreading.

Im using the PhysicsCollisionGroupListener, i forgot the prefix “Physics”.

its seems like that for the collosiondetection a box shape is used, but im using a DynamicMeshCollisionShape.

Yeah, you’re using the group listener, its not the correct collision listener for collision detection, its for collision prevention.

Thx, but which listener should i use? how do i get a notification about a collision?

As I said, implement PhysicsCollisionListener, there you implement the collision(PhysicsCollisionEvent event) method which gets called each collision after you add it with PhysicsSpace.addCollisionListener().

Sry, it was not realy clear but:

i wrote before: “and by using a CollisionListener im not getting collosionevents.”

and than i wrote “Im using the PhysicsCollisionGroupListener, i forgot the prefix “Physics”.”



I already tried the PhysicsCollisionListener.

the code:

[java]bulletAppState.getPhysicsSpace().addCollisionListener(pcl);

[/java]



[java] PhysicsCollisionListener pcl = new PhysicsCollisionListener() {

public void collision(PhysicsCollisionEvent event) {

System.out.println(“Collidate”);

}

};[/java]



Of course the pcl is created before is used

Uhm, so are they physics objects after all?

yes

I dont know why the method doesnt get called, for me collision works fine, can you create a test case for this?

Hmm, i dont think it would help.

Im loading the Scene from a .j3o file.

Does objects with a mass of zero collidate with objects with a mass of > 0?



Maybe the failure is in the code below?



[java] fpsText.removeFromParent();

statsView.removeFromParent();

isRunning = false;

bulletAppState = new BulletAppState();

stateManager.attach(bulletAppState);

bulletAppState.getPhysicsSpace().setBroadphaseType(BroadphaseType.DBVT);

bulletAppState.getPhysicsSpace().setAccuracy(1f / 30f);

bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, 0));

speed = 0.0000001f;

initGUI();

loadScene();

initInputController();

loadConfig();

initCamera();

bulletAppState.getPhysicsSpace().addCollisionListener(new PhysicsCollisionListener() {



public void collision(PhysicsCollisionEvent event) {

System.out.println(“Collidate!”);

}

});[/java]



“I dont know why the method doesnt get called, for me collision works fine”

Maybe its because ur using the latest version from the trunk?

this simple example isnt woking too:



[java]package mygame;



import com.jme3.app.SimpleApplication;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.PhysicsSpace.BroadphaseType;

import com.jme3.bullet.collision.PhysicsCollisionEvent;

import com.jme3.bullet.collision.PhysicsCollisionListener;

import com.jme3.bullet.nodes.PhysicsNode;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.renderer.RenderManager;

import com.jme3.scene.Geometry;

import com.jme3.scene.shape.Quad;

import com.jme3.scene.shape.Sphere;



/**

  • test
  • @author normenhansen

    */

    public class Main extends SimpleApplication {



    public static void main(String[] args) {

    Main app = new Main();

    app.start();

    }



    @Override

    public void simpleInitApp() {



    BulletAppState bulletAppState = new BulletAppState();

    stateManager.attach(bulletAppState);

    bulletAppState.getPhysicsSpace().setBroadphaseType(BroadphaseType.DBVT);

    bulletAppState.getPhysicsSpace().setAccuracy(1f / 30f);

    bulletAppState.getPhysicsSpace().setGravity(new Vector3f(0, 0, 0));



    bulletAppState.getPhysicsSpace().addCollisionListener(new PhysicsCollisionListener() {



    public void collision(PhysicsCollisionEvent event) {

    System.out.println("Collidate!");

    }

    });



    Sphere s = new Sphere(12, 12, 1);

    Geometry g = new Geometry("sphere", s);

    mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

    mat.setColor("m_Color", new ColorRGBA(0, 1, 0, 1));

    g.setMaterial(mat);

    PhysicsNode p = new PhysicsNode(g, CollisionShapeFactory.createDynamicMeshShape(g));

    p.setMass(323);

    rootNode.attachChild§;

    bulletAppState.getPhysicsSpace().add§;



    s = new Sphere(12, 12, 1);

    g = new Geometry("df", s);

    mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");

    mat.setColor("m_Color", new ColorRGBA(0, 0, 0, 1));

    g.setMaterial(mat);

    p = new PhysicsNode(g, CollisionShapeFactory.createDynamicMeshShape(g));

    p.setMass(323);

    rootNode.attachChild§;

    bulletAppState.getPhysicsSpace().add§;

    }



    @Override

    public void simpleUpdate(float tpf) {

    }



    @Override

    public void simpleRender(RenderManager rm) {

    }

    }[/java]

For me, physics are NOT working at all. Please run test providing with jme3 - one with stone ball shooting at brick wall, fancy car one or continous motion detection - they are all broken in current SVN.

Yeah, its fixed in svn now, there was a problem where the collisionshape would be overwritten.

Ive downloaded the latest engine from nifty builds and exchanged all libs in the jmeplatform.

now im getting an error if im trying to set the mass to a physicnode.

[java]physicsNode = new PhysicsNode();

physicsNode.setMass(0);

[/java]

a nullpointerexcetion is thrown :frowning:

This is not new behavior, the empty constructor of a PhysicsNode only for reading from disk, you have to specify a CollisionShape.

"This is not new behavior, the empty constructor of a PhysicsNode only for reading from disk, you have to specify a CollisionShape. "

But it worked with an older version before.



Ive downloaded the newst engine from the nightly build, everything works fine but i get an exception if two objetcs collidate:

[java]

Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:119)

at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)

at com.bulletphysics.collision.dispatch.CompoundCollisionAlgorithm.destroy(CompoundCollisionAlgorithm.java:76)

at com.bulletphysics.collision.dispatch.CollisionDispatcher.freeCollisionAlgorithm(CollisionDispatcher.java:120)

at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.cleanOverlappingPair(HashedOverlappingPairCache.java:219)

at com.bulletphysics.collision.broadphase.HashedOverlappingPairCache.removeOverlappingPair(HashedOverlappingPairCache.java:91)

at com.bulletphysics.collision.broadphase.DbvtBroadphase.collide(DbvtBroadphase.java:145)

at com.bulletphysics.collision.broadphase.DbvtBroadphase.calculateOverlappingPairs(DbvtBroadphase.java:235)

at com.bulletphysics.collision.dispatch.CollisionWorld.performDiscreteCollisionDetection(CollisionWorld.java:139)

at com.bulletphysics.dynamics.DiscreteDynamicsWorld.internalSingleStepSimulation(DiscreteDynamicsWorld.java:372)

at com.bulletphysics.dynamics.DiscreteDynamicsWorld.stepSimulation(DiscreteDynamicsWorld.java:337)

at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:361)

at com.jme3.bullet.PhysicsSpace.update(PhysicsSpace.java:327)

at com.jme3.bullet.BulletAppState.render(BulletAppState.java:163)

at com.jme3.app.state.AppStateManager.render(AppStateManager.java:162)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:215)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:141)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:203)

at java.lang.Thread.run(Thread.java:662)

[/java]

Mr.Sir said:
But it worked with an older version before.

like alpha-1 you mean? No, the empty constuctor is empty since at least alpha-2. I cannot reproduce the collision problem, please post a test case.