public LightViewer(Viewer viewer, TrainCar car) { Viewer = viewer; Car = car; positionSource = Car; LightGlowMaterial = viewer.MaterialManager.Load("LightGlow"); LightConeMaterial = viewer.MaterialManager.Load("LightCone"); UpdateState(); if (Car.Lights != null) { foreach (var light in Car.Lights) { switch (light.Type) { case LightType.Glow: LightPrimitives.Add(new LightGlowPrimitive(this, Viewer.RenderProcess, light)); break; case LightType.Cone: LightPrimitives.Add(new LightConePrimitive(this, Viewer.RenderProcess, light)); break; } } } HasLightCone = LightPrimitives.Any(lm => lm is LightConePrimitive); #if DEBUG_LIGHT_STATES Trace.WriteLine(); #endif UpdateActiveLightCone(); }
public TargetFinder(IWorldPosition origin, float range, IWorldGenerator worldGenerator, IEntityFactory <T> factory) { this.origin = origin; this.range = range; this.worldGenerator = worldGenerator; this.factory = factory; }
protected override void DoUpdate(double elapsedTime) { if (this.renderer == null) { this.renderer = this.BindingObject.Renderer as IWorldPosition; } //this.transform.Position = this.TargetTransform.Position + new vec3(0, 1, 0); this.renderer.Position = this.TargetRenderer.Position + new vec3(0, 0.3f, 0); }
public LabelPrimitive(Label3DMaterial material, Color color, Color outline, float offsetY, IWorldPosition positionSource, string text) { this.material = material; this.color = color; this.outline = outline; this.offsetY = offsetY; this.positionSource = positionSource; this.text = text; }
public ParticleEmitterViewer(Viewer viewer, ParticleEmitterData data, IWorldPosition positionSource) { Viewer = viewer; EmissionHoleM2 = (MathHelper.Pi * ((data.NozzleWidth / 2f) * (data.NozzleWidth / 2f))); Emitter = new ParticleEmitterPrimitive(viewer, data, positionSource); #if DEBUG_EMITTER_INPUT EmitterID = ++EmitterIDIndex; InputCycle = Viewer.Random.Next(InputCycleLimit); #endif }
private TargetFinder <IEntity> GetTargetFinder(float range, IWorldPosition origin, IEntity[] targets) { IWorldGenerator generator = Substitute.For <IWorldGenerator>(); var monsterFactory = Substitute.For <IEntityFactory <IEntity> >(); monsterFactory.GetActiveEntities().Returns(targets); generator.MapLength.Returns(100); var targetFinder = new TargetFinder <IEntity>(origin, range, generator, monsterFactory); return(targetFinder); }
protected int IAnimationMatrix = -1; // index of animation matrix /// <summary> /// Construct and initialize the class /// </summary> public TurntableShape(string path, IWorldPosition positionSource, ShapeFlags flags, Turntable turntable, double startingY) : base(path, positionSource, flags) { Turntable = turntable; Turntable.StartingY = (float)startingY; Turntable.TurntableFrameRate = SharedShape.Animations[0].FrameRate; animationKey = (Turntable.YAngle / (float)Math.PI * 1800.0f + 3600) % 3600.0f; for (var imatrix = 0; imatrix < SharedShape.Matrices.Length; ++imatrix) { if (SharedShape.MatrixNames[imatrix].ToLower() == turntable.Animations[0].ToLower()) { IAnimationMatrix = imatrix; break; } } if (viewer.Simulator.TRK.Route.DefaultTurntableSMS != null) { var soundPath = viewer.Simulator.RoutePath + @"\\sound\\" + viewer.Simulator.TRK.Route.DefaultTurntableSMS; try { Sound = new SoundSource(viewer, WorldPosition.WorldLocation, SoundEventSource.Turntable, soundPath); viewer.SoundProcess.AddSoundSources(this, new List <SoundSourceBase>() { Sound }); } catch { soundPath = viewer.Simulator.BasePath + @"\\sound\\" + viewer.Simulator.TRK.Route.DefaultTurntableSMS; try { Sound = new SoundSource(viewer, WorldPosition.WorldLocation, SoundEventSource.Turntable, soundPath); viewer.SoundProcess.AddSoundSources(this, new List <SoundSourceBase>() { Sound }); } catch (Exception error) { Trace.WriteLine(new FileLoadException(soundPath, error)); } } } for (var matrix = 0; matrix < SharedShape.Matrices.Length; ++matrix) { AnimateMatrix(matrix, animationKey); } MatrixExtension.Multiply(in XNAMatrices[IAnimationMatrix], in WorldPosition.XNAMatrix, out Matrix absAnimationMatrix); Turntable.ReInitTrainPositions(absAnimationMatrix); }
protected int IAnimationMatrix = -1; // index of animation matrix /// <summary> /// Construct and initialize the class /// </summary> public TransfertableShape(string path, IWorldPosition positionSource, ShapeFlags flags, Transfertable transfertable) : base(path, positionSource, flags) { Transfertable = transfertable; animationKey = (Transfertable.XPos - Transfertable.CenterOffset.X) / Transfertable.Width * SharedShape.Animations[0].FrameCount; for (var imatrix = 0; imatrix < SharedShape.Matrices.Length; ++imatrix) { if (SharedShape.MatrixNames[imatrix].ToLower() == transfertable.Animations[0].ToLower()) { IAnimationMatrix = imatrix; break; } } if (viewer.Simulator.TRK.Route.DefaultTurntableSMS != null) { var soundPath = viewer.Simulator.RoutePath + @"\\sound\\" + viewer.Simulator.TRK.Route.DefaultTurntableSMS; try { Sound = new SoundSource(viewer, WorldPosition.WorldLocation, SoundEventSource.Turntable, soundPath); viewer.SoundProcess.AddSoundSources(this, new List <SoundSourceBase>() { Sound }); } catch { soundPath = viewer.Simulator.BasePath + @"\\sound\\" + viewer.Simulator.TRK.Route.DefaultTurntableSMS; try { Sound = new SoundSource(viewer, WorldPosition.WorldLocation, SoundEventSource.Turntable, soundPath); viewer.SoundProcess.AddSoundSources(this, new List <SoundSourceBase>() { Sound }); } catch (Exception error) { Trace.WriteLine(new FileLoadException(soundPath, error)); } } } for (var matrix = 0; matrix < SharedShape.Matrices.Length; ++matrix) { AnimateMatrix(matrix, animationKey); } MatrixExtension.Multiply(in XNAMatrices[IAnimationMatrix], in WorldPosition.XNAMatrix, out Matrix absAnimationMatrix); Transfertable.ReInitTrainPositions(absAnimationMatrix); }
protected int IAnimationMatrix = -1; // index of animation matrix /// <summary> /// Construct and initialize the class /// </summary> public TurntableShape(string path, IWorldPosition positionSource, ShapeFlags flags, TurnTable turntable, double startingY) : base(path, positionSource, flags) { Turntable = turntable; //Turntable.StartingY = (float)startingY; Turntable.TurntableFrameRate = SharedShape.Animations[0].FrameRate; animationKey = (Turntable.YAngle / (float)Math.PI * 1800.0f + 3600) % 3600.0f; for (var imatrix = 0; imatrix < SharedShape.Matrices.Length; ++imatrix) { if (SharedShape.MatrixNames[imatrix].Equals(turntable.Animations[0], StringComparison.OrdinalIgnoreCase)) { IAnimationMatrix = imatrix; break; } } if (viewer.Simulator.Route.DefaultTurntableSMS != null) { string soundPath = viewer.Simulator.RouteFolder.SoundFile(viewer.Simulator.Route.DefaultTurntableSMS); if (File.Exists(soundPath)) { Sound = new SoundSource(viewer, WorldPosition.WorldLocation, SoundEventSource.Turntable, soundPath); viewer.SoundProcess.AddSoundSources(this, new List <SoundSourceBase>() { Sound }); } else if (File.Exists(soundPath = viewer.Simulator.RouteFolder.ContentFolder.SoundFile(viewer.Simulator.Route.DefaultTurntableSMS))) { Sound = new SoundSource(viewer, WorldPosition.WorldLocation, SoundEventSource.Turntable, soundPath); viewer.SoundProcess.AddSoundSources(this, new List <SoundSourceBase>() { Sound }); } else { Trace.WriteLine($"Turntable soundfile {soundPath} not found"); } } for (var matrix = 0; matrix < SharedShape.Matrices.Length; ++matrix) { AnimateMatrix(matrix, animationKey); } MatrixExtension.Multiply(in XNAMatrices[IAnimationMatrix], in WorldPosition.XNAMatrix, out Matrix absAnimationMatrix); Turntable.ReInitTrainPositions(absAnimationMatrix); }
public Vector3 GetDirection(IWorldPosition from, IWorldPosition to, float yOffset = 0) { var trueDistance = to.TruePosition.x - from.TruePosition.x; var repeatedDistance = trueDistance > 0 ? trueDistance - generator.MapLength : trueDistance + generator.MapLength; Vector3 targetPosition; if (Mathf.Abs(repeatedDistance) < Mathf.Abs(trueDistance)) { targetPosition = new Vector3(from.TruePosition.x + repeatedDistance, to.TruePosition.y + yOffset, to.TruePosition.z); } else { targetPosition = new Vector3(from.TruePosition.x + trueDistance, to.TruePosition.y + yOffset, to.TruePosition.z); } var direction = targetPosition - from.TruePosition; return(direction); }
private void Start() { playerInput = PlayerInput.Instance; position = GetComponent <IWorldPosition>(); }
private void Awake() { position = GetComponent <IWorldPosition>(); targetFinder = new TargetFinder <Monster>(position, range, WorldSettings.WorldGenerator, WorldSettings.MonsterFactory); shotTimer = attackDelay; }
private void Awake() { position = GetComponent <IWorldPosition>(); health = new Health(maxHealth); }
public SegmentColliderTracker(IWorldPosition trackedPosition) { position = trackedPosition; }
////////////////////////////////////////////////////////////////////////// public void Init() { if (m_RotationTarget == null) { m_RotationTarget = gameObject; } // algorithm sequence switch (m_Target) { case Target.NormalWorld: { m_WorldPosition = new WorldPositionNormal(transform.rotation.eulerAngles.z, transform); } break; case Target.NormalLocal: { m_WorldPosition = new WorldPositionNormalLocal(transform.parent, transform.localEulerAngles.z, transform); } break; case Target.Mouse: { m_WorldPosition = Core.Instance.MouseWorldPosition; } break; case Target.GameObject: { if (m_LookTarget == null) { m_WorldPosition = m_Space == Space.World ? new WorldPositionNormal(transform.rotation.eulerAngles.z, transform) : new WorldPositionNormalLocal(transform.parent, transform.localEulerAngles.z, transform); } else { m_WorldPosition = m_LookTarget.GetComponent <GLMonoBehaviour>(); if (m_WorldPosition == null) { m_WorldPosition = new GameObjectIWorldPositionWrapper(m_LookTarget); } } } break; case Target.GameObjectSafe: { if (m_LookTarget == null) { m_WorldPosition = m_Space == Space.World ? new WorldPositionNormal(transform.rotation.eulerAngles.z, transform) : new WorldPositionNormalLocal(transform.parent, transform.localEulerAngles.z, transform); } else { m_WorldPosition = new GameObjectIWorldPositionWrapperEx(m_LookTarget, () => m_WorldPosition = m_Space == Space.World ? new WorldPositionNormal(transform.rotation.eulerAngles.z, transform) : new WorldPositionNormalLocal(transform.parent, transform.localEulerAngles.z, transform)); } } break; } switch (m_Space) { case Space.World: if (m_Implementation == Implementation.Transform) { m_OptSpace = new OptionSpaceWorldTransform() { m_Owner = this }; break; } else { m_OptSpace = new OptionSpaceWorldPhysics() { m_Owner = this }; break; } case Space.Local: if (m_Implementation == Implementation.Transform) { m_OptSpace = new OptionSpaceLocalTransform() { m_Owner = this }; break; } else { m_OptSpace = new OptionSpaceLocalPhysics() { m_Owner = this }; break; } } switch (m_Restruction) { case Restruction.None: m_OptRestriction = new OptionRestrictionNone() { m_Owner = this }; break; case Restruction.Range: m_OptRestriction = new OptionRestrictionRange() { m_Owner = this }; break; } switch (m_Interpolation) { case Interpolation.Slerp: if (m_Implementation == Implementation.Transform) { m_OptInterpolation = m_Restruction == Restruction.None ? (Option) new OptionInterpolationSlerpRestructionNone() { m_Owner = this } : (Option) new OptionInterpolationSlerp() { m_Owner = this }; break; } else { m_OptInterpolation = m_Space == Space.Local ? (Option) new OptionInterpolationPhysicsFromLocal() { m_Owner = this } : (Option) new OptionInterpolationPhysicsFromWorld() { m_Owner = this }; break; } case Interpolation.SlerpCurve: if (m_Implementation == Implementation.Transform) { m_OptInterpolation = m_Restruction == Restruction.None ? (Option) new OptionInterpolationSlerpCurveRestructionNone() { m_Owner = this } : (Option) new OptionInterpolationSlerpCurve() { m_Owner = this }; break; } else { m_OptInterpolation = m_Space == Space.Local ? (Option) new OptionInterpolationPhysicsFromLocal() { m_Owner = this } : (Option) new OptionInterpolationPhysicsFromWorld() { m_Owner = this }; break; } } switch (m_Implementation) { case Implementation.Transform: switch (m_Space) { case Space.World: m_OptImplementation = new OptionImplementationTransformWorld() { m_Owner = this }; break; case Space.Local: m_OptImplementation = new OptionImplementationTransformLocal() { m_Owner = this }; break; } break; case Implementation.PhysicsForce: switch (m_Restruction) { case Restruction.None: m_ForcePredictionCurve.preWrapMode = WrapMode.Loop; m_ForcePredictionCurve.postWrapMode = WrapMode.Loop; break; case Restruction.Range: m_ForcePredictionCurve.preWrapMode = WrapMode.ClampForever; m_ForcePredictionCurve.postWrapMode = WrapMode.ClampForever; break; } m_RigidBody = m_RotationTarget.GetComponent <Rigidbody2D>(); m_OptImplementation = new OptionImplementationPhysics() { m_Owner = this }; break; } // runner if (m_UpdateRunner != null) { Destroy(m_UpdateRunner); } if (m_Implementation == Implementation.Transform) { m_UpdateRunner = gameObject.AddComponent <RunnerUpdate>(); m_UpdateRunner.Executable = this; } else if (m_Implementation == Implementation.PhysicsForce) { m_UpdateRunner = gameObject.AddComponent <RunnerFixedUpdate>(); m_UpdateRunner.Executable = this; } }
private void Awake() { position = GetComponent <IWorldPosition>(); direction = new RepeatedWorldDirection(WorldSettings.WorldGenerator); }
public SignalShape(SignalObject mstsSignal, string path, IWorldPosition positionSource, ShapeFlags flags) : base(path, positionSource, flags) { #if DEBUG_SIGNAL_SHAPES Console.WriteLine("{0} signal {1}:", Location.ToString(), mstsSignal.UID); UID = mstsSignal.UID; #endif var signalShape = Path.GetFileName(path).ToUpper(); if (!viewer.SIGCFG.SignalShapes.ContainsKey(signalShape)) { Trace.TraceWarning("{0} signal {1} has invalid shape {2}.", WorldPosition.ToString(), mstsSignal.UiD, signalShape); return; } var mstsSignalShape = viewer.SIGCFG.SignalShapes[signalShape]; #if DEBUG_SIGNAL_SHAPES Console.WriteLine(" Shape={0} SubObjs={1,-2} {2}", Path.GetFileNameWithoutExtension(path).ToUpper(), mstsSignalShape.SignalSubObjs.Count, mstsSignalShape.Description); #endif // The matrix names are used as the sub-object names. The sub-object visibility comes from // mstsSignal.SignalSubObj, which is mapped to names through mstsSignalShape.SignalSubObjs. var visibleMatrixNames = new bool[SharedShape.MatrixNames.Count]; for (var i = 0; i < mstsSignalShape.SignalSubObjs.Count; i++) { if ((((mstsSignal.SignalSubObject >> i) & 0x1) == 1) && (SharedShape.MatrixNames.Contains(mstsSignalShape.SignalSubObjs[i].MatrixName))) { visibleMatrixNames[SharedShape.MatrixNames.IndexOf(mstsSignalShape.SignalSubObjs[i].MatrixName)] = true; } } // All sub-objects except the one pointing to the first matrix (99.00% times it is the first one, but not always, see Protrain) are hidden by default. //For each other sub-object, look up its name in the hierarchy and use the visibility of that matrix. visibleMatrixNames[0] = true; SubObjVisible = new bool[SharedShape.LodControls[0].DistanceLevels[0].SubObjects.Length]; SubObjVisible[0] = true; for (var i = 1; i < SharedShape.LodControls[0].DistanceLevels[0].SubObjects.Length; i++) { if (i == SharedShape.RootSubObjectIndex) { SubObjVisible[i] = true; } else { var subObj = SharedShape.LodControls[0].DistanceLevels[0].SubObjects[i]; int minHiLevIndex = 0; if (subObj.ShapePrimitives[0].Hierarchy[subObj.ShapePrimitives[0].HierarchyIndex] > 0) // Search for ShapePrimitive with lowest Hierarchy Value and check visibility with it { var minHiLev = 999; for (var j = 0; j < subObj.ShapePrimitives.Length; j++) { if (subObj.ShapePrimitives[0].Hierarchy[subObj.ShapePrimitives[j].HierarchyIndex] < minHiLev) { minHiLevIndex = j; minHiLev = subObj.ShapePrimitives[0].Hierarchy[subObj.ShapePrimitives[j].HierarchyIndex]; } } } SubObjVisible[i] = visibleMatrixNames[SharedShape.LodControls[0].DistanceLevels[0].SubObjects[i].ShapePrimitives[minHiLevIndex].HierarchyIndex]; } } #if DEBUG_SIGNAL_SHAPES for (var i = 0; i < mstsSignalShape.SignalSubObjs.Count; i++) { Console.WriteLine(" SUBOBJ {1,-12} {0,-7} {2,3} {3,3} {4,2} {5,2} {6,-14} {8} ({7})", ((mstsSignal.SignalSubObj >> i) & 0x1) != 0 ? "VISIBLE" : "hidden", mstsSignalShape.SignalSubObjs[i].MatrixName, mstsSignalShape.SignalSubObjs[i].Optional ? "Opt" : "", mstsSignalShape.SignalSubObjs[i].Default ? "Def" : "", mstsSignalShape.SignalSubObjs[i].JunctionLink ? "JL" : "", mstsSignalShape.SignalSubObjs[i].BackFacing ? "BF" : "", mstsSignalShape.SignalSubObjs[i].SignalSubType == -1 ? "<none>" : MSTS.SignalShape.SignalSubObj.SignalSubTypes[mstsSignalShape.SignalSubObjs[i].SignalSubType], mstsSignalShape.SignalSubObjs[i].SignalSubSignalType, mstsSignalShape.SignalSubObjs[i].Description); } for (var i = 0; i < SubObjVisible.Length; i++) { Console.WriteLine(" SUBOBJ {0,-2} {1,-7}", i, SubObjVisible[i] ? "VISIBLE" : "hidden"); } #endif if (mstsSignal.SignalUnits == null) { Trace.TraceWarning("{0} signal {1} has no SignalUnits.", WorldPosition.ToString(), mstsSignal.UiD); return; } for (var i = 0; i < mstsSignal.SignalUnits.Count; i++) { #if DEBUG_SIGNAL_SHAPES Console.Write(" UNIT {0}: TrItem={1,-5} SubObj={2,-2}", i, mstsSignal.SignalUnits.Units[i].TrItem, mstsSignal.SignalUnits.Units[i].SubObj); #endif // Find the simulation SignalObject for this shape. var signalAndHead = viewer.Simulator.Signals.FindByTrItem(mstsSignal.SignalUnits[i].TrackItem); if (!signalAndHead.HasValue) { Trace.TraceWarning("Skipped {0} signal {1} unit {2} with invalid TrItem {3}", WorldPosition.ToString(), mstsSignal.UiD, i, mstsSignal.SignalUnits[i].TrackItem); continue; } // Get the signal sub-object for this unit (head). var mstsSignalSubObj = mstsSignalShape.SignalSubObjs[mstsSignal.SignalUnits[i].SubObject]; if (mstsSignalSubObj.SignalSubType != SignalSubType.Signal_Head) // SIGNAL_HEAD { Trace.TraceWarning("Skipped {0} signal {1} unit {2} with invalid SubObj {3}", WorldPosition.ToString(), mstsSignal.UiD, i, mstsSignal.SignalUnits[i].SubObject); continue; } var mstsSignalItem = (SignalItem)(viewer.Simulator.TDB.TrackDB.TrackItems[mstsSignal.SignalUnits[i].TrackItem]); try { // Go create the shape head. Heads.Add(new SignalShapeHead(viewer, this, i, signalAndHead.Value.Value, mstsSignalItem, mstsSignalSubObj)); } catch (InvalidDataException error) { Trace.TraceWarning(error.Message); } #if DEBUG_SIGNAL_SHAPES Console.WriteLine(); #endif } }
public UpdateLabelPosition(IWorldPosition targetRenderer, SceneObject obj = null) : base(obj) { this.TargetRenderer = targetRenderer; }