1 using Microsoft.Xna.Framework;
3 using System.Globalization;
20 private readonly
float[] receivedSignal =
new float[2];
21 private readonly
float[] timeSinceReceived =
new float[2];
49 for (
int i = 0; i < 2; i++)
51 timeSinceReceived[i] += deltaTime;
52 if (timeSinceReceived[i] > 0.1f)
54 receivedSignal[i] =
float.NaN;
57 if (!
float.IsNaN(receivedSignal[0]) && !
float.IsNaN(receivedSignal[1]))
59 float angle = (float)Math.Atan2(receivedSignal[1], receivedSignal[0]);
60 if (!
UseRadians) { angle = MathHelper.ToDegrees(angle); }
68 float.TryParse(signal.
value, NumberStyles.Float, CultureInfo.InvariantCulture, out
float value);
69 bool sendOutputImmediately =
true;
74 if (!
UseRadians) { value = MathHelper.ToRadians(value); }
75 value = MathF.Sin(value);
78 if (!
UseRadians) { value = MathHelper.ToRadians(value); }
79 value = MathF.Cos(value);
82 if (!
UseRadians) { value = MathHelper.ToRadians(value); }
84 if (!MathUtils.NearlyEqual(value % MathHelper.Pi, MathHelper.PiOver2))
86 value = MathF.Tan(value);
91 if (value >= -1.0f && value <= 1.0f)
93 float angle = MathF.Asin(value);
94 if (!
UseRadians) { angle = MathHelper.ToDegrees(angle); }
100 if (value >= -1.0f && value <= 1.0f)
102 float angle = MathF.Acos(value);
103 if (!
UseRadians) { angle = MathHelper.ToDegrees(angle); }
108 if (connection.
Name ==
"signal_in_x")
110 timeSinceReceived[0] = 0.0f;
111 float.TryParse(signal.
value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[0]);
112 sendOutputImmediately =
false;
114 else if (connection.
Name ==
"signal_in_y")
116 timeSinceReceived[1] = 0.0f;
117 float.TryParse(signal.
value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[1]);
118 sendOutputImmediately =
false;
122 float angle = MathF.Atan(value);
123 if (!
UseRadians) { angle = MathHelper.ToDegrees(angle); }
128 throw new NotImplementedException($
"Function {Function} has not been implemented.");
130 if (sendOutputImmediately)
132 signal.
value = value.ToString(
"G", CultureInfo.InvariantCulture);
void SendSignal(string signal, string connectionName)
The base class for components holding the different functionalities of the item
override void ReceiveSignal(Signal signal, Connection connection)
override void Update(float deltaTime, Camera cam)
TrigonometricFunctionComponent(Item item, ContentXElement element)