This seems to work...:
import java.io.*;
import java.util.*;
import org.lwjgl.opengl.Display;
import com.threed.jpct.*;
import com.threed.jpct.util.Light;
public class OnTrackZ
{
public static void main(String[] args) throws Exception
{
Config.farPlane=60000;
DataInputStream di=new DataInputStream(new FileInputStream("tracks.rac"));
List<SimpleVector> markers=new ArrayList<SimpleVector>();
di.readInt();
while (di.available()>0) {
SimpleVector s=new SimpleVector(di.readFloat(), di.readFloat(), di.readFloat());
float y=s.y;
s.y=-s.z;
s.z=-y;
markers.add(s);
}
FrameBuffer buffer=new FrameBuffer(800,600,FrameBuffer.SAMPLINGMODE_HARDWARE_ONLY);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
World world=new World();
Object3D car=Primitives.getCone(5, 2000);
car.rotateX((float)Math.PI/2f);
car.rotateMesh();
car.setRotationMatrix(new Matrix());
car.compile();
car.translate(markers.get(0));
SimpleVector initTrs=markers.get(1).calcSub(markers.get(0)).normalize();
car.setRotationMatrix(initTrs.getRotationMatrix());
world.addObject(car);
world.setAmbientLight(100, 100, 100);
world.buildAllObjects();
Light light=new Light(world);
light.setPosition(new SimpleVector(0,-1000,0));
light.setAttenuation(-1);
light.setIntensity(255, 0, 0);
Camera cam=world.getCamera();
cam.setPosition(car.getTranslation());
cam.moveCamera(Camera.CAMERA_MOVEUP, 50000);
cam.rotateX(-(float)Math.PI/2f);
Matrix lastRot=car.getRotationMatrix();
long start=0;
int fps=0;
int pos=0;
while (!Display.isCloseRequested()) {
int next=(pos+1)%markers.size();
SimpleVector cur=car.getTranslation();
SimpleVector dir=markers.get(next).calcSub(cur);
SimpleVector trs=dir.normalize();
if (trs.length()!=0) {
Matrix softMat=trs.getRotationMatrix();
lastRot.interpolate(lastRot, softMat, 0.008f);
car.setRotationMatrix(lastRot);
}
trs.scalarMul(5);
car.translate(trs);
if (car.getTranslation().calcSub(markers.get(next)).length()<5.5f) {
lastRot=trs.getRotationMatrix();
car.setTranslationMatrix(new Matrix());
car.translate(markers.get(next));
pos++;
pos%=markers.size();
System.out.println("Switching to: "+pos);
}
buffer.clear();
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
buffer.displayGLOnly();
fps++;
if (System.currentTimeMillis()-start>=1000) {
start=System.currentTimeMillis();
System.out.println(fps+" fps");
fps=0;
}
}
buffer.dispose();
System.exit(0);
}
}
...BUT: As said, this method relies on getRotationMatrix() of SimpleVector. getRotationMatrix() is very similar to the usual lookAt-method, which means that its outcome is correct in terms of what the Javadoc states that it does, but it depends on the internal command order how the result looks like. In other words: There are millions of ways to look at something from a given position because you can always turn yourself around your own z-axis. The method works fine for the usual x-z-plane worlds, but when used in the y-x-plane, it creates wrap-arounds at the poles. Again, this is correct in terms of what it is supposed to do, but its not what you want in this case.
This is why my test code transforms the markers from the x-y-plane to the x-z-plane. It seems to work much better that way. Give it a try, maybe it helps somehow...