Hi,
I have a problem with transformation of 2D coordinates to 3D coordinates. Based on the "Obje reco" example I've added my own 3d marker (motorcycle model) and above it I show a simple texture (simple png with text). After that I wrote a simple handler on tap event:
@Override public boolean onSingleTapUp(MotionEvent e) { if (mRenderer.isTapOnScreenInsideTarget(e.getX(), e.getY())){ showWebView(); } else { autofocusHandler.postDelayed(new Runnable() { public void run() { boolean result = CameraDevice.getInstance().setFocusMode(CameraDevice.FOCUS_MODE.FOCUS_MODE_TRIGGERAUTO); if (!result) Log.e("SingleTapUp", "Unable to trigger focus"); } }, 1000L); } return true; }
In the ObjectTargetRenderer I have a method isTapOnScreenInsideTarget (I've found a java implementation of that method on some post of this forum):
public boolean isTapOnScreenInsideTarget(float x, float y) { Vec3F intersection; if (isTracked) { DisplayMetrics metrics = new DisplayMetrics(); mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics); intersection = SampleMath.getPointToPlaneIntersection( SampleMath.Matrix44FInverse(mProjectionMatrix), modelViewMatrix_Vuforia, metrics.widthPixels, metrics.heightPixels, new Vec2F(x, y), new Vec3F(0, 0, 0), new Vec3F(0, 0, 1)); float leftX = targetPositiveDimensions.getData()[0] - 0.5f * targetPositiveDimensions.getData()[0]; float rightX = targetPositiveDimensions.getData()[0] + 0.5f * targetPositiveDimensions.getData()[0]; float bottomY = targetPositiveDimensions.getData()[1] - 0.5f * targetPositiveDimensions.getData()[1]; float topY = targetPositiveDimensions.getData()[1] + 0.5f * targetPositiveDimensions.getData()[1]; if ((intersection.getData()[0] >= leftX) && (intersection.getData()[0] <= rightX) && (intersection.getData()[1] >= bottomY) && (intersection.getData()[1] <= topY)) { return true; } } return false; }
Simple texture above the motorcycle model is in the position:
new double[]{ -0.50f, -0.50f, 1.50f, 0.50f, -0.50f, 1.50f, 0.50f, 0.50f, 1.50f, -0.50f, 0.50f, 1.50f}
I have a 3d marker so to have a texture above the 3d marker I've changed z axis. The problem is in transforming the tap coordinates to the texture coordinates. In targetPositiveDimensions I have always coordinates of the beginning of my marker not my texture above it. Maybe I forgot about some transformation? Could you give me some advice?
[/quote]