Package org.pollux3d.menu

Source Code of org.pollux3d.menu.BubbleLine

package org.pollux3d.menu;

import java.nio.FloatBuffer;

import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.scene.Mesh;
import com.jme3.scene.Mesh.Mode;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.util.BufferUtils;

public class BubbleLine extends Mesh {
 
  /**
   * The center.
   */
  private Vector3f center = Vector3f.ZERO;
  /**
   * The radius.
   */
  private float radius;
  /**
   * The width.
   */
  private float width;
  /**
   * The samples.
   */
  private int samples = 12;
 
  public BubbleLine(float height, float width) {
    super();
    this.radius = height/2f;
    this.width = width;
    center.z = width/2f;
    //center.x = 1f;
    //setMode(Mode.Lines);
    updateGeometry();
  }
 
  protected void updateGeometry() {
    FloatBuffer positions = BufferUtils.createFloatBuffer(samples * 6);
    FloatBuffer normals = BufferUtils.createFloatBuffer(samples * 6);
    short[] indices = new short[samples * 4];
    float rate = FastMath.PI / ((float) (samples-1));
    float angle = 0;
    for (int i = 0; i < samples; i++) {
      float x = FastMath.cos(angle) + center.x;
      float z = FastMath.sin(angle) + center.z;
      positions.put(x * radius).put(center.y).put(z * radius);
      normals.put(new float[] { 0, 1, 0 });
      indices[i * 2] = (short) i;
      indices[i * 2 + 1] = (short) (i + 1);
      angle += rate;
    }
    angle = FastMath.PI;
   
    center.z = center.z - width;
    for (int i = samples; i < samples*2; i++) {
      float x = FastMath.cos(angle) + center.x;
      float z = FastMath.sin(angle) + center.z;
      positions.put(x * radius).put(center.y).put(z * radius);
      normals.put(new float[] { 0, 1, 0 });
      indices[i * 2] = (short) i;
      if (i < samples*2 - 1)
        indices[i * 2 + 1] = (short) (i + 1);
      else
        indices[i * 2 + 1] = 0;
      angle += rate;
    }
   
    setBuffer(Type.Position, 3, positions);
    setBuffer(Type.Normal, 3, normals);
    setBuffer(Type.Index, 2, indices);
    setBuffer(Type.TexCoord, 2, new float[] { 0, 0, 1, 1 });
    updateBound();
  }
 

}
TOP

Related Classes of org.pollux3d.menu.BubbleLine

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.