VuforiaLibGDX icon indicating copy to clipboard operation
VuforiaLibGDX copied to clipboard

Handle clicks on model

Open AhmedGamal-Inmobly opened this issue 8 years ago • 2 comments

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 ?

AhmedGamal-Inmobly avatar Jan 11 '17 16:01 AhmedGamal-Inmobly

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.

vickysaini avatar Mar 22 '17 05:03 vickysaini

@AhmedGamal-Inmobly i also have this problem,
float radius = dimentions.len() * MODEL_SCALE / 2f;

this works fine

WangXiaoxi avatar Dec 14 '17 07:12 WangXiaoxi