Пример #1
0
  public void initScene() {
    Light light = new Light();
    light.ambient.setAll(0xff888888);
    light.position.setAll(3, 0, 3);
    scene.lights().add(light);

    // Create objects

    // * Note:
    // -------
    // While the order in which objects are drawn is not important in terms of
    // z-ordering (which is taken care of automatically by OpenGL), the order
    // _is_ important when it comes to transparency. Here, for the transparency
    // of the "_jupiter" sphere to be apparent, it must added as the second child
    // of the scene (which means it will be drawn second). The engine does not
    // manage this automatically for you.

    _cube = new Box(1.3f, 1.3f, 1.3f);
    _cube.position().x = +0.4f;
    _cube.normalsEnabled(false);
    scene.addChild(_cube);

    // Add textures in TextureManager

    Bitmap b;

    b = Utils.makeBitmapFromResourceId(R.drawable.jupiter);
    Shared.textureManager().addTextureId(b, "jupiter", false);
    b.recycle();

    // Add textures to sphere
    _cube.textures().addById("jupiter");
  }
Пример #2
0
  public Rectangle(float $width, float $height, int $segsW, int $segsH, Color4 color) {
    super(4 * $segsW * $segsH, 2 * $segsW * $segsH);

    int row, col;

    float w = $width / $segsW;
    float h = $height / $segsH;

    float width5 = $width / 2f;
    float height5 = $height / 2f;

    // Add vertices

    for (row = 0; row <= $segsH; row++) {
      for (col = 0; col <= $segsW; col++) {
        this.vertices()
            .addVertex(
                col * w - width5,
                row * h - height5,
                0f,
                (float) col / (float) $segsW,
                1 - (float) row / (float) $segsH,
                0,
                0,
                1f,
                color.r,
                color.g,
                color.b,
                color.a);
      }
    }

    // Add faces

    int colspan = $segsW + 1;

    for (row = 1; row <= $segsH; row++) {
      for (col = 1; col <= $segsW; col++) {
        int lr = row * colspan + col;
        int ll = lr - 1;
        int ur = lr - colspan;
        int ul = ur - 1;
        Utils.addQuad(this, ul, ur, lr, ll);
      }
    }
  }
Пример #3
0
    public void initScene() {
      _scene.backgroundColor().setAll(_backColor);

      _scene.lights().add(new Light());

      Bitmap b = null;
      switch (_wallTexture) {
        case 1:
          b = Utils.makeBitmapFromResourceId(R.drawable.wood);
          break;
        case 2:
          b = Utils.makeBitmapFromResourceId(R.drawable.checkerboard);
          break;
        case 3:
          b = Utils.makeBitmapFromResourceId(R.drawable.gray_waves);
          break;
        case 4:
          b = Utils.makeBitmapFromResourceId(R.drawable.paper);
          break;
      }
      if (b != null) {
        Shared.textureManager().addTextureId(b, "wall", false);
        b.recycle();

        Color4 planeColor = new Color4(255, 255, 255, 255);
        _east = new Rectangle(40, 12, 2, 2, planeColor);
        _west = new Rectangle(40, 12, 2, 2, planeColor);
        _up = new Rectangle(40, 12, 2, 2, planeColor);
        _down = new Rectangle(40, 12, 2, 2, planeColor);

        _east.position().x = -6;
        _east.rotation().y = -90;
        _east.position().z = -20;
        _east.lightingEnabled(false);
        _east.textures().addById("wall");

        _west.position().x = 6;
        _west.rotation().y = 90;
        _west.position().z = -20;
        _west.lightingEnabled(false);
        _west.textures().addById("wall");

        _up.rotation().x = -90;
        _up.rotation().z = 90;
        _up.position().y = 6;
        _up.position().z = -20;
        _up.lightingEnabled(false);
        _up.textures().addById("wall");

        _down.rotation().x = 90;
        _down.rotation().z = 90;
        _down.position().y = -6;
        _down.position().z = -20;
        _down.lightingEnabled(false);
        _down.textures().addById("wall");

        _scene.addChild(_east);
        _scene.addChild(_west);
        _scene.addChild(_up);
        _scene.addChild(_down);
      }

      _scene.fogColor(new Color4(0, 0, 0, 255));
      _scene.fogNear(10);
      _scene.fogFar(40);
      _scene.fogEnabled(true);

      if (_theme != 2) {
        // not rainbow

        _light = new Light();
        _light.type(LightType.POSITIONAL);
        _light.position.setZ(10);
        _light.direction.z = -100;
        _scene.lights().add(_light);

        if (_theme == 0) {
          _light.ambient.setAll(_ballColor);
          _light.diffuse.setAll(_ballColor);
        }
      }

      TextureVo t = null;
      if (_theme >= 3) {
        b = null;
        if (_theme == 3) b = Utils.makeBitmapFromResourceId(Shared.context(), R.drawable.earth);
        if (_theme == 4)
          b = Utils.makeBitmapFromResourceId(Shared.context(), R.drawable.beach_ball);
        if (_theme == 5) b = Utils.makeBitmapFromResourceId(Shared.context(), R.drawable.smiley);
        if (_theme == 6) b = Utils.makeBitmapFromResourceId(Shared.context(), R.drawable.google);
        if (_theme == 7)
          b = Utils.makeBitmapFromResourceId(Shared.context(), R.drawable.checkerboard);
        Shared.textureManager().addTextureId(b, "texture", false);
        b.recycle();
        t = new TextureVo("texture");
      }

      Random r = new Random();
      for (int i = 0; i < _ballCount; i++) {

        Sphere s = new Sphere((float) (_ballSize * .001), 10, 10);

        if (t != null) s.textures().add(t);

        if (_style == 0) s.renderType(RenderType.TRIANGLES);
        if (_style == 1) s.renderType(RenderType.POINTS);
        else if (_style == 2) s.renderType(RenderType.LINES);
        else if (_style == 3) s.renderType(RenderType.LINE_LOOP);
        else if (_style == 4) s.renderType(RenderType.LINE_STRIP);
        else if (_style == 5) s.renderType(RenderType.TRIANGLE_STRIP);
        else if (_style == 6) s.renderType(RenderType.TRIANGLE_FAN);

        s.position().x = r.nextFloat();
        s.position().y = r.nextFloat();
        s.position().z = r.nextInt(15) * -1;

        s.rotation().x = r.nextInt(100);
        s.rotation().y = r.nextInt(100);

        if (_theme == 2) {
          s.colorMaterialEnabled(true);
          s.vertexColorsEnabled(true);
        } else {
          s.vertexColorsEnabled(false);
        }

        _scene.addChild(s);
      }
    }