Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.android.view.visualization;
00018
00019 import android.opengl.GLSurfaceView;
00020 import org.ros.android.view.visualization.layer.Layer;
00021 import org.ros.android.view.visualization.layer.TfLayer;
00022 import org.ros.namespace.GraphName;
00023
00024 import javax.microedition.khronos.egl.EGLConfig;
00025 import javax.microedition.khronos.opengles.GL10;
00026
00033 public class XYOrthographicRenderer implements GLSurfaceView.Renderer {
00034
00035 private static final Color BACKGROUND_COLOR = new Color(0.87f, 0.87f, 0.87f, 1.f);
00036
00037 private final VisualizationView view;
00038
00039 public XYOrthographicRenderer(VisualizationView view) {
00040 this.view = view;
00041 }
00042
00043 @Override
00044 public void onSurfaceChanged(GL10 gl, int width, int height) {
00045 Viewport viewport = new Viewport(width, height);
00046 viewport.apply(gl);
00047 view.getCamera().setViewport(viewport);
00048 gl.glMatrixMode(GL10.GL_MODELVIEW);
00049 gl.glEnable(GL10.GL_BLEND);
00050 gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
00051 gl.glDisable(GL10.GL_DEPTH_TEST);
00052 gl.glClearColor(BACKGROUND_COLOR.getRed(), BACKGROUND_COLOR.getGreen(),
00053 BACKGROUND_COLOR.getBlue(), BACKGROUND_COLOR.getAlpha());
00054 for (Layer layer : view.getLayers()) {
00055 layer.onSurfaceChanged(view, gl, width, height);
00056 }
00057 }
00058
00059 @Override
00060 public void onDrawFrame(GL10 gl) {
00061 gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
00062 gl.glLoadIdentity();
00063 view.getCamera().apply(gl);
00064 drawLayers(gl);
00065 }
00066
00067 private void drawLayers(GL10 gl) {
00068 for (Layer layer : view.getLayers()) {
00069 gl.glPushMatrix();
00070 if (layer instanceof TfLayer) {
00071 GraphName layerFrame = ((TfLayer) layer).getFrame();
00072 if (layerFrame != null && view.getCamera().applyFrameTransform(gl, layerFrame)) {
00073 layer.draw(view, gl);
00074 }
00075 } else {
00076 layer.draw(view, gl);
00077 }
00078 gl.glPopMatrix();
00079 }
00080 }
00081
00082 @Override
00083 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
00084 for (Layer layer : view.getLayers()) {
00085 layer.onSurfaceCreated(view, gl, config);
00086 }
00087 }
00088 }