示例#1
0
  // The assets for the Cubemap are taken from the Samsung Developers website:
  // http://www.samsung.com/us/samsungdeveloperconnection/developer-resources/
  // gear-vr/apps-and-games/exercise-2-creating-the-splash-scene.html
  private void addSurroundings(GVRContext gvrContext, GVRScene scene) {
    FutureWrapper<GVRMesh> futureQuadMesh =
        new FutureWrapper<GVRMesh>(gvrContext.createQuad(CUBE_WIDTH, CUBE_WIDTH));
    Future<GVRTexture> futureCubemapTexture =
        gvrContext.loadFutureCubemapTexture(new GVRAndroidResource(gvrContext, R.raw.earth));

    GVRMaterial cubemapMaterial = new GVRMaterial(gvrContext, GVRMaterial.GVRShaderType.Cubemap.ID);
    cubemapMaterial.setMainTexture(futureCubemapTexture);

    // surrounding cube
    GVRSceneObject frontFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture);
    frontFace.getRenderData().setMaterial(cubemapMaterial);
    frontFace.setName("front");
    scene.addSceneObject(frontFace);
    frontFace.getTransform().setPosition(0.0f, 0.0f, -CUBE_WIDTH * 0.5f);

    GVRSceneObject backFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture);
    backFace.getRenderData().setMaterial(cubemapMaterial);
    backFace.setName("back");
    scene.addSceneObject(backFace);
    backFace.getTransform().setPosition(0.0f, 0.0f, CUBE_WIDTH * 0.5f);
    backFace.getTransform().rotateByAxis(180.0f, 0.0f, 1.0f, 0.0f);

    GVRSceneObject leftFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture);
    leftFace.getRenderData().setMaterial(cubemapMaterial);
    leftFace.setName("left");
    scene.addSceneObject(leftFace);
    leftFace.getTransform().setPosition(-CUBE_WIDTH * 0.5f, 0.0f, 0.0f);
    leftFace.getTransform().rotateByAxis(90.0f, 0.0f, 1.0f, 0.0f);

    GVRSceneObject rightFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture);
    rightFace.getRenderData().setMaterial(cubemapMaterial);
    rightFace.setName("right");
    scene.addSceneObject(rightFace);
    rightFace.getTransform().setPosition(CUBE_WIDTH * 0.5f, 0.0f, 0.0f);
    rightFace.getTransform().rotateByAxis(-90.0f, 0.0f, 1.0f, 0.0f);

    GVRSceneObject topFace = new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture);
    topFace.getRenderData().setMaterial(cubemapMaterial);
    topFace.setName("top");
    scene.addSceneObject(topFace);
    topFace.getTransform().setPosition(0.0f, CUBE_WIDTH * 0.5f, 0.0f);
    topFace.getTransform().rotateByAxis(90.0f, 1.0f, 0.0f, 0.0f);

    GVRSceneObject bottomFace =
        new GVRSceneObject(gvrContext, futureQuadMesh, futureCubemapTexture);
    bottomFace.getRenderData().setMaterial(cubemapMaterial);
    bottomFace.setName("bottom");
    scene.addSceneObject(bottomFace);
    bottomFace.getTransform().setPosition(0.0f, -CUBE_WIDTH * 0.5f, 0.0f);
    bottomFace.getTransform().rotateByAxis(-90.0f, 1.0f, 0.0f, 0.0f);
  }
示例#2
0
  @Override
  public void onCursorControllerAdded(final GVRCursorController controller) {
    GVRSceneObject sceneObject = new GVRSceneObject(gvrContext);
    Future<GVRTexture> texture =
        gvrContext.loadFutureTexture(new GVRAndroidResource(gvrContext, R.raw.earthmap1k));

    GVRMaterial material = new GVRMaterial(gvrContext, shaderManager.getShaderId());

    // stay away from the darker colors for the cursor
    float r = random.nextFloat() / 2.0f + 0.5f;
    float g = random.nextFloat() / 2.0f + 0.5f;
    float b = random.nextFloat() / 2.0f + 0.5f;

    material.setVec3(CustomShaderManager.COLOR_KEY, r, g, b);
    material.setTexture(CustomShaderManager.TEXTURE_KEY, texture);
    material.setMainTexture(texture);
    Future<GVRMesh> futureCursorMesh =
        gvrContext.loadFutureMesh(new GVRAndroidResource(gvrContext, R.raw.cursor));

    GVRRenderData cursorRenderData = new GVRRenderData(gvrContext);
    cursorRenderData.setMesh(futureCursorMesh);
    cursorRenderData.setMaterial(material);
    sceneObject.attachRenderData(cursorRenderData);

    mainScene.addSceneObject(sceneObject);
    controller.setSceneObject(sceneObject);

    // set the initial cursor position
    controller.setPosition(
        INITIAL_CURSOR_POSITION[0], INITIAL_CURSOR_POSITION[1], INITIAL_CURSOR_POSITION[2]);

    // set the min cursor depth
    controller.setNearDepth(NEAR_DEPTH);

    // set the max cursor depth
    controller.setFarDepth(FAR_DEPTH);
  }