Example #1
0
        public TrainCar(TrainCarDefinition definition)
        {
            m_definition = definition;
            m_visual     = Object.Instantiate(m_definition.Visual);

            m_signedSpeed = 0;

            InitialiseAnimations();

            m_bogies         = new Bogie[definition.Bogies.Length];
            m_fakeBogieIndex = -1;
            for (int bogieIndex = 0; bogieIndex < definition.Bogies.Length; bogieIndex++)
            {
                /*
                 * m_bogies[bogieIndex] = new Bogie(bogieIndex, definition.Bogies[bogieIndex], GroupNode);
                 * if (m_bogies[bogieIndex].Transform == null)
                 * {
                 *      Debug.Assert(m_fakeBogieIndex < 0);
                 *      m_fakeBogieIndex = bogieIndex;
                 * }
                 *
                 * m_debugWheelsetMarkers[bogieIndex] = new TransformNode[2];
                 * for (int wheelsetIndex = 0; wheelsetIndex < 2; wheelsetIndex++)
                 * {
                 *      var debugMarker = new TransformNode("DebugWheelsetMarker");
                 *      debugMarker.AddChild(GeometryNode.CreateCube(0.25f, Colour.White, null));
                 *      m_debugWheelsetMarkers[bogieIndex][wheelsetIndex] = debugMarker;
                 *      debugMarker.Enabled = false;
                 *      GroupNode.AddChild(debugMarker);
                 * }
                 * */
            }
        }
Example #2
0
        public void TimestepUpdate(Bogie previousBogie, float deltaPosition)
        {
            if (FirstWheelsetSegment == null || LastWheelsetSegment == null)
            {
                return;
            }

            SavePreviousParameters();

            // Move first wheelset to keep up with previous bogie
            Vector3 lastWheelsetPosition  = previousBogie.LastWheelsetSegment.GetCurvePositionInWorldSpace(previousBogie.LastWheelsetSegmentT);
            Vector3 firstWheelsetPosition = FirstWheelsetSegment.GetCurvePositionInWorldSpace(FirstWheelsetSegmentT);
            float   wantedDistance        = DistanceFromLastWheelsetOfPreviousBogieToFirstWheelset(previousBogie);
            float   actualDistance        = (lastWheelsetPosition - firstWheelsetPosition).magnitude;
            float   distanceToMove        = FirstWheelsetDirectionOfT * (actualDistance - wantedDistance);

            FirstWheelsetSegment = FirstWheelsetSegment.MoveSignedDistance(distanceToMove, ref FirstWheelsetSegmentT, ref FirstWheelsetDirectionOfT);
            if (FirstWheelsetSegment == null)
            {
                return;
            }

            // Move last wheelset to keep up with first wheelset
            UpdateLastWheelsetPosition();
            if (LastWheelsetSegment == null)
            {
                return;
            }

            WheelsetsTimeStepUpdate(deltaPosition);
        }
Example #3
0
        public void PutOnTrack(Bogie previousBogie)
        {
            Debug.Assert(previousBogie != null);

            float distance = DistanceFromLastWheelsetOfPreviousBogieToFirstWheelset(previousBogie) * -previousBogie.LastWheelsetDirectionOfT;

            FirstWheelsetSegmentT     = previousBogie.LastWheelsetSegmentT;
            FirstWheelsetDirectionOfT = previousBogie.LastWheelsetDirectionOfT;
            FirstWheelsetSegment      = previousBogie.LastWheelsetSegment.MoveSignedDistance(distance, ref FirstWheelsetSegmentT, ref FirstWheelsetDirectionOfT);

            PutLastWheelsetOnTrack();
        }
Example #4
0
 // TODO this is a constant for the train car (i.e. can be in definition)
 private float DistanceFromLastWheelsetOfPreviousBogieToFirstWheelset(Bogie previousBogie)
 {
     return(Definition.DistanceToFront - Definition.Wheelsets[0].SignedDistanceToBogie -
            previousBogie.Definition.DistanceToFront +
            previousBogie.Definition.Wheelsets[previousBogie.Definition.Wheelsets.Length - 1].SignedDistanceToBogie);
 }