public void updateMove(MouseEventArgs e) { if (null != TrackObj) { if (TrackObj.Moveable && TrackObj.Drag == true) { int x = e.X - mptLastPos.X; int y = e.Y - mptLastPos.Y; if (x != 0 || y != 0) { TrackObj.onPositionChange(new Point(x, y)); //mTrackObj.Property.SetValue("Location", mTrackObj.Location.X.ToString() + "," + mTrackObj.Location.Y.ToString()); mptLastPos = e.Location; m_AddToHistory = true; } } } }
public void onMouseDown(MouseEventArgs e) { DrawElement hitItem = null; mptLastPos = e.Location; hitItem = FindTrackObj(e.Location, HitObj); TrackObj = hitItem; m_AddToHistory = false; if (TrackObj != null) { if (TrackObj.Moveable) { TrackObj.Drag = true; HandleMouseDown(e); } // Need to move in the manager class TrackObj.onMouseDown(e); } }
/// <summary> /// Decompose and add a SuperElevation on top of MSTS track section /// </summary> /// <param name="viewer">Viewer reference.</param> /// <param name="trackList">DynamicTrackViewer list.</param> /// <param name="trackObj">Dynamic track section to decompose.</param> /// <param name="worldMatrixInput">Position matrix.</param> /// <param name="TileX">TileX coordinates.</param> /// <param name="TileZ">TileZ coordinates.</param> /// <param name="shapeFilePath">Path to the shape file.</param> public static bool DecomposeStaticSuperElevation(Viewer viewer, List <DynamicTrackViewer> trackList, TrackObj trackObj, WorldPosition worldMatrixInput, int TileX, int TileZ, string shapeFilePath) { TrackShape shape = null; try { shape = viewer.Simulator.TSectionDat.TrackShapes.Get(trackObj.SectionIdx); if (shape.RoadShape == true) { return(false); } } catch (Exception) { return(false); } SectionIdx[] SectionIdxs = shape.SectionIdxs; int count = -1; int drawn = 0; bool isTunnel = shape.TunnelShape; List <TrVectorSection> sectionsinShape = new List <TrVectorSection>(); //List<DynamicTrackViewer> tmpTrackList = new List<DynamicTrackViewer>(); foreach (SectionIdx id in SectionIdxs) { uint[] sections = id.TrackSections; for (int i = 0; i < sections.Length; i++) { count++; uint sid = id.TrackSections[i]; TrackSection section = viewer.Simulator.TSectionDat.TrackSections.Get(sid); if (Math.Abs(section.SectionSize.Width - viewer.Simulator.SuperElevationGauge) > 0.2) { continue; //the main route has a gauge different than mine } if (section.SectionCurve == null) { continue; //with strait track, will remove all related sections later } TrVectorSection tmp = null; if (section.SectionCurve != null) { tmp = FindSectionValue(shape, viewer.Simulator, section, TileX, TileZ, trackObj.UID); } if (tmp == null) //cannot find the track for super elevation, will return 0; { continue; } sectionsinShape.Add(tmp); drawn++; } } if (drawn <= count || isTunnel)//tunnel or not every section is in SE, will remove all sections in the shape out { if (sectionsinShape.Count > 0) { RemoveTracks(viewer.Simulator, sectionsinShape); } return(false); } return(true); }
/// <summary> /// Decompose and add a SuperElevation on top of MSTS track section converted from dynamic tracks /// </summary> /// <param name="viewer">Viewer reference.</param> /// <param name="dTrackList">DynamicTrackViewer list.</param> /// <param name="dTrackObj">Dynamic track section to decompose.</param> /// <param name="worldMatrixInput">Position matrix.</param> public static void DecomposeConvertedDynamicSuperElevation(Viewer viewer, List <DynamicTrackViewer> dTrackList, TrackObj dTrackObj, WorldPosition worldMatrixInput) { // The following vectors represent local positioning relative to root of original (5-part) section: Vector3 localV = Vector3.Zero; // Local position (in x-z plane) Vector3 localProjectedV; // Local next position (in x-z plane) Vector3 displacement; // Local displacement (from y=0 plane) Vector3 heading = Vector3.Forward; // Local heading (unit vector) WorldPosition worldMatrix = new WorldPosition(worldMatrixInput); // Make a copy so it will not be messed WorldPosition nextRoot = new WorldPosition(worldMatrix); // Will become initial root WorldPosition wcopy = new WorldPosition(nextRoot); Vector3 sectionOrigin = worldMatrix.XNAMatrix.Translation; // Save root position worldMatrix.XNAMatrix.Translation = Vector3.Zero; // worldMatrix now rotation-only TrackPath path; try { path = viewer.Simulator.TSectionDat.TSectionIdx.TrackPaths[dTrackObj.SectionIdx]; } catch (Exception) { return; //cannot find the path for the dynamic track } nextRoot = new WorldPosition(wcopy); // Will become initial root sectionOrigin = nextRoot.XNAMatrix.Translation; heading = Vector3.Forward; // Local heading (unit vector) localV = Vector3.Zero; // Local position (in x-z plane) Vector3 trackLoc = new Vector3(0, 0, 0);// +new Vector3(3, 0, 0); Matrix trackRot = Matrix.CreateRotationY(0); //heading = Vector3.Transform(heading, trackRot); // Heading change nextRoot.XNAMatrix = trackRot * nextRoot.XNAMatrix; uint[] sections = path.TrackSections; int count = -1; for (int i = 0; i < sections.Length; i++) { count++; float length, radius; uint sid = path.TrackSections[i]; TrackSection section = viewer.Simulator.TSectionDat.TrackSections[sid]; WorldPosition root = new WorldPosition(nextRoot); nextRoot.XNAMatrix.Translation = Vector3.Zero; if (section.SectionCurve == null) { length = section.SectionSize.Length; radius = -1; localProjectedV = localV + length * heading; displacement = Traveller.MSTSInterpolateAlongStraight(localV, heading, length, worldMatrix.XNAMatrix, out localProjectedV); } else { length = section.SectionCurve.Angle * 3.14f / 180; radius = section.SectionCurve.Radius; // meters Vector3 left; if (section.SectionCurve.Angle > 0) { left = radius * Vector3.Cross(Vector3.Down, heading); // Vector from PC to O } else { left = radius * Vector3.Cross(Vector3.Up, heading); // Vector from PC to O } Matrix rot = Matrix.CreateRotationY(-section.SectionCurve.Angle * 3.14f / 180); // Heading change (rotation about O) displacement = Traveller.MSTSInterpolateAlongCurve(localV, left, rot, worldMatrix.XNAMatrix, out localProjectedV); heading = Vector3.Transform(heading, rot); // Heading change nextRoot.XNAMatrix = trackRot * rot * nextRoot.XNAMatrix; // Store heading change } nextRoot.XNAMatrix.Translation = sectionOrigin + displacement; root.XNAMatrix.Translation += Vector3.Transform(trackLoc, worldMatrix.XNAMatrix); nextRoot.XNAMatrix.Translation += Vector3.Transform(trackLoc, worldMatrix.XNAMatrix); sv = ev = mv = 0f; dir = 1f; //if (section.SectionCurve != null) FindSectionValue(shape, root, nextRoot, viewer.Simulator, section, TileX, TileZ, dTrackObj.UID); //nextRoot.XNAMatrix.Translation += Vector3.Transform(trackLoc, worldMatrix.XNAMatrix); dTrackList.Add(new SuperElevationViewer(viewer, root, nextRoot, radius, length, sv, ev, mv, dir)); localV = localProjectedV; // Next subsection } }
/// <summary> /// Decompose and add a wire on top of MSTS track section /// </summary> /// <param name="viewer">Viewer reference.</param> /// <param name="trackList">DynamicTrackViewer list.</param> /// <param name="trackObj">Dynamic track section to decompose.</param> /// <param name="worldMatrixInput">Position matrix.</param> public static int DecomposeStaticWire(Viewer viewer, List <DynamicTrackViewer> trackList, TrackObj trackObj, WorldPosition worldMatrixInput) { // The following vectors represent local positioning relative to root of original (5-part) section: Vector3 localV = Vector3.Zero; // Local position (in x-z plane) Vector3 localProjectedV; // Local next position (in x-z plane) Vector3 displacement; // Local displacement (from y=0 plane) Vector3 heading = Vector3.Forward; // Local heading (unit vector) WorldPosition worldMatrix = new WorldPosition(worldMatrixInput); // Make a copy so it will not be messed WorldPosition nextRoot = new WorldPosition(worldMatrix); // Will become initial root WorldPosition wcopy = new WorldPosition(nextRoot); Vector3 sectionOrigin = worldMatrix.XNAMatrix.Translation; // Save root position worldMatrix.XNAMatrix.Translation = Vector3.Zero; // worldMatrix now rotation-only try { if (viewer.Simulator.TSectionDat.TrackShapes.Get(trackObj.SectionIdx).RoadShape == true) { return(1); } } catch (Exception) { return(0); } SectionIdx[] SectionIdxs = viewer.Simulator.TSectionDat.TrackShapes.Get(trackObj.SectionIdx).SectionIdxs; foreach (SectionIdx id in SectionIdxs) { nextRoot = new WorldPosition(wcopy); // Will become initial root sectionOrigin = nextRoot.XNAMatrix.Translation; heading = Vector3.Forward; // Local heading (unit vector) localV = Vector3.Zero; // Local position (in x-z plane) Vector3 trackLoc = new Vector3((float)id.X, (float)id.Y, (float)id.Z);// +new Vector3(3, 0, 0); Matrix trackRot = Matrix.CreateRotationY(-(float)id.A * 3.14f / 180); //heading = Vector3.Transform(heading, trackRot); // Heading change nextRoot.XNAMatrix = trackRot * nextRoot.XNAMatrix; uint[] sections = id.TrackSections; for (int i = 0; i < sections.Length; i++) { float length, radius; uint sid = id.TrackSections[i]; TrackSection section = viewer.Simulator.TSectionDat.TrackSections[sid]; WorldPosition root = new WorldPosition(nextRoot); nextRoot.XNAMatrix.Translation = Vector3.Zero; if (section.SectionCurve == null) { length = section.SectionSize.Length; radius = -1; localProjectedV = localV + length * heading; displacement = Traveller.MSTSInterpolateAlongStraight(localV, heading, length, worldMatrix.XNAMatrix, out localProjectedV); } else { length = section.SectionCurve.Angle * 3.14f / 180; radius = section.SectionCurve.Radius; // meters Vector3 left; if (section.SectionCurve.Angle > 0) { left = radius * Vector3.Cross(Vector3.Down, heading); // Vector from PC to O } else { left = radius * Vector3.Cross(Vector3.Up, heading); // Vector from PC to O } Matrix rot = Matrix.CreateRotationY(-section.SectionCurve.Angle * 3.14f / 180); // Heading change (rotation about O) displacement = Traveller.MSTSInterpolateAlongCurve(localV, left, rot, worldMatrix.XNAMatrix, out localProjectedV); heading = Vector3.Transform(heading, rot); // Heading change nextRoot.XNAMatrix = trackRot * rot * nextRoot.XNAMatrix; // Store heading change } nextRoot.XNAMatrix.Translation = sectionOrigin + displacement; root.XNAMatrix.Translation += Vector3.Transform(trackLoc, worldMatrix.XNAMatrix); //nextRoot.XNAMatrix.Translation += Vector3.Transform(trackLoc, worldMatrix.XNAMatrix); trackList.Add(new WireViewer(viewer, root, nextRoot, radius, length)); localV = localProjectedV; // Next subsection } } return(1); }