Android Open Source - block-composer Axis Renderer






From Project

Back to project page block-composer.

License

The source code is released under:

MIT License

If you think the Android project block-composer 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 bwr.blockcomposer.models;
/* ww  w .  j a va  2  s.co  m*/
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
import java.nio.IntBuffer;

import javax.microedition.khronos.opengles.GL10;

public class AxisRenderer {
  private final static int FLOAT_SIZE = 4;
  private final static int CHAR_SIZE = 2;
  private final static int AXIS_LENGTH = 20<<16;
  
  private int numVertices;
  
  private IntBuffer vertexBuffer;
  private CharBuffer indexBuffer;
  
  public void render(GL10 gl) {
    gl.glDisable(GL10.GL_LIGHTING);
    gl.glDisable(GL10.GL_TEXTURE_2D);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);    
    gl.glVertexPointer(3, GL10.GL_FIXED, 0, vertexBuffer);
    
    gl.glLineWidthx(1<<16);
    gl.glColor4x(1<<16, 1<<16, 1<<16, 1<<16);

    gl.glDrawElements(GL10.GL_LINES, numVertices, GL10.GL_UNSIGNED_SHORT, indexBuffer);
    
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnable(GL10.GL_LIGHTING);
    gl.glEnable(GL10.GL_TEXTURE_2D);
  }
  
  private void putVertex(int x, int y, int z) {
    vertexBuffer.put(x);
    vertexBuffer.put(y);
    vertexBuffer.put(z);
  }
  
  public AxisRenderer() {
    
    numVertices = 6;
            
    vertexBuffer = ByteBuffer.allocateDirect(numVertices*3*FLOAT_SIZE).order(ByteOrder.nativeOrder()).asIntBuffer();
    indexBuffer = ByteBuffer.allocateDirect(numVertices*CHAR_SIZE).order(ByteOrder.nativeOrder()).asCharBuffer();
    
        char index = 0; // vertex index
  
    putVertex(0, -AXIS_LENGTH, 0); indexBuffer.put(index++);
    putVertex(0,  AXIS_LENGTH, 0); indexBuffer.put(index++);

    putVertex(-AXIS_LENGTH, 0, 0); indexBuffer.put(index++);
    putVertex( AXIS_LENGTH, 0, 0); indexBuffer.put(index++);

    putVertex(0, 0, -AXIS_LENGTH); indexBuffer.put(index++);
    putVertex(0, 0,  AXIS_LENGTH); indexBuffer.put(index++);      
    
    vertexBuffer.position(0);
    indexBuffer.position(0);
  }
}




Java Source Code List

bwr.blockcomposer.AnimationFinishedListener.java
bwr.blockcomposer.BlockComposerActivity.java
bwr.blockcomposer.BlockComposerRenderer.java
bwr.blockcomposer.BlockComposer.java
bwr.blockcomposer.Camera.java
bwr.blockcomposer.GameResources.java
bwr.blockcomposer.OnUpdateAction.java
bwr.blockcomposer.gamedata.Block.java
bwr.blockcomposer.gamedata.GameEntity.java
bwr.blockcomposer.gamedata.GameState.java
bwr.blockcomposer.gamedata.LevelDimensions.java
bwr.blockcomposer.gamedata.LevelMask.java
bwr.blockcomposer.gamedata.LevelMetadata.java
bwr.blockcomposer.gamedata.LevelStore.java
bwr.blockcomposer.gamedata.Level.java
bwr.blockcomposer.gamedata.Move.java
bwr.blockcomposer.gamedata.StaticLevelStore.java
bwr.blockcomposer.gamedata.UserLevelStore.java
bwr.blockcomposer.misc.GLUtility.java
bwr.blockcomposer.misc.Timer.java
bwr.blockcomposer.models.AxisRenderer.java
bwr.blockcomposer.models.Model.java
bwr.blockcomposer.models.SelectBoxRenderer.java
bwr.blockcomposer.modes.EditMode.java
bwr.blockcomposer.modes.GameDialogMode.java
bwr.blockcomposer.modes.GameMode.java
bwr.blockcomposer.modes.LevelImportMode.java
bwr.blockcomposer.modes.LevelSelectMode.java
bwr.blockcomposer.modes.LogoDisplayMode.java
bwr.blockcomposer.modes.ModeController.java
bwr.blockcomposer.modes.Mode.java
bwr.blockcomposer.modes.OverlayMode.java
bwr.blockcomposer.types.FlipRotateFloat.java
bwr.blockcomposer.types.FloatValueVector3.java
bwr.blockcomposer.types.FloatValue.java
bwr.blockcomposer.types.IntVector.java
bwr.blockcomposer.types.RotatingFloat.java
bwr.blockcomposer.ui.TextRenderer.java
bwr.blockcomposer.ui.UIElementPicture.java
bwr.blockcomposer.ui.UIElementText.java
bwr.blockcomposer.ui.UIElement.java