Example usage for javax.media.j3d TriangleArray setNormal

List of usage examples for javax.media.j3d TriangleArray setNormal

Introduction

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

Prototype

public void setNormal(int index, float normal[]) 

Source Link

Document

Sets the normal associated with the vertex at the specified index for this object.

Usage

From source file:AppearanceTest.java

public Tetrahedron() {
    int i;//from  w w w . ja  v a 2s . c o  m

    TriangleArray tetra = new TriangleArray(12,
            TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2);

    tetra.setCoordinates(0, verts);
    for (i = 0; i < 12; i++) {
        tetra.setTextureCoordinate(0, i, texCoord[i % 3]);
    }

    int face;
    Vector3f normal = new Vector3f();
    Vector3f v1 = new Vector3f();
    Vector3f v2 = new Vector3f();
    Point3f[] pts = new Point3f[3];
    for (i = 0; i < 3; i++)
        pts[i] = new Point3f();

    for (face = 0; face < 4; face++) {
        tetra.getCoordinates(face * 3, pts);
        v1.sub(pts[1], pts[0]);
        v2.sub(pts[2], pts[0]);
        normal.cross(v1, v2);
        normal.normalize();
        for (i = 0; i < 3; i++) {
            tetra.setNormal((face * 3 + i), normal);
        }
    }
    this.setGeometry(tetra);
    this.setAppearance(new Appearance());
}

From source file:TickTockPicking.java

public Tetrahedron() {
    int i;/*from  w ww  .jav  a2 s .  c o  m*/

    TriangleArray tetra = new TriangleArray(12,
            TriangleArray.COORDINATES | TriangleArray.NORMALS | TriangleArray.TEXTURE_COORDINATE_2);

    tetra.setCoordinates(0, verts);
    for (i = 0; i < 12; i++) {
        tetra.setTextureCoordinate(0, i, texCoord[i % 3]);
    }

    int face;
    Vector3f normal = new Vector3f();
    Vector3f v1 = new Vector3f();
    Vector3f v2 = new Vector3f();
    Point3f[] pts = new Point3f[3];
    for (i = 0; i < 3; i++)
        pts[i] = new Point3f();

    for (face = 0; face < 4; face++) {
        tetra.getCoordinates(face * 3, pts);
        v1.sub(pts[1], pts[0]);
        v2.sub(pts[2], pts[0]);
        normal.cross(v1, v2);
        normal.normalize();
        for (i = 0; i < 3; i++) {
            tetra.setNormal((face * 3 + i), normal);
        }
    }

    tetra.setCapability(Geometry.ALLOW_INTERSECT);

    this.setGeometry(tetra);
    this.setAppearance(new Appearance());
}