import java.util.Vector; import java.util.Iterator; import java.util.StringTokenizer; import java.io.FileReader; import java.io.BufferedReader; import java.io.IOException; /** * A special type of group node, this acts as the root of a * subgraph that defines a mocap animation. *

* This class will read a mocap file and generate the hierarchy * for representation of the mocap data. * * @version 1.00 * @author Ben Carter */ public class jooglMocapGroup extends jooglGroup { /** The number of points of mocap data captured */ final private static int NUM_POINTS = 41; /** The maximum number of frames of data you need to support */ final private static int MAX_FRAMES = 5000; /** Milliseconds for each frame. */ private double millisPerFrame; /** The number of frames in the animation. */ private int numFrames; public jooglMocapGroup(String filename) { super(); setFrameRate(120); numFrames = setMocapData(filename); } public jooglMocapGroup(String filename, int framesPerSecond) { super(); setFrameRate(framesPerSecond); numFrames = setMocapData(filename); } public void setFrameRate(int framesPerSecond) { millisPerFrame = 1000.0 / framesPerSecond; } /** Set the current data from the provided file. */ public int setMocapData(String filename) { String oneLine; StringTokenizer tok; int currPoint = 0; int tosses[][] = new int[3][MAX_FRAMES]; int catches[][] = new int[3][MAX_FRAMES]; int numTosses[] = new int[3]; double frames[][][] = new double[NUM_POINTS][MAX_FRAMES][3]; numTosses[0] = numTosses[1] = numTosses[2] = 0; try { BufferedReader in = new BufferedReader(new FileReader(filename)); in.readLine(); in.readLine(); while((oneLine = in.readLine()) != null && numFrames < MAX_FRAMES) { tok = new StringTokenizer(oneLine); if(oneLine.charAt(0) == 'T') { int id = oneLine.charAt(1) - '0'; tosses[id][numTosses[id]] = numFrames-1; } else if(oneLine.charAt(0) == 'C') { int id = oneLine.charAt(1) - '0'; catches[id][numTosses[id]++] = numFrames-1; } else if(oneLine.charAt(0) == '*') { continue; }else { currPoint = 0; tok.nextToken(); while(tok.hasMoreTokens()) { frames[currPoint][numFrames][0] = Float.parseFloat(tok.nextToken()); frames[currPoint][numFrames][1] = Float.parseFloat(tok.nextToken()); frames[currPoint][numFrames][2] = Float.parseFloat(tok.nextToken()); ++currPoint; } ++numFrames; } } in.close(); } catch(IOException ioe) { System.out.println("IOException in setMocapData()"); } System.out.println("Number of throws for ball 0: " + numTosses[0]); System.out.println("Number of throws for ball 1: " + numTosses[1]); System.out.println("Number of throws for ball 2: " + numTosses[2]); return numFrames; } }