Пример #1
0
  protected void drawScene() {
    if (_scene.fogEnabled() == true) {
      _gl.glFogf(GL10.GL_FOG_MODE, _scene.fogType().glValue());
      _gl.glFogf(GL10.GL_FOG_START, _scene.fogNear());
      _gl.glFogf(GL10.GL_FOG_END, _scene.fogFar());
      _gl.glFogfv(GL10.GL_FOG_COLOR, _scene.fogColor().toFloatBuffer());
      _gl.glEnable(GL10.GL_FOG);
    } else {
      _gl.glDisable(GL10.GL_FOG);
    }

    for (int i = 0; i < _scene.children().size(); i++) {
      Object3d o = _scene.children().get(i);
      if (o.animationEnabled()) {
        ((AnimationObject3d) o).update();
      }
      drawObject(o);
    }
  }
Пример #2
0
  protected void drawObject(Object3d $o) {
    if ($o.isVisible() == false) return;

    // Various per-object settings:

    // Normals

    if ($o.hasNormals() && $o.normalsEnabled()) {
      $o.vertices().normals().buffer().position(0);
      _gl.glNormalPointer(GL10.GL_FLOAT, 0, $o.vertices().normals().buffer());
      _gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
    } else {
      _gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
    }

    // Is lighting enabled for object...

    /*
    // *** this version not working properly on emulator - why not? ***
    _scratchIntBuffer.position(0);
    _gl.glGetIntegerv(GL10.GL_LIGHTING, _scratchIntBuffer);
    if (useLighting != _scratchIntBuffer.get(0))
    {
    	if (useLighting == 1) {
    		_gl.glEnable(GL10.GL_LIGHTING);
    	} else {
    		_gl.glDisable(GL10.GL_LIGHTING);
    	}
    }
    */

    boolean useLighting =
        (_scene.lightingEnabled()
            && $o.hasNormals()
            && $o.normalsEnabled()
            && $o.lightingEnabled());
    if (useLighting) {
      _gl.glEnable(GL10.GL_LIGHTING);
    } else {
      _gl.glDisable(GL10.GL_LIGHTING);
    }

    // Shademodel

    _gl.glGetIntegerv(GL11.GL_SHADE_MODEL, _scratchIntBuffer);
    if ($o.shadeModel().glConstant() != _scratchIntBuffer.get(0)) {
      _gl.glShadeModel($o.shadeModel().glConstant());
    }

    // Colors: either per-vertex, or per-object

    if ($o.hasVertexColors() && $o.vertexColorsEnabled()) {
      $o.vertices().colors().buffer().position(0);
      _gl.glColorPointer(4, GL10.GL_UNSIGNED_BYTE, 0, $o.vertices().colors().buffer());
      _gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    } else {
      _gl.glColor4f(
          (float) $o.defaultColor().r / 255f,
          (float) $o.defaultColor().g / 255f,
          (float) $o.defaultColor().b / 255f,
          (float) $o.defaultColor().a / 255f);
      _gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
    }

    // Colormaterial

    _gl.glGetIntegerv(GL10.GL_COLOR_MATERIAL, _scratchIntBuffer);
    _scratchB = (_scratchIntBuffer.get(0) != 0);
    if ($o.colorMaterialEnabled() != _scratchB) {
      if ($o.colorMaterialEnabled()) _gl.glEnable(GL10.GL_COLOR_MATERIAL);
      else _gl.glDisable(GL10.GL_COLOR_MATERIAL);
    }

    // Point size

    if ($o.renderType() == RenderType.POINTS) {
      if ($o.pointSmoothing()) _gl.glEnable(GL10.GL_POINT_SMOOTH);
      else _gl.glDisable(GL10.GL_POINT_SMOOTH);

      _gl.glPointSize($o.pointSize());
    }

    // Line properties

    if ($o.renderType() == RenderType.LINES
        || $o.renderType() == RenderType.LINE_STRIP
        || $o.renderType() == RenderType.LINE_LOOP) {
      if ($o.lineSmoothing() == true) {
        _gl.glEnable(GL10.GL_LINE_SMOOTH);
      } else {
        _gl.glDisable(GL10.GL_LINE_SMOOTH);
      }

      _gl.glLineWidth($o.lineWidth());
    }

    // Backface culling

    if ($o.doubleSidedEnabled()) {
      _gl.glDisable(GL10.GL_CULL_FACE);
    } else {
      _gl.glEnable(GL10.GL_CULL_FACE);
    }

    drawObject_textures($o);

    // Matrix operations in modelview

    _gl.glPushMatrix();

    // from NyARToolkit
    _gl.glLoadMatrixf($o.matrix(), 0);

    _gl.glTranslatef($o.position().x, $o.position().y, $o.position().z);

    _gl.glRotatef($o.rotation().x, 1, 0, 0);
    _gl.glRotatef($o.rotation().y, 0, 1, 0);
    _gl.glRotatef($o.rotation().z, 0, 0, 1);

    _gl.glScalef($o.scale().x, $o.scale().y, $o.scale().z);

    // Draw

    $o.vertices().points().buffer().position(0);
    _gl.glVertexPointer(3, GL10.GL_FLOAT, 0, $o.vertices().points().buffer());

    if (!$o.ignoreFaces()) {
      int pos, len;

      if (!$o.faces().renderSubsetEnabled()) {
        pos = 0;
        len = $o.faces().size();
      } else {
        pos = $o.faces().renderSubsetStartIndex() * FacesBufferedList.PROPERTIES_PER_ELEMENT;
        len = $o.faces().renderSubsetLength();
      }

      $o.faces().buffer().position(pos);

      _gl.glDrawElements(
          $o.renderType().glValue(),
          len * FacesBufferedList.PROPERTIES_PER_ELEMENT,
          GL10.GL_UNSIGNED_SHORT,
          $o.faces().buffer());
    } else {
      _gl.glDrawArrays($o.renderType().glValue(), 0, $o.vertices().size());
    }

    //
    // Recurse on children
    //

    if ($o instanceof Object3dContainer) {
      Object3dContainer container = (Object3dContainer) $o;

      for (int i = 0; i < container.children().size(); i++) {
        Object3d o = container.children().get(i);
        drawObject(o);
      }
    }

    // Restore matrix

    _gl.glPopMatrix();
  }