在增强现实中的“相机视图”上绘制位置标记时,某些标记卡住了

时间:2019-06-18 05:05:01

标签: android augmented-reality android-augmented-reality

我可以使用此tutorial

绘制位置标记

但是问题是,当我绘制标记时,其中一些标记处于静态位置,并且在Camera移动时不会改变。这些标记还会绘制多次。一个在屏幕上的X和Y位置正确,另一个刚好停留在其初始位置。

这里是video在屏幕上绘制时的样子。

@Override
protected void onDraw(Canvas canvas) {
     super.onDraw(canvas);

     if (currentLocation == null || arPoints == null ||arPoints.isEmpty()) {
            return;
        }

        final int radius = 30;
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setStyle(Paint.Style.FILL);
        paint.setColor(Color.WHITE);
        paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL));
        paint.setTextSize(20);

        for (int i = 0; i < arPoints.size(); i++) {


            float[] currentLocationInECEF = ARHelper.WSG84toECEF(currentLocation);
            float[] pointInECEF = ARHelper.WSG84toECEF(arPoints.get(i).getLocation());
            float[] pointInENU = ARHelper.ECEFtoENU(currentLocation, currentLocationInECEF, pointInECEF);

            //distanceText = arPoints.get(i).getKmAway(distance);
            float[] cameraCoordinateVector = new float[4];
            Matrix.multiplyMV(cameraCoordinateVector, 0, rotatedProjectionMatrix, 0, pointInENU, 0);

            // cameraCoordinateVector[2] is z, that always less than 0 to display on right position
            // if z > 0, the point will display on the opposite
            if (cameraCoordinateVector[2] < 0 && !arPoints.get(i).getAddress().contains("Al Tawhidi")) {
                float x = (0.5f + cameraCoordinateVector[0] / cameraCoordinateVector[3]) * canvas.getWidth();
                float y = (0.5f - cameraCoordinateVector[1] / cameraCoordinateVector[3]) * canvas.getHeight();

                canvas.drawBitmap(arPoints.get(i).getBitmap(), x, y, paint);
            }
        }
        invalidate();
 }

0 个答案:

没有答案