*/
@Override
public void onAction(String name, boolean isPressed, float tpf) {
// only execute on button/key release
if (!isPressed) {
Singleton sin = Singleton.get();
Vector3f origin = camera.getWorldCoordinates(
inputManager.getCursorPosition(), 0.0f);
Vector3f direction = camera.getWorldCoordinates(
inputManager.getCursorPosition(), 0.3f);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
sin.getSceneManager().getRoot().collideWith(ray, results);
if (results.size() > 0) {
Geometry geom = null;
for (CollisionResult res : results) {
geom = res.getGeometry();
if (geom != null) {
log.fine("picked " + geom.getName());
Integer id = geom.getUserData(Entity.ENTITY_ID);
if (id != null) {
//Just create a target component rest is done in the jmeupdatesystem
Node n = res.getGeometry().getParent();
String na = n.getName();
log.fine("picked " + na + " id:"+ id);
Vector3f loc = n.getLocalTranslation();
sin.getClientFacade().sendAction(id, loc.x, loc.y, loc.z, false, true);
results.clear();
return;
} else {//FIXME click on anything, check nav, then send request
// this is the one
Vector3f location = res.getContactPoint();
if(location != null){
Path p = new Path();
PositioningComponent pos = (PositioningComponent) sin.getEntityManager().getComponent(handler.getSelectedObjectId(), PositioningComponent.class);
if(pos != null){
if(sin.getNavManager().buildNavigationPath(p, pos.position, location.clone())) {
log.fine("new loc:" + location
+ " sent:"+ ServerValues.getServerCoordX(location.x)
+ ","+ ServerValues.getServerCoordY(location.z)
+ ","+ ServerValues.getServerCoordZ(location.y));
sin.getClientFacade().sendMoveToAction(handler.getSelectedObjectId(), pos.position.x, pos.position.y, pos.position.z, location.x, location.y,
location.z);
results.clear();
return;
} else {
log.fine("Unable to build path from "+pos.position+" to "+location);