Beispiel #1
0
  /**
   * Updates the sky box textures with a single texture.
   *
   * @param resourceId int the resource id of the new texture.
   * @throws Exception
   */
  public void updateSkybox(int resourceId) throws Exception {
    if (mSkyboxTexture.getClass() != Texture.class)
      throw new Exception("The skybox texture cannot be updated.");

    Texture texture = (Texture) mSkyboxTexture;
    texture.setResourceId(resourceId);
    mRenderer.getTextureManager().replaceTexture(texture);
  }
  /**
   * Displays different heads-up display components. These are rendered on different planes which
   * are positioned depending on current camera position and orientation.
   */
  private void showHudComponents() {
    Quaternion currentOrientation = getCurrentCamera().getOrientation();
    Vector3 currentPosition = getCurrentCamera().getPosition();

    showHudHelper(currentOrientation.clone(), currentPosition);
    showHudPositionHelper(currentOrientation);

    // Show points and remaining rockets.
    //        int rockets = state.getTopLevelManager().getRocketsAvailable();
    //        int totalAsteroids = state.getAsteroidManager().getAsteroids().size();
    Bitmap pointBitmap = drawTextToBitmap(state.displayString);
    Texture currentTexture = (Texture) leftTopPlane.getMaterial().getTextureList().get(0);
    currentTexture.getBitmap().recycle();
    currentTexture.setBitmap(pointBitmap);
    getTextureManager().replaceTexture(currentTexture);
    //            leftTopPlane.getMaterial().addTexture(new Texture("123", pointBitmap));
    // TODO

    // Show remaining rockets.
    // TODO.
  }
  @Override
  public void initScene() {
    // Set singleton renderer to current object to be referenced by various Managers.
    currentRenderer = this;

    // Set frame rate.
    setFrameRate(30);

    // Set up lights.
    DirectionalLight light = new DirectionalLight(0.2f, -1f, 0f);
    light.setPower(.7f);
    getCurrentScene().addLight(light);

    light = new DirectionalLight(0.2f, 1f, 0f);
    light.setPower(1f);
    getCurrentScene().addLight(light);

    // Set cropping plane.
    getCurrentCamera().setFarPlane(1000);

    // Background.
    getCurrentScene().setBackgroundColor(0x000000);

    // Create the surrounding.
    createFloor();

    // Instantiate game state to kick off the game.
    state = new GameState(getCurrentScene(), this);

    // Create sample asteroid
    Material material = new Material();
    material.enableLighting(true);
    material.setDiffuseMethod(new DiffuseMethod.Lambert());
    material.setColor(0);

    Texture earthTexture = new Texture("Asteroid", R.drawable.asteroid_small);
    try {
      material.addTexture(earthTexture);

    } catch (TextureException error) {
      RajLog.i("DEBUG TEXTURE ERROR");
    }

    // Set up crosshair.
    centralPane = new Plane(1, 1, 1, 1);
    Material crosshairMaterial = getStandardMaterial();
    Bitmap crosshairBitmap =
        BitmapFactory.decodeResource(mContext.getResources(), R.drawable.crosshair);
    //        Bitmap crosshairBitmap = drawTextToBitmap(mContext, "HELLO POINTS!!!");

    Texture tex = (Texture) crosshairMaterial.getTextureList().get(0);
    tex.setBitmap(crosshairBitmap);

    centralPane.setMaterial(crosshairMaterial);
    centralPane.setDoubleSided(true);
    centralPane.setTransparent(true);
    getCurrentScene().addChild(centralPane);

    leftTopPlane = new Plane(2, 2, 1, 1);
    leftTopPlane.setMaterial(getStandardMaterial());
    leftTopPlane.setTransparent(true);
    leftTopPlane.setDoubleSided(true);
    getCurrentScene().addChild(leftTopPlane);

    leftBottomPlane = new Plane(1, 1, 1, 1);
    leftBottomPlane.setMaterial(getStandardMaterial());
    leftBottomPlane.setTransparent(true);
    leftBottomPlane.setDoubleSided(true);
    //        getCurrentScene().addChild(leftBottomPlane);

    super.initScene();
  }