Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.nolimitscoaster.*;
- import nlvm.math3d.*;
- /* **************************************************************************
- This is a generic object attachment script.
- Directions to use this script.
- 1) Copy and paste attach_object.nlvm to the same directory as your .nl2sco file.
- 2) Open the NL2SCO Editor and go to the Scripts tab.
- 3) Select attach_object.nlvm from the Script Class dialog.
- 4) Save the file and Refresh the scene object.
- View the in-game Help for creating .nl2sco files for your 3D models.
- It is unlikely that your object will be positioned exactly where you want it at first.
- You can modify the positional offset off the 3D model by adding or subtracting
- from xOffset, yOffset, zOffset below.
- *************************************************************************** */
- public class attach_object extends Script
- {
- // ====== CUSTOMIZABLE VARIABLES =======
- // Note: Decimal point "float" values must be followed by an 'f' (e.g. 0.5f, -9.205f). Whole values do not need the 'f'.
- private static final float xOffset = 0; // left/right
- private static final float yOffset = 1.5f; //up/down
- private static final float zOffset = 0; //back/forth
- private static final float range = 15; // The first train within this range of the scene object will receive the attachment. (range is in meters)
- private static final int carToAttach = 0; // Defines the car on the train that will receive the attachment. (0 = lead car or zero car)
- // ======================================
- private SceneObject sco; // Scenery object handle.
- private Train train; // Train handle.
- private Vector3f posOut = new Vector3f(0,0,0); // Will store the scenery object's position based on the car's position.
- private Vector3f pitchHeadBankOut = new Vector3f(0,0,0); // Will store the scenery object's orientation based on the car's orientation.
- private Matrix4x4f carMatrix = new Matrix4x4f(); // Will store the car's orientation.
- //**************************************************************************************
- // onInit is called when the scene object is loaded. Use this for initialization.
- // onInit should return true if initialization succeeds, else false.
- // If onInit returns false then the script will be disabled automatically and onNextFrame will never be called.
- //**************************************************************************************
- public bool onInit()
- {
- // ********************************************
- // Get the scene object handle.
- // ********************************************
- sco = sim.getSceneObjectForEntityId(getParentEntityId());
- if (sco == null)
- {
- System.err.println("attach_object.nlvm: This script must be assigned to a scene object.");
- return false;
- }
- // ********************************************
- // Determine if there is a track within range of the scenery object.
- // ********************************************
- TrackPos trackPos = sim.findNearestCoasterTrack(sco.getTranslation(), range);
- if (trackPos == null)
- {
- System.err.println("attach_object.nlvm: No track found within range of " + range + " meters.");
- return false;
- }
- // ********************************************
- // Determine if there is a train within range of the scenery object.
- // ********************************************
- Coaster coaster = trackPos.getCoaster();
- train = coaster.findNearestTrain(sco.getTranslation(), range);
- if (train == null)
- {
- System.err.println("attach_object.nlvm: No train found within range of " + range + " meters.");
- return false;
- }
- return true;
- }
- public void onNextFrame(float tick)
- {
- // ********************************************
- // Obtain the orientation matrix of the last car
- // ********************************************
- train.getCarMatrix(carToAttach, carMatrix);
- // ********************************************
- // Convert the matrix obtained from getCarMatrix()
- // to the Euler angle vector used in setRotation()
- // ********************************************
- Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
- // ********************************************
- // Calculate XYZ offset
- // ********************************************
- Matrix4x4f matrix = new Matrix4x4f();
- matrix.initTrans(xOffset, yOffset, zOffset);
- carMatrix.multRight(matrix);
- // ********************************************
- // Update the scene object's rotation and
- // position for this frame.
- // ********************************************
- Tools.matrixToPitchHeadBankPos(carMatrix, pitchHeadBankOut, posOut);
- sco.setRotation(pitchHeadBankOut);
- sco.setTranslation(posOut);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement