Now to my problem: I am using this code:
Code: Select all
private static final Vector3 rayFrom = new Vector3();
private static final Vector3 rayTo = new Vector3();
private static final ClosestRayResultCallback callback = new ClosestRayResultCallback(rayFrom, rayTo);
public static btCollisionObject rayTest(btCollisionWorld collisionWorld, Ray ray) {
rayFrom.set(ray.origin);
// 50 meters max from the origin
rayTo.set(ray.direction).scl(50f).add(rayFrom);
// we reuse the ClosestRayResultCallback, thus we need to reset its
// values
callback.setCollisionObject(null);
callback.setClosestHitFraction(1f);
callback.getRayFromWorld().setValue(rayFrom.x, rayFrom.y, rayFrom.z);
callback.getRayToWorld().setValue(rayTo.x, rayTo.y, rayTo.z);
collisionWorld.rayTest(rayFrom, rayTo, callback);
if (callback.hasHit()) {
return callback.getCollisionObject();
}
return null;
}
Code: Select all
private Viewport pickingViewport;
private btCollisionWorld collisionWorld;
// a constructor which takes a Viewport and the collision world and stores them
public BulletInputProcessor(...) { ... }
public boolean click(screenX, screenY) {
Ray pickRay = pickingViewport.getPickRay(screenX, screenY);
btCollisionObject body = rayTest(collisionWorld, pickRay); //using our function, which returns an collision object.
if (body != null) {
// do whatever you want with this body now
return true;
}
return false;
}
So my question is: How to know which side of block i am clicking? Cant I just add some magic lines to my boxShape? Probably cant.