j3d.org Code

org.j3d.geom Class NormalUtils

java.lang.Object org.j3d.geom.NormalUtils

public class NormalUtils
extends java.lang.Object

A utility class that can be used to modify or create normal values of an item of geometry.

The utility class may be used as either a single shared instance or as a normal class. Sometimes you have a lot of different code all wanting to do similar modifications simultaneously and so having a single static-only class with synchronised methods would be very bad for performance.

Version:
\$Revision: 1.4 \$
Author:
Justin Couch

Constructor Summary
NormalUtils()
Create a default instance of the utility class.

Method Summary
void createFaceNormal(float[][] coords, int p, int p1, int p2, float[][] normals, int offset)
Convenience method to create a normal for the given vertex coordinates and normal array.
void createFaceNormal(float[] coords, int p, int p1, int p2, float[] normals, int offset)
Convenience method to create a normal for the given vertex coordinates and normal array.
void createRadialNormal(float[][] coords, int p, float[][] normals, int offset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the origin.
void createRadialNormal(float[][] coords, int p, float[][] origin, int originOffset, float[][] normals, int offset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the given point.
void createRadialNormal(float[] coords, int p, float[] normals, int offset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the origin.
void createRadialNormal(float[] coords, int p, float[] origin, int originOffset, float[] normals, int offset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the given point.
static NormalUtils getSharedInstance()
Fetch the currently shared singleton instance.
void negate(float[][] normals, int numNormals)
Negate the normals, in place.
void negate(float[] normals, int numNormals)
Negate the normals, in place.
void negate(float[] srcNormals, int numNormals, float[] destNormals)
Translate the coordintes by the given amount in each direction and place them in the destination array.
void translate(float[][] srcNormals, int numNormals, float[][] destNormals)
Translate the coordintes by the given amount in each direction and place them in the destination array.

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

NormalUtils

public NormalUtils()
Create a default instance of the utility class.

Method Detail

getSharedInstance

public static NormalUtils getSharedInstance()
Fetch the currently shared singleton instance.

Returns:
The current instance

negate

public void negate(float[] normals,
int numNormals)
Negate the normals, in place. A negative normal points in the opposite direction to the original value. It assumes that the array has the coordinate values as a flat array of values.

Parameters:
normals - The source coordinate array to copy
numNormals - The number of valid normals in the array

negate

public void negate(float[][] normals,
int numNormals)
Negate the normals, in place. A negative normal points in the opposite direction to the original value. It assumes that the

Parameters:
normals - The source coordinate array to copy
numNormals - The number of valid normals in the array

negate

public void negate(float[] srcNormals,
int numNormals,
float[] destNormals)
Translate the coordintes by the given amount in each direction and place them in the destination array. It assumes that the array has the coordinate values as a flat array of values.

Parameters:
srcNormals - The source coordinate array to copy
numNormals - The number of valid coordinates in the array
destNormals - The array to copy the values into

translate

public void translate(float[][] srcNormals,
int numNormals,
float[][] destNormals)
Translate the coordintes by the given amount in each direction and place them in the destination array. It assumes that the array has the coordinate values as a flat array of values.

Parameters:
srcNormals - The source coordinate array to copy
numNormals - The number of valid coordinates in the array
destNormals - The array to copy the values into

createFaceNormal

public void createFaceNormal(float[] coords,
int p,
int p1,
int p2,
float[] normals,
int offset)
Convenience method to create a normal for the given vertex coordinates and normal array. This performs a cross product of the two vectors described by the middle and two end points.

Parameters:
coords - The coordinate array to read values from
p - The index of the middle point
p1 - The index of the first point
p2 - The index of the second point
normals - The array to leave the computed result in
offset - The offset into the normal array to place the normal values

createFaceNormal

public void createFaceNormal(float[][] coords,
int p,
int p1,
int p2,
float[][] normals,
int offset)
Convenience method to create a normal for the given vertex coordinates and normal array. This performs a cross product of the two vectors described by the middle and two end points.

Parameters:
coords - The coordinate array to read values from
p - The index of the middle point
p1 - The index of the first point
p2 - The index of the second point
normals - The array to leave the computed result in
offset - The offset into the normal array to place the normal values

int p,
float[] normals,
int offset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the origin. This will create a normal that points directly along the vector from the origin to the point.

Parameters:
coords - The coordinate array to read values from
p - The index of the point to calculate
normals - The array to leave the computed result in
offset - The offset into the normal array to place the normal values

int p,
float[][] normals,
int offset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the origin. This will create a normal that points directly along the vector from the origin to the point.

Parameters:
coords - The coordinate array to read values from
p - The index of the point to calculate
normals - The array to leave the computed result in
offset - The offset into the normal array to place the normal values

int p,
float[] origin,
int originOffset,
float[] normals,
int offset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the given point. This will create a normal that points directly along the vector from the given point to the coordinate.

Parameters:
coords - The coordinate array to read values from
p - The index of the point to calculate
origin - The origin to calculate relative to
originOffset - The offset into the origin array to use

int p,
float[][] origin,
int originOffset,
float[][] normals,
int offset)
Create a normal based on the given vertex position, assuming that it is a point in space, relative to the given point. This will create a normal that points directly along the vector from the given point to the coordinate.

Parameters:
coords - The coordinate array to read values from
p - The index of the point to calculate
origin - The origin to calculate relative to
originOffset - The offset into the origin array to use

j3d.org Code

Latest Info from http://code.j3d.org/