Esempio n. 1
0
  public static void loadBackGroundImage(Scene scene) {
    if (background == null) {
      IParser parser =
          Parser.createParser(
              Parser.Type.OBJ, Shared.context().getResources(), "com.knb:raw/background_obj", true);
      parser.parse();
      background = parser.getParsedObject();
      background.scale().x = background.scale().y = background.scale().z = SBStore.BACKGROUND_SCALE;
      background.position().z = -1.99f;
    }

    if (scene != null) {

      scene.addChild(background);
    }
  }
Esempio n. 2
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);
      }
    }