import com.nolimitscoaster.*;
import nlvm.math3d.*;
public class Perso extends Script {
int carToAttach;
bool bogie;
bool camerasEnabled;
SceneObject sco;
Coaster coaster;
TrackPos trackPos;
float range = 5.0f;
Train train;
Vector3f[] camEntryPoint = new Vector3f[5];
Matrix4x4f[] cameraLocation = new Matrix4x4f[5];
Matrix4x4f carMatrix = new Matrix4x4f();
private Vector3f posOut = new Vector3f(0,0,0);
private Vector3f pitchHeadBankOut = new Vector3f(0,0,0);
float[] camera1 = new float[3];
float[] camera2 = new float[3];
float[] camera3 = new float[3];
float[] camera4 = new float[3];
float[] camera5 = new float[3];
ExternalRideView[] erv = new ExternalRideView[5];
public bool onInit(){
carToAttach = 1;
bogie = false;
camerasEnabled = true;
sco = sim.getSceneObjectForEntityId(getParentEntityId());
if(sco == null){
System.err.println("Not bound to a Scene Object!");
return false;
}
trackPos = sim.findNearestCoasterTrack(sco.getTranslation(), range);
if (trackPos == null){
System.err.println(" No track found within range of " + range + " meters.");
return false;
}
coaster = trackPos.getCoaster();
train = coaster.findNearestTrain(sco.getTranslation(), range);
if (train == null){
System.err.println(" No train found within range of " + range + " meters.");
return false;
}
camera1[0] = 0.0f;
camera1[1] = 0.0f;
camera1[2] = 0.0f;
camera2[0] = 0.0f;
camera2[1] = 0.0f;
camera2[2] = 0.0f;
camera3[0] = 0.0f;
camera3[1] = 0.0f;
camera3[2] = 0.0f;
camera4[0] = 0.0f;
camera4[1] = 0.0f;
camera4[2] = 0.0f;
camera5[0] = 0.0f;
camera5[1] = 0.0f;
camera5[2] = 0.0f;
camEntryPoint[0] = new Vector3f(camera1[0],camera1[1],camera1[2]);
camEntryPoint[1] = new Vector3f(camera2[0],camera2[1],camera2[2]);
camEntryPoint[2] = new Vector3f(camera3[0],camera3[1],camera3[2]);
camEntryPoint[3] = new Vector3f(camera4[0],camera4[1],camera4[2]);
camEntryPoint[4] = new Vector3f(camera5[0],camera5[1],camera5[2]);
for(int i = 0; i < erv.length; i++){
cameraLocation[i] = new Matrix4x4f();
erv[i] = sim.createExternalRideView();
erv[i].setLabel("Enter View " + i);
erv[i].setEnterWarpPoint(camEntryPoint[i],2.0f);
erv[i].setEnterWarpPointEnabled(camerasEnabled);
}
return true;
}
public void onNextFrame(float tick){
if(bogie){
train.getBogieMatrix(carToAttach, carMatrix);
}else{
train.getCarMatrix(carToAttach, carMatrix);
}
Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
sco.setRotation(pitchHeadBankOut);
sco.setTranslation(posOut);
for(int i = 0; i < erv.length; i++){
if(bogie){
train.getBogieMatrix(carToAttach, carMatrix);
}else{
train.getCarMatrix(carToAttach, carMatrix);
}
Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
cameraLocation[i].initTrans(camEntryPoint[i].x,camEntryPoint[i].y,camEntryPoint[i].z);
posOut.add(camEntryPoint[i]);
erv[i].setEnterWarpPoint(posOut,2.0f);
carMatrix.multRight(cameraLocation[i]);
erv[i].setCameraMatrix(carMatrix);
}
Matrix4x4f matrix = new Matrix4x4f();
carMatrix.multRight(matrix);
}