Android Open Source - min3d Example Light Properties






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;
/*  www.  j  av a2  s  .  com*/
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

import com.min3d.lib.core.Object3dContainer;
import com.min3d.lib.core.RendererActivity;
import com.min3d.lib.objectPrimitives.Box;
import com.min3d.lib.objectPrimitives.Sphere;
import com.min3d.lib.vos.Light;
import com.min3d.lib.vos.LightType;
import com.min3d.lib.vos.Number3d;

/**
 * Light properties explorer.
 * Position, direction, spotCutoff, spotExpo, type, visibility... 
 * 
 * Can also be used as a testbed for other parameter-related testing. 
 * 
 * @author Lee
 */
public class ExampleLightProperties extends RendererActivity
{
  Object3dContainer _rect;
  Object3dContainer _obj;
  Light _light;
  
  
  @Override
  protected void onCreateSetContentView()
  {
    setContentView(R.layout.lightproperties_layout);
    
    // Add OpenGL surface
        LinearLayout ll = (LinearLayout) this.findViewById(R.id.scene1Holder);
        ll.addView(_glSurfaceView);
  }
  
  @Override
    public void onInitScene()
  {
        // Add seekbar listeners
        int[] ids = { R.id.seekbarA1, R.id.seekbarA2, R.id.seekbarA3, R.id.seekbarB1, R.id.seekbarB2, R.id.seekbarB3, R.id.seekbarC1, R.id.seekbarC2 };

        for (int id : ids)
        {
            SeekBar b;
            b = (SeekBar) this.findViewById(id);
            b.setProgress(50);
            b.setOnSeekBarChangeListener(seekChange);
        }
        
        // Add checkbox listeners
        int[] ids2 = { R.id.cbx1, R.id.cbx2 };
        
        for (int id : ids2)
        {
            CheckBox ck = (CheckBox) this.findViewById(id);
            ck.setOnCheckedChangeListener(checkChange);
        }
        
        // Set some defaults
        CheckBox c1 = (CheckBox) this.findViewById(R.id.cbx1);
        c1.setChecked(true);
        
        CheckBox c2 = (CheckBox) this.findViewById(R.id.cbx2);
        c2.setChecked(true);
        
        SeekBar sB3 = (SeekBar) this.findViewById(R.id.seekbarB3);
        sB3.setProgress(100); // pointing away from camera
        
        SeekBar sAngle = (SeekBar) this.findViewById(R.id.seekbarC1);
        sAngle.setProgress(33); // some angle
        
        SeekBar sExp = (SeekBar) this.findViewById(R.id.seekbarC2);
        sExp.setProgress(45); // cutoff
  }
  
    OnSeekBarChangeListener seekChange = new OnSeekBarChangeListener() 
    {
      public void onProgressChanged(SeekBar $s, int $progress, boolean $touch)
      {
        float n = (float)$progress/100f;
        n = (n - 0.5f) * 2f;
        
        switch($s.getId())
        {
          case R.id.seekbarA1:
            _light.position.setX(n*3);
            break;
          case R.id.seekbarA2:
            _light.position.setY(n*3);
            break;
          case R.id.seekbarA3:
            _light.position.setZ(n*3); // +3 + n*6);
            break;
            
          case R.id.seekbarB1:
            //_light.spotDirection.setX(n);
            scene.camera().position.x = n*10;
            break;
          case R.id.seekbarB2:
            //_light.spotDirection.setY(n);
            scene.camera().position.y = n*10;
            break;
          case R.id.seekbarB3:
            //_light.spotDirection.setZ(n);
            scene.camera().position.z = n*10;
            break;
            
          case R.id.seekbarC1:
            n += 1; //[0,2]
            n *= 45+4;
            if (n > 90) n = 180;
            _light.spotCutoffAngle(n);
            Log.v("x", "cutoff " + n);
            break;
            
          case R.id.seekbarC2:
            n += 1; //[0,2]
            n *= 22; // [0,44]
            n -= 4; // [-4,40]
            if (n < 0) n = 0;
            _light.spotExponent(n);
            Log.v("x", "exp " + n);
            break;
        }

        Log.v("x", "campos" + scene.camera().position.toString());

        if (_light.position.isDirty())
        {
          Log.v("x", "pos " + _light.position.toString());          
        }
        
        if (_light.direction.isDirty())
        {
          Number3d n3 = _light.direction.toNumber3d();
          n3.normalize();
          _light.direction.setAllFrom(n3);
          Log.v("x", "dir " + _light.direction.toString());
        }
      }
      
      
      public void onStartTrackingTouch(SeekBar $s)
      {
        
      }
      public void onStopTrackingTouch(SeekBar $s)
      {
        
      }
    };
    
    OnCheckedChangeListener checkChange = new OnCheckedChangeListener() 
    {
    public void onCheckedChanged(CompoundButton $ck, boolean isChecked) 
    {
      switch($ck.getId())
      {
        case R.id.cbx1:
          if (isChecked)
            _light.type(LightType.DIRECTIONAL);
          else
            _light.type(LightType.POSITIONAL);
          Log.v("x", "light is now " + _light.type() + _light.type().glValue());
          break;
          
        case R.id.cbx2:
          _light.isVisible(isChecked);
          Log.v("x", "light visible: " + _light.isVisible());
          break;
      }
    }
  };
    
    //
  
  public void initScene() 
  {
    scene.backgroundColor().setAll(0xff222222);

    _light = new Light();
    _light.position.setAll(0, 0, +3);
    _light.diffuse.setAll(255, 255, 255, 255);
    _light.ambient.setAll(0, 0, 0, 0);
    _light.specular.setAll(0, 0, 0, 0);
    _light.emissive.setAll(0, 0, 0, 0);
    scene.lights().add(_light);

    _rect = new Box(6, 6, .1f);
    _rect.position().z = -3;
    scene.addChild(_rect);
    
    _obj = new Sphere(1.5f, 20,20);
    scene.addChild(_obj);
  }

  @Override 
  public void updateScene() 
  {
    //_rect.rotation().y+=0.33;
  }
  
  @Override 
  public void onUpdateScene()
  {
  }
  
}




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