Yes and no.
Let's say it's better now.
I have to "play" with Xith Runmodes.
So my application is initialized in RunMode RUN_IN_SEPARATE_THREAD_AND_WAIT.
It's ok when viewing the 3d scene and moving the camera with the mouse or the keyboard (interactive mode).
But when i want to update the canvas fastly, for example for launching an animation, i have to change the runmode before.
Else, only the last frame is displayed when the animation is finished.
Here is the class AnimCamera i have made for my project:
/**
* Animates the camera from a list of points
*/
package fr.ign.cogit.appli.risques.ihm;
import java.util.ArrayList;
import java.util.List;
import org.openmali.vecmath.Matrix3f;
import org.openmali.vecmath.Vector3f;
import org.xith3d.base.Xith3DEnvironment;
import org.xith3d.loop.RenderLoop;
import org.xith3d.loop.RenderLoop.RunMode;
import org.xith3d.loop.RenderLoop.StopOperation;
import org.xith3d.loop.UpdatingThread.TimingMode;
import org.xith3d.scenegraph.StaticTransform;
import org.xith3d.scenegraph.Transformable;
import org.xith3d.utility.view.CameraFlightListener;
/**
* @author Ludo
*
*/
public class AnimCamera implements CameraFlightListener {
private CameraFlight camFlight = null;
private long gameTime = 0;
private Transformable cam;
private RenderLoop loop;
private boolean endAnim = false;
private List<Vector3f> posList;
private Xith3DEnvironment env;
long t0;
public AnimCamera(Transformable cam, RenderLoop loop, Xith3DEnvironment env) {
this.cam = cam;
this.loop = loop;
this.env = env;
posList = new ArrayList<Vector3f>();
}
public void startFlight()
{
t0 = System.currentTimeMillis();
camFlight = new CameraFlight();
computeRotCam();
camFlight.addCameraFlightListener( this );
loop.setStopOperation(StopOperation.DO_NOTHING);
System.out.println( loop.getStopOperation().toString() );
loop.end();
loop.begin(RunMode.RUN_IN_SAME_THREAD);
camFlight.start( loop.getGameTime() + (System.currentTimeMillis() - t0) );
System.out.println( "CameraFlight started." );
gameTime = loop.getGameTime();
endAnim = false;
while (!endAnim) {
updateCamera();
}
}
public void stopFlight()
{
camFlight = null;
}
/* (non-Javadoc)
* @see org.xith3d.utility.view.CameraFlightListener#onCameraFlightEnded(long, long, double)
*/
public void onCameraFlightEnded(long frames, long millis, double averageFPS) {
final double roundedFPS = ((double)((int)(averageFPS * 100.0)) / 100.0);
// loop.end();
loop.setStopOperation(StopOperation.DESTROY);
// loop.begin(RunMode.RUN_IN_SEPARATE_THREAD_AND_WAIT);
endAnim = true;
System.out.println( "CameraFlight ended. (average FPS: " + roundedFPS + ")" );
}
public void addPos(Vector3f pos) {
posList.add( new Vector3f(pos) );
}
private void computeRotCam() {
for (int i = 0; i < posList.size(); i++) {
Vector3f point = new Vector3f();
Vector3f vec = new Vector3f();
point.set( posList.get( i ) );
if ( i!= posList.size() -1 ) {
vec.set( posList.get(i + 1) );
}
else {
vec.set( posList.get(0) );
}
vec.sub(point);
Matrix3f rot = new Matrix3f();
cam.getTransform().getRotation(rot);
// rot.set( StaticTransform.getRotationMatrix( new Vector3f(0f, 0f, 1f), vec.angle(new Vector3f(1f, 0f, 0f)) ) );
System.out.println(rot + "\n" + point);
camFlight.addRotPos( rot, vec, 1000f );
}
}
public void updateCamera() {
gameTime = loop.getGameTime() + (System.currentTimeMillis() - t0);
camFlight.updateCamera(cam, gameTime);
loop.nextFrame();
}
}
PS: The constuctor of CameraFlight() shouldn't not be null. It should initialize the list of points instead:
/**
* Creates a new CameraFlight
*/
public CameraFlight()
{
interPoints = new ArrayList<InterpolationPoint>();
}