Android Open Source - 4est Map






From Project

Back to project page 4est.

License

The source code is released under:

MIT License

If you think the Android project 4est 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.wordsaretoys.forest;
/* w w  w .j  a v  a 2  s  .c  o  m*/
import java.util.Random;

import com.wordsaretoys.rise.utility.Misc;

/**
 * represents the debris map and the attributes of its components
 */

public class Map {

  public static final int Engine = 0;
  public static final int Shard = 1;

  public interface Listener {
    public void onObject(long id, int what, float x, float y, float z, float r);
  }
  
  static final float CellSize = 0.5f;
  
  static final float[] probabilityMap = { 0.009f, 0.05f };
  static final float[] maxRadius = { 0.05f, 0.2f };
  
  Random rng = new Random();
  
  /**
   * scans the specified volume for objects
   * calls Listener.onObject for each found
   */
  public void scanVolume(float cx, float cy, float cz, float r, Listener l) {
    
    float x0 = (float)Math.floor((cx - r) / CellSize) * CellSize;
    float y0 = (float)Math.floor((cy - r) / CellSize) * CellSize;
    float z0 = (float)Math.floor((cz - r) / CellSize) * CellSize;
    float x1 = (float)Math.floor((cx + r) / CellSize) * CellSize;
    float y1 = (float)Math.floor((cy + r) / CellSize) * CellSize;
    float z1 = (float)Math.floor((cz + r) / CellSize) * CellSize;
    float hs = CellSize * 0.5f;
    
    if (y0 < -2) y0 = -3;
    if (y1 > 2) y1 = 3;
    
    for (float x = x0 + hs; x < x1; x += CellSize) {
      for (float y = y0 + hs; y < y1; y += CellSize) {
        for (float z = z0 + hs; z < z1; z += CellSize) {
          
          rng.setSeed(Misc.hash(x, y, z, 0));
          float select = rng.nextFloat();
          for (int i = 0; i < probabilityMap.length; i++) {
            if (select < probabilityMap[i]) {
              
              float mr = maxRadius[i];
              
              float ox = x + hs * Misc.scale(rng.nextFloat(), -1, 1);
              float oy = y + hs * Misc.scale(rng.nextFloat(), -1, 1);
              float oz = z + hs * Misc.scale(rng.nextFloat(), -1, 1);
              
              long id = Misc.hash(ox, oy, oz, i);
              
              l.onObject(id, i, ox, oy, oz, mr);
              
              break;
            }
          }
          
        }
      }
    }
    
  }
  
}




Java Source Code List

com.wordsaretoys.forest.Audio.java
com.wordsaretoys.forest.Debris.java
com.wordsaretoys.forest.Game.java
com.wordsaretoys.forest.GlView.java
com.wordsaretoys.forest.MainActivity.java
com.wordsaretoys.forest.Map.java
com.wordsaretoys.forest.Player.java
com.wordsaretoys.forest.Render.java
com.wordsaretoys.forest.Rotors.java
com.wordsaretoys.forest.Shared.java
com.wordsaretoys.forest.Skybox.java
com.wordsaretoys.rise.geometry.Camera.java
com.wordsaretoys.rise.geometry.Geom.java
com.wordsaretoys.rise.geometry.Mote.java
com.wordsaretoys.rise.geometry.Ortho.java
com.wordsaretoys.rise.geometry.Quaternion.java
com.wordsaretoys.rise.geometry.Vector.java
com.wordsaretoys.rise.glwrapper.Mesh.java
com.wordsaretoys.rise.glwrapper.Shader.java
com.wordsaretoys.rise.glwrapper.Texture.java
com.wordsaretoys.rise.meshutil.HeightMapper.java
com.wordsaretoys.rise.meshutil.IndexBuffer.java
com.wordsaretoys.rise.meshutil.SurfaceMapper.java
com.wordsaretoys.rise.meshutil.VertexBuffer.java
com.wordsaretoys.rise.meshutil.Vindexer.java
com.wordsaretoys.rise.pattern.Bitmap.java
com.wordsaretoys.rise.pattern.F2FSumMap.java
com.wordsaretoys.rise.pattern.I2FCutMap.java
com.wordsaretoys.rise.pattern.I2FMap.java
com.wordsaretoys.rise.pattern.I2IMap.java
com.wordsaretoys.rise.pattern.Pattern.java
com.wordsaretoys.rise.pattern.Ring.java
com.wordsaretoys.rise.utility.Asset.java
com.wordsaretoys.rise.utility.Board.java
com.wordsaretoys.rise.utility.Dbg.java
com.wordsaretoys.rise.utility.Interval.java
com.wordsaretoys.rise.utility.Misc.java
com.wordsaretoys.rise.utility.Needle.java