Example usage for javax.media.j3d QuadArray setCoordinates

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

Introduction

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

Prototype

public void setCoordinates(int index, float coordinates[]) 

Source Link

Document

Sets the coordinates associated with the vertices starting at the specified index for this object.

Usage

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 ww .  j av a 2s.c o m*/
 * 
 * @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:Drag.java

public Cube(Appearance appearance) {

    QuadArray quadArray = new QuadArray(24,
            QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2);
    quadArray.setCoordinates(0, verts);
    quadArray.setNormals(0, normals);/*  w  w  w.j  ava 2  s.  co  m*/
    quadArray.setTextureCoordinates(0, textCoords);

    shape3D = new Shape3D(quadArray, appearance);
}

From source file:TickTockPicking.java

public Cube() {
    super();//from  www  .  j a  va  2 s .  c om

    int i;

    QuadArray cube = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS);

    cube.setCoordinates(0, verts);
    for (i = 0; i < 24; i++) {
        cube.setNormal(i, normals[i / 4]);
    }

    cube.setCapability(Geometry.ALLOW_INTERSECT);
    setGeometry(cube);
    setAppearance(new Appearance());
}

From source file:EnvironmentExplorer.java

void setupGrid() {

    // create a Switch for the spheres, allow switch changes
    gridSwitch = new Switch(Switch.CHILD_NONE);
    gridSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    // Set up an appearance to make the square3s with red ambient,
    // black emmissive, red diffuse and black specular coloring
    Material material = new Material(red, black, red, black, 64);
    Appearance appearance = new Appearance();
    appearance.setMaterial(material);//from w  ww  .j a  v a 2 s .c  o  m

    // create a grid of quads
    int gridSize = 20; // grid is gridSize quads along each side
    int numQuads = gridSize * gridSize;
    int numVerts = numQuads * 4; // 4 verts per quad
    // there will be 3 floats per coord and 4 coords per quad
    float[] coords = new float[3 * numVerts];
    // All the quads will use the same normal at each vertex, so
    // allocate an array to hold references to the same normal
    Vector3f[] normals = new Vector3f[numVerts];
    Vector3f vertNormal = new Vector3f(0.0f, 0.0f, 1.0f);
    float edgeLength = 5.0f; // length of each edge of the grid
    float gridGap = 0.03f; // the gap between each quad
    // length of each quad is (total length - sum of the gaps) / gridSize
    float quadLength = (edgeLength - gridGap * (gridSize - 1)) / gridSize;

    // create a grid of quads in the z=0 plane
    // each has a TransformGroup to position the sphere which contains
    // a link to the shared group for the sphere
    float curX, curY;
    for (int y = 0; y < gridSize; y++) {
        curY = y * (quadLength + gridGap); // offset to lower left corner
        curY -= edgeLength / 2; // center on 0,0
        for (int x = 0; x < gridSize; x++) {
            // this is the offset into the vertex array for the first
            // vertex of the quad
            int vertexOffset = (y * gridSize + x) * 4;
            // this is the offset into the coord array for the first
            // vertex of the quad, where there are 3 floats per vertex
            int coordOffset = vertexOffset * 3;
            curX = x * (quadLength + gridGap); // offset to ll corner
            curX -= edgeLength / 2; // center on 0,0
            // lower left corner
            coords[coordOffset + 0] = curX;
            coords[coordOffset + 1] = curY;
            coords[coordOffset + 2] = 0.0f; // z
            // lower right corner
            coords[coordOffset + 3] = curX + quadLength;
            coords[coordOffset + 4] = curY;
            coords[coordOffset + 5] = 0.0f; // z
            // upper right corner
            coords[coordOffset + 6] = curX + quadLength;
            coords[coordOffset + 7] = curY + quadLength;
            coords[coordOffset + 8] = 0.0f; // z
            // upper left corner
            coords[coordOffset + 9] = curX;
            coords[coordOffset + 10] = curY + quadLength;
            coords[coordOffset + 11] = 0.0f; // z
            for (int i = 0; i < 4; i++) {
                normals[vertexOffset + i] = vertNormal;
            }
        }
    }
    // now that we have the data, create the QuadArray
    QuadArray quads = new QuadArray(numVerts, QuadArray.COORDINATES | QuadArray.NORMALS);
    quads.setCoordinates(0, coords);
    quads.setNormals(0, normals);

    // create the shape
    Shape3D shape = new Shape3D(quads, appearance);

    // add it to the switch
    gridSwitch.addChild(shape);
}

From source file:TickTockCollision.java

public Box(double xsize, double ysize, double zsize) {
    super();//from ww w.ja  v a  2 s.co  m
    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:AppearanceExplorer.java

Shape3D createTexSquare() {

    // color cube
    Point3f pnt[] = new Point3f[4];
    pnt[0] = new Point3f(-1.0f, -1.0f, 0.0f);
    pnt[1] = new Point3f(1.0f, -1.0f, 0.0f);
    pnt[2] = new Point3f(1.0f, 1.0f, 0.0f);
    pnt[3] = new Point3f(-1.0f, 1.0f, 0.0f);
    TexCoord2f texCoord[] = new TexCoord2f[4];
    texCoord[0] = new TexCoord2f(0.0f, 0.0f);
    texCoord[1] = new TexCoord2f(1.0f, 0.0f);
    texCoord[2] = new TexCoord2f(1.0f, 1.0f);
    texCoord[3] = new TexCoord2f(0.0f, 1.0f);

    QuadArray qa = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
    qa.setCoordinates(0, pnt);
    qa.setTextureCoordinates(0, 0, texCoord);

    return new Shape3D(qa, appearance);
}

From source file:AppearanceExplorer.java

Shape3D createLargeTexSquare() {

    // color cube
    Point3f pnt[] = new Point3f[4];
    pnt[0] = new Point3f(-1.0f, -1.0f, 0.0f);
    pnt[1] = new Point3f(1.0f, -1.0f, 0.0f);
    pnt[2] = new Point3f(1.0f, 1.0f, 0.0f);
    pnt[3] = new Point3f(-1.0f, 1.0f, 0.0f);
    TexCoord2f texCoord[] = new TexCoord2f[4];
    texCoord[0] = new TexCoord2f(-1.0f, -1.0f);
    texCoord[1] = new TexCoord2f(2.0f, -1.0f);
    texCoord[2] = new TexCoord2f(2.0f, 2.0f);
    texCoord[3] = new TexCoord2f(-1.0f, 2.0f);

    QuadArray qa = new QuadArray(4, GeometryArray.COORDINATES | GeometryArray.TEXTURE_COORDINATE_2);
    qa.setCoordinates(0, pnt);
    qa.setTextureCoordinates(0, 0, texCoord);

    return new Shape3D(qa, appearance);
}

From source file:FourByFour.java

public BigCube(Appearance appearance) {

    QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS);
    quadArray.setCoordinates(0, verts);
    quadArray.setNormals(0, normals);/*from ww w . j a  v a2 s .c o m*/

    shape3D = new Shape3D(quadArray, appearance);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
}

From source file:FourByFour.java

public Cube(Appearance appearance) {

    QuadArray quadArray = new QuadArray(24,
            QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2);
    quadArray.setCoordinates(0, verts);
    quadArray.setNormals(0, normals);// w  w w .  j  av  a  2  s  .c om

    shape3D = new Shape3D(quadArray, appearance);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
}

From source file:FourByFour.java

public Cube(Appearance appearance, float size) {

    QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS);
    for (int i = 0; i < 72; i++)
        verts[i] *= size;//from  ww  w.  j  a v a  2 s. c om

    quadArray.setCoordinates(0, verts);
    quadArray.setNormals(0, normals);

    shape3D = new Shape3D(quadArray, appearance);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
}