@Override public BillBoard read( ByteBuffer billBuffer ) { skipHeader( billBuffer ); String id = readString( billBuffer ); float[] location = new float[3]; location[0] = billBuffer.getFloat(); location[1] = billBuffer.getFloat(); location[2] = billBuffer.getFloat(); float width = billBuffer.getFloat(); float height = billBuffer.getFloat(); return new BillBoard( id, location, width, height ); }
@Override public void write( ByteBuffer buffer, DataObjectInfo<BillBoard> object ) { writeHeader( buffer, object ); BillBoard bb = object.getData(); writeString( buffer, bb.getTextureID() ); float[] location = bb.getLocation(); buffer.putFloat( location[0] ); buffer.putFloat( location[1] ); buffer.putFloat( location[2] ); buffer.putFloat( bb.getWidth() ); buffer.putFloat( bb.getHeight() ); }
@Override public int compare( BillBoard o1, BillBoard o2 ) { float distA = Vectors3f.distance( eye, o1.getPosition() ); float distB = Vectors3f.distance( eye, o2.getPosition() ); // /** // * Trees that are near to each other might have the same texture. // */ // if ( Math.abs( distA - distB ) < 35 ) { // int res = o1.getTextureID().compareTo( o2.getTextureID() ); // if ( res == 0 ) { // res = -Float.compare( distA, distB ); // } // return res; // } return -Float.compare( distA, distB ); }
/** * @param ps * @param b * @param index * @throws SQLException */ private Envelope getEnvelope( BillBoard b ) { float[] location = b.getLocation(); float width = b.getWidth() * 0.5f; float height = b.getHeight(); return geomFac.createEnvelope( new double[] { location[0] - width, location[1] - width, location[2] }, new double[] { location[0] + width, location[1] + width, location[2] + height }, null ); }
BillBoard b = it.next(); context.glPushMatrix(); Texture t = TexturePool.getTexture( glRenderContext, b.getTextureID() ); if ( t != null ) { if ( currentTexture == null || t.getTextureObject() != currentTexture.getTextureObject() ) { currentTexture = t; b.renderPrepared( context, eye2 );
@Override public int serializedObjectSize( DataObjectInfo<BillBoard> bb ) { return ( sizeOfString( bb.getData().getTextureID() ) + ( 5 * AllocatedHeapMemory.FLOAT_SIZE ) ); }
/** * @param context * @param eye */ public void renderPrepared( GL context, float[] eye ) { // the translation context.glTranslatef( location[0], location[1], location[2] ); // the rotation calculateAndSetRotation( context, eye ); context.glScalef( width, 1, height ); context.glDrawArrays( GL.GL_QUADS, 0, 4 ); }
@Override public void render( RenderContext glRenderContext ) { Point3d eye = glRenderContext.getViewParams().getViewFrustum().getEyePos(); GL context = glRenderContext.getContext(); context.glPushMatrix(); context.glDepthMask( false ); context.glEnable( GL.GL_TEXTURE_2D ); context.glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY ); // the translation context.glTranslatef( location[0], location[1], location[2] ); // the rotation calculateAndSetRotation( context, new float[] { (float) eye.x, (float) eye.y, (float) eye.z } ); context.glScalef( width, 1, height ); TexturePool.loadTexture( glRenderContext, textureID ); // context.glMaterialfv( GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, new float[] { 1, 1, 1, .1f }, 0 ); context.glVertexPointer( 3, GL.GL_FLOAT, 0, coordBuffer ); context.glTexCoordPointer( 2, GL.GL_FLOAT, 0, textureBuffer ); // context.glDisableClientState( GL.GL_NORMAL_ARRAY ); context.glDrawArrays( GL.GL_QUADS, 0, 4 ); context.glDisableClientState( GL.GL_TEXTURE_COORD_ARRAY ); context.glDisable( GL.GL_TEXTURE_2D ); context.glDepthMask( true ); context.glMatrixMode( GL.GL_MODELVIEW ); context.glPopMatrix(); }
/** * @param mappedColumns * @param values * @return */ private BillBoard createBillBoard( Map<Column, Integer> mappedColumns, String[] values ) { float height = parseFloatingPoint( values[mappedColumns.get( Column.HEIGHT )], Column.HEIGHT ); float width = parseFloatingPoint( values[mappedColumns.get( Column.WIDTH )], Column.WIDTH ); float northing = parseFloatingPoint( values[mappedColumns.get( Column.NORTHING )], Column.NORTHING ); northing += wpvsTranslationVector[1]; float easting = parseFloatingPoint( values[mappedColumns.get( Column.EASTING )], Column.EASTING ); easting += wpvsTranslationVector[0]; float groundLevel = parseFloatingPoint( values[mappedColumns.get( Column.GROUND_LEVEL )], Column.GROUND_LEVEL ); String texture = values[mappedColumns.get( Column.IMAGE )]; if ( !usedTextures.contains( texture ) ) { if ( !checkTextureReference( texture ) ) { invalidTextures.add( texture ); LOG.warn( "Texture: " + texture + " does not denote an image in the textureDir: " + textureDir.getAbsolutePath() + " is this correct?." ); } usedTextures.add( texture ); } return new BillBoard( texture, new float[] { easting, northing, groundLevel }, width, height ); }