Viewport.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  *
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
00015  */
00016 
00017 package org.ros.android.view.visualization;
00018 
00019 import javax.microedition.khronos.opengles.GL10;
00020 
00024 public class Viewport {
00025 
00026   private final int width;
00027   private final int height;
00028 
00029   public Viewport(int width, int height) {
00030     this.width = width;
00031     this.height = height;
00032   }
00033 
00034   public void apply(GL10 gl) {
00035     gl.glViewport(0, 0, width, height);
00036     // Set the perspective projection to be orthographic.
00037     gl.glMatrixMode(GL10.GL_PROJECTION);
00038     gl.glLoadIdentity();
00039     // This corrects for the aspect ratio of the viewport. The viewport can now
00040     // be reasoned about in pixels. The zNear and zFar only need to be
00041     // sufficiently large to avoid clipping. The z-buffer is not otherwise used.
00042     gl.glOrthof(-width / 2.0f, width / 2.0f, -height / 2.0f, height / 2.0f, -1e4f, 1e4f);
00043   }
00044 
00045   public int getWidth() {
00046     return width;
00047   }
00048 
00049   public int getHeight() {
00050     return height;
00051   }
00052 }


android_core
Author(s): Damon Kohler
autogenerated on Thu Aug 27 2015 12:11:33