jmonkeyengine - How to detect the intersections between 2 nodes in jMonkey -
i'm working on java project; "car game" , want detect collisions between car , object ("node"); such cones on road.
similar tutorial; http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_picking
the tutorial shows finding intersection between ray , node has boxes attached it. want replace ray car chassis intersection detection.
assume have 2 collidables , b , want detect collisions between them. collision parties can geometries, nodes geometries attached (including rootnode), planes, quads, lines, or rays. important restriction can collide geometry vs bounding volumes or rays. (this means example must of type node or geometry , b respectively of type boundingbox, boundingsphere or ray.)
the interface com.jme3.collision.collidable declares 1 method returns how many collisions found between 2 collidables: collidewith(collidable other, collisionresults results).
code sample:
// calculate detection results collisionresults results = new collisionresults(); a.collidewith(b, results); system.out.println("number of collisions between" + a.getname()+ " , " + b.getname() + ": " + results.size()); // use results if (results.size() > 0) { // how react when collision detected collisionresult closest = results.getclosestcollision(); system.out.println("what hit? " + closest.getgeometry().getname() ); system.out.println("where hit? " + closest.getcontactpoint() ); system.out.println("distance? " + closest.getdistance() ); } else { // how react when no collision occured } }
i think need read tutorial
http://hub.jmonkeyengine.org/wiki/doku.php/jme3:advanced:collision_and_intersection
hope helps.
Comments
Post a Comment