SHARE
TWEET

Untitled

a guest May 27th, 2017 3 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.nolimitscoaster.*;
  2. import nlvm.math3d.*;
  3.  
  4. public class CarHandler implements TrackTriggerListener {
  5.    
  6.     private CarScript mainScript;
  7.     private Simulator sim;
  8.     private Coaster coaster;
  9.     private Train train;
  10.     private int carID;
  11.     private SceneObject sco;
  12.     private SceneObjectElement cameraElement;
  13.    
  14.     private CarAction actions[];
  15.     private int actionAmount;
  16.     private int currentAction;
  17.    
  18.     private Matrix4x4f trainMatrix;
  19.     private Vector3f posOut = new Vector3f(0, 0, 0);
  20.     private Vector3f pitchHeadBankOut = new Vector3f(0, 0, 0);
  21.    
  22.     private ExternalRideView camera;
  23.    
  24.     //Action triggers
  25.     private String action1TriggerName = "action1";
  26.     private String action2TriggerName = "action2";
  27.     private TrackTrigger action1Trigger;
  28.     private TrackTrigger action2Trigger;
  29.    
  30.     //Animation directions
  31.     private final int LEFT = 0;
  32.     private final int RIGHT = 1;
  33.     private final int FRONT = 2;
  34.     private final int BACK = 3;
  35.    
  36.     //Rotation values
  37.     private float xRot;
  38.     private float yRot;
  39.     private float zRot;
  40.    
  41.     public CarHandler(CarScript mainScript, Simulator sim, Coaster coaster, Train train, int carID) {
  42.         this.mainScript = mainScript;
  43.         this.sim = sim;
  44.         this.coaster = coaster;
  45.         this.train = train;
  46.         this.carID = carID;
  47.        
  48.         actionAmount = 2;
  49.         currentAction = 0;
  50.        
  51.         trainMatrix = new Matrix4x4f();
  52.        
  53.         sco = sim.getSceneObject("car" + carID);
  54.         if (sco == null) {
  55.             System.err.println("CarHandler: Can't find scene object car" + carID + "!");
  56.             return;
  57.         }
  58.        
  59.         cameraElement = sco.getElementForName("PlayerCamera");
  60.         if (cameraElement == null) {
  61.             System.err.println("CarHandler: Can't find scene object element PlayerCamera!");
  62.             return;
  63.         }
  64.         cameraElement.setVisible(false);
  65.         camera = sim.createExternalRideView();
  66.        
  67.         action1Trigger = coaster.getTrackTrigger(action1TriggerName);
  68.         if (action1Trigger == null) {
  69.             System.err.println("CarHandler: Can't find trigger " + action1TriggerName + "!");
  70.             return;
  71.         }
  72.         action1Trigger.addTrackTriggerListener(this);
  73.        
  74.         action2Trigger = coaster.getTrackTrigger(action2TriggerName);
  75.         if (action2Trigger == null) {
  76.             System.err.println("CarHandler: Can't find trigger " + action2TriggerName + "!");
  77.             return;
  78.         }
  79.         action2Trigger.addTrackTriggerListener(this);
  80.     }
  81.    
  82.     public void process(float tick) {
  83.         train.getCarMatrix(0, trainMatrix);
  84.        
  85.         Tools.matrixToPitchHeadBankPos(trainMatrix, pitchHeadBankOut, posOut);
  86.        
  87.         Matrix4x4f matrix = new Matrix4x4f();
  88.         matrix.initTrans(0.f, 0.f, 0.f);
  89.         //matrix.initXRot(xRot);
  90.         //matrix.initYRot(yRot);
  91.         matrix.initZRot(zRot);
  92.         trainMatrix.multRight(matrix);
  93.        
  94.         sco.setMatrix(trainMatrix);
  95.        
  96.         if (camera != null) {
  97.             camera.setCameraMatrix(cameraElement.getAbsoluteMatrix());
  98.             camera.setEnterWarpPoint(cameraElement.getAbsoluteMatrix().getTrans(), 3.5f);
  99.         }
  100.        
  101.         if (actions == null) {
  102.             return;
  103.         }
  104.        
  105.         for (int i = 0; i < actionAmount; i++) {
  106.             if (actions[i] != null) {
  107.                 actions[i].process(tick);
  108.             }
  109.         }
  110.     }
  111.    
  112.     public void start() {
  113.         actions = new CarAction[actionAmount];
  114.     }
  115.    
  116.     public void stop() {
  117.         actions = null;
  118.         currentAction = 0;
  119.     }
  120.    
  121.     public void changeXRotation(bool add, float value) {
  122.         if (add) {
  123.             xRot += value;
  124.             System.out.println("Add X " + value + " " + xRot);
  125.         } else {
  126.             xRot -= value;
  127.             System.out.println("Sub X " + value + " " + xRot);
  128.         }
  129.     }
  130.    
  131.     public void changeYRotation(bool add, float value) {
  132.         if (add) {
  133.             yRot += value;
  134.         } else {
  135.             yRot -= value;
  136.         }
  137.     }
  138.    
  139.     public void changeZRotation(bool add, float value) {
  140.         if (add) {
  141.             zRot += value;
  142.         } else {
  143.             zRot -= value;
  144.         }
  145.     }
  146.    
  147.     public float getXRotation() {
  148.         return xRot;
  149.     }
  150.    
  151.     public float getYRotation() {
  152.         return yRot;
  153.     }
  154.    
  155.     public float getZRotation() {
  156.         return zRot;
  157.     }
  158.    
  159.     public Train getTrain() {
  160.         return train;
  161.     }
  162.    
  163.     public Simulator getSim() {
  164.         return sim;
  165.     }
  166.    
  167.     public SceneObject getSco() {
  168.         return sco;
  169.     }
  170.    
  171.     public void onTrainEntering(TrackTrigger trigger, Train train) {
  172.         if (train != this.train) {
  173.             return;
  174.         }
  175.         if (trigger == action1Trigger) {
  176.             if (actions == null) {
  177.                 start();
  178.             }
  179.            
  180.             actions[currentAction] = new CarAction(this, sim.getCurAbsSimulationTimeSec(), 1.5f, RIGHT);
  181.             currentAction++;
  182.         }
  183.        
  184.         if (trigger == action2Trigger) {
  185.             actions[currentAction] = new CarAction(this, sim.getCurAbsSimulationTimeSec(), 1.5f, LEFT);
  186.             currentAction++;
  187.         }
  188.     }
  189.    
  190.     public void onTrainLeaving(TrackTrigger trigger, Train train) {
  191.        
  192.     }
  193. }
RAW Paste Data
Top