Какой-то маркер застрял при рисовании маркера местоположения в режиме «Вид с камеры» в дополненной реальности - PullRequest
0 голосов
/ 18 июня 2019

Я могу нарисовать маркер местоположения, используя этот учебник

Но проблема в том, что когда я рисую маркер, некоторые из них занимают статическое положение и не меняются при перемещении камеры.А также эти маркеры рисуют несколько раз.Один получил правильную позицию X и Y на экране, а другой просто застрял в исходной позиции.

Вот видео того, как оно выглядит, когда рисует на экране.

@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();
 }
...