j3d.org Code

org.j3d.util.interpolator
Class NormalInterpolator

java.lang.Object
  extended by org.j3d.util.interpolator.Interpolator
      extended by org.j3d.util.interpolator.NormalInterpolator

public class NormalInterpolator
extends Interpolator

An interpolator that works with sets of normals.

The interpolation routine is a constant-angle interpolation between each of the normals in the pairs of normal sets. The interpolator may take arbitrarily spaced keyframes and compute correct values. Based on the CoordinateInterpolator.java by Justin Couch.

The interpolation implementation is based on the following: 0 <= f <= 1, N1, N2 are normalized input normals, A is angle between N1 and N2 == acos(N1xN2), N3 = (sin((1-f)*A)*N1 + sin(f*A)*N2 Normalized result is N3/(|N3|)

Version:
$Revision: 1.3 $
Author:
Guy Carpenter

Field Summary
 
Fields inherited from class org.j3d.util.interpolator.Interpolator
allocatedSize, ARRAY_INCREMENT, currentSize, DEFAULT_SIZE, interpolationType, keys, LINEAR, STEP
 
Constructor Summary
NormalInterpolator()
          Create a new linear interpolator instance with the default size for the number of key values.
NormalInterpolator(int size)
          Create an linear interpolator with the given basic size.
NormalInterpolator(int size, int type)
          Create a interpolator with the given basic size using the interpolation type.
 
Method Summary
 void addKeyFrame(float key, float[] normals)
          Add a key frame set of values at the given key point.
 float[] floatValue(float key)
          Get the interpolated normal set for the given key value.
 java.lang.String toString()
           
 
Methods inherited from class org.j3d.util.interpolator.Interpolator
clear, findKeyIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NormalInterpolator

public NormalInterpolator()
Create a new linear interpolator instance with the default size for the number of key values.


NormalInterpolator

public NormalInterpolator(int size)
Create an linear interpolator with the given basic size.

Parameters:
size - The starting number of items in interpolator

NormalInterpolator

public NormalInterpolator(int size,
                          int type)
Create a interpolator with the given basic size using the interpolation type.

Parameters:
size - The starting number of items in interpolator
type - The type of interpolation scheme to use
Method Detail

addKeyFrame

public void addKeyFrame(float key,
                        float[] normals)
Add a key frame set of values at the given key point. This will insert the values at the correct position within the array for the given key. If two keys have the same value, the new key is inserted after the old one.

Parameters:
key - The value of the key to use
normals - The normals at this key

floatValue

public float[] floatValue(float key)
Get the interpolated normal set for the given key value. If the key lies outside the range of the values defined, it will be clamped to the end point value. For speed reasons, this will return a reusable float array. Do not modify the values or keep a reference to this as it will change values between calls.

Parameters:
key - The key value to get the position for
Returns:
An array of the normal values at that position. All normals are flattened into a single array of [x, y, z] values. The length of the array will be 3 times the number of normals returned.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

j3d.org Code

Latest Info from http://code.j3d.org/
Copyright © 2001 - j3d.org