Home | History | Annotate | Download | only in renderers
      1 /*
      2  * Copyright (C) 2014 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.cts.verifier.sensors.renderers;
     18 
     19 import java.nio.ByteBuffer;
     20 import java.nio.ByteOrder;
     21 import java.nio.FloatBuffer;
     22 import java.nio.ShortBuffer;
     23 
     24 import javax.microedition.khronos.opengles.GL10;
     25 
     26 /**
     27  * Rectangular block that is rotated by {@link GLRotationGuideRenderer}.
     28  */
     29 class Monolith {
     30     private static final int NUM_VERTICES = 8;
     31     private static final int NUM_INDICES = 36;
     32 
     33     private final FloatBuffer mVertexBuffer;
     34     private final ShortBuffer mIndexBuffer;
     35 
     36     public Monolith() {
     37         mVertexBuffer = ByteBuffer.allocateDirect(NUM_VERTICES * 3 * 4)
     38                 .order(ByteOrder.nativeOrder())
     39                 .asFloatBuffer();
     40 
     41         float[] coordinates = {
     42                 -0.65f, -1, 0.2f,
     43                 -0.65f, 1, 0.2f,
     44                 0.65f, 1, 0.2f,
     45                 0.65f, -1, 0.2f,
     46 
     47                 -0.65f, -1, -0.2f,
     48                 -0.65f, 1, -0.2f,
     49                 0.65f, 1, -0.2f,
     50                 0.65f, -1, -0.2f,
     51         };
     52 
     53         for (int i = 0; i < coordinates.length; i++) {
     54             mVertexBuffer.put(coordinates[i]);
     55         }
     56 
     57         mIndexBuffer = ByteBuffer.allocateDirect(NUM_INDICES * 2)
     58                 .order(ByteOrder.nativeOrder())
     59                 .asShortBuffer();
     60 
     61         // Front
     62         mIndexBuffer.put((short) 0);
     63         mIndexBuffer.put((short) 1);
     64         mIndexBuffer.put((short) 2);
     65         mIndexBuffer.put((short) 0);
     66         mIndexBuffer.put((short) 2);
     67         mIndexBuffer.put((short) 3);
     68 
     69         // Back
     70         mIndexBuffer.put((short) 7);
     71         mIndexBuffer.put((short) 6);
     72         mIndexBuffer.put((short) 5);
     73         mIndexBuffer.put((short) 7);
     74         mIndexBuffer.put((short) 5);
     75         mIndexBuffer.put((short) 4);
     76 
     77         // Right
     78         mIndexBuffer.put((short) 3);
     79         mIndexBuffer.put((short) 2);
     80         mIndexBuffer.put((short) 6);
     81         mIndexBuffer.put((short) 3);
     82         mIndexBuffer.put((short) 6);
     83         mIndexBuffer.put((short) 7);
     84 
     85         // Left
     86         mIndexBuffer.put((short) 4);
     87         mIndexBuffer.put((short) 5);
     88         mIndexBuffer.put((short) 1);
     89         mIndexBuffer.put((short) 4);
     90         mIndexBuffer.put((short) 1);
     91         mIndexBuffer.put((short) 0);
     92 
     93         // Top
     94         mIndexBuffer.put((short) 1);
     95         mIndexBuffer.put((short) 5);
     96         mIndexBuffer.put((short) 6);
     97         mIndexBuffer.put((short) 1);
     98         mIndexBuffer.put((short) 6);
     99         mIndexBuffer.put((short) 2);
    100 
    101         // Bottom
    102         mIndexBuffer.put((short) 3);
    103         mIndexBuffer.put((short) 7);
    104         mIndexBuffer.put((short) 4);
    105         mIndexBuffer.put((short) 3);
    106         mIndexBuffer.put((short) 4);
    107         mIndexBuffer.put((short) 0);
    108 
    109         mVertexBuffer.position(0);
    110         mIndexBuffer.position(0);
    111     }
    112 
    113     public void draw(GL10 gl) {
    114         gl.glColor4f(0.5f, 0.5f, 0.5f, 1f);
    115         gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
    116         gl.glDrawElements(GL10.GL_TRIANGLES, NUM_INDICES, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
    117     }
    118 }
    119