Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.nolimitscoaster.*;
- import nlvm.math3d.*;
- public class CarHandler implements TrackTriggerListener {
- private CarScript mainScript;
- private Simulator sim;
- private Coaster coaster;
- private Train train;
- private int carID;
- private SceneObject sco;
- private SceneObjectElement cameraElement;
- private CarAction actions[];
- private int actionAmount;
- private int currentAction;
- private Matrix4x4f trainMatrix;
- private Vector3f posOut = new Vector3f(0, 0, 0);
- private Vector3f pitchHeadBankOut = new Vector3f(0, 0, 0);
- private ExternalRideView camera;
- //Action triggers
- private String action1TriggerName = "action1";
- private String action2TriggerName = "action2";
- private TrackTrigger action1Trigger;
- private TrackTrigger action2Trigger;
- //Animation directions
- private final int LEFT = 0;
- private final int RIGHT = 1;
- private final int FRONT = 2;
- private final int BACK = 3;
- //Rotation values
- private float xRot;
- private float yRot;
- private float zRot;
- public CarHandler(CarScript mainScript, Simulator sim, Coaster coaster, Train train, int carID) {
- this.mainScript = mainScript;
- this.sim = sim;
- this.coaster = coaster;
- this.train = train;
- this.carID = carID;
- actionAmount = 2;
- currentAction = 0;
- trainMatrix = new Matrix4x4f();
- sco = sim.getSceneObject("car" + carID);
- if (sco == null) {
- System.err.println("CarHandler: Can't find scene object car" + carID + "!");
- return;
- }
- cameraElement = sco.getElementForName("PlayerCamera");
- if (cameraElement == null) {
- System.err.println("CarHandler: Can't find scene object element PlayerCamera!");
- return;
- }
- cameraElement.setVisible(false);
- camera = sim.createExternalRideView();
- action1Trigger = coaster.getTrackTrigger(action1TriggerName);
- if (action1Trigger == null) {
- System.err.println("CarHandler: Can't find trigger " + action1TriggerName + "!");
- return;
- }
- action1Trigger.addTrackTriggerListener(this);
- action2Trigger = coaster.getTrackTrigger(action2TriggerName);
- if (action2Trigger == null) {
- System.err.println("CarHandler: Can't find trigger " + action2TriggerName + "!");
- return;
- }
- action2Trigger.addTrackTriggerListener(this);
- }
- public void process(float tick) {
- train.getCarMatrix(0, trainMatrix);
- Tools.matrixToPitchHeadBankPos(trainMatrix, pitchHeadBankOut, posOut);
- Matrix4x4f matrix = new Matrix4x4f();
- matrix.initTrans(0.f, 0.f, 0.f);
- //matrix.initXRot(xRot);
- //matrix.initYRot(yRot);
- matrix.initZRot(zRot);
- trainMatrix.multRight(matrix);
- sco.setMatrix(trainMatrix);
- if (camera != null) {
- camera.setCameraMatrix(cameraElement.getAbsoluteMatrix());
- camera.setEnterWarpPoint(cameraElement.getAbsoluteMatrix().getTrans(), 3.5f);
- }
- if (actions == null) {
- return;
- }
- for (int i = 0; i < actionAmount; i++) {
- if (actions[i] != null) {
- actions[i].process(tick);
- }
- }
- }
- public void start() {
- actions = new CarAction[actionAmount];
- }
- public void stop() {
- actions = null;
- currentAction = 0;
- }
- public void changeXRotation(bool add, float value) {
- if (add) {
- xRot += value;
- System.out.println("Add X " + value + " " + xRot);
- } else {
- xRot -= value;
- System.out.println("Sub X " + value + " " + xRot);
- }
- }
- public void changeYRotation(bool add, float value) {
- if (add) {
- yRot += value;
- } else {
- yRot -= value;
- }
- }
- public void changeZRotation(bool add, float value) {
- if (add) {
- zRot += value;
- } else {
- zRot -= value;
- }
- }
- public float getXRotation() {
- return xRot;
- }
- public float getYRotation() {
- return yRot;
- }
- public float getZRotation() {
- return zRot;
- }
- public Train getTrain() {
- return train;
- }
- public Simulator getSim() {
- return sim;
- }
- public SceneObject getSco() {
- return sco;
- }
- public void onTrainEntering(TrackTrigger trigger, Train train) {
- if (train != this.train) {
- return;
- }
- if (trigger == action1Trigger) {
- if (actions == null) {
- start();
- }
- actions[currentAction] = new CarAction(this, sim.getCurAbsSimulationTimeSec(), 1.5f, RIGHT);
- currentAction++;
- }
- if (trigger == action2Trigger) {
- actions[currentAction] = new CarAction(this, sim.getCurAbsSimulationTimeSec(), 1.5f, LEFT);
- currentAction++;
- }
- }
- public void onTrainLeaving(TrackTrigger trigger, Train train) {
- }
- }
Add Comment
Please, Sign In to add comment