Thursday, June 29, 2006

BoxStack Milestone

I set my goal back in January 2005 to implement my own BoxStack. Finally, 1.5 years later, I declare a milestone for this project. The initial idea was somewhat unrealistic. The current implementation employs Java3D for graphics, GJK for collision detection, DEEP for estimating penetration depth.


Monday, June 26, 2006

Embeded Google Video

Google video now directly provides html to embed a video. Here is my cranktrain simulation video.

Java Web Start for Cranktrain Simulation

I have put out a Java web start version of cranktrain simulation for a while. The tricky thing about Java web start is loading a data file. After reading all the available document on the web (which is very little), I learned that ClassLoader is necessary to invoke files in the JAR file.

ClassLoader cl;

crankShape = Trimesh.loadObj(cl.getResource("images/crank.obj"));

I used Java3D ObjLoader class to load the OBJ files. However, I am still confounded about how to directly read a text file in a web start app. The combustion force file was stripped from the current web start version of the crank model until I figured out a way to do it.

Tuesday, June 06, 2006

Make Movies

Step 1:

Do screen grab at every frame and encode the captured image to JPEG format. The solution could come from Java 3D but using Robot seems to be a more stable method (from I read from different forums).


try {
//setLocationRelativeTo(null);
Rectangle win = getBounds();
Robot robot = new Robot(getGraphicsConfiguration().getDevice());
BufferedImage image =
robot.createScreenCapture(new Rectangle(win.x, win.y,
win.width, win.height));
FileOutputStream out = new FileOutputStream("image" + jpgCount + ".jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
param.setQuality(0.9f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(image);
out.close();
} catch(AWTException e) {
e.printStackTrace();
} catch(IOException e) {
System.err.println("I/O exception!");
}
jpgCount++;


Step 2:

Stitch the still images into a movie using ffmpeg:

ffmpeg -i image%d.jpg -b 800 movie.mpg


or

ffmpeg -i image%d.jpg -sameq movie.mpg


Bit rate is probably the main factor for quality. Choose wisely. The default bit rate of 200 yields low quality result.