public Renderer(Scene $scene) {
    _scene = $scene;

    _scratchIntBuffer = IntBuffer.allocate(4);
    _scratchFloatBuffer = FloatBuffer.allocate(4);

    _textureManager = new TextureManager();
    Shared.textureManager(_textureManager);

    _activityManager =
        (ActivityManager) Shared.context().getSystemService(Context.ACTIVITY_SERVICE);
    _memoryInfo = new ActivityManager.MemoryInfo();
  }
  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");
  }
Esempio n. 3
0
    public Min3dRenderer(Context c) {

      Shared.context(getApplicationContext());

      _scene = new Scene();
      _renderer = new min3d.core.Renderer(_scene, null);
      Shared.renderer(_renderer);

      _sensor = new SensorListener(c);
      _lastDraw = System.currentTimeMillis();

      _prefs = Balls.this.getSharedPreferences(BallsSettings.SHARED_PREFS_NAME, 0);
      _prefs.registerOnSharedPreferenceChangeListener(this);
      onSharedPreferenceChanged(_prefs, null);
      loadPrefs();
    }
Esempio n. 4
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);
    }
  }
  private void reset() {
    // Reset TextureManager
    Shared.textureManager().reset();

    // Do OpenGL settings which we are using as defaults, or which we will not be changing on-draw

    // Explicit depth settings
    _gl.glEnable(GL10.GL_DEPTH_TEST);
    _gl.glClearDepthf(1.0f);
    _gl.glDepthFunc(GL10.GL_LESS);
    _gl.glDepthRangef(0, 1f);
    _gl.glDepthMask(true);

    // Alpha enabled
    _gl.glEnable(GL10.GL_BLEND);
    _gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    // "Transparency is best implemented using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    // with primitives sorted from farthest to nearest."

    // Texture
    _gl.glTexParameterf(
        GL10.GL_TEXTURE_2D,
        GL10.GL_TEXTURE_MIN_FILTER,
        GL10.GL_NEAREST); // (OpenGL default is GL_NEAREST_MIPMAP)
    _gl.glTexParameterf(
        GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); // (is OpenGL default)

    // CCW frontfaces only, by default
    _gl.glFrontFace(GL10.GL_CCW);
    _gl.glCullFace(GL10.GL_BACK);
    _gl.glEnable(GL10.GL_CULL_FACE);

    // Disable lights by default
    for (int i = GL10.GL_LIGHT0; i < GL10.GL_LIGHT0 + NUM_GLLIGHTS; i++) {
      _gl.glDisable(i);
    }

    //
    // Scene object init only happens here, when we get GL for the first time
    //
  }
Esempio n. 6
0
  @Override
  public AnimationObject3d getParsedAnimationObject() {
    Log.d(Min3d.TAG, "Start object creation");
    Bitmap texture = null;
    AnimationObject3d animObj;

    if (textureAtlas.hasBitmaps()) {
      textureAtlas.generate();
      texture = textureAtlas.getBitmap();
      Shared.textureManager().addTextureId(texture, textureAtlas.getId(), generateMipMap);
    }

    Log.d(Min3d.TAG, "Creating object " + co.name);
    animObj = co.getParsedObject(textureAtlas, materialMap, frames);

    if (textureAtlas.hasBitmaps()) {
      if (texture != null) texture.recycle();
    }
    Log.d(Min3d.TAG, "Object creation finished");

    super.cleanup();

    return animObj;
  }
Esempio n. 7
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);
      }
    }