Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/LibRender2/Trains/CarSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public CarSection(HostInterface Host, ObjectType Type, bool visibleFromInterior,
Groups[0].Elements = new AnimatedObject[a.Objects.Length];
for (int h = 0; h < a.Objects.Length; h++)
{
Groups[0].Elements[h] = a.Objects[h].Clone();
Groups[0].Elements[h] = a.Objects[h].Clone() as AnimatedObject;
Groups[0].Elements[h].IsPartOfTrain = true;
currentHost.CreateDynamicObject(ref Groups[0].Elements[h].internalObject);
}
Expand Down
36 changes: 26 additions & 10 deletions source/OpenBveApi/Objects/ObjectTypes/AnimatedObject.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System.IO;
using System.Linq;
using CSScriptLibrary;
using OpenBveApi.FunctionScripting;
using OpenBveApi.Graphics;
using OpenBveApi.Hosts;
using OpenBveApi.Interface;
using OpenBveApi.Math;
using OpenBveApi.Trains;
using OpenBveApi.World;

namespace OpenBveApi.Objects
{
/// <summary>The base type for an animated object</summary>
public class AnimatedObject
public class AnimatedObject : UnifiedObject
{
/// <summary>The array of states</summary>
public ObjectState[] States;
Expand Down Expand Up @@ -109,9 +106,19 @@ public AnimatedObject(HostInterface host)
States = new ObjectState[] { };
}

public override void CreateObject(Vector3 Position, Transformation WorldTransformation, Transformation LocalTransformation, int SectionIndex, double StartingDistance, double EndingDistance, double TrackPosition, double Brightness, bool DuplicateMaterials = false)
{
throw new System.NotImplementedException();
}

public override void OptimizeObject(bool PreserveVerticies, int Threshold, bool VertexCulling)
{
throw new System.NotImplementedException();
}

/// <summary>Clones this object</summary>
/// <returns>The new object</returns>
public AnimatedObject Clone()
public override UnifiedObject Clone()
{
AnimatedObject Result = new AnimatedObject(currentHost) { States = States.Select(x => (ObjectState)x.Clone()).ToArray() };

Expand Down Expand Up @@ -169,6 +176,16 @@ public AnimatedObject Clone()
return Result;
}

public override UnifiedObject Mirror()
{
throw new System.NotImplementedException();
}

public override UnifiedObject Transform(double NearDistance, double FarDistance)
{
throw new System.NotImplementedException();
}

/// <summary>Checks whether this object contains any functions</summary>
public bool IsFreeOfFunctions()
{
Expand Down Expand Up @@ -563,7 +580,7 @@ public void Update(AbstractTrain Train, int CarIndex, double TrackPosition, Vect
t = 1.0;
}

t = t - System.Math.Floor(t);
t -= System.Math.Floor(t);
t = 0.5 * (1.0 - System.Math.Tan(0.25 * (System.Math.PI - 2.0 * System.Math.PI * t)));
double cx = (1.0 - t) * LEDVectors[(currentEdge + 3) % 4].X + t * LEDVectors[currentEdge].X;
double cy = (1.0 - t) * LEDVectors[(currentEdge + 3) % 4].Y + t * LEDVectors[currentEdge].Y;
Expand Down Expand Up @@ -704,10 +721,9 @@ public void Update(AbstractTrain Train, int CarIndex, double TrackPosition, Vect
/// <param name="Position">The absolute position</param>
/// <param name="WorldTransformation">The world transformation to apply (e.g. ground, rail)</param>
/// <param name="LocalTransformation">The local transformation to apply in order to rotate the model</param>
/// <param name="SectionIndex">The index of the section if placed using a SigF command</param>
/// <param name="TrackPosition">The absolute track position</param>
/// <param name="Brightness">The brightness value at the track position</param>
public void CreateObject(Vector3 Position, Transformation WorldTransformation, Transformation LocalTransformation, int SectionIndex, double TrackPosition, double Brightness)
public void CreateObject(Vector3 Position, Transformation WorldTransformation, Transformation LocalTransformation, double TrackPosition, double Brightness)
{

int a = currentHost.AnimatedWorldObjectsUsed;
Expand All @@ -716,7 +732,7 @@ public void CreateObject(Vector3 Position, Transformation WorldTransformation, T
//Place track followers if required
if (TrackFollowerFunction != null)
{
var o = this.Clone();
var o = this.Clone() as AnimatedObject;
currentHost.CreateDynamicObject(ref o.internalObject);
TrackFollowingObject currentObject = new TrackFollowingObject(currentHost)
{
Expand Down Expand Up @@ -761,7 +777,7 @@ public void CreateObject(Vector3 Position, Transformation WorldTransformation, T
}
else
{
var o = this.Clone();
var o = this.Clone() as AnimatedObject;
currentHost.CreateDynamicObject(ref o.internalObject);
AnimatedWorldObject currentObject = new AnimatedWorldObject(currentHost)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public override void CreateObject(Vector3 Position, Transformation WorldTransfor
}
else
{
Objects[i].CreateObject(Position, WorldTransformation, LocalTransformation, SectionIndex, TrackPosition, Brightness);
Objects[i].SectionIndex = SectionIndex;
Objects[i].CreateObject(Position, WorldTransformation, LocalTransformation, TrackPosition, Brightness);
}
}
}
Expand All @@ -82,7 +83,8 @@ public override void CreateObject(Vector3 Position, Transformation WorldTransfor
{
if (Objects[i].States.Length != 0)
{
Objects[i].CreateObject(Position, WorldTransformation, LocalTransformation, SectionIndex, TrackPosition, Brightness);
Objects[i].SectionIndex = SectionIndex;
Objects[i].CreateObject(Position, WorldTransformation, LocalTransformation, TrackPosition, Brightness);
}
}
}
Expand Down Expand Up @@ -123,7 +125,7 @@ public override UnifiedObject Clone()
AnimatedObjectCollection aoc = new AnimatedObjectCollection(currentHost);
if (Objects != null)
{
aoc.Objects = Objects.Select(x => x?.Clone()).ToArray();
aoc.Objects = Objects.Select(x => x?.Clone() as AnimatedObject).ToArray();
}
if (Sounds != null)
{
Expand All @@ -141,7 +143,7 @@ public override UnifiedObject Mirror()
};
for (int i = 0; i < Objects.Length; i++)
{
Result.Objects[i] = Objects[i].Clone();
Result.Objects[i] = Objects[i].Clone() as AnimatedObject;
for (int j = 0; j < Objects[i].States.Length; j++)
{
Result.Objects[i].States[j].Prototype = (StaticObject)Result.Objects[i].States[j].Prototype.Mirror();
Expand Down
2 changes: 1 addition & 1 deletion source/OpenBveApi/Objects/ObjectTypes/WorldObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected WorldObject(Hosts.HostInterface Host)
public virtual WorldObject Clone()
{
WorldObject wo = (WorldObject)MemberwiseClone();
wo.Object = Object?.Clone();
wo.Object = Object?.Clone() as AnimatedObject;

if (wo.Object != null)
{
Expand Down
2 changes: 1 addition & 1 deletion source/Plugins/Object.Animated/Plugin.Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ private static AnimatedObjectCollection ReadObject(string FileName, System.Text.
{
AnimatedWorldObjectStateSound snd = new AnimatedWorldObjectStateSound(currentHost)
{
Object = Result.Objects[ObjectCount - 1].Clone(),
Object = Result.Objects[ObjectCount - 1].Clone() as AnimatedObject,
Buffers = new SoundHandle[fileNames.Length]
};
for (int j = 0; j < fileNames.Length; j++)
Expand Down
2 changes: 1 addition & 1 deletion source/Plugins/Object.LokSim/GroupParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ internal static AnimatedObjectCollection ReadObject(string FileName, System.Text
{
if (AnimatedObject.Objects[o - rl] != null)
{
Result.Objects[o] = AnimatedObject.Objects[o - rl].Clone();
Result.Objects[o] = AnimatedObject.Objects[o - rl].Clone() as AnimatedObject;
for (int si = 0; si < Result.Objects[o].States.Length; si++)
{
Result.Objects[o].States[si].Translation *= Matrix4D.CreateTranslation(CurrentObjects[i].Position.X, CurrentObjects[i].Position.Y, -CurrentObjects[i].Position.Z);
Expand Down
5 changes: 3 additions & 2 deletions source/Plugins/Route.Mechanik/MechanikRouteParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,9 @@ private static void ProcessRoute(bool PreviewOnly)
{
nextHeldAtRed = true;
}

signal.Object().CreateObject(worldPosition + eyePosition, t, Transformation.NullTransformation, s + 1, StartingDistance, 1.0);

signal.Object().SectionIndex = s + 1;
signal.Object().CreateObject(worldPosition + eyePosition, t, Transformation.NullTransformation, StartingDistance, 1.0);
}

if (currentRouteData.Blocks[i].HornBlow)
Expand Down