Example #1
0
 public static float getYRotationAngle(GVRSceneObject rotatingObject, GVRCameraRig targetObject) {
   return (float)
       Math.toDegrees(
           Math.atan2(
               targetObject.getTransform().getPositionX()
                   - rotatingObject.getTransform().getPositionX(),
               targetObject.getTransform().getPositionZ()
                   - rotatingObject.getTransform().getPositionZ()));
 }
Example #2
0
 public static double distance(GVRSceneObject object, GVRCameraRig gvrCameraRig) {
   return Math.sqrt(
       Math.pow(
               object.getTransform().getPositionX() - gvrCameraRig.getTransform().getPositionX(),
               2)
           + Math.pow(
               object.getTransform().getPositionY() - gvrCameraRig.getTransform().getPositionY(),
               2)
           + Math.pow(
               object.getTransform().getPositionZ() - gvrCameraRig.getTransform().getPositionZ(),
               2));
 }
Example #3
0
  public static float[] calculatePointBetweenTwoObjects(
      GVRSceneObject object, GVRCameraRig gvrCameraRig, float desiredDistance) {
    float[] point = new float[3];
    float ratio = desiredDistance / (float) distance(object, gvrCameraRig);
    point[0] =
        (1 - ratio) * gvrCameraRig.getTransform().getPositionX()
            + (ratio) * object.getTransform().getPositionX();
    point[1] =
        (1 - ratio) * gvrCameraRig.getTransform().getPositionY()
            + (ratio) * object.getTransform().getPositionY();
    point[2] =
        (1 - ratio) * gvrCameraRig.getTransform().getPositionZ()
            + (ratio) * object.getTransform().getPositionZ();

    return point;
  }
  @Override
  public void onInit(GVRContext gvrContext) throws IOException {

    mAnimationEngine = gvrContext.getAnimationEngine();

    mMainScene =
        gvrContext.getNextMainScene(
            new Runnable() {

              @Override
              public void run() {
                for (GVRAnimation animation : mAnimations) {
                  animation.start(mAnimationEngine);
                }
                mAnimations = null;
              }
            });

    // Apply frustum culling
    mMainScene.setFrustumCulling(true);

    GVRCameraRig mainCameraRig = mMainScene.getMainCameraRig();
    mainCameraRig.getLeftCamera().setBackgroundColor(Color.BLACK);
    mainCameraRig.getRightCamera().setBackgroundColor(Color.BLACK);
    mainCameraRig.getTransform().setPosition(0.0f, 0.0f, 0.0f);

    // Model with texture
    GVRSceneObject astroBoyModel = gvrContext.getAssimpModel("astro_boy.dae");

    // Model with color
    GVRSceneObject benchModel = gvrContext.getAssimpModel("bench.dae");

    ModelPosition astroBoyModelPosition = new ModelPosition();

    astroBoyModelPosition.setPosition(0.0f, -0.4f, -0.5f);

    astroBoyModel.getTransform().setScale(3, 3, 3);

    astroBoyModel
        .getTransform()
        .setPosition(astroBoyModelPosition.x, astroBoyModelPosition.y, astroBoyModelPosition.z);
    astroBoyModel.getTransform().setRotationByAxis(180.0f, 0.0f, 1.0f, 0.0f);

    ModelPosition benchModelPosition = new ModelPosition();

    benchModelPosition.setPosition(0.0f, -4.0f, -30.0f);

    benchModel
        .getTransform()
        .setPosition(benchModelPosition.x, benchModelPosition.y, benchModelPosition.z);
    benchModel.getTransform().setRotationByAxis(180.0f, 0.0f, 1.0f, 0.0f);

    mMainScene.addSceneObject(astroBoyModel);
    mMainScene.addSceneObject(benchModel);

    rotateModel(astroBoyModel, 10f, astroBoyModelPosition);
  }