Esempio n. 1
0
  private void updateLoader() {
    if (NavigineApp.Navigation == null) return;

    // Log.d(TAG, String.format(Locale.ENGLISH, "Update loader: %d", mLoader));

    long timeNow = DateTimeUtils.currentTimeMillis();
    if (mLoader < 0) return;

    int status = LocationLoader.checkLocationLoader(mLoader);
    if (status < 100) {
      if ((Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT / 3 && status == 0)
          || (Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT)) {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText("Loading timeout!\nPlease, check your internet connection!");
        Log.d(TAG, String.format(Locale.ENGLISH, "Load stopped on timeout!"));
        LocationLoader.stopLocationLoader(mLoader);
        mLoader = -1;
      } else {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText(String.format(Locale.ENGLISH, "Loading content (%d%%)", status));
      }
    } else {
      Log.d(TAG, String.format(Locale.ENGLISH, "Load finished with result: %d", status));
      LocationLoader.stopLocationLoader(mLoader);
      mLoader = -1;

      if (status == 100) {
        parseMapsXml();
        if (mInfoList.isEmpty()) {
          mListView.setVisibility(View.GONE);
          mStatusLabel.setVisibility(View.VISIBLE);
          mStatusLabel.setText("No locations available");
        } else {
          mListView.setVisibility(View.VISIBLE);
          mStatusLabel.setVisibility(View.GONE);
        }
      } else {
        mListView.setVisibility(View.GONE);
        mStatusLabel.setVisibility(View.VISIBLE);
        mStatusLabel.setText("Error loading!\nPlease, check your ID!");
      }
    }
  }
 private void updateTextureAndDistortionMesh() {
   final ScreenParams screen = this.mHmd.getScreenParams();
   final CardboardDeviceParams cdp = this.mHmd.getCardboardDeviceParams();
   if (this.mProgramHolder == null) {
     this.mProgramHolder = this.createProgramHolder();
   }
   if (this.mProgramHolderAberration == null) {
     this.mProgramHolderAberration = (ProgramHolderAberration) this.createProgramHolder(true);
   }
   final float textureWidthTanAngle = this.mLeftEyeViewport.width + this.mRightEyeViewport.width;
   final float textureHeightTanAngle =
       Math.max(this.mLeftEyeViewport.height, this.mRightEyeViewport.height);
   final int[] maxTextureSize = {0};
   GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
   final int textureWidthPx =
       Math.min(Math.round(textureWidthTanAngle * this.mXPxPerTanAngle), maxTextureSize[0]);
   final int textureHeightPx =
       Math.min(Math.round(textureHeightTanAngle * this.mYPxPerTanAngle), maxTextureSize[0]);
   float xEyeOffsetTanAngleScreen =
       (screen.getWidthMeters() / 2.0f - cdp.getInterLensDistance() / 2.0f)
           / this.mMetersPerTanAngle;
   final float yEyeOffsetTanAngleScreen =
       (cdp.getVerticalDistanceToLensCenter() - screen.getBorderSizeMeters())
           / this.mMetersPerTanAngle;
   this.mLeftEyeDistortionMesh =
       this.createDistortionMesh(
           this.mLeftEyeViewport,
           textureWidthTanAngle,
           textureHeightTanAngle,
           xEyeOffsetTanAngleScreen,
           yEyeOffsetTanAngleScreen);
   xEyeOffsetTanAngleScreen =
       screen.getWidthMeters() / this.mMetersPerTanAngle - xEyeOffsetTanAngleScreen;
   this.mRightEyeDistortionMesh =
       this.createDistortionMesh(
           this.mRightEyeViewport,
           textureWidthTanAngle,
           textureHeightTanAngle,
           xEyeOffsetTanAngleScreen,
           yEyeOffsetTanAngleScreen);
   this.setupRenderTextureAndRenderbuffer(textureWidthPx, textureHeightPx);
   this.mFovsChanged = false;
 }
 public void updateViewports(final Viewport leftViewport, final Viewport rightViewport) {
   leftViewport.setViewport(
       Math.round(this.mLeftEyeViewport.x * this.mXPxPerTanAngle * this.mResolutionScale),
       Math.round(this.mLeftEyeViewport.y * this.mYPxPerTanAngle * this.mResolutionScale),
       Math.round(this.mLeftEyeViewport.width * this.mXPxPerTanAngle * this.mResolutionScale),
       Math.round(this.mLeftEyeViewport.height * this.mYPxPerTanAngle * this.mResolutionScale));
   rightViewport.setViewport(
       Math.round(this.mRightEyeViewport.x * this.mXPxPerTanAngle * this.mResolutionScale),
       Math.round(this.mRightEyeViewport.y * this.mYPxPerTanAngle * this.mResolutionScale),
       Math.round(this.mRightEyeViewport.width * this.mXPxPerTanAngle * this.mResolutionScale),
       Math.round(this.mRightEyeViewport.height * this.mYPxPerTanAngle * this.mResolutionScale));
   this.mViewportsChanged = false;
 }
Esempio n. 4
0
        public void run() {
          if (NavigineApp.Navigation == null) return;

          long timeNow = DateTimeUtils.currentTimeMillis();

          String userHash = NavigineApp.Settings.getString("user_hash", "");
          if (userHash.length() == 0) return;

          if (mLoader >= 0) updateLoader();

          if (Math.abs(timeNow - mUpdateLocationLoadersTime) > 1000) updateLocationLoaders();
        }
 private EyeViewport initViewportForEye(final FieldOfView fov, final float xOffset) {
   final float left = (float) Math.tan(Math.toRadians(fov.getLeft()));
   final float right = (float) Math.tan(Math.toRadians(fov.getRight()));
   final float bottom = (float) Math.tan(Math.toRadians(fov.getBottom()));
   final float top = (float) Math.tan(Math.toRadians(fov.getTop()));
   final EyeViewport vp = new EyeViewport();
   vp.x = xOffset;
   vp.y = 0.0f;
   vp.width = left + right;
   vp.height = bottom + top;
   vp.eyeX = left + xOffset;
   vp.eyeY = bottom;
   return vp;
 }
Esempio n. 6
0
  private void updateLocationLoaders() {
    if (NavigineApp.Navigation == null) return;

    long timeNow = DateTimeUtils.currentTimeMillis();
    mUpdateLocationLoadersTime = timeNow;

    synchronized (mLoaderMap) {
      Iterator<Map.Entry<String, LoaderState>> iter = mLoaderMap.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String, LoaderState> entry = iter.next();

        LoaderState loader = entry.getValue();
        if (loader.state < 100) {
          loader.timeLabel = timeNow;
          if (loader.type == DOWNLOAD) loader.state = LocationLoader.checkLocationLoader(loader.id);
          if (loader.type == UPLOAD) loader.state = LocationLoader.checkLocationUploader(loader.id);
        } else if (loader.state == 100) {
          String archivePath = NavigineApp.Navigation.getArchivePath();
          String locationFile =
              LocationLoader.getLocationFile(NavigineApp.AppContext, loader.location);
          if (archivePath != null && archivePath.equals(locationFile)) {
            Log.d(TAG, "Reloading archive " + archivePath);
            if (NavigineApp.Navigation.loadArchive(archivePath)) {
              SharedPreferences.Editor editor = NavigineApp.Settings.edit();
              editor.putString("map_file", archivePath);
              editor.commit();
            }
          }
          if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id);
          if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id);
          iter.remove();
        } else {
          // Load failed
          if (Math.abs(timeNow - loader.timeLabel) > 5000) {
            if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id);
            if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id);
            iter.remove();
          }
        }
      }
    }
    updateLocalVersions();
    mAdapter.updateList();
  }
 public DistortionMesh(
     final Distortion distortionRed,
     final Distortion distortionGreen,
     final Distortion distortionBlue,
     final float screenWidth,
     final float screenHeight,
     final float xEyeOffsetScreen,
     final float yEyeOffsetScreen,
     final float textureWidth,
     final float textureHeight,
     final float xEyeOffsetTexture,
     final float yEyeOffsetTexture,
     final float viewportXTexture,
     final float viewportYTexture,
     final float viewportWidthTexture,
     final float viewportHeightTexture) {
   super();
   this.mArrayBufferId = -1;
   this.mElementBufferId = -1;
   final float[] vertexData = new float[14400];
   short vertexOffset = 0;
   for (int row = 0; row < ROWS; ++row) {
     for (int col = 0; col < COLS; ++col) {
       final float uTextureBlue =
           col / 39.0f * (viewportWidthTexture / textureWidth) + viewportXTexture / textureWidth;
       final float vTextureBlue =
           row / 39.0f * (viewportHeightTexture / textureHeight)
               + viewportYTexture / textureHeight;
       final float xTexture = uTextureBlue * textureWidth - xEyeOffsetTexture;
       final float yTexture = vTextureBlue * textureHeight - yEyeOffsetTexture;
       final float rTexture = (float) Math.sqrt(xTexture * xTexture + yTexture * yTexture);
       final float textureToScreenBlue =
           (rTexture > 0.0f) ? (distortionBlue.distortInverse(rTexture) / rTexture) : 1.0f;
       final float xScreen = xTexture * textureToScreenBlue;
       final float yScreen = yTexture * textureToScreenBlue;
       final float uScreen = (xScreen + xEyeOffsetScreen) / screenWidth;
       final float vScreen = (yScreen + yEyeOffsetScreen) / screenHeight;
       final float rScreen = rTexture * textureToScreenBlue;
       final float screenToTextureGreen =
           (rScreen > 0.0f) ? distortionGreen.distortionFactor(rScreen) : 1.0f;
       final float uTextureGreen =
           (xScreen * screenToTextureGreen + xEyeOffsetTexture) / textureWidth;
       final float vTextureGreen =
           (yScreen * screenToTextureGreen + yEyeOffsetTexture) / textureHeight;
       final float screenToTextureRed =
           (rScreen > 0.0f) ? distortionRed.distortionFactor(rScreen) : 1.0f;
       final float uTextureRed =
           (xScreen * screenToTextureRed + xEyeOffsetTexture) / textureWidth;
       final float vTextureRed =
           (yScreen * screenToTextureRed + yEyeOffsetTexture) / textureHeight;
       final float vignetteSizeTexture = VIGNETTE_SIZE_TAN_ANGLE / textureToScreenBlue;
       final float dxTexture =
           xTexture
               + xEyeOffsetTexture
               - clamp(
                   xTexture + xEyeOffsetTexture,
                   viewportXTexture + vignetteSizeTexture,
                   viewportXTexture + viewportWidthTexture - vignetteSizeTexture);
       final float dyTexture =
           yTexture
               + yEyeOffsetTexture
               - clamp(
                   yTexture + yEyeOffsetTexture,
                   viewportYTexture + vignetteSizeTexture,
                   viewportYTexture + viewportHeightTexture - vignetteSizeTexture);
       final float drTexture = (float) Math.sqrt(dxTexture * dxTexture + dyTexture * dyTexture);
       float vignette;
       if (DistortionRenderer.this.mVignetteEnabled) {
         vignette = 1.0f - clamp(drTexture / vignetteSizeTexture, 0.0f, 1.0f);
       } else {
         vignette = 1.0f;
       }
       vertexData[vertexOffset + 0] = 2.0f * uScreen - 1.0f;
       vertexData[vertexOffset + 1] = 2.0f * vScreen - 1.0f;
       vertexData[vertexOffset + 2] = vignette;
       vertexData[vertexOffset + 3] = uTextureRed;
       vertexData[vertexOffset + 4] = vTextureRed;
       vertexData[vertexOffset + 5] = uTextureGreen;
       vertexData[vertexOffset + 6] = vTextureGreen;
       vertexData[vertexOffset + 7] = uTextureBlue;
       vertexData[vertexOffset + 8] = vTextureBlue;
       vertexOffset += COMPONENTS_PER_VERT;
     }
   }
   this.nIndices = 3158;
   final short[] indexData = new short[this.nIndices];
   short indexOffset = 0;
   vertexOffset = 0;
   for (int row2 = 0; row2 < 39; ++row2) {
     if (row2 > 0) {
       indexData[indexOffset] = indexData[indexOffset - 1];
       ++indexOffset;
     }
     for (int col2 = 0; col2 < 40; ++col2) {
       if (col2 > 0) {
         if (row2 % 2 == 0) {
           ++vertexOffset;
         } else {
           --vertexOffset;
         }
       }
       indexData[indexOffset] = vertexOffset;
       ++indexOffset;
       indexData[indexOffset] = (short) (vertexOffset + 40);
       ++indexOffset;
     }
     vertexOffset += 40;
   }
   final FloatBuffer vertexBuffer =
       ByteBuffer.allocateDirect(vertexData.length * BYTES_PER_FLOAT)
           .order(ByteOrder.nativeOrder())
           .asFloatBuffer();
   vertexBuffer.put(vertexData).position(0);
   final ShortBuffer indexBuffer =
       ByteBuffer.allocateDirect(indexData.length * BYTES_PER_SHORT)
           .order(ByteOrder.nativeOrder())
           .asShortBuffer();
   indexBuffer.put(indexData).position(0);
   final int[] bufferIds = new int[2];
   GLES20.glGenBuffers(2, bufferIds, 0);
   this.mArrayBufferId = bufferIds[0];
   this.mElementBufferId = bufferIds[1];
   GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, this.mArrayBufferId);
   GLES20.glBufferData(
       GLES20.GL_ARRAY_BUFFER,
       vertexData.length * BYTES_PER_FLOAT,
       (Buffer) vertexBuffer,
       GLES20.GL_STATIC_DRAW);
   GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, this.mElementBufferId);
   GLES20.glBufferData(
       GLES20.GL_ELEMENT_ARRAY_BUFFER,
       indexData.length * BYTES_PER_SHORT,
       (Buffer) indexBuffer,
       GLES20.GL_STATIC_DRAW);
   GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
   GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
 }
 private static float clamp(final float val, final float min, final float max) {
   return Math.max(min, Math.min(max, val));
 }
Esempio n. 9
0
 public static int bringToBounds(final int n, final int n2, final int n3) {
   return Math.max(n, Math.min(n2, n3));
 }