Android Open Source - min3d Light






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.vos;
//from   ww  w . jav  a2  s . com
import com.min3d.lib.Utils;
import com.min3d.lib.interfaces.IDirtyParent;

import java.nio.FloatBuffer;

/**
 * Light must be added to Scene to take effect.
 * 
 * Eg, "scene.lights().add(myLight);"  
 */
public class Light extends AbstractDirtyManaged implements IDirtyParent
{
  /**
   * Position is relative to eye space, not world space.
   */
  public Number3dManaged     position;
  
  /**
   * Direction is a vector and should be normalized.
   */
  public Number3dManaged     direction;  
  
  public Color4Managed     ambient;
  public Color4Managed     diffuse;
  public Color4Managed     specular;
  public Color4Managed     emissive;
  
  private LightType      _type;

  public Light()
  {
    super(null);
    
     ambient = new Color4Managed(128,128,128, 255, this);
     diffuse = new Color4Managed(255,255,255, 255, this);
     specular = new Color4Managed(0,0,0,255, this);
     emissive = new Color4Managed(0,0,0,255, this);
     
     position = new Number3dManaged(0f, 0f, 1f, this);       
     
     direction = new Number3dManaged(0f, 0f, -1f, this);  
     _spotCutoffAngle = new FloatManaged(180, this);    
     _spotExponent = new FloatManaged(0f, this);      
     
     _attenuation = new Number3dManaged(1f,0f,0f, this);   
     
     _type = LightType.DIRECTIONAL;                
     
     _isVisible = new BooleanManaged(true, this);
     
     _positionAndTypeBuffer = Utils.makeFloatBuffer4(0, 0, 0, 0);
     
     setDirtyFlag();
  }

  public boolean isVisible()
  {
    return _isVisible.get();
  }
  public void isVisible(Boolean $b)
  {
    _isVisible.set($b);
  }
  
  /**
   * Default is DIRECTIONAL, matching OpenGL's default value.
   */
  public LightType type()
  {
    return _type;
  }
  
  public void type(LightType $type)
  {
    _type = $type;
    position.setDirtyFlag(); // .. position and type share same data structure
  }
  
  /**
   * 0 = no attenuation towards edges of spotlight. Max is 128.
   * Default is 0, matching OpenGL's default value.
   */
  public float spotExponent()
  {
    return _spotExponent.get();
  }
  public void spotExponent(float $f)
  {
    if ($f < 0) $f = 0;
    if ($f > 128) $f = 128;
    _spotExponent.set($f);
  }
  
  /**
   * Legal range is 0 to 90, plus 180, which is treated by OpenGL to mean no cutoff.
   * Default is 180, matching OpenGL's default value.
   */
  public float spotCutoffAngle()
  {
    return _spotCutoffAngle.get();
  }
  public void spotCutoffAngle(Float $f)
  {
    if ($f < 0) 
      _spotCutoffAngle.set(0);
    else if ($f <= 90)
      _spotCutoffAngle.set($f);
    else if ($f == 180)
      _spotCutoffAngle.set($f);
    else
      _spotCutoffAngle.set(90);
  }
  
  /**
   * No cutoff angle (ie, no spotlight effect)
   * (represented internally with a value of 180)
   */
  public void spotCutoffAngleNone()
  {
    _spotCutoffAngle.set(180);
  }
  
  public float attenuationConstant()
  {
    return _attenuation.getX();
  }
  public void attenuationConstant(float $normalizedValue)
  {
    _attenuation.setX($normalizedValue);
    setDirtyFlag();
  }
  
  public float attenuationLinear()
  {
    return _attenuation.getY();
  }
  public void attenuationLinear(float $normalizedValue)
  {
    _attenuation.setY($normalizedValue);
    setDirtyFlag();
  }
  
  public float attenuationQuadratic()
  {
    return _attenuation.getZ();
  }
  public void attenuationQuadratic(float $normalizedValue)
  {
    _attenuation.setZ($normalizedValue);
    setDirtyFlag();
  }
  
  /**
   * Defaults are 1,0,0 (resulting in no attenuation over distance), 
   * which match OpenGL default values. 
   */
  public void attenuationSetAll(float $constant, float $linear, float $quadratic)
  {
    _attenuation.setAll($constant, $linear, $quadratic);
    setDirtyFlag();
  }

  //
  
  public void setAllDirty()
  {
    position.setDirtyFlag();
    ambient.setDirtyFlag();
    diffuse.setDirtyFlag();
    specular.setDirtyFlag();
    emissive.setDirtyFlag();
    direction.setDirtyFlag();
    _spotCutoffAngle.setDirtyFlag();
    _spotExponent.setDirtyFlag();
    _attenuation.setDirtyFlag();
    _isVisible.setDirtyFlag();
  }

  public void onDirty()
  {
    setDirtyFlag();
  }
  
  /**
   * Used by Renderer
   * Normal clients of this class should use "isVisible" getter/setter.
   */
  public BooleanManaged _isVisible;

  /**
   * Used by Renderer
   */
  public FloatBuffer _positionAndTypeBuffer;

  /**
   * Used by Renderer
   */
  public void commitPositionAndTypeBuffer()
  {
    // GL_POSITION takes 4 arguments, the first 3 being x/y/z position, 
    // and the 4th being what we're calling 'type' (positional or directional)
    
    _positionAndTypeBuffer.position(0);
    _positionAndTypeBuffer.put(position.getX());
    _positionAndTypeBuffer.put(position.getY());
    _positionAndTypeBuffer.put(position.getZ());
    _positionAndTypeBuffer.put(_type.glValue());
    _positionAndTypeBuffer.position(0);
  }
  
  /**
   * Used by Renderer. 
   * Normal clients of this class should use "useSpotProperties" getter/setter.
   */
  public FloatManaged _spotExponent; 

  /**
   * Used by Renderer. Normal clients of this class should use "useSpotProperties" getter/setter.
   */
  public FloatManaged _spotCutoffAngle;
  
  /**
   * Used by Renderer. Normal clients of this class should use attenuation getter/setters.
   */
  public Number3dManaged _attenuation; // (the 3 properties of N3D used for the 3 attenuation properties)
}




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