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:AvatarTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {//from  www . java 2 s .co  m
    QuadArray quadArray = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);

    float[] coordArray = { -LAND_WIDTH, LAND_HEIGHT, 0, LAND_WIDTH, LAND_HEIGHT, 0, LAND_WIDTH, LAND_HEIGHT,
            LAND_LENGTH, -LAND_WIDTH, LAND_HEIGHT, LAND_LENGTH };

    float[] texArray = { 0, 0, 1, 0, 1, 1, 0, 1 };

    quadArray.setCoordinates(0, coordArray, 0, 4);

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

    Shape3D sh = new Shape3D(quadArray, app);

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

From source file:ExDepthCue.java

public Shape3D buildSurface(double freqAlpha, double freqTheta, double radius, float red, float green,
        float blue) {
    int nAngles = 64;
    double amp = radius / 4.0;

    int nAlpha = nAngles / 2;
    double theta, alpha;
    double x, y, z, rprime, r;
    double deltaTheta, deltaAlpha;
    int i, j;/*ww  w .  ja va 2  s . com*/
    int i1, i2, i3, i4;

    deltaTheta = 360.0 / (nAngles - 1.0);
    deltaAlpha = 180.0 / (nAlpha - 1.0);

    // Build an appearance
    Appearance app = new Appearance();

    LineAttributes latt = new LineAttributes();
    latt.setLineWidth(1.0f);
    app.setLineAttributes(latt);

    ColoringAttributes catt = new ColoringAttributes();
    catt.setColor(red, green, blue);
    app.setColoringAttributes(catt);

    PolygonAttributes patt = new PolygonAttributes();
    patt.setCullFace(PolygonAttributes.CULL_NONE);
    patt.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    app.setPolygonAttributes(patt);

    // Compute coordinates
    double[] coordinates = new double[nAlpha * nAngles * 3];
    alpha = 90.0;
    int n = 0;
    for (i = 0; i < nAlpha; i++) {
        theta = 0.0;
        for (j = 0; j < nAngles; j++) {
            r = radius + amp * Math.sin((freqAlpha * ((double) i / (double) (nAlpha - 1))
                    + freqTheta * ((double) j / (double) (nAngles - 1))) * 2.0 * Math.PI);
            y = r * Math.sin(alpha / 180.0 * Math.PI);
            rprime = y / Math.tan(alpha / 180.0 * Math.PI);
            x = rprime * Math.cos(theta / 180.0 * Math.PI);
            z = rprime * Math.sin(theta / 180.0 * Math.PI);

            coordinates[n + 0] = x;
            coordinates[n + 1] = y;
            coordinates[n + 2] = z;
            n += 3;
            theta += deltaTheta;
        }
        alpha -= deltaAlpha;
    }

    // Compute coordinate indexes
    int[] indexes = new int[(nAlpha - 1) * nAngles * 4];
    n = 0;
    for (i = 0; i < nAlpha - 1; i++) {
        for (j = 0; j < nAngles; j++) {
            i1 = i * nAngles + j;
            if (j == nAngles - 1) {
                i2 = i1 - j;
                i3 = (i + 1) * nAngles;
            } else {
                i2 = i1 + 1;
                i3 = (i + 1) * nAngles + j + 1;
            }
            i4 = (i + 1) * nAngles + j;

            indexes[n + 0] = i1;
            indexes[n + 1] = i2;
            indexes[n + 2] = i3;
            indexes[n + 3] = i4;
            n += 4;
        }
    }

    // Build the shape
    IndexedQuadArray lines = new IndexedQuadArray(coordinates.length / 3, // Number
            // of
            // coordinates
            GeometryArray.COORDINATES, // coordinates only
            indexes.length); // Number of indexes
    lines.setCoordinates(0, coordinates);
    lines.setCoordinateIndices(0, indexes);

    Shape3D shape = new Shape3D(lines, app);

    return shape;
}

From source file:GearTest.java

void addBodyDisks(float shaftRadius, float bodyOuterRadius, float thickness, Appearance look) {
    int gearBodySegmentVertexCount; // #(segments) per tooth-unit
    int gearBodyTotalVertexCount; // #(vertices) in a gear face
    int gearBodyStripCount[] = new int[1]; // per strip (1) vertex count

    // A ray from the gear center, used in normal calculations
    float xDirection, yDirection;

    // 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, xShaft0, yShaft0;
    float xRoot3, yRoot3, xShaft3, yShaft3;
    float xRoot4, yRoot4, xShaft4, yShaft4;

    // Temporary variables for storing coordinates and vectors
    Point3f coordinate = new Point3f(0.0f, 0.0f, 0.0f);

    // Gear start differential angle. All gears are constructed with the
    // center of a tooth at Z-axis angle = 0.
    double gearStartAngle = -1.0 * toothTopCenterAngle;

    // Temporaries that store start angle for each portion of tooth facet
    double toothStartAngle, toothTopStartAngle, toothDeclineStartAngle, toothValleyStartAngle,
            nextToothStartAngle;/*w w  w.j av  a 2 s  . co  m*/

    Shape3D newShape;
    int index;

    // The z coordinates for the body disks
    final float frontZ = -0.5f * thickness;
    final float rearZ = 0.5f * thickness;

    /*
     * Construct the gear's front body (front facing torus disk) __2__ - | -
     * 4 - /| /- / / | /| \ 0\ / | / / > \ / | / | > \ / | / / | \ / ____|/ | >
     * \-- --__/ | 1 3 5
     *  
     */
    gearBodySegmentVertexCount = 4;
    gearBodyTotalVertexCount = 2 + gearBodySegmentVertexCount * toothCount;
    gearBodyStripCount[0] = gearBodyTotalVertexCount;

    TriangleStripArray frontGearBody = new TriangleStripArray(gearBodyTotalVertexCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS, gearBodyStripCount);

    xDirection = (float) Math.cos(gearStartAngle);
    yDirection = (float) Math.sin(gearStartAngle);
    xShaft0 = shaftRadius * xDirection;
    yShaft0 = shaftRadius * yDirection;
    xRoot0 = bodyOuterRadius * xDirection;
    yRoot0 = bodyOuterRadius * yDirection;

    coordinate.set(xRoot0, yRoot0, frontZ);
    frontGearBody.setCoordinate(0, coordinate);
    frontGearBody.setNormal(0, frontNormal);

    coordinate.set(xShaft0, yShaft0, frontZ);
    frontGearBody.setCoordinate(1, coordinate);
    frontGearBody.setNormal(1, frontNormal);

    for (int count = 0; count < toothCount; count++) {
        index = 2 + count * 4;
        toothStartAngle = gearStartAngle + circularPitchAngle * (double) count;
        toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement;
        nextToothStartAngle = toothStartAngle + circularPitchAngle;

        xDirection = (float) Math.cos(toothValleyStartAngle);
        yDirection = (float) Math.sin(toothValleyStartAngle);
        xShaft3 = shaftRadius * xDirection;
        yShaft3 = shaftRadius * yDirection;
        xRoot3 = bodyOuterRadius * xDirection;
        yRoot3 = bodyOuterRadius * yDirection;

        xDirection = (float) Math.cos(nextToothStartAngle);
        yDirection = (float) Math.sin(nextToothStartAngle);
        xShaft4 = shaftRadius * xDirection;
        yShaft4 = shaftRadius * yDirection;
        xRoot4 = bodyOuterRadius * xDirection;
        yRoot4 = bodyOuterRadius * yDirection;

        coordinate.set(xRoot3, yRoot3, frontZ);
        frontGearBody.setCoordinate(index, coordinate);
        frontGearBody.setNormal(index, frontNormal);

        coordinate.set(xShaft3, yShaft3, frontZ);
        frontGearBody.setCoordinate(index + 1, coordinate);
        frontGearBody.setNormal(index + 1, frontNormal);

        coordinate.set(xRoot4, yRoot4, frontZ);
        frontGearBody.setCoordinate(index + 2, coordinate);
        frontGearBody.setNormal(index + 2, frontNormal);

        coordinate.set(xShaft4, yShaft4, frontZ);
        frontGearBody.setCoordinate(index + 3, coordinate);
        frontGearBody.setNormal(index + 3, frontNormal);
    }
    newShape = new Shape3D(frontGearBody, look);
    this.addChild(newShape);

    // Construct the gear's rear body (rear facing torus disc)
    TriangleStripArray rearGearBody = new TriangleStripArray(gearBodyTotalVertexCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS, gearBodyStripCount);
    xDirection = (float) Math.cos(gearStartAngle);
    yDirection = (float) Math.sin(gearStartAngle);
    xShaft0 = shaftRadius * xDirection;
    yShaft0 = shaftRadius * yDirection;
    xRoot0 = bodyOuterRadius * xDirection;
    yRoot0 = bodyOuterRadius * yDirection;

    coordinate.set(xShaft0, yShaft0, rearZ);
    rearGearBody.setCoordinate(0, coordinate);
    rearGearBody.setNormal(0, rearNormal);

    coordinate.set(xRoot0, yRoot0, rearZ);
    rearGearBody.setCoordinate(1, coordinate);
    rearGearBody.setNormal(1, rearNormal);

    for (int count = 0; count < toothCount; count++) {
        index = 2 + count * 4;
        toothStartAngle = gearStartAngle + circularPitchAngle * (double) count;
        toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement;
        nextToothStartAngle = toothStartAngle + circularPitchAngle;

        xDirection = (float) Math.cos(toothValleyStartAngle);
        yDirection = (float) Math.sin(toothValleyStartAngle);
        xShaft3 = shaftRadius * xDirection;
        yShaft3 = shaftRadius * yDirection;
        xRoot3 = bodyOuterRadius * xDirection;
        yRoot3 = bodyOuterRadius * yDirection;

        xDirection = (float) Math.cos(nextToothStartAngle);
        yDirection = (float) Math.sin(nextToothStartAngle);
        xShaft4 = shaftRadius * xDirection;
        yShaft4 = shaftRadius * yDirection;
        xRoot4 = bodyOuterRadius * xDirection;
        yRoot4 = bodyOuterRadius * yDirection;

        coordinate.set(xShaft3, yShaft3, rearZ);
        rearGearBody.setCoordinate(index, coordinate);
        rearGearBody.setNormal(index, rearNormal);

        coordinate.set(xRoot3, yRoot3, rearZ);
        rearGearBody.setCoordinate(index + 1, coordinate);
        rearGearBody.setNormal(index + 1, rearNormal);

        coordinate.set(xShaft4, yShaft4, rearZ);
        rearGearBody.setCoordinate(index + 2, coordinate);
        rearGearBody.setNormal(index + 2, rearNormal);

        coordinate.set(xRoot4, yRoot4, rearZ);
        rearGearBody.setCoordinate(index + 3, coordinate);
        rearGearBody.setNormal(index + 3, rearNormal);

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

From source file:J3dSwingFrame.java

private void constructGeometry() {
    int flags = GeometryArray.COORDINATES | GeometryArray.COLOR_4 | GeometryArray.NORMALS;

    geom = new IndexedQuadArray(4, flags, 4);

    double[] coordinates = { 0.5, 0.5, 0, 0.5, -0.5, 0, -0.5, -0.5, 0, -0.5, 0.5, 0 };

    int[] indices = { 0, 1, 2, 3 };

    geom.setCoordinates(0, coordinates);
    geom.setCoordinateIndices(0, indices);

    float[] colors = { 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0 };

    geom.setColors(0, colors);/* w ww  .  j  a va  2 s.c om*/
    geom.setColorIndices(0, indices);

    float[] normal = { 0, 0, 1 };

    geom.setNormal(0, normal);
    geom.setNormal(1, normal);
    geom.setNormal(2, normal);
    geom.setNormal(3, normal);

    setGeometry(geom);
}

From source file:ffx.potential.MolecularAssembly.java

/**
 * <p>//w w w .ja v  a2s . c  o  m
 * createBox</p>
 */
public void createBox() {
    int vertices = 8;
    LineArray la = new LineArray(4 * vertices,
            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);
    // Create a normal
    // for (ListIterator li = bondlist.listIterator(); li.hasNext(); ){
    // la.setCoordinate(i, a1);
    // la.setColor(i, col);
    // la.setNormal(i++, a1);
    // }
    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), 10.0));
    try {
        wireframe.setBoundsAutoCompute(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    wireframe.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    wireframe.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    // return wire;
}

From source file:PickTest.java

TetrahedronILSA() {
    super(4, GeometryArray.COORDINATES | GeometryArray.COLOR_3, 8, lineLengths);

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

    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);

    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);

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

    pntsIndex[0] = 0;/*from w w  w.  j a v a  2 s .co  m*/
    clrsIndex[0] = 0;
    pntsIndex[1] = 1;
    clrsIndex[1] = 1;
    pntsIndex[2] = 3;
    clrsIndex[2] = 3;
    pntsIndex[3] = 2;
    clrsIndex[3] = 2;

    pntsIndex[4] = 1;
    clrsIndex[4] = 1;
    pntsIndex[5] = 2;
    clrsIndex[5] = 2;
    pntsIndex[6] = 0;
    clrsIndex[6] = 0;
    pntsIndex[7] = 3;
    clrsIndex[7] = 3;

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

From source file:ExSound.java

private Shape3D buildBox(float width, float height, float depth, Appearance app) {
    float w2 = width / 2.0f;
    float h2 = height / 2.0f;
    float d2 = depth / 2.0f;

    float[] coordinates = new float[8 * 3];
    int n = 0;/*from   w  ww.j a  v a  2 s .c  om*/
    // Around the bottom of the box
    coordinates[n + 0] = -w2;
    coordinates[n + 1] = -h2;
    coordinates[n + 2] = d2;
    n += 3;
    coordinates[n + 0] = w2;
    coordinates[n + 1] = -h2;
    coordinates[n + 2] = d2;
    n += 3;
    coordinates[n + 0] = w2;
    coordinates[n + 1] = -h2;
    coordinates[n + 2] = -d2;
    n += 3;
    coordinates[n + 0] = -w2;
    coordinates[n + 1] = -h2;
    coordinates[n + 2] = -d2;
    n += 3;

    // Around the top of the box
    coordinates[n + 0] = -w2;
    coordinates[n + 1] = h2;
    coordinates[n + 2] = d2;
    n += 3;
    coordinates[n + 0] = w2;
    coordinates[n + 1] = h2;
    coordinates[n + 2] = d2;
    n += 3;
    coordinates[n + 0] = w2;
    coordinates[n + 1] = h2;
    coordinates[n + 2] = -d2;
    n += 3;
    coordinates[n + 0] = -w2;
    coordinates[n + 1] = h2;
    coordinates[n + 2] = -d2;
    n += 3;

    IndexedQuadArray quads = new IndexedQuadArray(coordinates.length, // vertex
            // count
            GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2,
            coordinateIndices.length);
    quads.setCoordinates(0, coordinates);
    quads.setCoordinateIndices(0, coordinateIndices);
    quads.setNormals(0, normals);
    quads.setNormalIndices(0, normalIndices);
    quads.setTextureCoordinates(0, textureCoordinates);
    quads.setTextureCoordinateIndices(0, textureCoordinateIndices);

    Shape3D shape = new Shape3D(quads, app);
    return shape;
}

From source file:ExBackgroundImage.java

public Arch(double startPhi, double endPhi, int nPhi, double startTheta, double endTheta, int nTheta,
        double startPhiRadius, double endPhiRadius, double startPhiThickness, double endPhiThickness,
        Appearance app) {// w  ww  . ja v  a  2 s.  c  om
    double theta, phi, radius, radius2, thickness;
    double x, y, z;
    double[] xyz = new double[3];
    float[] norm = new float[3];
    float[] tex = new float[3];

    // Compute some values for our looping
    double deltaTheta = (endTheta - startTheta) / (double) (nTheta - 1);
    double deltaPhi = (endPhi - startPhi) / (double) (nPhi - 1);
    double deltaTexX = 1.0 / (double) (nTheta - 1);
    double deltaTexY = 1.0 / (double) (nPhi - 1);
    double deltaPhiRadius = (endPhiRadius - startPhiRadius) / (double) (nPhi - 1);
    double deltaPhiThickness = (endPhiThickness - startPhiThickness) / (double) (nPhi - 1);

    boolean doThickness = true;
    if (startPhiThickness == 0.0 && endPhiThickness == 0.0)
        doThickness = false;

    //  Create geometry
    int vertexCount = nTheta * nPhi;
    if (doThickness)
        vertexCount *= 2;
    int indexCount = (nTheta - 1) * (nPhi - 1) * 4; // Outer surface
    if (doThickness) {
        indexCount *= 2; // plus inner surface
        indexCount += (nPhi - 1) * 4 * 2; // plus left & right edges
    }

    IndexedQuadArray polys = new IndexedQuadArray(vertexCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2, indexCount);

    //
    //  Compute coordinates, normals, and texture coordinates
    //
    theta = startTheta;
    tex[0] = 0.0f;
    int index = 0;
    for (int i = 0; i < nTheta; i++) {
        phi = startPhi;
        radius = startPhiRadius;
        thickness = startPhiThickness;
        tex[1] = 0.0f;

        for (int j = 0; j < nPhi; j++) {
            norm[0] = (float) (Math.cos(phi) * Math.cos(theta));
            norm[1] = (float) (Math.sin(phi));
            norm[2] = (float) (-Math.cos(phi) * Math.sin(theta));
            xyz[0] = radius * norm[0];
            xyz[1] = radius * norm[1];
            xyz[2] = radius * norm[2];
            polys.setCoordinate(index, xyz);
            polys.setNormal(index, norm);
            polys.setTextureCoordinate(index, tex);
            index++;

            if (doThickness) {
                radius2 = radius - thickness;
                xyz[0] = radius2 * norm[0];
                xyz[1] = radius2 * norm[1];
                xyz[2] = radius2 * norm[2];
                norm[0] *= -1.0f;
                norm[1] *= -1.0f;
                norm[2] *= -1.0f;
                polys.setCoordinate(index, xyz);
                polys.setNormal(index, norm);
                polys.setTextureCoordinate(index, tex);
                index++;
            }

            phi += deltaPhi;
            radius += deltaPhiRadius;
            thickness += deltaPhiThickness;
            tex[1] += deltaTexY;
        }
        theta += deltaTheta;
        tex[0] += deltaTexX;
    }

    //
    //  Compute coordinate indexes
    //  (also used as normal and texture indexes)
    //
    index = 0;
    int phiRow = nPhi;
    int phiCol = 1;
    if (doThickness) {
        phiRow += nPhi;
        phiCol += 1;
    }
    int[] indices = new int[indexCount];

    // Outer surface
    int n;
    for (int i = 0; i < nTheta - 1; i++) {
        for (int j = 0; j < nPhi - 1; j++) {
            n = i * phiRow + j * phiCol;
            indices[index + 0] = n;
            indices[index + 1] = n + phiRow;
            indices[index + 2] = n + phiRow + phiCol;
            indices[index + 3] = n + phiCol;
            index += 4;
        }
    }

    // Inner surface
    if (doThickness) {
        for (int i = 0; i < nTheta - 1; i++) {
            for (int j = 0; j < nPhi - 1; j++) {
                n = i * phiRow + j * phiCol;
                indices[index + 0] = n + 1;
                indices[index + 1] = n + phiCol + 1;
                indices[index + 2] = n + phiRow + phiCol + 1;
                indices[index + 3] = n + phiRow + 1;
                index += 4;
            }
        }
    }

    // Edges
    if (doThickness) {
        for (int j = 0; j < nPhi - 1; j++) {
            n = j * phiCol;
            indices[index + 0] = n;
            indices[index + 1] = n + phiCol;
            indices[index + 2] = n + phiCol + 1;
            indices[index + 3] = n + 1;
            index += 4;
        }
        for (int j = 0; j < nPhi - 1; j++) {
            n = (nTheta - 1) * phiRow + j * phiCol;
            indices[index + 0] = n;
            indices[index + 1] = n + 1;
            indices[index + 2] = n + phiCol + 1;
            indices[index + 3] = n + phiCol;
            index += 4;
        }
    }

    polys.setCoordinateIndices(0, indices);
    polys.setNormalIndices(0, indices);
    polys.setTextureCoordinateIndices(0, indices);

    //
    //  Build a shape
    //
    arch = new Shape3D();
    arch.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    arch.setGeometry(polys);
    arch.setAppearance(app);
    addChild(arch);
}

From source file:AvatarTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {//from w  w  w .  j  av a 2 s .c  om
    // creates a segment of road 200 x 2

    QuadArray quadArray = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);

    float[] coordArray = { -ROAD_WIDTH, ROAD_HEIGHT, 0, ROAD_WIDTH, ROAD_HEIGHT, 0, ROAD_WIDTH, ROAD_HEIGHT,
            ROAD_LENGTH, -ROAD_WIDTH, ROAD_HEIGHT, ROAD_LENGTH };

    float[] texArray = { 0, 0, 1, 0, 1, 1, 0, 1 };

    quadArray.setCoordinates(0, coordArray, 0, 4);

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

    Shape3D sh = new Shape3D(quadArray, app);

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

From source file:GearTest.java

void addCylinderSkins(float shaftRadius, float length, int normalDirection, Appearance look) {
    int insideShaftVertexCount; // #(vertices) for shaft
    int insideShaftStripCount[] = new int[1]; // #(vertices) in strip/strip
    double toothStartAngle, nextToothStartAngle, toothValleyStartAngle;

    // A ray from the gear center, used in normal calculations
    float xDirection, yDirection;

    // The z coordinates for the body disks
    final float frontZ = -0.5f * length;
    final float rearZ = 0.5f * length;

    // Temporary variables for storing coordinates, points, and vectors
    float xShaft3, yShaft3, xShaft4, yShaft4;
    Point3f coordinate = new Point3f(0.0f, 0.0f, 0.0f);
    Vector3f surfaceNormal = new Vector3f();

    Shape3D newShape;/*w  w  w  . ja  v a2s  . c  om*/
    int index;
    int firstIndex;
    int secondIndex;

    /*
     * Construct gear's inside shaft cylinder First the tooth's up, flat
     * outer, and down distances Second the tooth's flat inner distance
     * 
     * Outward facing vertex order: 0_______2____4 | /| /| | / | / | | / | / |
     * |/______|/___| 1 3 5
     * 
     * Inward facing vertex order: 1_______3____5 |\ |\ | | \ | \ | | \ | \ |
     * |______\|___\| 0 2 4
     */
    insideShaftVertexCount = 4 * toothCount + 2;
    insideShaftStripCount[0] = insideShaftVertexCount;

    TriangleStripArray insideShaft = new TriangleStripArray(insideShaftVertexCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS, insideShaftStripCount);
    xShaft3 = shaftRadius * (float) Math.cos(gearStartAngle);
    yShaft3 = shaftRadius * (float) Math.sin(gearStartAngle);

    if (normalDirection == OutwardNormals) {
        surfaceNormal.set(1.0f, 0.0f, 0.0f);
        firstIndex = 1;
        secondIndex = 0;
    } else {
        surfaceNormal.set(-1.0f, 0.0f, 0.0f);
        firstIndex = 0;
        secondIndex = 1;
    }

    // Coordinate labeled 0 in the strip
    coordinate.set(shaftRadius, 0.0f, frontZ);
    insideShaft.setCoordinate(firstIndex, coordinate);
    insideShaft.setNormal(firstIndex, surfaceNormal);

    // Coordinate labeled 1 in the strip
    coordinate.set(shaftRadius, 0.0f, rearZ);
    insideShaft.setCoordinate(secondIndex, coordinate);
    insideShaft.setNormal(secondIndex, surfaceNormal);

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

        toothStartAngle = circularPitchAngle * (double) count;
        toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement;
        nextToothStartAngle = toothStartAngle + circularPitchAngle;

        xDirection = (float) Math.cos(toothValleyStartAngle);
        yDirection = (float) Math.sin(toothValleyStartAngle);
        xShaft3 = shaftRadius * xDirection;
        yShaft3 = shaftRadius * yDirection;
        if (normalDirection == OutwardNormals)
            surfaceNormal.set(xDirection, yDirection, 0.0f);
        else
            surfaceNormal.set(-xDirection, -yDirection, 0.0f);

        // Coordinate labeled 2 in the strip
        coordinate.set(xShaft3, yShaft3, frontZ);
        insideShaft.setCoordinate(index + firstIndex, coordinate);
        insideShaft.setNormal(index + firstIndex, surfaceNormal);

        // Coordinate labeled 3 in the strip
        coordinate.set(xShaft3, yShaft3, rearZ);
        insideShaft.setCoordinate(index + secondIndex, coordinate);
        insideShaft.setNormal(index + secondIndex, surfaceNormal);

        xDirection = (float) Math.cos(nextToothStartAngle);
        yDirection = (float) Math.sin(nextToothStartAngle);
        xShaft4 = shaftRadius * xDirection;
        yShaft4 = shaftRadius * yDirection;
        if (normalDirection == OutwardNormals)
            surfaceNormal.set(xDirection, yDirection, 0.0f);
        else
            surfaceNormal.set(-xDirection, -yDirection, 0.0f);

        // Coordinate labeled 4 in the strip
        coordinate.set(xShaft4, yShaft4, frontZ);
        insideShaft.setCoordinate(index + 2 + firstIndex, coordinate);
        insideShaft.setNormal(index + 2 + firstIndex, surfaceNormal);

        // Coordinate labeled 5 in the strip
        coordinate.set(xShaft4, yShaft4, rearZ);
        insideShaft.setCoordinate(index + 2 + secondIndex, coordinate);
        insideShaft.setNormal(index + 2 + secondIndex, surfaceNormal);

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