Example #1
0
        /// <summary>
        /// Translate a World-Location to a Vertex position, without taking height into account.
        /// This means that we take the (cornerIndexX,0,cornerIndexZ) vector between the location and some (center of) a reference tile.
        /// </summary>
        /// <param name="location">Source World location</param>
        public Vector3 VertexPosition(WorldLocation location)
        {
            WorldLocation normalizedLocation = new WorldLocation(location);

            normalizedLocation.NormalizeTo(referenceTileX, referenceTileZ);
            return(new Vector3(normalizedLocation.Location.X, 0, normalizedLocation.Location.Z));
        }
Example #2
0
        public string GetStatusInformation(WorldLocation location)
        {
            // first make sure we normalize to the snapped tile
            WorldLocation snappedLocation = new WorldLocation(location);

            snappedLocation.NormalizeTo(this.snappedTileX, this.snappedTileZ);

            float totalSize   = 2048 * this.TileSize;
            int   patchIndexX = (int)((snappedLocation.Location.X + 1024) / totalSize * this.textureNames.GetLength(0));
            int   patchIndexZ = (int)((snappedLocation.Location.Z + 1024) / totalSize * this.textureNames.GetLength(1));

            patchIndexZ = this.textureNames.GetLength(1) - patchIndexZ - 1;

            return(String.Format(System.Globalization.CultureInfo.CurrentCulture,
                                 "({1}, {2}) for {3}x{3} tile: {0}", textureNames[patchIndexX, patchIndexZ], patchIndexX, patchIndexZ, this.TileSize));
        }
Example #3
0
        /// <summary>
        /// Do the dragging itself, meaning moving the label to a different position and show that
        /// </summary>
        internal void OnLeftMouseMoved()
        {
            if (!dragging)
            {
                return;
            }

            //We have three locations. Where the original/reference label. Where the dragging starts, and where the mouse now is
            //The new location is then 'original' + 'current' - 'start'.
            draggingStartLocation = draggingStartLocation.NormalizeTo(drawArea.MouseLocation.TileX, drawArea.MouseLocation.TileZ);
            WorldLocation shiftedLocation = new WorldLocation(
                draggingLabelToReplace.WorldLocation.TileX + drawArea.MouseLocation.TileX - draggingStartLocation.TileX,
                draggingLabelToReplace.WorldLocation.TileZ + drawArea.MouseLocation.TileZ - draggingStartLocation.TileZ,
                draggingLabelToReplace.WorldLocation.Location.X + drawArea.MouseLocation.Location.X - draggingStartLocation.Location.X,
                0,
                draggingLabelToReplace.WorldLocation.Location.Z + drawArea.MouseLocation.Location.Z - draggingStartLocation.Location.Z,
                true);

            draggingLabel = new StorableLabel(shiftedLocation, draggingLabelToReplace.LabelText);
        }
Example #4
0
        public void UpdateSoundPosition()
        {
            if (Car.SoundSourceIDs.Count == 0 || Viewer.Camera == null)
            {
                return;
            }

            if (Car.Train != null)
            {
                var realSpeedMpS = Car.SpeedMpS;
                //TODO Following if block is needed due to physics flipping when using rear cab
                // If such physics flipping is removed next block has to be removed.
                if (Car is MSTSLocomotive)
                {
                    var loco = Car as MSTSLocomotive;
                    if (loco.UsingRearCab)
                    {
                        realSpeedMpS = -realSpeedMpS;
                    }
                }
                Vector3 directionVector = Vector3.Multiply(Car.WorldPosition.XNAMatrix.Forward, realSpeedMpS);
                Velocity = new float[] { directionVector.X, directionVector.Y, -directionVector.Z };
            }
            else
            {
                Velocity = new float[] { 0, 0, 0 }
            };

            // TODO This entire block of code (down to TODO END) should be inside the SoundProcess, not here.
            SoundLocation = new WorldLocation(Car.WorldPosition.WorldLocation);
            SoundLocation.NormalizeTo(Camera.SoundBaseTile.X, Camera.SoundBaseTile.Y);
            float[] position = new float[] {
                SoundLocation.Location.X,
                SoundLocation.Location.Y,
                SoundLocation.Location.Z
            };

            // make a copy of SoundSourceIDs, but check that it didn't change during the copy; if it changed, try again up to 5 times.
            var sSIDsFinalCount = -1;
            var sSIDsInitCount  = -2;

            int[] soundSourceIDs = { 0 };
            int   trialCount     = 0;

            try
            {
                while (sSIDsInitCount != sSIDsFinalCount && trialCount < 5)
                {
                    sSIDsInitCount  = Car.SoundSourceIDs.Count;
                    soundSourceIDs  = Car.SoundSourceIDs.ToArray();
                    sSIDsFinalCount = Car.SoundSourceIDs.Count;
                    trialCount++;
                }
            }
            catch
            {
                Trace.TraceInformation("Skipped update of position and speed of sound sources");
                return;
            }
            if (trialCount >= 5)
            {
                return;
            }
            foreach (var soundSourceID in soundSourceIDs)
            {
                Viewer.Simulator.updaterWorking = true;
                if (OpenAL.alIsSource(soundSourceID))
                {
                    OpenAL.alSourcefv(soundSourceID, OpenAL.AL_POSITION, position);
                    OpenAL.alSourcefv(soundSourceID, OpenAL.AL_VELOCITY, Velocity);
                }
                Viewer.Simulator.updaterWorking = false;
            }
            // TODO END
        }
    }