Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Physics Nodes #163

Merged
merged 1 commit into from
Sep 13, 2023
Merged
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
12 changes: 12 additions & 0 deletions NEOSPlus/Logix/Math/Physics/CentripetalForceNode.cs
Original file line number Diff line number Diff line change
@@ -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
{
}
}
27 changes: 27 additions & 0 deletions NEOSPlus/Logix/Math/Physics/DragNode.cs
Original file line number Diff line number Diff line change
@@ -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<float> FluidDensity; // rho
public readonly Input<float3> ObjectVelocity; // v
public readonly Input<float> DragCoefficient; // Cd
public readonly Input<float> CrossSectionalArea; // A

public readonly Output<float3> 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
}
}
23 changes: 23 additions & 0 deletions NEOSPlus/Logix/Math/Physics/KineticFrictionNode.cs
Original file line number Diff line number Diff line change
@@ -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<float3> NormalForce; // Assuming it's a 3D force, change as needed
public readonly Input<float> KineticFrictionCoefficient;

public readonly Output<float3> 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;
}
}
32 changes: 32 additions & 0 deletions NEOSPlus/Logix/Math/Physics/Refractions.cs
Original file line number Diff line number Diff line change
@@ -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<float> RefractiveIndex1; // Refractive index of medium 1
public readonly Input<float> RefractiveIndex2; // Refractive index of medium 2
public readonly Input<float> AngleOfIncidence; // Angle of incidence in degrees

public readonly Output<float> 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
}
}
Loading