< Zurück | Inhalt | Weiter >

From Utils.java in the org.selman.java3d.book package


static public TCBKeyFrame[] readKeyFrames( URL urlKeyframes )

{

StringBuffer szBufferData = readFile( urlKeyframes );


if( szBufferData == null ) return null;


Vector keyFramesVector = new Vector();


//create a tokenizer to tokenize the input file at whitespace java.util.StringTokenizer tokenizer =

new java.util.StringTokenizer( szBufferData.toString() );


/*

* Each keyframe is defined as follows:

* − knot (0 >= k <= 1)

* − position (x,y,z)

* − rotation (rx,ry,rz)

* − scale (x,y,z)

* − tension (−1 >= t <= 1)

* − continuity (−1 >= c <= 1)

* − bias (−1 >= b <= 1)

* − linear (int − 0 or 1)

*/

while( true )

{

try

{

float knot = Float.parseFloat( tokenizer.nextToken() );


float posX = Float.parseFloat( tokenizer.nextToken() ); float posY = Float.parseFloat( tokenizer.nextToken() ); float posZ = Float.parseFloat( tokenizer.nextToken() );


float rotX = Float.parseFloat( tokenizer.nextToken() ); float rotY = Float.parseFloat( tokenizer.nextToken() ); float rotZ = Float.parseFloat( tokenizer.nextToken() );


float scaleX = Float.parseFloat( tokenizer.nextToken() ); float scaleY = Float.parseFloat( tokenizer.nextToken() ); float scaleZ = Float.parseFloat( tokenizer.nextToken() );


float tension = Float.parseFloat( tokenizer.nextToken() ); float continuity = Float.parseFloat( tokenizer.nextToken() ); float bias = Float.parseFloat( tokenizer.nextToken() );


int linear = Integer.parseInt( tokenizer.nextToken() );


//create the actual keyframe from the data just read TCBKeyFrame keyframe = new TCBKeyFrame(

knot, linear,

new Point3f( posX, posY, posZ ), createQuaternionFromEuler( rotX, rotY, rotZ ), new Point3f( scaleX, scaleY, scaleZ ), tension,

continuity, bias );


keyFramesVector.add( keyframe );

}

catch( Exception e )

{

break;

}

}


//create the return structure and populate TCBKeyFrame[] keysReturn =

new TCBKeyFrame[ keyFramesVector.size() ];


for( int n = 0; n <keysReturn.length; n++ ) keysReturn[n] = (TCBKeyFrame) keyFramesVector.get( n );


//return the array return keysReturn;

}


image