Example usage for javax.media.j3d GeometryArray COORDINATES

List of usage examples for javax.media.j3d GeometryArray COORDINATES

Introduction

In this page you can find the example usage for javax.media.j3d GeometryArray COORDINATES.

Prototype

int COORDINATES

To view the source code for javax.media.j3d GeometryArray COORDINATES.

Click Source Link

Document

Specifies that this GeometryArray contains an array of coordinates.

Usage

From source file:ExLinearFog.java

private void addBox(float width, float height, float depth, float y, float width2, float depth2, int flags) {
    float[] coordinates = {
            // around the bottom
            -width / 2.0f, -height / 2.0f, depth / 2.0f, width / 2.0f, -height / 2.0f, depth / 2.0f,
            width / 2.0f, -height / 2.0f, -depth / 2.0f, -width / 2.0f, -height / 2.0f, -depth / 2.0f,

            // around the top
            -width2 / 2.0f, height / 2.0f, depth2 / 2.0f, width2 / 2.0f, height / 2.0f, depth2 / 2.0f,
            width2 / 2.0f, height / 2.0f, -depth2 / 2.0f, -width2 / 2.0f, height / 2.0f, -depth2 / 2.0f, };
    int[] fullCoordinateIndexes = { 0, 1, 5, 4, // front
            1, 2, 6, 5, // right
            2, 3, 7, 6, // back
            3, 0, 4, 7, // left
            4, 5, 6, 7, // top
            3, 2, 1, 0, // bottom
    };//from   w ww .ja v a  2s. c  o m
    float v = -(width2 - width) / height;
    float[] normals = { 0.0f, v, 1.0f, // front
            1.0f, v, 0.0f, // right
            0.0f, v, -1.0f, // back
            -1.0f, v, 0.0f, // left
            0.0f, 1.0f, 0.0f, // top
            0.0f, -1.0f, 0.0f, // bottom
    };
    int[] fullNormalIndexes = { 0, 0, 0, 0, // front
            1, 1, 1, 1, // right
            2, 2, 2, 2, // back
            3, 3, 3, 3, // left
            4, 4, 4, 4, // top
            5, 5, 5, 5, // bottom
    };
    float[] textureCoordinates = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, };
    int[] fullTextureCoordinateIndexes = { 0, 1, 2, 3, // front
            0, 1, 2, 3, // right
            0, 1, 2, 3, // back
            0, 1, 2, 3, // left
            0, 1, 2, 3, // top
            0, 1, 2, 3, // bottom
    };

    // Select indexes needed
    int[] coordinateIndexes;
    int[] normalIndexes;
    int[] textureCoordinateIndexes;
    if (flags == 0) {
        // build neither top or bottom
        coordinateIndexes = new int[4 * 4];
        textureCoordinateIndexes = new int[4 * 4];
        normalIndexes = new int[4 * 4];
        for (int i = 0; i < 4 * 4; i++) {
            coordinateIndexes[i] = fullCoordinateIndexes[i];
            textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i];
            normalIndexes[i] = fullNormalIndexes[i];
        }
    } else if ((flags & (BUILD_TOP | BUILD_BOTTOM)) == (BUILD_TOP | BUILD_BOTTOM)) {
        // build top and bottom
        coordinateIndexes = fullCoordinateIndexes;
        textureCoordinateIndexes = fullTextureCoordinateIndexes;
        normalIndexes = fullNormalIndexes;
    } else if ((flags & BUILD_TOP) != 0) {
        // build top but not bottom
        coordinateIndexes = new int[5 * 4];
        textureCoordinateIndexes = new int[5 * 4];
        normalIndexes = new int[5 * 4];
        for (int i = 0; i < 5 * 4; i++) {
            coordinateIndexes[i] = fullCoordinateIndexes[i];
            textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i];
            normalIndexes[i] = fullNormalIndexes[i];
        }
    } else {
        // build bottom but not top
        coordinateIndexes = new int[5 * 4];
        textureCoordinateIndexes = new int[5 * 4];
        normalIndexes = new int[5 * 4];
        for (int i = 0; i < 4 * 4; i++) {
            coordinateIndexes[i] = fullCoordinateIndexes[i];
            textureCoordinateIndexes[i] = fullTextureCoordinateIndexes[i];
            normalIndexes[i] = fullNormalIndexes[i];
        }
        for (int i = 5 * 4; i < 6 * 4; i++) {
            coordinateIndexes[i - 4] = fullCoordinateIndexes[i];
            textureCoordinateIndexes[i - 4] = fullTextureCoordinateIndexes[i];
            normalIndexes[i - 4] = fullNormalIndexes[i];
        }
    }

    IndexedQuadArray quads = new IndexedQuadArray(coordinates.length, // number
            // of
            // vertexes
            GeometryArray.COORDINATES | // vertex coordinates given
                    GeometryArray.NORMALS | // normals given
                    GeometryArray.TEXTURE_COORDINATE_2, // texture
            // coordinates given
            coordinateIndexes.length); // number of coordinate indexes
    quads.setCoordinates(0, coordinates);
    quads.setCoordinateIndices(0, coordinateIndexes);
    quads.setNormals(0, normals);
    quads.setNormalIndices(0, normalIndexes);
    quads.setTextureCoordinates(0, textureCoordinates);
    quads.setTextureCoordinateIndices(0, textureCoordinateIndexes);
    Shape3D box = new Shape3D(quads, mainAppearance);

    Vector3f trans = new Vector3f(0.0f, y, 0.0f);
    Transform3D tr = new Transform3D();
    tr.set(trans); // translate
    TransformGroup tg = new TransformGroup(tr);
    tg.addChild(box);
    addChild(tg);
}

From source file:PickTest.java

IcosahedronITSA() {
    super(12, GeometryArray.COORDINATES | GeometryArray.COLOR_3, 32, sVertCnt);

    Point3f verts[] = new Point3f[12];
    Color3f colors[] = new Color3f[12];

    verts[0] = new Point3f(0.0f, 1.4f, 0.8652f);
    verts[1] = new Point3f(0.0f, 1.4f, -0.8652f);
    verts[2] = new Point3f(1.4f, 0.8652f, 0.0f);
    verts[3] = new Point3f(1.4f, -0.8652f, 0.0f);
    verts[4] = new Point3f(0.0f, -1.4f, -0.8652f);
    verts[5] = new Point3f(0.0f, -1.4f, 0.8652f);
    verts[6] = new Point3f(0.8652f, 0.0f, 1.4f);
    verts[7] = new Point3f(-0.8652f, 0.0f, 1.4f);
    verts[8] = new Point3f(0.8652f, 0.0f, -1.4f);
    verts[9] = new Point3f(-0.8652f, 0.0f, -1.4f);
    verts[10] = new Point3f(-1.4f, 0.8652f, 0.0f);
    verts[11] = new Point3f(-1.4f, -0.8652f, 0.0f);

    colors[0] = new Color3f(1.0f, 0.0f, 0.0f);
    colors[1] = new Color3f(0.0f, 1.0f, 0.0f);
    colors[2] = new Color3f(0.0f, 0.0f, 1.0f);
    colors[3] = new Color3f(1.0f, 1.0f, 0.0f);
    colors[4] = new Color3f(0.0f, 1.0f, 1.0f);
    colors[5] = new Color3f(1.0f, 0.0f, 1.0f);
    colors[6] = new Color3f(0.0f, 0.5f, 0.0f);
    colors[7] = new Color3f(0.0f, 0.0f, 0.5f);
    colors[8] = new Color3f(0.5f, 0.5f, 0.0f);
    colors[9] = new Color3f(0.0f, 0.5f, 0.5f);
    colors[10] = new Color3f(0.5f, 0.0f, 0.5f);
    colors[11] = new Color3f(0.5f, 0.5f, 0.5f);

    int pntsIndex[] = new int[32];
    int clrsIndex[] = new int[32];

    pntsIndex[0] = 4;/*  w ww  .j  a  v a2s .com*/
    clrsIndex[0] = 4;
    pntsIndex[1] = 5;
    clrsIndex[1] = 5;
    pntsIndex[2] = 11;
    clrsIndex[2] = 11;

    pntsIndex[3] = 11;
    clrsIndex[3] = 11;
    pntsIndex[4] = 5;
    clrsIndex[4] = 5;
    pntsIndex[5] = 7;
    clrsIndex[5] = 7;

    pntsIndex[6] = 6;
    clrsIndex[6] = 6;

    pntsIndex[7] = 0;
    clrsIndex[7] = 0;

    pntsIndex[8] = 2;
    clrsIndex[8] = 2;

    pntsIndex[9] = 1;
    clrsIndex[9] = 1;

    pntsIndex[10] = 8;
    clrsIndex[10] = 8;

    pntsIndex[11] = 9;
    clrsIndex[11] = 9;

    pntsIndex[12] = 4;
    clrsIndex[12] = 4;

    pntsIndex[13] = 11;
    clrsIndex[13] = 11;

    pntsIndex[14] = 2;
    clrsIndex[14] = 2;
    pntsIndex[15] = 6;
    clrsIndex[15] = 6;
    pntsIndex[16] = 3;
    clrsIndex[16] = 3;

    pntsIndex[17] = 5;
    clrsIndex[17] = 5;

    pntsIndex[18] = 4;
    clrsIndex[18] = 4;

    pntsIndex[19] = 4;
    clrsIndex[19] = 4;
    pntsIndex[20] = 8;
    clrsIndex[20] = 8;
    pntsIndex[21] = 3;
    clrsIndex[21] = 3;

    pntsIndex[22] = 2;
    clrsIndex[22] = 2;

    pntsIndex[23] = 0;
    clrsIndex[23] = 0;
    pntsIndex[24] = 1;
    clrsIndex[24] = 1;
    pntsIndex[25] = 10;
    clrsIndex[25] = 10;

    pntsIndex[26] = 9;
    clrsIndex[26] = 9;

    pntsIndex[27] = 11;
    clrsIndex[27] = 11;

    pntsIndex[28] = 0;
    clrsIndex[28] = 0;
    pntsIndex[29] = 10;
    clrsIndex[29] = 10;
    pntsIndex[30] = 7;
    clrsIndex[30] = 7;

    pntsIndex[31] = 11;
    clrsIndex[31] = 11;

    setCoordinates(0, verts);
    setCoordinateIndices(0, pntsIndex);
    setColors(0, colors);
    setColorIndices(0, clrsIndex);
}

From source file:ExBackgroundImage.java

private void rebuild() {
    // Build a shape
    if (shape == null) {
        shape = new Shape3D();
        shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
        shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
        shape.setAppearance(mainAppearance);
        addChild(shape);/*from w  w w  .  java2 s .  c  om*/
    } else {
        shape.setAppearance(mainAppearance);
    }

    if (xDimension < 2 || zDimension < 2 || heights == null || heights.length < 4) {
        tristrip = null;
        shape.setGeometry(null);
        return;
    }

    // Create a list of coordinates, one per grid row/column
    double[] coordinates = new double[xDimension * zDimension * 3];
    double x, z;
    int n = 0, k = 0;
    z = ((double) (zDimension - 1)) * zSpacing / 2.0; // start at front edge
    for (int i = 0; i < zDimension; i++) {
        x = -((double) (xDimension - 1)) * xSpacing / 2.0;// start at left
        // edge
        for (int j = 0; j < xDimension; j++) {
            coordinates[n++] = x;
            coordinates[n++] = heights[k++];
            coordinates[n++] = z;
            x += xSpacing;
        }
        z -= zSpacing;
    }

    // Create a list of normals, one per grid row/column
    float[] normals = new float[xDimension * zDimension * 3];
    Vector3f one = new Vector3f(0.0f, 0.0f, 0.0f);
    Vector3f two = new Vector3f(0.0f, 0.0f, 0.0f);
    Vector3f norm = new Vector3f(0.0f, 0.0f, 0.0f);
    n = 0;
    k = 0;
    for (int i = 0; i < zDimension - 1; i++) {
        for (int j = 0; j < xDimension - 1; j++) {
            // Vector to right in X
            one.set((float) xSpacing, (float) (heights[k + 1] - heights[k]), 0.0f);

            // Vector back in Z
            two.set(0.0f, (float) (heights[k + xDimension] - heights[k]), (float) -zSpacing);

            // Cross them to get the normal
            norm.cross(one, two);
            normals[n++] = norm.x;
            normals[n++] = norm.y;
            normals[n++] = norm.z;
            k++;
        }

        // Last normal in row is a copy of the previous one
        normals[n] = normals[n - 3]; // X
        normals[n + 1] = normals[n - 2]; // Y
        normals[n + 2] = normals[n - 1]; // Z
        n += 3;
        k++;
    }

    // Last row of normals is a copy of the previous row
    for (int j = 0; j < xDimension; j++) {
        normals[n] = normals[n - xDimension * 3]; // X
        normals[n + 1] = normals[n - xDimension * 3 + 1]; // Y
        normals[n + 2] = normals[n - xDimension * 3 + 2]; // Z
        n += 3;
    }

    // Create a list of texture coordinates, one per grid row/column
    float[] texcoordinates = new float[xDimension * zDimension * 2];
    float deltaS = 1.0f / (float) (xDimension - 1);
    float deltaT = 1.0f / (float) (zDimension - 1);
    float s = 0.0f;
    float t = 0.0f;
    n = 0;
    for (int i = 0; i < zDimension; i++) {
        s = 0.0f;
        for (int j = 0; j < xDimension; j++) {
            texcoordinates[n++] = s;
            texcoordinates[n++] = t;
            s += deltaS;
        }
        t += deltaT;
    }

    // Create a list of triangle strip indexes. Each strip goes
    // down one row (X direction) of the elevation grid.
    int[] indexes = new int[xDimension * (zDimension - 1) * 2];
    int[] stripCounts = new int[zDimension - 1];
    n = 0;
    k = 0;
    for (int i = 0; i < zDimension - 1; i++) {
        stripCounts[i] = xDimension * 2;
        for (int j = 0; j < xDimension; j++) {
            indexes[n++] = k + xDimension;
            indexes[n++] = k;
            k++;
        }
    }

    // Create geometry for collection of triangle strips, one
    // strip per row of the elevation grid
    tristrip = new IndexedTriangleStripArray(coordinates.length,
            GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2,
            indexes.length, stripCounts);
    tristrip.setCoordinates(0, coordinates);
    tristrip.setNormals(0, normals);
    tristrip.setTextureCoordinates(0, texcoordinates);
    tristrip.setCoordinateIndices(0, indexes);
    tristrip.setNormalIndices(0, indexes);
    tristrip.setTextureCoordinateIndices(0, indexes);

    // Set the geometry for the shape
    shape.setGeometry(tristrip);
}

From source file:ExLinearFog.java

private void addCylinder(float radius, float height, float y) {
    ////w  w w.j a v a2 s  .  co m
    //  Compute coordinates, normals, and texture coordinates
    //  around the top and bottom of a cylinder
    //
    float[] coordinates = new float[NSTEPS * 2 * 3]; // xyz
    float[] normals = new float[NSTEPS * 2 * 3]; // xyz vector
    float[] textureCoordinates = new float[NSTEPS * 2 * 2]; // st
    float angle = 0.0f;
    float deltaAngle = 2.0f * (float) Math.PI / ((float) NSTEPS - 1);
    float s = 0.0f;
    float deltaS = 1.0f / ((float) NSTEPS - 1);
    int n = 0;
    int tn = 0;
    float h2 = height / 2.0f;
    for (int i = 0; i < NSTEPS; i++) {
        // bottom
        normals[n + 0] = (float) Math.cos(angle);
        normals[n + 1] = 0.0f;
        normals[n + 2] = -(float) Math.sin(angle);
        coordinates[n + 0] = radius * normals[n + 0];
        coordinates[n + 1] = -h2;
        coordinates[n + 2] = radius * normals[n + 2];
        textureCoordinates[tn + 0] = s;
        textureCoordinates[tn + 1] = 0.0f;
        n += 3;
        tn += 2;

        // top
        normals[n + 0] = normals[n - 3];
        normals[n + 1] = 0.0f;
        normals[n + 2] = normals[n - 1];
        coordinates[n + 0] = coordinates[n - 3];
        coordinates[n + 1] = h2;
        coordinates[n + 2] = coordinates[n - 1];
        textureCoordinates[tn + 0] = s;
        textureCoordinates[tn + 1] = 1.0f;
        n += 3;
        tn += 2;

        angle += deltaAngle;
        s += deltaS;
    }

    //
    //  Compute coordinate indexes, normal indexes, and texture
    //  coordinate indexes awround the sides of a cylinder.
    //  For this application, we don't need top or bottom, so
    //  skip them.
    //
    int[] indexes = new int[NSTEPS * 4];
    n = 0;
    int p = 0; // panel count
    for (int i = 0; i < NSTEPS - 1; i++) {
        indexes[n + 0] = p; // bottom left
        indexes[n + 1] = p + 2; // bottom right (next panel)
        indexes[n + 2] = p + 3; // top right (next panel)
        indexes[n + 3] = p + 1; // top left
        n += 4;
        p += 2;
    }
    indexes[n + 0] = p; // bottom left
    indexes[n + 1] = 0; // bottom right (next panel)
    indexes[n + 2] = 1; // top right (next panel)
    indexes[n + 3] = p + 1; // top left

    IndexedQuadArray quads = new IndexedQuadArray(coordinates.length / 3, // number
            // of
            // vertexes
            GeometryArray.COORDINATES | // format
                    GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2,
            indexes.length); // number
    // of
    // indexes
    quads.setCoordinates(0, coordinates);
    quads.setTextureCoordinates(0, textureCoordinates);
    quads.setNormals(0, normals);
    quads.setCoordinateIndices(0, indexes);
    quads.setTextureCoordinateIndices(0, indexes);
    quads.setNormalIndices(0, indexes);

    Shape3D shape = new Shape3D(quads, mainAppearance);

    Vector3f trans = new Vector3f(0.0f, y, 0.0f);
    Transform3D tr = new Transform3D();
    tr.set(trans); // translate
    TransformGroup tg = new TransformGroup(tr);

    tg.addChild(shape);
    addChild(tg);
}

From source file:PickTest.java

OctahedronTFA() {
    super(12, GeometryArray.COORDINATES | GeometryArray.COLOR_3, sVertCnt);

    Point3f verts[] = new Point3f[6];
    Color3f colors[] = new Color3f[6];

    verts[0] = new Point3f(0.0f, 0.0f, -1.5f);
    verts[1] = new Point3f(0.0f, 0.0f, 1.5f);
    verts[2] = new Point3f(0.0f, -1.5f, 0.0f);
    verts[3] = new Point3f(0.0f, 1.5f, 0.0f);
    verts[4] = new Point3f(1.5f, 0.0f, 0.0f);
    verts[5] = new Point3f(-1.5f, 0.0f, 0.0f);

    colors[0] = new Color3f(1.0f, 0.0f, 0.0f);
    colors[1] = new Color3f(0.0f, 1.0f, 0.0f);
    colors[2] = new Color3f(0.0f, 0.0f, 1.0f);
    colors[3] = new Color3f(1.0f, 1.0f, 0.0f);
    colors[4] = new Color3f(1.0f, 0.0f, 1.0f);
    colors[5] = new Color3f(0.0f, 1.0f, 1.0f);

    Point3f pnts[] = new Point3f[12];
    Color3f clrs[] = new Color3f[12];

    pnts[0] = verts[4];/*from   w  ww .j  ava2s  .c  o  m*/
    clrs[0] = colors[4];
    pnts[1] = verts[2];
    clrs[1] = colors[2];
    pnts[2] = verts[0];
    clrs[2] = colors[0];

    pnts[3] = verts[3];
    clrs[3] = colors[3];

    pnts[4] = verts[1];
    clrs[4] = colors[1];

    pnts[5] = verts[2];
    clrs[5] = colors[2];

    pnts[6] = verts[5];
    clrs[6] = colors[5];
    pnts[7] = verts[1];
    clrs[7] = colors[1];
    pnts[8] = verts[3];
    clrs[8] = colors[3];

    pnts[9] = verts[0];
    clrs[9] = colors[0];

    pnts[10] = verts[2];
    clrs[10] = colors[2];

    pnts[11] = verts[1];
    clrs[11] = colors[1];

    setCoordinates(0, pnts);
    setColors(0, clrs);
}

From source file:PickTest.java

OctahedronITFA() {
    super(6, GeometryArray.COORDINATES | GeometryArray.COLOR_3, 12, sVertCnt);

    Point3f verts[] = new Point3f[6];
    Color3f colors[] = new Color3f[6];

    verts[0] = new Point3f(0.0f, 0.0f, -1.5f);
    verts[1] = new Point3f(0.0f, 0.0f, 1.5f);
    verts[2] = new Point3f(0.0f, -1.5f, 0.0f);
    verts[3] = new Point3f(0.0f, 1.5f, 0.0f);
    verts[4] = new Point3f(1.5f, 0.0f, 0.0f);
    verts[5] = new Point3f(-1.5f, 0.0f, 0.0f);

    colors[0] = new Color3f(1.0f, 0.0f, 0.0f);
    colors[1] = new Color3f(0.0f, 1.0f, 0.0f);
    colors[2] = new Color3f(0.0f, 0.0f, 1.0f);
    colors[3] = new Color3f(1.0f, 1.0f, 0.0f);
    colors[4] = new Color3f(1.0f, 0.0f, 1.0f);
    colors[5] = new Color3f(0.0f, 1.0f, 1.0f);

    int pntsIndex[] = new int[12];
    int clrsIndex[] = new int[12];

    pntsIndex[0] = 4;//  w w w  .j a  v a  2 s .  c o  m
    clrsIndex[0] = 4;
    pntsIndex[1] = 2;
    clrsIndex[1] = 2;
    pntsIndex[2] = 0;
    clrsIndex[2] = 0;

    pntsIndex[3] = 3;
    clrsIndex[3] = 3;

    pntsIndex[4] = 1;
    clrsIndex[4] = 1;

    pntsIndex[5] = 2;
    clrsIndex[5] = 2;

    pntsIndex[6] = 5;
    clrsIndex[6] = 5;
    pntsIndex[7] = 1;
    clrsIndex[7] = 1;
    pntsIndex[8] = 3;
    clrsIndex[8] = 3;

    pntsIndex[9] = 0;
    clrsIndex[9] = 0;

    pntsIndex[10] = 2;
    clrsIndex[10] = 2;

    pntsIndex[11] = 1;
    clrsIndex[11] = 1;

    setCoordinates(0, verts);
    setCoordinateIndices(0, pntsIndex);
    setColors(0, colors);
    setColorIndices(0, clrsIndex);
}

From source file:GearTest.java

/**
 * Construct a SpurGear's teeth by adding the teeth shape nodes
 * /*  w w w .  j ava  2  s . c  om*/
 * @param pitchCircleRadius
 *            radius at center of teeth
 * @param rootRadius
 *            distance from pitch circle to top of teeth
 * @param outsideRadius
 *            distance from pitch circle to root of teeth
 * @param gearThickness
 *            thickness of the gear
 * @param toothTipThickness
 *            thickness of the tip of the tooth
 * @param toothToValleyAngleRatio
 *            the ratio of the angle subtended by the tooth to the angle
 *            subtended by the valley (must be <= .25)
 * @param look
 *            the gear's appearance object
 */
void addTeeth(float pitchCircleRadius, float rootRadius, float outsideRadius, float gearThickness,
        float toothTipThickness, float toothToValleyAngleRatio, Appearance look) {
    int index;
    Shape3D newShape;

    // Temporaries that store start angle for each portion of tooth facet
    double toothStartAngle, toothTopStartAngle, toothDeclineStartAngle, toothValleyStartAngle,
            nextToothStartAngle;

    // The x and y coordinates at each point of a facet and at each
    // point on the gear: at the shaft, the root of the teeth, and
    // the outer point of the teeth
    float xRoot0, yRoot0;
    float xOuter1, yOuter1;
    float xOuter2, yOuter2;
    float xRoot3, yRoot3;
    float xRoot4, yRoot4;

    // The z coordinates for the gear
    final float frontZ = -0.5f * gearThickness;
    final float rearZ = 0.5f * gearThickness;

    // The z coordinates for the tooth tip of the gear
    final float toothTipFrontZ = -0.5f * toothTipThickness;
    final float toothTipRearZ = 0.5f * toothTipThickness;

    int toothFacetVertexCount; // #(vertices) per tooth facet
    int toothFacetCount; // #(facets) per tooth
    int toothFaceTotalVertexCount; // #(vertices) in all teeth
    int toothFaceStripCount[] = new int[toothCount];
    // per tooth vertex count
    int topVertexCount; // #(vertices) for teeth tops
    int topStripCount[] = new int[1]; // #(vertices) in strip/strip

    // Front and rear facing normals for the teeth faces
    Vector3f frontToothNormal = new Vector3f(0.0f, 0.0f, -1.0f);
    Vector3f rearToothNormal = new Vector3f(0.0f, 0.0f, 1.0f);

    // Normals for teeth tops up incline, tooth top, and down incline
    Vector3f leftNormal = new Vector3f(-1.0f, 0.0f, 0.0f);
    Vector3f rightNormal = new Vector3f(1.0f, 0.0f, 0.0f);
    Vector3f outNormal = new Vector3f(1.0f, 0.0f, 0.0f);
    Vector3f inNormal = new Vector3f(-1.0f, 0.0f, 0.0f);

    // Temporary variables for storing coordinates and vectors
    Point3f coordinate = new Point3f(0.0f, 0.0f, 0.0f);
    Point3f tempCoordinate1 = new Point3f(0.0f, 0.0f, 0.0f);
    Point3f tempCoordinate2 = new Point3f(0.0f, 0.0f, 0.0f);
    Point3f tempCoordinate3 = new Point3f(0.0f, 0.0f, 0.0f);
    Vector3f tempVector1 = new Vector3f(0.0f, 0.0f, 0.0f);
    Vector3f tempVector2 = new Vector3f(0.0f, 0.0f, 0.0f);

    /*
     * Construct the gear's front facing teeth facets 0______2 / /\ / / \ / / \
     * //___________\ 1 3
     */
    toothFacetVertexCount = 4;
    toothFaceTotalVertexCount = toothFacetVertexCount * toothCount;
    for (int i = 0; i < toothCount; i++)
        toothFaceStripCount[i] = toothFacetVertexCount;

    TriangleStripArray frontGearTeeth = new TriangleStripArray(toothFaceTotalVertexCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS, toothFaceStripCount);

    for (int count = 0; count < toothCount; count++) {
        index = count * toothFacetVertexCount;

        toothStartAngle = gearStartAngle + circularPitchAngle * (double) count;
        toothTopStartAngle = toothStartAngle + toothTopAngleIncrement;
        toothDeclineStartAngle = toothStartAngle + toothDeclineAngleIncrement;
        toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement;

        xRoot0 = rootRadius * (float) Math.cos(toothStartAngle);
        yRoot0 = rootRadius * (float) Math.sin(toothStartAngle);
        xOuter1 = outsideRadius * (float) Math.cos(toothTopStartAngle);
        yOuter1 = outsideRadius * (float) Math.sin(toothTopStartAngle);
        xOuter2 = outsideRadius * (float) Math.cos(toothDeclineStartAngle);
        yOuter2 = outsideRadius * (float) Math.sin(toothDeclineStartAngle);
        xRoot3 = rootRadius * (float) Math.cos(toothValleyStartAngle);
        yRoot3 = rootRadius * (float) Math.sin(toothValleyStartAngle);

        tempCoordinate1.set(xRoot0, yRoot0, frontZ);
        tempCoordinate2.set(xRoot3, yRoot3, frontZ);
        tempVector1.sub(tempCoordinate2, tempCoordinate1);

        tempCoordinate2.set(xOuter1, yOuter1, toothTipFrontZ);
        tempVector2.sub(tempCoordinate2, tempCoordinate1);

        frontToothNormal.cross(tempVector1, tempVector2);
        frontToothNormal.normalize();

        coordinate.set(xOuter1, yOuter1, toothTipFrontZ);
        frontGearTeeth.setCoordinate(index, coordinate);
        frontGearTeeth.setNormal(index, frontToothNormal);

        coordinate.set(xRoot0, yRoot0, frontZ);
        frontGearTeeth.setCoordinate(index + 1, coordinate);
        frontGearTeeth.setNormal(index + 1, frontToothNormal);

        coordinate.set(xOuter2, yOuter2, toothTipFrontZ);
        frontGearTeeth.setCoordinate(index + 2, coordinate);
        frontGearTeeth.setNormal(index + 2, frontToothNormal);

        coordinate.set(xRoot3, yRoot3, frontZ);
        frontGearTeeth.setCoordinate(index + 3, coordinate);
        frontGearTeeth.setNormal(index + 3, frontToothNormal);
    }
    newShape = new Shape3D(frontGearTeeth, look);
    this.addChild(newShape);

    /*
     * Construct the gear's rear facing teeth facets (Using Quads) 1______2 / \ / \ / \
     * /____________\ 0 3
     */
    toothFacetVertexCount = 4;
    toothFaceTotalVertexCount = toothFacetVertexCount * toothCount;

    QuadArray rearGearTeeth = new QuadArray(toothCount * toothFacetVertexCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS);

    for (int count = 0; count < toothCount; count++) {

        index = count * toothFacetVertexCount;
        toothStartAngle = gearStartAngle + circularPitchAngle * (double) count;
        toothTopStartAngle = toothStartAngle + toothTopAngleIncrement;
        toothDeclineStartAngle = toothStartAngle + toothDeclineAngleIncrement;
        toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement;

        xRoot0 = rootRadius * (float) Math.cos(toothStartAngle);
        yRoot0 = rootRadius * (float) Math.sin(toothStartAngle);
        xOuter1 = outsideRadius * (float) Math.cos(toothTopStartAngle);
        yOuter1 = outsideRadius * (float) Math.sin(toothTopStartAngle);
        xOuter2 = outsideRadius * (float) Math.cos(toothDeclineStartAngle);
        yOuter2 = outsideRadius * (float) Math.sin(toothDeclineStartAngle);
        xRoot3 = rootRadius * (float) Math.cos(toothValleyStartAngle);
        yRoot3 = rootRadius * (float) Math.sin(toothValleyStartAngle);

        tempCoordinate1.set(xRoot0, yRoot0, rearZ);
        tempCoordinate2.set(xRoot3, yRoot3, rearZ);
        tempVector1.sub(tempCoordinate2, tempCoordinate1);
        tempCoordinate2.set(xOuter1, yOuter1, toothTipRearZ);
        tempVector2.sub(tempCoordinate2, tempCoordinate1);
        rearToothNormal.cross(tempVector2, tempVector1);
        rearToothNormal.normalize();

        coordinate.set(xRoot0, yRoot0, rearZ);
        rearGearTeeth.setCoordinate(index, coordinate);
        rearGearTeeth.setNormal(index, rearToothNormal);

        coordinate.set(xOuter1, yOuter1, toothTipRearZ);
        rearGearTeeth.setCoordinate(index + 1, coordinate);
        rearGearTeeth.setNormal(index + 1, rearToothNormal);

        coordinate.set(xOuter2, yOuter2, toothTipRearZ);
        rearGearTeeth.setCoordinate(index + 2, coordinate);
        rearGearTeeth.setNormal(index + 2, rearToothNormal);

        coordinate.set(xRoot3, yRoot3, rearZ);
        rearGearTeeth.setCoordinate(index + 3, coordinate);
        rearGearTeeth.setNormal(index + 3, rearToothNormal);

    }
    newShape = new Shape3D(rearGearTeeth, look);
    this.addChild(newShape);

    /*
     * Construct the gear's top teeth faces (As seen from above) Root0
     * Outer1 Outer2 Root3 Root4 (RearZ) 0_______3 2_______5 4_______7
     * 6_______9 |0 3| |4 7| |8 11| |12 15| | | | | | | | | | | | | | | | |
     * |1_____2| |5_____6| |9____10| |13___14| 1 2 3 4 5 6 7 8 Root0 Outer1
     * Outer2 Root3 Root4 (FrontZ)
     * 
     * Quad 0123 uses a left normal Quad 2345 uses an out normal Quad 4567
     * uses a right normal Quad 6789 uses an out normal
     */
    topVertexCount = 8 * toothCount + 2;
    topStripCount[0] = topVertexCount;

    toothFacetVertexCount = 4;
    toothFacetCount = 4;

    QuadArray topGearTeeth = new QuadArray(toothCount * toothFacetVertexCount * toothFacetCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS);

    for (int count = 0; count < toothCount; count++) {
        index = count * toothFacetCount * toothFacetVertexCount;
        toothStartAngle = gearStartAngle + circularPitchAngle * (double) count;
        toothTopStartAngle = toothStartAngle + toothTopAngleIncrement;
        toothDeclineStartAngle = toothStartAngle + toothDeclineAngleIncrement;
        toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement;
        nextToothStartAngle = toothStartAngle + circularPitchAngle;

        xRoot0 = rootRadius * (float) Math.cos(toothStartAngle);
        yRoot0 = rootRadius * (float) Math.sin(toothStartAngle);
        xOuter1 = outsideRadius * (float) Math.cos(toothTopStartAngle);
        yOuter1 = outsideRadius * (float) Math.sin(toothTopStartAngle);
        xOuter2 = outsideRadius * (float) Math.cos(toothDeclineStartAngle);
        yOuter2 = outsideRadius * (float) Math.sin(toothDeclineStartAngle);
        xRoot3 = rootRadius * (float) Math.cos(toothValleyStartAngle);
        yRoot3 = rootRadius * (float) Math.sin(toothValleyStartAngle);
        xRoot4 = rootRadius * (float) Math.cos(nextToothStartAngle);
        yRoot4 = rootRadius * (float) Math.sin(nextToothStartAngle);

        // Compute normal for quad 1
        tempCoordinate1.set(xRoot0, yRoot0, frontZ);
        tempCoordinate2.set(xOuter1, yOuter1, toothTipFrontZ);
        tempVector1.sub(tempCoordinate2, tempCoordinate1);
        leftNormal.cross(frontNormal, tempVector1);
        leftNormal.normalize();

        // Coordinate labeled 0 in the quad
        coordinate.set(xRoot0, yRoot0, rearZ);
        topGearTeeth.setCoordinate(index, coordinate);
        topGearTeeth.setNormal(index, leftNormal);

        // Coordinate labeled 1 in the quad
        coordinate.set(tempCoordinate1);
        topGearTeeth.setCoordinate(index + 1, coordinate);
        topGearTeeth.setNormal(index + 1, leftNormal);

        // Coordinate labeled 2 in the quad
        topGearTeeth.setCoordinate(index + 2, tempCoordinate2);
        topGearTeeth.setNormal(index + 2, leftNormal);
        topGearTeeth.setCoordinate(index + 5, tempCoordinate2);

        // Coordinate labeled 3 in the quad
        coordinate.set(xOuter1, yOuter1, toothTipRearZ);
        topGearTeeth.setCoordinate(index + 3, coordinate);
        topGearTeeth.setNormal(index + 3, leftNormal);
        topGearTeeth.setCoordinate(index + 4, coordinate);

        // Compute normal for quad 2
        tempCoordinate1.set(xOuter1, yOuter1, toothTipFrontZ);
        tempCoordinate2.set(xOuter2, yOuter2, toothTipFrontZ);
        tempVector1.sub(tempCoordinate2, tempCoordinate1);
        outNormal.cross(frontNormal, tempVector1);
        outNormal.normalize();

        topGearTeeth.setNormal(index + 4, outNormal);
        topGearTeeth.setNormal(index + 5, outNormal);

        // Coordinate labeled 4 in the quad
        topGearTeeth.setCoordinate(index + 6, tempCoordinate2);
        topGearTeeth.setNormal(index + 6, outNormal);
        topGearTeeth.setCoordinate(index + 9, tempCoordinate2);

        // Coordinate labeled 5 in the quad
        coordinate.set(xOuter2, yOuter2, toothTipRearZ);
        topGearTeeth.setCoordinate(index + 7, coordinate);
        topGearTeeth.setNormal(index + 7, outNormal);
        topGearTeeth.setCoordinate(index + 8, coordinate);

        // Compute normal for quad 3
        tempCoordinate1.set(xOuter2, yOuter2, toothTipFrontZ);
        tempCoordinate2.set(xRoot3, yRoot3, frontZ);
        tempVector1.sub(tempCoordinate2, tempCoordinate1);
        rightNormal.cross(frontNormal, tempVector1);
        rightNormal.normalize();

        topGearTeeth.setNormal(index + 8, rightNormal);
        topGearTeeth.setNormal(index + 9, rightNormal);

        // Coordinate labeled 7 in the quad
        topGearTeeth.setCoordinate(index + 10, tempCoordinate2);
        topGearTeeth.setNormal(index + 10, rightNormal);
        topGearTeeth.setCoordinate(index + 13, tempCoordinate2);

        // Coordinate labeled 6 in the quad
        coordinate.set(xRoot3, yRoot3, rearZ);
        topGearTeeth.setCoordinate(index + 11, coordinate);
        topGearTeeth.setNormal(index + 11, rightNormal);
        topGearTeeth.setCoordinate(index + 12, coordinate);

        // Compute normal for quad 4
        tempCoordinate1.set(xRoot3, yRoot3, frontZ);
        tempCoordinate2.set(xRoot4, yRoot4, frontZ);
        tempVector1.sub(tempCoordinate2, tempCoordinate1);
        outNormal.cross(frontNormal, tempVector1);
        outNormal.normalize();

        topGearTeeth.setNormal(index + 12, outNormal);
        topGearTeeth.setNormal(index + 13, outNormal);

        // Coordinate labeled 9 in the quad
        topGearTeeth.setCoordinate(index + 14, tempCoordinate2);
        topGearTeeth.setNormal(index + 14, outNormal);

        // Coordinate labeled 8 in the quad
        coordinate.set(xRoot4, yRoot4, rearZ);
        topGearTeeth.setCoordinate(index + 15, coordinate);
        topGearTeeth.setNormal(index + 15, outNormal);

        // Prepare for the loop by computing the new normal
        toothTopStartAngle = nextToothStartAngle + toothTopAngleIncrement;
        xOuter1 = outsideRadius * (float) Math.cos(toothTopStartAngle);
        yOuter1 = outsideRadius * (float) Math.sin(toothTopStartAngle);

        tempCoordinate1.set(xRoot4, yRoot4, toothTipFrontZ);
        tempCoordinate2.set(xOuter1, yOuter1, toothTipFrontZ);
        tempVector1.sub(tempCoordinate2, tempCoordinate1);
        leftNormal.cross(frontNormal, tempVector1);
        leftNormal.normalize();
    }
    newShape = new Shape3D(topGearTeeth, look);
    this.addChild(newShape);
}

From source file:ffx.potential.MolecularAssembly.java

private Shape3D renderWire() {
    ArrayList<ROLS> bonds = getBondList();
    int numbonds = bonds.size();
    if (numbonds < 1) {
        return null;
    }/*from  w  ww  .j  av a 2 s.c  om*/

    Vector3d bondmidpoint = new Vector3d();
    double[] mid = { 0, 0, 0 };
    Vector3d v1 = new Vector3d();
    Vector3d v2 = new Vector3d();
    float[] a1 = { 0, 0, 0 };
    float[] a2 = { 0, 0, 0 };
    float[] col = new float[4];
    Bond bond;

    Atom atom1, atom2;
    LineArray la = new LineArray(4 * numbonds,
            GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS);
    la.setCapability(LineArray.ALLOW_COORDINATE_WRITE);
    la.setCapability(LineArray.ALLOW_COORDINATE_READ);
    la.setCapability(LineArray.ALLOW_COLOR_WRITE);
    la.setCapability(LineArray.ALLOW_COUNT_READ);
    la.setCapability(LineArray.ALLOW_INTERSECT);
    la.setCapability(LineArray.ALLOW_FORMAT_READ);
    atomLookUp = new Atom[4 * numbonds];
    int i = 0;
    col[3] = 0.9f;
    for (ListIterator li = bonds.listIterator(); li.hasNext();) {
        bond = (Bond) li.next();
        bond.setWire(la, i);
        atom1 = bond.getAtom(0);
        atom2 = bond.getAtom(1);
        atom1.getV3D(v1);
        atom2.getV3D(v2);
        a1[0] = (float) v1.x;
        a1[1] = (float) v1.y;
        a1[2] = (float) v1.z;
        a2[0] = (float) v2.x;
        a2[1] = (float) v2.y;
        a2[2] = (float) v2.z;
        // Find the bond center
        bondmidpoint.add(v1, v2);
        bondmidpoint.scale(0.5d);
        bondmidpoint.get(mid);
        // Atom #1
        Atom.AtomColor.get(atom1.getAtomicNumber()).get(col);
        atomLookUp[i] = atom1;
        la.setCoordinate(i, a1);
        la.setColor(i, col);
        la.setNormal(i, a2);
        i++;

        atomLookUp[i] = atom1;
        la.setCoordinate(i, mid);
        la.setColor(i, col);
        la.setNormal(i, a2);
        i++;
        // Atom #2

        Atom.AtomColor.get(atom2.getAtomicNumber()).get(col);
        atomLookUp[i] = atom2;
        la.setCoordinate(i, a2);
        la.setColor(i, col);
        la.setNormal(i, a1);
        i++;

        atomLookUp[i] = atom2;
        la.setCoordinate(i, mid);
        la.setColor(i, col);
        la.setNormal(i, a1);
        i++;

    }

    ColoringAttributes cola = new ColoringAttributes(new Color3f(), ColoringAttributes.SHADE_GOURAUD);
    Appearance app = new Appearance();
    lineAttributes = new LineAttributes();
    lineAttributes.setLineWidth(RendererCache.bondwidth);
    lineAttributes.setCapability(LineAttributes.ALLOW_WIDTH_WRITE);
    lineAttributes.setLineAntialiasingEnable(true);
    app.setLineAttributes(lineAttributes);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_READ);
    app.setCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
    RenderingAttributes ra = new RenderingAttributes();
    ra.setAlphaTestValue(0.1f);
    ra.setAlphaTestFunction(RenderingAttributes.GREATER);
    ra.setDepthBufferEnable(true);
    ra.setDepthBufferWriteEnable(true);
    app.setRenderingAttributes(ra);
    app.setColoringAttributes(cola);
    Shape3D wireframe = new Shape3D(la, app);
    // PickTool.setCapabilities(wire, PickTool.INTERSECT_COORD);
    wireframe.setUserData(this);
    wireframe.setBounds(new BoundingSphere(new Point3d(0, 0, 0), 1000.0));
    try {
        wireframe.setBoundsAutoCompute(false);
    } catch (Exception e) {
        e.printStackTrace();
    }

    wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    wireframe.setCapability(Shape3D.ALLOW_LOCAL_TO_VWORLD_READ);
    return wireframe;
}

From source file:KeyNavigateTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {/*  w w w  . ja v a  2  s  .  c  o  m*/
    int nFlags = GeometryArray.COORDINATES | GeometryArray.NORMALS;

    if ((m_nFlags & TEXTURE) == TEXTURE)
        nFlags |= GeometryArray.TEXTURE_COORDINATE_2;

    QuadArray quadArray = new QuadArray(24, nFlags);

    quadArray.setCoordinates(0, verts, 0, 24);

    for (int n = 0; n < 24; n++)
        quadArray.setNormal(n, normals[n / 4]);

    if ((m_nFlags & TEXTURE) == TEXTURE) {
        quadArray.setTextureCoordinates(0, 0, tcoords, 0, 24);
        setTexture(app, szTextureFile);
    }

    Shape3D shape = new Shape3D(quadArray, app);

    BranchGroup bg = new BranchGroup();
    bg.addChild(shape);
    return bg;
}

From source file:PickTest.java

CubeQA() {
    super(24, GeometryArray.COORDINATES | GeometryArray.COLOR_3);

    Point3f verts[] = new Point3f[8];
    Color3f colors[] = new Color3f[6];

    verts[0] = new Point3f(1.0f, 1.0f, 1.0f);
    verts[1] = new Point3f(-1.0f, 1.0f, 1.0f);
    verts[2] = new Point3f(-1.0f, -1.0f, 1.0f);
    verts[3] = new Point3f(1.0f, -1.0f, 1.0f);
    verts[4] = new Point3f(1.0f, 1.0f, -1.0f);
    verts[5] = new Point3f(-1.0f, 1.0f, -1.0f);
    verts[6] = new Point3f(-1.0f, -1.0f, -1.0f);
    verts[7] = new Point3f(1.0f, -1.0f, -1.0f);

    colors[0] = new Color3f(1.0f, 0.0f, 0.0f);
    colors[1] = new Color3f(0.0f, 1.0f, 0.0f);
    colors[2] = new Color3f(0.0f, 0.0f, 1.0f);
    colors[3] = new Color3f(1.0f, 1.0f, 0.0f);
    colors[4] = new Color3f(1.0f, 0.0f, 1.0f);
    colors[5] = new Color3f(0.0f, 1.0f, 1.0f);

    Point3f pnts[] = new Point3f[24];
    Color3f clrs[] = new Color3f[24];

    pnts[0] = verts[0];/*from   ww w  . j av  a2  s .c  o m*/
    clrs[0] = colors[0];
    pnts[1] = verts[3];
    clrs[1] = colors[0];
    pnts[2] = verts[7];
    clrs[2] = colors[0];
    pnts[3] = verts[4];
    clrs[3] = colors[0];

    pnts[4] = verts[1];
    clrs[4] = colors[1];
    pnts[5] = verts[5];
    clrs[5] = colors[1];
    pnts[6] = verts[6];
    clrs[6] = colors[1];
    pnts[7] = verts[2];
    clrs[7] = colors[1];

    pnts[8] = verts[0];
    clrs[8] = colors[2];
    pnts[9] = verts[4];
    clrs[9] = colors[2];
    pnts[10] = verts[5];
    clrs[10] = colors[2];
    pnts[11] = verts[1];
    clrs[11] = colors[2];

    pnts[12] = verts[3];
    clrs[12] = colors[3];
    pnts[13] = verts[2];
    clrs[13] = colors[3];
    pnts[14] = verts[6];
    clrs[14] = colors[3];
    pnts[15] = verts[7];
    clrs[15] = colors[3];

    pnts[16] = verts[0];
    clrs[16] = colors[4];
    pnts[17] = verts[1];
    clrs[17] = colors[4];
    pnts[18] = verts[2];
    clrs[18] = colors[4];
    pnts[19] = verts[3];
    clrs[19] = colors[4];

    pnts[20] = verts[7];
    clrs[20] = colors[5];
    pnts[21] = verts[6];
    clrs[21] = colors[5];
    pnts[22] = verts[5];
    clrs[22] = colors[5];
    pnts[23] = verts[4];
    clrs[23] = colors[5];

    setCoordinates(0, pnts);
    setColors(0, clrs);
}