public void updateDrawData() {
    mBGStarPositionsBuffer.position(0);
    mBGStarColorsBuffer.position(0);
    mBGStarTexturesBuffer.position(0);

    // Update the star data
    for (Star star : BGStarSet) {
      Geocentric position = star.getCoords();
      Geocentric u = MathUtils.normalize(MathUtils.crossProduct(position, Z_UP_VECTOR));
      Geocentric v = MathUtils.crossProduct(u, position);

      float sizer = star.magnitude * mRenderer.mPointSizeFactor;
      Geocentric sized_u = new Geocentric(u.x * sizer, u.y * sizer, u.z * sizer);
      Geocentric sized_v = new Geocentric(v.x * sizer, v.y * sizer, v.z * sizer);

      float[] bottomLeft = {
        position.x - sized_u.x - sized_v.x,
        position.y - sized_u.y - sized_v.y,
        position.z - sized_u.z - sized_v.z
      };
      float[] topLeft = {
        position.x - sized_u.x + sized_v.x,
        position.y - sized_u.y + sized_v.y,
        position.z - sized_u.z + sized_v.z
      };
      float[] bottomRight = {
        position.x + sized_u.x - sized_v.x,
        position.y + sized_u.y - sized_v.y,
        position.z + sized_u.z - sized_v.z
      };
      float[] topRight = {
        position.x + sized_u.x + sized_v.x,
        position.y + sized_u.y + sized_v.y,
        position.z + sized_u.z + sized_v.z
      };

      // Inserting first triangle (counter-clockwise)
      mBGStarPositionsBuffer.put(topLeft);
      mBGStarPositionsBuffer.put(bottomLeft);
      mBGStarPositionsBuffer.put(topRight);
      // Inserting second triangle (counter-clockwise)
      mBGStarPositionsBuffer.put(bottomLeft);
      mBGStarPositionsBuffer.put(bottomRight);
      mBGStarPositionsBuffer.put(topRight);

      // Inserting Color per Star (white)
      mBGStarColorsBuffer.put(STAR_COLOR_DATA_ARRAY);

      // Inserting Texture Coordinates per Star
      mBGStarTexturesBuffer.put(TEX_COORD_ARRAY);
    }
    mBGStarPositionsBuffer.position(0);
    mBGStarColorsBuffer.position(0);
    mBGStarTexturesBuffer.position(0);
  }
Ejemplo n.º 2
0
  private void changeMapX(float radians) {
    Geocentric lookVector = mUser.getLookDir();
    Geocentric crossVector = MathUtils.crossProduct(lookVector, mUser.getLookNormal());
    Geocentric deltaLookVector =
        new Geocentric(crossVector.x * radians, crossVector.y * radians, crossVector.z * radians);

    Geocentric newLookDir = MathUtils.add(lookVector, deltaLookVector);
    newLookDir = MathUtils.normalize(newLookDir);

    mUser.setLookDir(newLookDir);
  }
Ejemplo n.º 3
0
  private void rotate(float radians) {
    Geocentric lookVector = mUser.getLookDir();
    Geocentric upVector = mUser.getLookNormal();

    Matrix3x3 rotationMatrix = MathUtils.createRotationMatrix(radians, lookVector);
    Geocentric newUpVector = MathUtils.multiplyGeocentricAndMatrix3x3(rotationMatrix, upVector);

    newUpVector = MathUtils.normalize(newUpVector);

    mUser.setLookNormal(newUpVector);
  }
Ejemplo n.º 4
0
  private void changeMapY(float radians) {
    Geocentric lookVector = mUser.getLookDir();
    Geocentric upVector = mUser.getLookNormal();

    Geocentric deltaLookVector =
        new Geocentric(upVector.x * -radians, upVector.y * -radians, upVector.z * -radians);
    Geocentric newLookDir = MathUtils.add(lookVector, deltaLookVector);
    newLookDir = MathUtils.normalize(newLookDir);

    Geocentric deltaUpVector =
        new Geocentric(lookVector.x * radians, lookVector.y * radians, lookVector.z * radians);
    Geocentric newUpDir = MathUtils.add(upVector, deltaUpVector);
    newUpDir = MathUtils.normalize(newUpDir);

    mUser.setLookDir(newLookDir);
    mUser.setLookNormal(newUpDir);
  }
  @Override
  public void onSensorChanged(SensorEvent event) {
    // smoothing code
    for (int i = 0; i < 3; ++i) {
      last[i] = current[i];
      float diff = event.values[i] - last[i];
      float correction = diff * alpha;
      for (int j = 1; j < exponent; ++j) {
        correction *= Math.abs(diff);
      }
      if (correction > Math.abs(diff) || correction < -Math.abs(diff)) {
        correction = diff;
      }
      current[i] = last[i] + correction;
    }

    mNewAccelerationReading.x = -current[0];
    mNewAccelerationReading.y = -current[1];
    mNewAccelerationReading.z = -current[2];

    mUser.setAcceleration(mNewAccelerationReading);

    Matrix3x3 phoneSpaceMatrix = mUser.getLocalNorthAndUpMatrix_PhoneSpace();
    Matrix3x3 celestialSpaceMatrix = mUser.getLocalNorthAndUpMatrix_CelestialSpace();
    Matrix3x3 viewTransform = MathUtils.multiplyMatrices(celestialSpaceMatrix, phoneSpaceMatrix);

    Geocentric lookVector = MathUtils.multiplyGeocentricAndMatrix3x3(viewTransform, Z_DOWN_VECTOR);
    Geocentric upVector = MathUtils.multiplyGeocentricAndMatrix3x3(viewTransform, INIT_UP_VECTOR);

    //		Log.d("AccelerometerModel", "INSIDE ACCELEROMETER SENSORCHANGED");

    //		Log.d("AccelerometerModel", "ps_xx: " + String.valueOf(phoneSpaceMatrix.xx) + " ps_xy: " +
    // String.valueOf(phoneSpaceMatrix.xy) + " ps_xz: " + String.valueOf(phoneSpaceMatrix.xz));
    //		Log.d("AccelerometerModel", "ps_yx: " + String.valueOf(phoneSpaceMatrix.yx) + " ps_yy: " +
    // String.valueOf(phoneSpaceMatrix.yy) + " ps_yz: " + String.valueOf(phoneSpaceMatrix.yz));
    //		Log.d("AccelerometerModel", "ps_zx: " + String.valueOf(phoneSpaceMatrix.zx) + " ps_zy: " +
    // String.valueOf(phoneSpaceMatrix.zy) + " ps_zz: " + String.valueOf(phoneSpaceMatrix.zz));

    //		Log.d("AccelerometerModel", "vt_xx: " + String.valueOf(viewTransform.xx) + " vt_xy: " +
    // String.valueOf(viewTransform.xy) + " vt_xz: " + String.valueOf(viewTransform.xz));
    //		Log.d("AccelerometerModel", "vt_yx: " + String.valueOf(viewTransform.yx) + " vt_yy: " +
    // String.valueOf(viewTransform.yy) + " vt_yz: " + String.valueOf(viewTransform.yz));
    //		Log.d("AccelerometerModel", "vt_zx: " + String.valueOf(viewTransform.zx) + " vt_zy: " +
    // String.valueOf(viewTransform.zy) + " vt_zz: " + String.valueOf(viewTransform.zz));

    //		Log.d("AccelerometerModel", "event.values[0]: " + String.valueOf(event.values[0]) + "
    // event.values[1]: " + String.valueOf(event.values[1] + " event.values[2]: " +
    // String.valueOf(event.values[2])));

    mUser.lookDir = lookVector;
    mUser.lookNormal = upVector;

    mRenderer.mLookX = mUser.getLookX();
    mRenderer.mLookY = mUser.getLookY();
    mRenderer.mLookZ = mUser.getLookZ();
    mRenderer.mUpX = mUser.getNormalX();
    mRenderer.mUpY = mUser.getNormalY();
    mRenderer.mUpZ = mUser.getNormalZ();

    //		Log.d("AccelerometerModel", "lastX: " + String.valueOf(last[0]) + " lastY: " +
    // String.valueOf(last[1]) + " lastZ: " + String.valueOf(last[2]));
    //		Log.d("AccelerometerModel", "currentX: " + String.valueOf(current[0]) + " currentY: " +
    // String.valueOf(current[1]) + " currentZ: " + String.valueOf(current[2]));
    //		Log.d("AccelerometerModel", "mLookX: " + String.valueOf(mUser.getLookX()) + " mLookY: " +
    // String.valueOf(mUser.getLookY()) + " mLookZ: " + String.valueOf(mUser.getLookZ()));
    //		Log.d("AccelerometerModel", "mUpX: " + String.valueOf(mUser.getNormalX()) + " mUpY: " +
    // String.valueOf(mUser.getNormalY()) + " mUpZ: " + String.valueOf(mUser.getNormalZ()));

    // mGLSurfaceView.requestRender();
  }