VuforiaLibGDX
VuforiaLibGDX copied to clipboard
Handle clicks on model
I've been trying to catch clicks on the 3d model but have troubles with that. So far I figured out that the clicks get caught if the model scale factor is 1, here's my code
if (Gdx.input.justTouched()) {
final int x = Gdx.input.getX();
final int y = Gdx.input.getY();
Ray ray = camera.getPickRay(x, y);
Vector3 dimentions = new Vector3();
BoundingBox boundingBox = new BoundingBox();
mDisplay.modelInstance.calculateBoundingBox(boundingBox);
boundingBox.getDimensions(dimentions);
float radius = dimentions.len() / 2f;
mDisplay.modelInstance.transform.getTranslation(mPosition);
final Vector3 center = new Vector3();
mPosition.add(boundingBox.getCenter(center));
if (Intersector.intersectRaySphere(ray, mPosition, radius, null)) {
Log.i("test", "click in model");
}
}
Any ideas ?
I was also trying with Intersector.intersectRaySphere(ray, mPosition, radius, null), but I got no success.
You can use Intersector.intersectRayBounds(ray, boundingBox, null)
. I got it working using this.
@AhmedGamal-Inmobly i also have this problem,
float radius = dimentions.len() * MODEL_SCALE / 2f;
this works fine