コード例 #1
0
  protected void drawSetup() {
    // View frustrum

    if (_scene.camera().frustum.isDirty()) {
      updateViewFrustrum();
    }

    // Camera

    _gl.glMatrixMode(GL10.GL_MODELVIEW);
    _gl.glLoadIdentity();

    GLU.gluLookAt(
        _gl,
        _scene.camera().position.x,
        _scene.camera().position.y,
        _scene.camera().position.z,
        _scene.camera().target.x,
        _scene.camera().target.y,
        _scene.camera().target.z,
        _scene.camera().upAxis.x,
        _scene.camera().upAxis.y,
        _scene.camera().upAxis.z);

    // Background color

    if (_scene.backgroundColor().isDirty()) {
      if (_scene.backgroundTransparent() == true) _gl.glClearColor(0, 0, 0, 0);
      else
        _gl.glClearColor(
            (float) _scene.backgroundColor().r() / 255f,
            (float) _scene.backgroundColor().g() / 255f,
            (float) _scene.backgroundColor().b() / 255f,
            (float) _scene.backgroundColor().a() / 255f);
      _scene.backgroundColor().clearDirtyFlag();
    }

    _gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    drawSetupLights();

    // Always on:
    _gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  }
コード例 #2
0
  protected void updateViewFrustrum() {
    FrustumManaged vf = _scene.camera().frustum;
    float n = vf.shortSideLength() / 2f;

    float lt, rt, btm, top;

    lt = vf.horizontalCenter() - n * _surfaceAspectRatio;
    rt = vf.horizontalCenter() + n * _surfaceAspectRatio;
    btm = vf.verticalCenter() - n * 1;
    top = vf.verticalCenter() + n * 1;

    if (_surfaceAspectRatio > 1) {
      lt *= 1f / _surfaceAspectRatio;
      rt *= 1f / _surfaceAspectRatio;
      btm *= 1f / _surfaceAspectRatio;
      top *= 1f / _surfaceAspectRatio;
    }

    _gl.glMatrixMode(GL10.GL_PROJECTION);
    _gl.glLoadIdentity();
    _gl.glFrustumf(lt, rt, btm, top, vf.zNear(), vf.zFar());

    vf.clearDirtyFlag();
  }