Example usage for javax.media.j3d GeometryArray getNormal

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

Introduction

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

Prototype

public void getNormal(int index, Vector3f normal) 

Source Link

Document

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

Usage

From source file:MyJava3D.java

private int computeIntensity(GeometryArray geometryArray, int index, int numPoints) {
    int intensity = 0;

    if (computeIntensity != false) {
        // if we have a normal vector compute the intensity under the
        // lighting
        if ((geometryArray.getVertexFormat() & GeometryArray.NORMALS) == GeometryArray.NORMALS) {
            double cos_theta;
            double cos_alpha;
            double cos_beta;

            for (int n = 0; n < numPoints; n++)
                geometryArray.getNormal(index + n, normalsArray[n]);

            // take the average normal vector
            averageVector(surf_norm, normalsArray, numPoints);
            temp.set(view);//from w  w  w . j  a v a2  s.  c  o  m
            temp.scale(1.0f, surf_norm);

            cos_beta = temp.x + temp.y + temp.z;

            if (cos_beta > 0.0) {
                cos_theta = surf_norm.dot(light);

                if (cos_theta <= 0.0) {
                    intensity = (int) (lightMax * lightAmbient);
                } else {
                    temp.set(surf_norm);
                    temp.scale((float) cos_theta);
                    temp.normalize();
                    temp.sub(light);
                    temp.normalize();

                    cos_alpha = view.dot(temp);

                    intensity = (int) (lightMax * (lightAmbient + lightDiffuse * cos_theta
                            + lightSpecular * Math.pow(cos_alpha, lightGlossiness)));
                }
            }
        }
    }

    return intensity;
}