Example usage for javax.media.j3d QuadArray QuadArray

List of usage examples for javax.media.j3d QuadArray QuadArray

Introduction

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

Prototype

public QuadArray(int vertexCount, int vertexFormat) 

Source Link

Document

Constructs an empty QuadArray object using the specified parameters.

Usage

From source file:FarbWurfelAsQuads.java

/**
 * Erstellung des ColorCube/*from   www  .  j a  v a 2  s  .c o  m*/
 * 
 * @return
 */
private QuadArray makeCube() {
    QuadArray plane = new QuadArray(24, GeometryArray.COORDINATES | GeometryArray.COLOR_3);
    // Punkte und Farben
    Point3f pa = new Point3f(-1.0f, 1.0f, -1.0f);
    Point3f pb = new Point3f(-1.0f, -1.0f, -1.0f);
    Point3f pc = new Point3f(1.0f, -1.0f, -1.0f);
    Point3f pd = new Point3f(1.0f, 1.0f, -1.0f);
    Point3f pe = new Point3f(-1.0f, 1.0f, 1.0f);
    Point3f pf = new Point3f(-1.0f, -1.0f, 1.0f);
    Point3f pg = new Point3f(1.0f, -1.0f, 1.0f);
    Point3f ph = new Point3f(1.0f, 1.0f, 1.0f);
    // Coloreigenschaften
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);
    Color3f green = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f cyan = new Color3f(0.0f, 1.0f, 1.0f);
    Color3f yellow = new Color3f(1.0f, 1.0f, 0.0f);
    Color3f magenta = new Color3f(1.0f, 0.0f, 1.0f);

    // 1. Seite
    plane.setCoordinate(0, pa);
    plane.setColor(0, red);
    plane.setCoordinate(1, pb);
    plane.setColor(1, red);
    plane.setCoordinate(2, pc);
    plane.setColor(2, red);
    plane.setCoordinate(3, pd);
    plane.setColor(3, red);
    // 2. Seite
    plane.setCoordinate(4, pe);
    plane.setColor(4, blue);
    plane.setCoordinate(5, pf);
    plane.setColor(5, blue);
    plane.setCoordinate(6, pg);
    plane.setColor(6, blue);
    plane.setCoordinate(7, ph);
    plane.setColor(7, blue);
    // 3. Seite
    plane.setCoordinate(8, pe);
    plane.setColor(8, green);
    plane.setCoordinate(9, pf);
    plane.setColor(9, green);
    plane.setCoordinate(10, pb);
    plane.setColor(10, green);
    plane.setCoordinate(11, pa);
    plane.setColor(11, green);
    // 4. Seite
    plane.setCoordinate(12, pd);
    plane.setColor(12, cyan);
    plane.setCoordinate(13, pc);
    plane.setColor(13, cyan);
    plane.setCoordinate(14, pg);
    plane.setColor(14, cyan);
    plane.setCoordinate(15, ph);
    plane.setColor(15, cyan);
    // 5. Seite
    plane.setCoordinate(16, pe);
    plane.setColor(16, yellow);
    plane.setCoordinate(17, pa);
    plane.setColor(17, yellow);
    plane.setCoordinate(18, pd);
    plane.setColor(18, yellow);
    plane.setCoordinate(19, ph);
    plane.setColor(19, yellow);
    // 6. Seite
    plane.setCoordinate(20, pf);
    plane.setColor(20, magenta);
    plane.setCoordinate(21, pb);
    plane.setColor(21, magenta);
    plane.setCoordinate(22, pc);
    plane.setColor(22, magenta);
    plane.setCoordinate(23, pg);
    plane.setColor(23, magenta);
    // ubergib den Wurfel
    return plane;
}

From source file:LightScopeApp.java

Shape3D createXZPlane(Point3f p0, Point3f p1, Point3f p2, Point3f p3) {
    Shape3D plane = new Shape3D();
    QuadArray planeGeom = new QuadArray(4, QuadArray.COORDINATES | QuadArray.NORMALS);
    planeGeom.setCoordinate(0, p0);/*from   w w  w . ja v a 2  s  . co  m*/
    planeGeom.setCoordinate(1, p1);
    planeGeom.setCoordinate(2, p2);
    planeGeom.setCoordinate(3, p3);
    Vector3f norm = new Vector3f(0.0f, 1.0f, 0.0f);
    planeGeom.setNormal(0, norm);
    planeGeom.setNormal(1, norm);
    planeGeom.setNormal(2, norm);
    planeGeom.setNormal(3, norm);
    plane.setGeometry(planeGeom);
    return plane;
}

From source file:SimpleWorld.java

/**
 * This constructs a cube as an array of quadrilateral polygons. There are
 * six faces, each with four vertices (obviously!). The cube extends 1 unit
 * along each axis in the positive and negavtive directions and is centred
 * on the origin./*from w  w w.j a  v  a 2 s .c om*/
 * 
 * @return Shape3D that is the cube
 */
protected Shape3D buildCube() {
    //Create the array of numbers that will form the
    //vertex information.
    float[] cubeFaces = { 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f,
            -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f,
            1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f,
            1.0f, -1.0f, -1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f,
            1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f };

    //Create the array of quadrilaterals from the vertices
    QuadArray cubeData = new QuadArray(24, QuadArray.COORDINATES);
    cubeData.setCoordinates(0, cubeFaces);

    //Create a default appearance
    Appearance app = new Appearance();

    //Create and return the cube
    return new Shape3D(cubeData, app);
}

From source file:AppearanceTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    TransformGroup zoomTg = new TransformGroup();
    zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    zoomTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // attach a navigation behavior to the position of the viewer
    KeyNavigatorBehavior key = new KeyNavigatorBehavior(zoomTg);
    key.setSchedulingBounds(createApplicationBounds());
    key.setEnable(true);//from  w  w w .j av a2 s.c  o m
    objRoot.addChild(key);

    // create a TransformGroup to flip the hand onto its end and enlarge it.
    TransformGroup objTrans1 = new TransformGroup();
    Transform3D tr = new Transform3D();
    objTrans1.getTransform(tr);
    tr.setEuler(new Vector3d(0.5 * Math.PI, 0.6, 0));
    objTrans1.setTransform(tr);

    // Set up the global lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(getApplicationBounds());
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(getApplicationBounds());

    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    int nScale = 50;

    Box box = new Box(nScale, nScale, nScale, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS,
            m_Appearance);

    Shape3D frontFace = box.getShape(Box.LEFT);

    // create a new left face so we can
    // assign per-vertex colors

    GeometryArray geometry = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.NORMALS
            | GeometryArray.COLOR_4 | GeometryArray.TEXTURE_COORDINATE_2);

    nScale = 40;

    final float[] verts = {
            // left face
            -1.0f * nScale, -1.0f * nScale, 1.0f * nScale, -1.0f * nScale, 1.0f * nScale, 1.0f * nScale,
            -1.0f * nScale, 1.0f * nScale, -1.0f * nScale, -1.0f * nScale, -1.0f * nScale, -1.0f * nScale };

    final float[] colors = {
            // left face
            1, 0, 0, 0, 0, 1, 0, 0.2f, 0, 0, 1, 0.8f, 0, 0, 0, 1, };

    float[] tcoords = {
            // left
            1, 0, 1, 1, 0, 1, 0, 0 };

    Vector3f normalVector = new Vector3f(-1.0f, 0.0f, 0.0f);

    geometry.setColors(0, colors, 0, 4);

    for (int n = 0; n < 4; n++)
        geometry.setNormal(n, normalVector);

    geometry.setTextureCoordinates(0, tcoords, 0, 4);

    geometry.setCoordinates(0, verts);

    frontFace.setGeometry(geometry);

    // connect the scenegraph
    objTrans1.addChild(box);
    zoomTg.addChild(objTrans1);
    objRoot.addChild(zoomTg);

    return objRoot;
}

From source file:TickTockCollision.java

public Box(double xsize, double ysize, double zsize) {
    super();//from w w w . ja  v a2 s.  com
    double xmin = -xsize / 2.0;
    double xmax = xsize / 2.0;
    double ymin = -ysize / 2.0;
    double ymax = ysize / 2.0;
    double zmin = -zsize / 2.0;
    double zmax = zsize / 2.0;

    QuadArray box = new QuadArray(24, QuadArray.COORDINATES);

    Point3d verts[] = new Point3d[24];

    // front face
    verts[0] = new Point3d(xmax, ymin, zmax);
    verts[1] = new Point3d(xmax, ymax, zmax);
    verts[2] = new Point3d(xmin, ymax, zmax);
    verts[3] = new Point3d(xmin, ymin, zmax);
    // back face
    verts[4] = new Point3d(xmin, ymin, zmin);
    verts[5] = new Point3d(xmin, ymax, zmin);
    verts[6] = new Point3d(xmax, ymax, zmin);
    verts[7] = new Point3d(xmax, ymin, zmin);
    // right face
    verts[8] = new Point3d(xmax, ymin, zmin);
    verts[9] = new Point3d(xmax, ymax, zmin);
    verts[10] = new Point3d(xmax, ymax, zmax);
    verts[11] = new Point3d(xmax, ymin, zmax);
    // left face
    verts[12] = new Point3d(xmin, ymin, zmax);
    verts[13] = new Point3d(xmin, ymax, zmax);
    verts[14] = new Point3d(xmin, ymax, zmin);
    verts[15] = new Point3d(xmin, ymin, zmin);
    // top face
    verts[16] = new Point3d(xmax, ymax, zmax);
    verts[17] = new Point3d(xmax, ymax, zmin);
    verts[18] = new Point3d(xmin, ymax, zmin);
    verts[19] = new Point3d(xmin, ymax, zmax);
    // bottom face
    verts[20] = new Point3d(xmin, ymin, zmax);
    verts[21] = new Point3d(xmin, ymin, zmin);
    verts[22] = new Point3d(xmax, ymin, zmin);
    verts[23] = new Point3d(xmax, ymin, zmax);

    box.setCoordinates(0, verts);
    setGeometry(box);
    setAppearance(new Appearance());
}

From source file:Drag.java

public Cube(Appearance appearance) {

    QuadArray quadArray = new QuadArray(24,
            QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2);
    quadArray.setCoordinates(0, verts);//  w  w  w  . ja  v  a 2s .com
    quadArray.setNormals(0, normals);
    quadArray.setTextureCoordinates(0, textCoords);

    shape3D = new Shape3D(quadArray, appearance);
}

From source file:CuboidTest.java

private GeometryArray processQuadStrips() {
    GeometryArray obj = null;//from   w w  w.j  a v a2  s .  co m
    int i;
    int totalVerts = 0;

    for (i = 0; i < currPrimCnt; i++) {
        int numQuadStripVerts;

        numQuadStripVerts = currPrimEndVertex[i] - currPrimStartVertex[i];
        totalVerts += (numQuadStripVerts / 2 - 1) * 4;
    }

    if (debug >= 1)
        System.out.println("totalVerts " + totalVerts);

    if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) {
        obj = new QuadArray(totalVerts,
                QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2);
    } else if (((flags & GENERATE_NORMALS) == 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) {
        obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2);
    } else if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) == 0)) {
        obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.NORMALS);
    } else {
        obj = new QuadArray(totalVerts, QuadArray.COORDINATES);
    }

    Point3f[] newpts = new Point3f[totalVerts];
    Vector3f[] newnormals = new Vector3f[totalVerts];
    TexCoord2f[] newtcoords = new TexCoord2f[totalVerts];
    int currVert = 0;

    for (i = 0; i < currPrimCnt; i++) {
        for (int j = currPrimStartVertex[i] + 2; j < currPrimEndVertex[i]; j += 2) {
            outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j - 2);
            outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j - 1);
            outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 1);
            outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j);
            numTris += 2;
        }
    }
    numVerts = currVert;

    obj.setCoordinates(0, newpts);
    if ((flags & GENERATE_NORMALS) != 0)
        obj.setNormals(0, newnormals);
    if ((flags & GENERATE_TEXTURE_COORDS) != 0)
        obj.setTextureCoordinates(0, 0, newtcoords);

    geometry = obj;
    return obj;
}

From source file:AvatarTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {/*from w w w .j  a va2 s  . com*/
    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:CuboidTest.java

private GeometryArray processQuads() {
    GeometryArray obj = null;//w  w w  .  j  ava 2s.  c  o m
    int i;
    int totalVerts = 0;

    for (i = 0; i < currPrimCnt; i++) {
        totalVerts += currPrimEndVertex[i] - currPrimStartVertex[i];
    }

    if (debug >= 1)
        System.out.println("totalVerts " + totalVerts);

    if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) {
        obj = new QuadArray(totalVerts,
                QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2);
    } else if (((flags & GENERATE_NORMALS) == 0) && ((flags & GENERATE_TEXTURE_COORDS) != 0)) {
        obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.TEXTURE_COORDINATE_2);
    } else if (((flags & GENERATE_NORMALS) != 0) && ((flags & GENERATE_TEXTURE_COORDS) == 0)) {
        obj = new QuadArray(totalVerts, QuadArray.COORDINATES | QuadArray.NORMALS);
    } else {
        obj = new QuadArray(totalVerts, QuadArray.COORDINATES);
    }

    Point3f[] newpts = new Point3f[totalVerts];
    Vector3f[] newnormals = new Vector3f[totalVerts];
    TexCoord2f[] newtcoords = new TexCoord2f[totalVerts];
    int currVert = 0;

    if (debug > 1)
        System.out.println("total prims " + currPrimCnt);

    for (i = 0; i < currPrimCnt; i++) {
        if (debug > 1)
            System.out.println("start " + currPrimStartVertex[i] + " end " + currPrimEndVertex[i]);
        for (int j = currPrimStartVertex[i]; j < currPrimEndVertex[i] - 3; j += 4) {
            outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j);
            outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 1);
            outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 2);
            outVertex(newpts, newnormals, newtcoords, currVert++, pts, normals, tcoords, j + 3);
            numTris += 2;
        }
    }
    numVerts = currVert;

    obj.setCoordinates(0, newpts);
    if ((flags & GENERATE_NORMALS) != 0)
        obj.setNormals(0, newnormals);
    if ((flags & GENERATE_TEXTURE_COORDS) != 0)
        obj.setTextureCoordinates(0, 0, newtcoords);

    geometry = obj;
    return obj;
}

From source file:AvatarTest.java

protected Group createGeometryGroup(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile) {/*from www  .ja v  a  2  s. com*/
    // 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;
}