Skip to content

Commit

Permalink
Math Nodes Constants and randoms
Browse files Browse the repository at this point in the history
ProtoFlux/Math/Constants/EpsilonDouble.cs
ProtoFlux/Math/Constants/EpsilonFloat.cs
ProtoFlux/Math/Random/RandomInt2.cs
ProtoFlux/Math/Random/RandomBool2.cs
ProtoFlux/Math/Random/RandomBool3.cs
ProtoFlux/Math/Random/RandomDouble.cs
ProtoFlux/Math/Random/RandomEulerAngles.cs
ProtoFlux/Math/Random/RandomBool4.cs
ProtoFlux/Math/Random/RandomCharacter.cs
  • Loading branch information
Xlinka authored Apr 17, 2024
2 parents 86a4e4e + 2963861 commit 117c4ef
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ProtoFlux/Math/Constants/EpsilonDouble.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Elements.Core;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

[NodeCategory("LogiX/NeosPlus/Math/Constants")]
[NodeName("Epsilon Double")]
public class EpsilonDouble : ValueFunctionNode<ExecutionContext, double>
{
protected override double Compute(ExecutionContext context)
{
return MathX.DOUBLE_EPSILON;
}
}
13 changes: 13 additions & 0 deletions ProtoFlux/Math/Constants/EpsilonFloat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Elements.Core;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

[NodeCategory("Protoflux/Obsidian/Math/Constants")]
[NodeName("Epsilon Float")]
public class EpsilonFloat : ValueFunctionNode<ExecutionContext, float>
{
protected override float Compute(ExecutionContext context)
{
return MathX.FLOAT_EPSILON;
}
}
23 changes: 23 additions & 0 deletions ProtoFlux/Math/Random/RandomBool2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using Elements.Core;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;
using ProtoFlux.Runtimes.Execution.Nodes.Actions;

[NodeCategory("ProtoFlux/Obsidian/Math/Random")]
[ContinuouslyChanging]

public class RandomBool2 : ObjectFunctionNode<ExecutionContext, bool2>
{
public ValueInput<float2> Chance;

protected override bool2 Compute(ExecutionContext context)
{
float2 chance = Chance.Evaluate(context);
bool2 result = new bool2(
RandomX.Chance(chance.x),
RandomX.Chance(chance.y)
);
return result;
}
}
19 changes: 19 additions & 0 deletions ProtoFlux/Math/Random/RandomBool3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Elements.Core;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;
using ProtoFlux.Runtimes.Execution.Nodes.Actions;
using FrooxEngine;

[NodeCategory("ProtoFlux/Obsidian/Math/Random")]
[NodeName("Random Bool3")]
[ContinuouslyChanging]
public class RandomBool3 : ValueFunctionNode<ExecutionContext, bool3>
{
public ValueInput<float3> Chance;

protected override bool3 Compute(ExecutionContext context)
{
var chance = Chance.Evaluate(context);
return new bool3(RandomX.Chance(chance.x), RandomX.Chance(chance.y), RandomX.Chance(chance.z));
}
}
24 changes: 24 additions & 0 deletions ProtoFlux/Math/Random/RandomBool4.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Elements.Core;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;
using ProtoFlux.Runtimes.Execution.Nodes.Actions;
using FrooxEngine;

[NodeCategory("ProtoFlux/Obsidian/Math/Random")]
[NodeName("Random Bool4")]
[ContinuouslyChanging]
public class RandomBool4 : ValueFunctionNode<ExecutionContext, bool4>
{
public ValueInput<float4> Chance;

protected override bool4 Compute(ExecutionContext context)
{
var chance = Chance.Evaluate(context);
return new bool4(
RandomX.Chance(chance.x),
RandomX.Chance(chance.y),
RandomX.Chance(chance.z),
RandomX.Chance(chance.w)
);
}
}
22 changes: 22 additions & 0 deletions ProtoFlux/Math/Random/RandomCharacter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Elements.Core;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;
using ProtoFlux.Runtimes.Execution.Nodes.Actions;

[NodeCategory("ProtoFlux/Obsidian/Math/Random")]
[NodeName("Random Character")]
[ContinuouslyChanging]
public class RandomCharacter : ValueFunctionNode<ExecutionContext, char>
{
public ValueInput<int> Start;
public ValueInput<int> End;
public ObjectInput<string> String;

protected override char Compute(ExecutionContext context)
{
var str = String.Evaluate(context);
var start = MathX.Clamp(Start.Evaluate(context), 0, str.Length);
var end = MathX.Clamp(End.Evaluate(context,str.Length), start, str.Length);
return str[RandomX.Range(start, end)];
}
}
28 changes: 28 additions & 0 deletions ProtoFlux/Math/Random/RandomDouble.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Elements.Core;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;
using ProtoFlux.Runtimes.Execution.Nodes.Actions;

[NodeCategory("ProtoFlux/Obsidian/Math/Random")]
[NodeName("Random Double")]
[ContinuouslyChanging]
public class RandomDouble : ValueFunctionNode<ExecutionContext, double>
{
public ValueInput<double> Min;
public ValueInput<double> Max;

protected override double Compute(ExecutionContext context)
{
var min = Min.Evaluate(context);
var max = Max.Evaluate(context);
if (min > max)
{
var num1 = max;
var num2 = min;
min = num1;
max = num2;
}

return min + RandomX.Double * (max - min);
}
}
27 changes: 27 additions & 0 deletions ProtoFlux/Math/Random/RandomEulerAngles.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Elements.Core;
using FrooxEngine;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

[NodeCategory("ProtoFlux/Obsidian/Math/Random")]
[NodeName("Random Euler Angles")]
[ContinuouslyChanging]

public class RandomEulerAngles : ValueFunctionNode<ExecutionContext, float3>
{
public ValueInput<float> minPitch;
public ValueInput<float> maxPitch;
public ValueInput<float> minYaw;
public ValueInput<float> maxYaw;
public ValueInput<float> minRoll;
public ValueInput<float> maxRoll;

protected override float3 Compute(ExecutionContext context)
{
float pitch = RandomX.Range(minPitch.Evaluate(context), maxPitch.Evaluate(context));
float yaw = RandomX.Range(minYaw.Evaluate(context), maxYaw.Evaluate(context));
float roll = RandomX.Range(minRoll.Evaluate(context), maxRoll.Evaluate(context));

return new float3(pitch, yaw, roll);
}
}
19 changes: 19 additions & 0 deletions ProtoFlux/Math/Random/RandomInt2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Elements.Core;
using ProtoFlux.Core;
using ProtoFlux.Runtimes.Execution;

[NodeCategory("ProtoFlux/Obsidian/Math/Random")]
[NodeName("Random Int2")]
public class RandomInt2 : ValueFunctionNode<ExecutionContext, int2>
{
public ValueInput<int2> Min;
public ValueInput<int2> Max;

protected override int2 Compute(ExecutionContext context)
{
int2 min = Min.Evaluate(context,int2.Zero);
int2 max = Max.Evaluate(context,int2.One);

return new int2(RandomX.Range(min.x, max.x), RandomX.Range(min.y, max.y));
}
}

0 comments on commit 117c4ef

Please sign in to comment.