Android Open Source - min3d Managed Light List






From Project

Back to project page min3d.

License

The source code is released under:

MIT License

If you think the Android project min3d listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.min3d.lib.core;
/*from w w w .  j av a  2  s .  co  m*/
import android.util.Log;

import com.min3d.lib.Min3d;
import com.min3d.lib.vos.Light;

import java.util.ArrayList;
import java.util.HashMap;

public class ManagedLightList 
{
  // List of Light objects
  private ArrayList<Light> _lights;

  // Map Light objects to GL_LIGHT indices
  private HashMap<Light, Integer> _lightToGlIndex;

  // 'Pool' of available GL_LIGHT id's
  private ArrayList<Integer> _availGlIndices;

  // Array of which GL_LIGHTS are enabled, where index corresponds to
  // GL_LIGHT[index]
  private boolean[] _glIndexEnabled;

  // Array of dirty flags, where index corresponds to GL_LIGHT[index]
  private boolean[] _glIndexEnabledDirty;

  // "GL index" here means an int from 0 to 8 that corresponds to
  // the int constants GL10.GL_LIGHT0 to GL10.GL_LIGHT7

  public ManagedLightList() 
  {
    reset();
  }

  public void reset() 
  {
    Log.i(Min3d.TAG, "ManagedLightList.reset()");

    _availGlIndices = new ArrayList<Integer>();
    for (int i = 0; i < Renderer.NUM_GLLIGHTS; i++) {
      _availGlIndices.add(i);
    }

    _lightToGlIndex = new HashMap<Light, Integer>();

    _glIndexEnabled = new boolean[Renderer.NUM_GLLIGHTS];
    _glIndexEnabledDirty = new boolean[Renderer.NUM_GLLIGHTS];
    for (int i = 0; i < Renderer.NUM_GLLIGHTS; i++) {
      _glIndexEnabled[i] = false;
      _glIndexEnabledDirty[i] = true;
    }

    _lights = new ArrayList<Light>();
  }

  public boolean add(Light $light) 
  {
    if (_lights.contains($light)) {
      return false;
    }

    if (_lights.size() > Renderer.NUM_GLLIGHTS)
      throw new Error("Exceeded maximum number of Lights");

    boolean result = _lights.add($light);

    int glIndex = _availGlIndices.remove(0);

    _lightToGlIndex.put($light, glIndex);

    _glIndexEnabled[glIndex] = true;
    _glIndexEnabledDirty[glIndex] = true;
    
    return result;
  }

  public void remove(Light $light) 
  {
    boolean result = _lights.remove($light);

    if (!result) return;

    int glIndex = _lightToGlIndex.get($light);
    
    _availGlIndices.add(glIndex);

    _glIndexEnabled[glIndex] = false;
    _glIndexEnabledDirty[glIndex] = true;
  }

  public void removeAll() 
  {
    reset();
  }

  public int size() 
  {
    return _lights.size();
  }

  public Light get(int $index) 
  {
    return _lights.get($index);
  }

  public Light[] toArray() {
    return (Light[]) _lights.toArray(new Light[_lights.size()]);
  }

  /**
   * Used by Renderer
   */
  int getGlIndexByLight(Light $light) /* package-private */
  {
    return _lightToGlIndex.get($light);
  }

  /**
   * Used by Renderer
   */
  Light getLightByGlIndex(int $glIndex) /* package-private */
  {
    for (int i = 0; i < _lights.size(); i++) 
    {
      Light light = _lights.get(i);
      if (_lightToGlIndex.get(light) == $glIndex)
        return light;
    }
    return null;
  }

  /**
   * Used by Renderer
   */
  boolean[] glIndexEnabledDirty() /* package-private */
  {
    return _glIndexEnabledDirty;
  }

  /**
   * Used by Renderer
   */
  boolean[] glIndexEnabled() /* package-private */
  {
    return _glIndexEnabled;
  }
}




Java Source Code List

com.min3d.ApplicationTest.java
com.min3d.ExampleAccelerometer.java
com.min3d.ExampleAnimatedTexture.java
com.min3d.ExampleAnimatingVertices.java
com.min3d.ExampleAssigningTexturesDynamically.java
com.min3d.ExampleCamera.java
com.min3d.ExampleFog.java
com.min3d.ExampleFromScratch.java
com.min3d.ExampleInsideLayout.java
com.min3d.ExampleKeyframeAnimation.java
com.min3d.ExampleLightProperties.java
com.min3d.ExampleLoad3DSFile.java
com.min3d.ExampleLoadMD2File.java
com.min3d.ExampleLoadObjFileMultiple.java
com.min3d.ExampleLoadObjFile.java
com.min3d.ExampleMipMap.java
com.min3d.ExampleMostMinimal.java
com.min3d.ExampleMultiTexture.java
com.min3d.ExampleMultipleLights.java
com.min3d.ExampleRenderType.java
com.min3d.ExampleRotatingPlanets.java
com.min3d.ExampleSubsetOfFaces.java
com.min3d.ExampleTextureOffset.java
com.min3d.ExampleTextureWrap.java
com.min3d.ExampleTextures.java
com.min3d.ExampleTransparentGlSurface.java
com.min3d.ExampleVertexColors.java
com.min3d.ExampleVerticesVariations.java
com.min3d.ScratchActivity.java
com.min3d.SplashActivity.java
com.min3d.lib.AParser.java
com.min3d.lib.ApplicationTest.java
com.min3d.lib.IParser.java
com.min3d.lib.LittleEndianDataInputStream.java
com.min3d.lib.MD2Parser.java
com.min3d.lib.Max3DSParser.java
com.min3d.lib.Min3d.java
com.min3d.lib.ObjParser.java
com.min3d.lib.ParseObjectData.java
com.min3d.lib.ParseObjectFace.java
com.min3d.lib.Parser.java
com.min3d.lib.Shared.java
com.min3d.lib.Utils.java
com.min3d.lib.animation.AnimationObject3d.java
com.min3d.lib.animation.KeyFrame.java
com.min3d.lib.core.Color4BufferList.java
com.min3d.lib.core.FacesBufferedList.java
com.min3d.lib.core.ManagedLightList.java
com.min3d.lib.core.Number3dBufferList.java
com.min3d.lib.core.Object3dContainer.java
com.min3d.lib.core.Object3d.java
com.min3d.lib.core.RenderCaps.java
com.min3d.lib.core.RendererActivity.java
com.min3d.lib.core.Renderer.java
com.min3d.lib.core.Scene.java
com.min3d.lib.core.TextureList.java
com.min3d.lib.core.TextureManager.java
com.min3d.lib.core.UvBufferList.java
com.min3d.lib.core.Vertices.java
com.min3d.lib.interfaces.IDirtyManaged.java
com.min3d.lib.interfaces.IDirtyParent.java
com.min3d.lib.interfaces.IObject3dContainer.java
com.min3d.lib.interfaces.ISceneController.java
com.min3d.lib.objectPrimitives.Box.java
com.min3d.lib.objectPrimitives.HollowCylinder.java
com.min3d.lib.objectPrimitives.Rectangle.java
com.min3d.lib.objectPrimitives.SkyBox.java
com.min3d.lib.objectPrimitives.Sphere.java
com.min3d.lib.objectPrimitives.Torus.java
com.min3d.lib.vos.AbstractDirtyManaged.java
com.min3d.lib.vos.BooleanManaged.java
com.min3d.lib.vos.CameraVo.java
com.min3d.lib.vos.Color4Managed.java
com.min3d.lib.vos.Color4.java
com.min3d.lib.vos.Face.java
com.min3d.lib.vos.FloatManaged.java
com.min3d.lib.vos.FogType.java
com.min3d.lib.vos.FrustumManaged.java
com.min3d.lib.vos.LightType.java
com.min3d.lib.vos.Light.java
com.min3d.lib.vos.Number3dManaged.java
com.min3d.lib.vos.Number3d.java
com.min3d.lib.vos.RenderType.java
com.min3d.lib.vos.ShadeModelManaged.java
com.min3d.lib.vos.ShadeModel.java
com.min3d.lib.vos.TexEnvxVo.java
com.min3d.lib.vos.TextureVo.java
com.min3d.lib.vos.Uv.java
com.min3d.lib.vos.Vertex3d.java