From 933a2932d3f07b7a471675b34fb64ca11cae4cc7 Mon Sep 17 00:00:00 2001 From: xLinka Date: Wed, 13 Sep 2023 18:34:20 +0100 Subject: [PATCH] Physics Nodes CentipetalForce Drag Kinectic Friction Refraction --- .../Math/Physics/CentripetalForceNode.cs | 12 +++++++ NEOSPlus/Logix/Math/Physics/DragNode.cs | 27 ++++++++++++++++ .../Logix/Math/Physics/KineticFrictionNode.cs | 23 +++++++++++++ NEOSPlus/Logix/Math/Physics/Refractions.cs | 32 +++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 NEOSPlus/Logix/Math/Physics/CentripetalForceNode.cs create mode 100644 NEOSPlus/Logix/Math/Physics/DragNode.cs create mode 100644 NEOSPlus/Logix/Math/Physics/KineticFrictionNode.cs create mode 100644 NEOSPlus/Logix/Math/Physics/Refractions.cs diff --git a/NEOSPlus/Logix/Math/Physics/CentripetalForceNode.cs b/NEOSPlus/Logix/Math/Physics/CentripetalForceNode.cs new file mode 100644 index 0000000..9b82e75 --- /dev/null +++ b/NEOSPlus/Logix/Math/Physics/CentripetalForceNode.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NEOSPlus.Logix.Math.Physics +{ + internal class FileName + { + } +} diff --git a/NEOSPlus/Logix/Math/Physics/DragNode.cs b/NEOSPlus/Logix/Math/Physics/DragNode.cs new file mode 100644 index 0000000..aeaec07 --- /dev/null +++ b/NEOSPlus/Logix/Math/Physics/DragNode.cs @@ -0,0 +1,27 @@ +using System; +using BaseX; + +namespace FrooxEngine.LogiX.Math; + +[NodeName("Drag Calculation")] +[Category(new string[] { "LogiX/Math/Physics" })] +internal class DragNode : LogixNode +{ + public readonly Input FluidDensity; // rho + public readonly Input ObjectVelocity; // v + public readonly Input DragCoefficient; // Cd + public readonly Input CrossSectionalArea; // A + + public readonly Output DragForce; + + protected override void OnEvaluate() + { + float rho = FluidDensity.EvaluateRaw(); + float3 v = ObjectVelocity.EvaluateRaw(); + float Cd = DragCoefficient.EvaluateRaw(); + float A = CrossSectionalArea.EvaluateRaw(); + + float3 dragForce = 0.5f * rho * v * v * Cd * A; // Calculate the drag force + DragForce.Value = -dragForce; // Drag acts in the opposite direction of motion + } +} diff --git a/NEOSPlus/Logix/Math/Physics/KineticFrictionNode.cs b/NEOSPlus/Logix/Math/Physics/KineticFrictionNode.cs new file mode 100644 index 0000000..5c3b389 --- /dev/null +++ b/NEOSPlus/Logix/Math/Physics/KineticFrictionNode.cs @@ -0,0 +1,23 @@ +using System; +using BaseX; + +namespace FrooxEngine.LogiX.Math; + +[NodeName("Kinetic Friction Calculation")] +[Category(new string[] { "LogiX/Math/Physics" })] +internal class KineticFrictionNode : LogixNode +{ + public readonly Input NormalForce; // Assuming it's a 3D force, change as needed + public readonly Input KineticFrictionCoefficient; + + public readonly Output KineticFrictionalForce; + + protected override void OnEvaluate() + { + float3 normal = NormalForce.EvaluateRaw(); + float coefficient = KineticFrictionCoefficient.EvaluateRaw(0f); // Default to 0 if not provided + + // Kinetic friction formula: f_kinetic = mu_kinetic * N + KineticFrictionalForce.Value = coefficient * normal; + } +} diff --git a/NEOSPlus/Logix/Math/Physics/Refractions.cs b/NEOSPlus/Logix/Math/Physics/Refractions.cs new file mode 100644 index 0000000..2e00d4f --- /dev/null +++ b/NEOSPlus/Logix/Math/Physics/Refractions.cs @@ -0,0 +1,32 @@ +using System; +using BaseX; + +namespace FrooxEngine.LogiX.Math; + +[NodeName("Refraction Calculation")] +[Category(new string[] { "LogiX/Math/Physics" })] +internal class RefractionNode : LogixNode +{ + public readonly Input RefractiveIndex1; // Refractive index of medium 1 + public readonly Input RefractiveIndex2; // Refractive index of medium 2 + public readonly Input AngleOfIncidence; // Angle of incidence in degrees + + public readonly Output AngleOfRefraction; // Angle of refraction in degrees + + protected override void OnEvaluate() + { + float n1 = RefractiveIndex1.EvaluateRaw(); + float n2 = RefractiveIndex2.EvaluateRaw(); + float theta1Rad = AngleOfIncidence.EvaluateRaw() * (float)MathX.PI / 180.0f; // Convert angle to radians + // for the love of god why does mathx not have a toradians function + + // Calculate using Snell's Law + float sinTheta2 = n1 * (float)MathX.Sin(theta1Rad) / n2; + + // Ensure value is within [-1, 1] due to numerical inaccuracies + sinTheta2 = MathX.Min(MathX.Max(sinTheta2, -1.0f), 1.0f); + + float theta2Rad = (float)MathX.Asin(sinTheta2); + AngleOfRefraction.Value = theta2Rad * 180.0f / (float)MathX.PI; // Convert angle back to degrees + } +}