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.rosjava_geometry.FrameName;
00023 import java.util.List;
00024
00025 import javax.microedition.khronos.egl.EGLConfig;
00026 import javax.microedition.khronos.opengles.GL10;
00027
00034 public class XYOrthographicRenderer implements GLSurfaceView.Renderer {
00035
00040 private List<Layer> layers;
00041
00042 private Camera camera;
00043
00044 public XYOrthographicRenderer(Camera camera) {
00045 this.camera = camera;
00046 }
00047
00048 @Override
00049 public void onSurfaceChanged(GL10 gl, int width, int height) {
00050 Viewport viewport = new Viewport(width, height);
00051 viewport.apply(gl);
00052 camera.setViewport(viewport);
00053 gl.glMatrixMode(GL10.GL_MODELVIEW);
00054 gl.glEnable(GL10.GL_BLEND);
00055 gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
00056 gl.glDisable(GL10.GL_DEPTH_TEST);
00057 }
00058
00059 @Override
00060 public void onDrawFrame(GL10 gl) {
00061 gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
00062 gl.glLoadIdentity();
00063 camera.apply(gl);
00064 drawLayers(gl);
00065 }
00066
00067 @Override
00068 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
00069 }
00070
00071 private void drawLayers(GL10 gl) {
00072 if (layers == null) {
00073 return;
00074 }
00075 for (Layer layer : getLayers()) {
00076 gl.glPushMatrix();
00077 if (layer instanceof TfLayer) {
00078 FrameName layerFrame = ((TfLayer) layer).getFrame();
00079 if (layerFrame != null && camera.applyFrameTransform(gl, layerFrame)) {
00080 layer.draw(gl);
00081 }
00082 } else {
00083 layer.draw(gl);
00084 }
00085 gl.glPopMatrix();
00086 }
00087 }
00088
00089 public List<Layer> getLayers() {
00090 return layers;
00091 }
00092
00093 public void setLayers(List<Layer> layers) {
00094 this.layers = layers;
00095 }
00096 }