Fix Direction.ToVector3
This commit is contained in:
parent
c86b01ae57
commit
bb39435892
@ -56,6 +56,10 @@ namespace LinearAlgebra {
|
|||||||
|
|
||||||
public readonly float inRevolutions => this.value / 360.0f;
|
public readonly float inRevolutions => this.value / 360.0f;
|
||||||
|
|
||||||
|
public override string ToString() {
|
||||||
|
return $"{this.inDegrees} deg.";
|
||||||
|
}
|
||||||
|
|
||||||
public static readonly AngleFloat zero = Degrees(0);
|
public static readonly AngleFloat zero = Degrees(0);
|
||||||
public static readonly AngleFloat deg90 = Degrees(90);
|
public static readonly AngleFloat deg90 = Degrees(90);
|
||||||
public static readonly AngleFloat deg180 = Degrees(180);
|
public static readonly AngleFloat deg180 = Degrees(180);
|
||||||
|
|||||||
@ -66,6 +66,10 @@ namespace LinearAlgebra {
|
|||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override readonly string ToString() {
|
||||||
|
return $"Direction(h: {this.horizontal}, v: {this.vertical})";
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A forward direction with zero for both angles
|
/// A forward direction with zero for both angles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -107,10 +111,17 @@ namespace LinearAlgebra {
|
|||||||
/// Convert the direction into a carthesian vector
|
/// Convert the direction into a carthesian vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The carthesian vector corresponding to this direction.</returns>
|
/// <returns>The carthesian vector corresponding to this direction.</returns>
|
||||||
public UnityEngine.Vector3 ToVector3() {
|
public readonly UnityEngine.Vector3 ToVector3() {
|
||||||
UnityEngine.Quaternion q = UnityEngine.Quaternion.Euler(90 - this.vertical.inDegrees, this.horizontal.inDegrees, 0);
|
// Convert degrees to radians
|
||||||
UnityEngine.Vector3 v = q * UnityEngine.Vector3.forward;
|
float radH = this.horizontal.inRadians;
|
||||||
return v;
|
float radV = this.vertical.inRadians;
|
||||||
|
|
||||||
|
// Calculate Vector
|
||||||
|
float x = MathF.Cos(radV) * MathF.Cos(radH);
|
||||||
|
float y = MathF.Sin(radV);
|
||||||
|
float z = MathF.Cos(radV) * MathF.Sin(radH);
|
||||||
|
|
||||||
|
return new UnityEngine.Vector3(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -132,9 +143,20 @@ namespace LinearAlgebra {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The carthesian vector corresponding to this direction.</returns>
|
/// <returns>The carthesian vector corresponding to this direction.</returns>
|
||||||
public Vector3Float ToVector3() {
|
public Vector3Float ToVector3() {
|
||||||
Quaternion q = Quaternion.Euler(90 - this.vertical.inDegrees, this.horizontal.inDegrees, 0);
|
// Quaternion q = Quaternion.Euler(90 - this.vertical.inDegrees, this.horizontal.inDegrees, 0);
|
||||||
Vector3Float v = q * Vector3Float.forward;
|
// Vector3Float v = q * Vector3Float.forward;
|
||||||
return v;
|
// return v;
|
||||||
|
// Convert degrees to radians
|
||||||
|
float radH = this.horizontal.inRadians;
|
||||||
|
float radV = this.vertical.inRadians;
|
||||||
|
|
||||||
|
// Calculate Vector
|
||||||
|
float x = MathF.Cos(radV) * MathF.Cos(radH);
|
||||||
|
float y = MathF.Sin(radV);
|
||||||
|
float z = MathF.Cos(radV) * MathF.Sin(radH);
|
||||||
|
|
||||||
|
return new Vector3Float(x, y, z);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -83,7 +83,9 @@ public class Neuroid : Nucleus {
|
|||||||
Vector3 direction = synapseNucleus.outputValue.direction.ToVector3();
|
Vector3 direction = synapseNucleus.outputValue.direction.ToVector3();
|
||||||
|
|
||||||
float weight = synapse.weight;
|
float weight = synapse.weight;
|
||||||
float magnitude = weight * curve.Evaluate(synapseNucleus.outputValue.magnitude);
|
float activatedValue = curve.Evaluate(synapseNucleus.outputValue.magnitude);
|
||||||
|
float magnitude = weight * activatedValue;
|
||||||
|
Debug.Log($"{this.name} {synapseNucleus.outputValue.direction} {synapseNucleus.outputValue.direction.horizontal}{synapseNucleus.outputValue.direction.vertical} {direction}");
|
||||||
|
|
||||||
result += direction * magnitude;
|
result += direction * magnitude;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -374,10 +374,10 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::SwarmControl
|
m_EditorClassIdentifier: Assembly-CSharp::SwarmControl
|
||||||
speed: 1
|
speed: 1
|
||||||
inertia: 0.8
|
inertia: 0.9
|
||||||
alignmentForce: 2
|
alignmentForce: 2
|
||||||
cohesionForce: 2
|
cohesionForce: 2
|
||||||
avoidanceForce: 100
|
avoidanceForce: 10
|
||||||
separationDistance: 0.3
|
separationDistance: 0.3
|
||||||
perceptionDistance: 2
|
perceptionDistance: 2
|
||||||
boundaryForce: 5
|
boundaryForce: 5
|
||||||
@ -395,7 +395,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: ec888ca5333d45a438f9f417fa5ce135, type: 3}
|
m_Script: {fileID: 11500000, guid: ec888ca5333d45a438f9f417fa5ce135, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::SwarmSpawn
|
m_EditorClassIdentifier: Assembly-CSharp::SwarmSpawn
|
||||||
count: 100
|
count: 1
|
||||||
boidPrefab: {fileID: 8702527964058765413, guid: f9c706268554ce449a8773675b2864b8, type: 3}
|
boidPrefab: {fileID: 8702527964058765413, guid: f9c706268554ce449a8773675b2864b8, type: 3}
|
||||||
spawnAreaSize: {x: 0.5, y: 0.5, z: 0.5}
|
spawnAreaSize: {x: 0.5, y: 0.5, z: 0.5}
|
||||||
minDelay: 0.05
|
minDelay: 0.05
|
||||||
|
|||||||
@ -9,14 +9,12 @@ public class SwarmControl_Editor : Editor {
|
|||||||
DrawDefaultInspector();
|
DrawDefaultInspector();
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck()) {
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
|
|
||||||
SwarmControl swarmControl = (SwarmControl)target;
|
SwarmControl swarmControl = (SwarmControl)target;
|
||||||
NanoBrainObj[] nanoBrains = FindObjectsByType<NanoBrainObj>(FindObjectsSortMode.None);
|
NanoBrainObj[] nanoBrains = FindObjectsByType<NanoBrainObj>(FindObjectsSortMode.None);
|
||||||
|
|
||||||
foreach (NanoBrainObj brain in nanoBrains) {
|
foreach (NanoBrainObj brain in nanoBrains) {
|
||||||
UpdateWeight(brain, "Avoidance", swarmControl.avoidanceForce);
|
UpdateWeight(brain, "Avoidance", swarmControl.avoidanceForce);
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
Debug.Log("Updated weights");
|
Debug.Log("Updated weights");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user