FileDocCategorySizeDatePackage
Annulus.javaAPI DocAndroid 1.5 API3955Wed May 06 22:41:08 BST 2009com.android.globaltime

Annulus

public class Annulus extends Shape
A class that draws a ring with a given center and inner and outer radii. The inner and outer rings each have a color and the remaining pixels are colored by interpolation. GlobalTime uses this class to simulate an "atmosphere" around the earth.

Fields Summary
Constructors Summary
public Annulus(float centerX, float centerY, float Z, float innerRadius, float outerRadius, float rInner, float gInner, float bInner, float aInner, float rOuter, float gOuter, float bOuter, float aOuter, int sectors)
Constructs an annulus.

param
centerX the X coordinate of the center point
param
centerY the Y coordinate of the center point
param
Z the fixed Z for the entire ring
param
innerRadius the inner radius
param
outerRadius the outer radius
param
rInner the red channel of the color of the inner ring
param
gInner the green channel of the color of the inner ring
param
bInner the blue channel of the color of the inner ring
param
aInner the alpha channel of the color of the inner ring
param
rOuter the red channel of the color of the outer ring
param
gOuter the green channel of the color of the outer ring
param
bOuter the blue channel of the color of the outer ring
param
aOuter the alpha channel of the color of the outer ring
param
sectors the number of sectors used to approximate curvature

        super(GL10.GL_TRIANGLES, GL10.GL_UNSIGNED_SHORT,
              false, false, true);

        int radii = sectors + 1;

        int[] vertices = new int[2 * 3 * radii];
        int[] colors = new int[2 * 4 * radii];
        short[] indices = new short[2 * 3 * radii];

        int vidx = 0;
        int cidx = 0;
        int iidx = 0;

        for (int i = 0; i < radii; i++) {
            float theta = (i * TWO_PI) / (radii - 1);
            float cosTheta = (float) Math.cos(theta);
            float sinTheta = (float) Math.sin(theta);

            vertices[vidx++] = toFixed(centerX + innerRadius * cosTheta);
            vertices[vidx++] = toFixed(centerY + innerRadius * sinTheta);
            vertices[vidx++] = toFixed(Z);

            vertices[vidx++] = toFixed(centerX + outerRadius * cosTheta);
            vertices[vidx++] = toFixed(centerY + outerRadius * sinTheta);
            vertices[vidx++] = toFixed(Z);
        
            colors[cidx++] = toFixed(rInner);
            colors[cidx++] = toFixed(gInner);
            colors[cidx++] = toFixed(bInner);
            colors[cidx++] = toFixed(aInner);

            colors[cidx++] = toFixed(rOuter);
            colors[cidx++] = toFixed(gOuter);
            colors[cidx++] = toFixed(bOuter);
            colors[cidx++] = toFixed(aOuter);
        }

        for (int i = 0; i < sectors; i++) {
            indices[iidx++] = (short) (2 * i);
            indices[iidx++] = (short) (2 * i + 1);
            indices[iidx++] = (short) (2 * i + 2);

            indices[iidx++] = (short) (2 * i + 1);
            indices[iidx++] = (short) (2 * i + 3);
            indices[iidx++] = (short) (2 * i + 2);
        }
        
        allocateBuffers(vertices, null, null, colors, indices);
    
Methods Summary