Package java.nio

Examples of java.nio.FloatBuffer


    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    FloatBuffer matSpecular = BufferUtils.createFloatBuffer(4).put(
        new float[] { 1, 1, 1, 1 });
    FloatBuffer matOcean = BufferUtils.createFloatBuffer(4).put(
        new float[] { 0.3f, 0.3f, 1, 1 });
    FloatBuffer lightPosition = BufferUtils.createFloatBuffer(4).put(
        new float[] { 1, 1, -40000, 0 });
    FloatBuffer whiteLight = BufferUtils.createFloatBuffer(4).put(
        new float[] { 1, 1, 1, 1 });
    FloatBuffer sunLight = BufferUtils.createFloatBuffer(4).put(
        new float[] { 1, 1, 0.9f, 1 });
    FloatBuffer lModelAmbient = BufferUtils.createFloatBuffer(4).put(
        new float[] { 0.1f, 0.1f, 0.1f, 1 });
    matSpecular.flip();
    matOcean.flip();
    lightPosition.flip();
    whiteLight.flip();
    sunLight.flip();
    lModelAmbient.flip();
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glMaterial(GL_FRONT, GL_SPECULAR, matSpecular);
    glMaterialf(GL_FRONT, GL_SHININESS, 10.0f);
    glLight(GL_LIGHT0, GL_POSITION, lightPosition);
View Full Code Here


  public void buildTextureCoordinates() {
    float offsetX = getOffset().x + (getOffsetAmount() * getStepScale().x);
    float offsetY = getOffset().y + (getOffsetAmount() * getStepScale().z);
    TriangleBatch batch = getBatch(0);

    FloatBuffer texs = BufferUtils.createVector2Buffer(batch
        .getTextureBuffers().get(0), batch.getVertexCount());
    batch.getTextureBuffers().set(0, texs);
    texs.clear();

    batch.getVertexBuffer().rewind();
    float firstX = -1.0f;
    float firstY = -1.0f;
    for (int i = 0; i < batch.getVertexCount(); i++) {
      Vector2f mapCoord = new Vector2f();
      mapCoord.x = (batch.getVertexBuffer().get() + offsetX) / (getStepScale().x);
      batch.getVertexBuffer().get(); // ignore vert y coord.
      mapCoord.y = (batch.getVertexBuffer().get() + offsetY) / (getStepScale().z);
   
      if( firstX == -1.0f ) {
        firstX = mapCoord.x;
      }
      if( firstY == -1.0f ) {
        firstY = mapCoord.y;
      }
   
      float up = 1.0f;//((float)TILE_SIZE+1.0f) / (float)TILE_SIZE;
      float tileIndexX = (mapCoord.x % TILE_SIZE) / TILE_SIZE;
      float tileIndexY = (mapCoord.y % TILE_SIZE) / TILE_SIZE;
     
     
     
      float oX = tileIndexX * up;
      float oY = tileIndexY * up;

      if( tileIndexX == 0.0f ) {
        ifmapCoord.x != firstX ) {
          oX = 1.0f;
        } else {
          oX = 0.00f;
        }
      }
     
      if( tileIndexY == 0.0f ) {
        if( mapCoord.y != firstY ) {
          oY = 1.0f;
        } else {
          oY = 0.00f;
        }
      }
           
      Vector2f texCoord = materialMap.textureForMap(mapCoord);

     
      float fX = texCoord.x + (0.5f * oX);
      float fY = texCoord.y + (0.5f * oY);
      texs.put(fX);
      texs.put(fY);
    }
  }
 
View Full Code Here

        BufferUtils.setInBuffer(point, batch.getVertexBuffer(),
            (x + (y * getSize())));
      }
    }
   
    FloatBuffer fb = BufferUtils.createVector3Buffer( null, batch.getVertexCount());

    float offsetX = getOffset().x + (getOffsetAmount() * getStepScale().x);
    float offsetY = getOffset().y + (getOffsetAmount() * getStepScale().z);

    for (int x = 0; x < getSize(); x++) {
View Full Code Here

    this.origin = origin;
    this.initialize();
  }
 
  public void initialize() {
    FloatBuffer vertex = BufferUtils.createVector3Buffer( 4 );
    IntBuffer  index  = BufferUtils.createIntBuffer( 6 );
    baseTextureBuffer = BufferUtils.createVector3Buffer( 4 );
   
   
    System.out.println( "origin = " + origin.toString() );
    System.out.println( origin.add( new Vector3f( -1.0f, 1.0f, 0.0f ) ).toString() );
    System.out.println( origin.add( new Vector3f( -1.0f, -1.0f, 0.0f ) ).toString() );
    System.out.println( origin.add( new Vector3f( 1.0f, -1.0f, 0.0f ) ).toString() );
    System.out.println( origin.add( new Vector3f( 1.0f, 1.0f, 0.0f ) ).toString() );

    BufferUtils.setInBuffer( origin.add( new Vector3f( -1.0f, 1.0f, 0.0f )),  vertex,  0 );
    BufferUtils.setInBuffer( origin.add( new Vector3f( -1.0f, -1.0f, 0.0f )),  vertex,  1 );
    BufferUtils.setInBuffer( origin.add( new Vector3f( 1.0f, -1.0f, 0.0f )),  vertex,  2 );
    BufferUtils.setInBuffer( origin.add( new Vector3f( 1.0f, 1.0f, 0.0f )),  vertex,  3 );
   
    index.put( 0 );
    index.put( 1 );
    index.put( 2 );
    index.put( 0 );
    index.put( 2 );
    index.put( 3 );
   
    BufferUtils.setInBuffer( new Vector2f( baseTextureCoord.x, baseTextureCoord.y +  TileTexture.TILE_HEIGHT ),  baseTextureBuffer,  0 );
    BufferUtils.setInBuffer( baseTextureCoord,  baseTextureBuffer,  1 );
    BufferUtils.setInBuffer( new Vector2f( baseTextureCoord.x + TileTexture.TILE_WIDTH, baseTextureCoord.y ),  baseTextureBuffer,  2 );
    BufferUtils.setInBuffer( new Vector2f( baseTextureCoord.x + TileTexture.TILE_WIDTH, baseTextureCoord.y + TileTexture.TILE_HEIGHT ),  baseTextureBuffer,  3 );

    if( overTextureCoord != null ) {
      FloatBuffer vertexOver = BufferUtils.createVector3Buffer( 4 );
      IntBuffer  indexOver  = BufferUtils.createIntBuffer( 6 );
      overTextureBuffer = BufferUtils.createVector3Buffer( 4 );

      BufferUtils.setInBuffer( origin.add( new Vector3f( -1.0f, 1.0f, 0.0f )),  vertexOver,  0 );
      BufferUtils.setInBuffer( origin.add( new Vector3f( -1.0f, -1.0f, 0.0f )),  vertexOver,  1 );
View Full Code Here

        , false, true );
    //setting to default value just to show
    waterEffectRenderPass.setWaterPlane( new Plane( new Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ) );

    waterQuad = new Quad( "waterQuad", 1, 1 );
    FloatBuffer normBuf = waterQuad.getNormalBuffer( 0 );
    normBuf.clear();
    normBuf.put( 0 ).put( 1 ).put( 0 );
    normBuf.put( 0 ).put( 1 ).put( 0 );
    normBuf.put( 0 ).put( 1 ).put( 0 );
    normBuf.put( 0 ).put( 1 ).put( 0 );

    Torus torus = new Torus( "Torus", 50, 50, 10, 20 );
    torus.setLocalTranslation( new Vector3f( 50, -5, 20 ) );
   
    waterEffectRenderPass.setWaterEffectOnSpatial( torus );
View Full Code Here

    rootNode.setRenderQueueMode( Renderer.QUEUE_OPAQUE );
    fpsNode.setRenderQueueMode( Renderer.QUEUE_OPAQUE );
  }

  private void setVertexCoords( float x, float y, float z ) {
    FloatBuffer vertBuf = waterQuad.getVertexBuffer( 0 );
    vertBuf.clear();

    vertBuf.put( x - farPlane ).put( y ).put( z - farPlane );
    vertBuf.put( x - farPlane ).put( y ).put( z + farPlane );
    vertBuf.put( x + farPlane ).put( y ).put( z + farPlane );
    vertBuf.put( x + farPlane ).put( y ).put( z - farPlane );
  }
View Full Code Here

  private void setTextureCoords( int buffer, float x, float y, float textureScale ) {
    x *= textureScale * 0.5f;
    y *= textureScale * 0.5f;
    textureScale = farPlane * textureScale;
    FloatBuffer texBuf;
    texBuf = waterQuad.getTextureBuffer( 0, buffer );
    texBuf.clear();
    texBuf.put( x ).put( textureScale + y );
    texBuf.put( x ).put( y );
    texBuf.put( textureScale + x ).put( y );
    texBuf.put( textureScale + x ).put( textureScale + y );
  }
View Full Code Here

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
          arrayStart = getArrayStartAddress(fs.getAddress());
          buf = ByteBuffer.allocate(arraySize * 4);
          FloatBuffer floatbuf = buf.asFloatBuffer();
          float[] floatArray = new float[arraySize];
          for (int i = arrayStart; i < arrayStart + arraySize; i++) {
            floatArray[i - arrayStart] = Float.intBitsToFloat(this.getHeap().heap[i]);
          }
          floatbuf.put(floatArray);
          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_BOOLEAN_ARRAY)
            || type.getName().equals(CAS.TYPE_NAME_BYTE_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
View Full Code Here

          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_FLOAT_ARRAY)) {
          arrayStart = getArrayStartAddress(fs.getAddress());
          buf = ByteBuffer.allocate(arraySize * 4);
          FloatBuffer floatbuf = buf.asFloatBuffer();
          float[] floatArray = new float[arraySize];
          for (int i = arrayStart; i < arrayStart + arraySize; i++) {
            floatArray[i - arrayStart] = Float.intBitsToFloat(this.getHeap().heap[i]);
          }
          floatbuf.put(floatArray);
          ByteArrayInputStream bis = new ByteArrayInputStream(buf.array());
          return bis;
        } else if (type.getName().equals(CAS.TYPE_NAME_BOOLEAN_ARRAY)
            || type.getName().equals(CAS.TYPE_NAME_BYTE_ARRAY)) {
          arrayStart = this.getHeap().heap[getArrayStartAddress(fs.getAddress())];
View Full Code Here

                oldPosition * Sizeof.cl_float);
            buffer.position(oldPosition);
        }
        else if (buffer.hasArray())
        {
            FloatBuffer t = FloatBuffer.wrap(buffer.array());
            int elementOffset = buffer.position() + buffer.arrayOffset();
            result = Pointer.to(t).withByteOffset(
                elementOffset * Sizeof.cl_float);
        }
        else
View Full Code Here

TOP

Related Classes of java.nio.FloatBuffer

Copyright © 2018 www.massapicom. 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.