Android Open Source - Flight-Computer-Android-Flightradar24 open Gl Utils






From Project

Back to project page Flight-Computer-Android-Flightradar24.

License

The source code is released under:

GNU General Public License

If you think the Android project Flight-Computer-Android-Flightradar24 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.flightcomputer;
import javax.microedition.khronos.opengles.GL10;
import android.graphics.Color;
import com.nutiteq.components.MapPos;
import com.nutiteq.projections.EPSG3857;
import com.nutiteq.projections.Projection;
import com.nutiteq.utils.Const;
// w w w .j  a  v a 2 s .  co  m
import static javax.microedition.khronos.opengles.GL10.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.ArrayList;

public class openGlUtils {
  private static float lX;
  private static float lY;
  private static float lZ;  
  private static Projection proj=new EPSG3857();
    public static void drawPoint(GL10 gl, MapPos point ,int ired,int igreen,int iblue) {
        ByteBuffer vbb = ByteBuffer.allocateDirect(4 * 2 * 1);
        vbb.order(ByteOrder.nativeOrder());
        FloatBuffer vertices = vbb.asFloatBuffer();
        lX = (float) proj.toInternal(point.x, point.y).x;
        lY = (float) proj.toInternal(point.x, point.y).y;  
        vertices.put(lX);
        vertices.put(lY);        
        vertices.position(0);
        float red =(1.0f/255)*ired;     
        float green =(1.0f/255)*igreen;       
        float blue =(1.0f/255)*iblue;   
        gl.glColor4f(red,green,blue, 1.0f);
        gl.glPointSize(5);
        gl.glVertexPointer(2, GL_FLOAT, 0, vertices);
        gl.glEnableClientState(GL_VERTEX_ARRAY);
        gl.glDrawArrays(GL_POINTS, 0, 1);
        gl.glDisableClientState(GL_VERTEX_ARRAY);
    }      
    public static void drawPoints(GL10 gl, ArrayList<MapPos> points,ArrayList<Integer> colorlist,float width,boolean threeaxis) { 
        try{
        ByteBuffer vbb = ByteBuffer.allocateDirect(4 * 3 * points.size());
          vbb.order(ByteOrder.nativeOrder());
          FloatBuffer vertices = vbb.asFloatBuffer();         
          FloatBuffer colorBuffer;   
          ByteBuffer cbb = ByteBuffer.allocateDirect(4 * 4 * points.size());
          cbb.order(ByteOrder.nativeOrder()); // Use native byte order (NEW)
          colorBuffer = cbb.asFloatBuffer();           
          for (int i = 0; i < points.size(); i++) {   
          lX = (float) proj.toInternal(points.get(i).x, points.get(i).y).x;
            lY = (float) proj.toInternal(points.get(i).x, points.get(i).y).y; 
            lZ = (float) points.get(i).z;
            float red =(1.0f/255)*Color.red(colorlist.get(i));     
            float green =(1.0f/255)*Color.green(colorlist.get(i));       
            float blue =(1.0f/255)*Color.blue(colorlist.get(i));          
               vertices.put(lX);
               vertices.put(lY);  
               if(threeaxis){         
                 vertices.put(lZ);  
               }else
                 vertices.put(0); 
               
               colorBuffer.put(red); 
               colorBuffer.put(green); 
               colorBuffer.put(blue); 
               colorBuffer.put(1f); 
          } 
          colorBuffer.position(0); 
          vertices.position(0);
          gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
          gl.glLineWidth(width); 
          
          gl.glEnableClientState(GL_VERTEX_ARRAY);       
          gl.glEnableClientState(GL_COLOR_ARRAY);
          
          gl.glVertexPointer(3, GL_FLOAT , 0, vertices);           
          gl.glColorPointer(4, GL_FLOAT , 0,colorBuffer);
          gl.glPushMatrix();
          gl.glDrawArrays(GL_LINE_STRIP, 0, points.size()); 
          gl.glPopMatrix();
          
          gl.glDisableClientState(GL_VERTEX_ARRAY); 
          gl.glDisableClientState(GL_COLOR_ARRAY);
         
        }catch(Exception e){}
    }   
    public static void drawPoints2D(GL10 gl, ArrayList<MapPos>  points,  ArrayList<Integer> colorlist,float width) { 
        ByteBuffer vbb = ByteBuffer.allocateDirect(4 * 3 * points.size());
        vbb.order(ByteOrder.nativeOrder());
        FloatBuffer vertices = vbb.asFloatBuffer();         
        FloatBuffer colorBuffer;   
        ByteBuffer cbb = ByteBuffer.allocateDirect(4 * 4 * points.size());
        cbb.order(ByteOrder.nativeOrder()); // Use native byte order (NEW)
        colorBuffer = cbb.asFloatBuffer();           
        for (int i = 0; i < points.size(); i++) {   
        lX = (float) proj.toInternal(points.get(i).x, points.get(i).y).x;
          lY = (float) proj.toInternal(points.get(i).x, points.get(i).y).y;            
          float red =(1.0f/255)*Color.red(colorlist.get(i));     
          float green =(1.0f/255)*Color.green(colorlist.get(i));       
          float blue =(1.0f/255)*Color.blue(colorlist.get(i));          
             vertices.put(lX);
             vertices.put(lY);   
             colorBuffer.put(red); 
             colorBuffer.put(green); 
             colorBuffer.put(blue); 
             colorBuffer.put(1f); 
        } 
        colorBuffer.position(0); 
        vertices.position(0);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
        gl.glLineWidth(width); 
        
        gl.glEnableClientState(GL_VERTEX_ARRAY);       
        gl.glEnableClientState(GL_COLOR_ARRAY);
        
        gl.glVertexPointer(2, GL_FLOAT , 0, vertices);  
       
        gl.glColorPointer(4, GL_FLOAT , 0,colorBuffer);
        gl.glPushMatrix();
        gl.glDrawArrays(GL_LINE_STRIP, 0, points.size()); 
        gl.glPopMatrix();
        
        gl.glDisableClientState(GL_VERTEX_ARRAY); 
        gl.glDisableClientState(GL_COLOR_ARRAY);
    }   
    public static void drawLine(GL10 gl, MapPos origin, MapPos destination,float ired,float igreen,float iblue) {
        ByteBuffer vbb = ByteBuffer.allocateDirect(4 * 2 * 2);
        vbb.order(ByteOrder.nativeOrder());
        FloatBuffer vertices = vbb.asFloatBuffer();        
            lX = (float) proj.toInternal(origin.x, origin.y).x;
          lY = (float) proj.toInternal(origin.x, origin.y).y;  
          vertices.put(lX);
          vertices.put(lY);
          lX = (float) proj.toInternal(origin.x, destination.y).x;
          lY = (float) proj.toInternal(origin.x, destination.y).y;  
          vertices.put(lX);
          vertices.put(lY);        
        vertices.position(0);
        float red =(1.0f/255)*ired;     
        float green =(1.0f/255)*igreen;       
        float blue =(1.0f/255)*iblue;   
        gl.glColor4f(red,green,blue, 1.0f);
        gl.glLineWidth(5.0f); 
        gl.glVertexPointer(2, GL_FLOAT, 0, vertices);
        gl.glEnableClientState(GL_VERTEX_ARRAY);
        gl.glDrawArrays(GL_LINE_STRIP, 0, 2);
        gl.glDisableClientState(GL_VERTEX_ARRAY);        
    }
private static final int NR_OF_CIRCLE_VERTS = 180;   
public static void drawCircle(GL10 gl, MapPos center, double r, Integer color,float zoomPow2) {     
      double incomingdiameter=r/2;
      lX= (float) proj.toInternal(center.x, center.y).x;
      lY = (float) proj.toInternal(center.x, center.y).y;
      ByteBuffer byteBuffer = ByteBuffer
                .allocateDirect((NR_OF_CIRCLE_VERTS + 2) * 3 * Float.SIZE / 8);
        byteBuffer.order(ByteOrder.nativeOrder());
        FloatBuffer vertices = byteBuffer.asFloatBuffer();
        float degreesPerVert = 360.0f / NR_OF_CIRCLE_VERTS;
        vertices.put(0);
        vertices.put(0);
        vertices.put(0);
        for (float tsj = 0; tsj < 360; tsj += degreesPerVert) {
          vertices.put(android.util.FloatMath.cos(tsj * Const.DEG_TO_RAD));
          vertices.put(android.util.FloatMath.sin(tsj * Const.DEG_TO_RAD));
          vertices.put(0);
        }
        vertices.put(1);
        vertices.put(0);
        vertices.put(0);
        vertices.position(0);
        float diameter = (float) Math.max(
                Const.UNIT_SIZE * incomingdiameter / 7500000f, // based on GPS accuracy. This constant depends on latitude
                Const.UNIT_SIZE / zoomPow2 * 0.2f);         
      
        gl.glBindTexture(GL_TEXTURE_2D, 0);
        if(color==Color.RED)
          gl.glColor4f(1,0,0,0.5f);     
        else if(color==Color.GREEN)
          gl.glColor4f(0,1,0,0.5f);  
        else
          gl.glColor4f(0,0,1,0.5f);  
        gl.glEnableClientState(GL_VERTEX_ARRAY); 
        gl.glVertexPointer(3, GL_FLOAT , 0, vertices);   
        gl.glPushMatrix();
        gl.glTranslatef(lX, lY, 0);        
        gl.glScalef(diameter ,diameter , 1);
        gl.glDrawArrays(GL_TRIANGLE_FAN, 0,  NR_OF_CIRCLE_VERTS + 2); 
        gl.glPopMatrix();        
        gl.glDisableClientState(GL_VERTEX_ARRAY);        
        
    }
}




Java Source Code List

com.flightcomputer.Circle.java
com.flightcomputer.DownloadActivity.java
com.flightcomputer.EditPreferences.java
com.flightcomputer.FCActivity.java
com.flightcomputer.GpsSkyActivity.java
com.flightcomputer.IgcLoad.java
com.flightcomputer.LeonardoLiveWriter.java
com.flightcomputer.MapEventListener.java
com.flightcomputer.PositionWriter.java
com.flightcomputer.PressureAltimeterActivity.java
com.flightcomputer.RouteLine.java
com.flightcomputer.Task.java
com.flightcomputer.TrckLine.java
com.flightcomputer.filefilter.FilterByFileExtension.java
com.flightcomputer.filefilter.ValidFileFilter.java
com.flightcomputer.filefilter.ValidMapFile.java
com.flightcomputer.filefilter.ValidRenderTheme.java
com.flightcomputer.filepicker.FilePickerIconAdapter.java
com.flightcomputer.filepicker.FilePicker.java
com.flightcomputer.utilities.BaroService.java
com.flightcomputer.utilities.BeepThread.java
com.flightcomputer.utilities.GpsSkyView.java
com.flightcomputer.utilities.KalmanFilter.java
com.flightcomputer.utilities.PiecewiseLinearFunction.java
com.flightcomputer.utilities.Point2d.java
com.flightcomputer.utilities.VerticalProgressBar_Reverse.java
com.flightcomputer.utilities.VerticalProgressBar.java
com.flightcomputer.openGlUtils.java
com.nutiteq.advancedmap.mapquest.SearchQueryResults.java
com.nutiteq.advancedmap.mapquest.SearchSuggestionProvider.java
com.nutiteq.services.geocode.MapQuestGeocoder.java
com.nutiteq.utils.MapsforgeMapLayer.java
com.nutiteq.utils.MbTilesDatabaseHelper.java
com.nutiteq.utils.MyLocationCircle.java
com.nutiteq.utils.NetUtils.java
com.nutiteq.utils.UiUtils.java
com.nutiteq.utils.UtfGridHelper.java
com.nutiteq.utils.UtfGridLayerInterface.java