Merge commit 'c5dc3b6bf5b8f39e91df49bdfb16fc9d68518679'
This commit is contained in:
commit
d96cf9fdb2
@ -1,4 +1,4 @@
|
|||||||
using Vector3 = UnityEngine.Vector3;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Passer.LinearAlgebra {
|
namespace Passer.LinearAlgebra {
|
||||||
public class Spherical {
|
public class Spherical {
|
||||||
@ -6,6 +6,7 @@ namespace Passer.LinearAlgebra {
|
|||||||
public Direction direction;
|
public Direction direction;
|
||||||
|
|
||||||
public static Spherical zero = new(0, 0, 0);
|
public static Spherical zero = new(0, 0, 0);
|
||||||
|
public static Spherical forward = new(1, 0, 0);
|
||||||
|
|
||||||
public Spherical(float distance, float horizontal, float vertical) {
|
public Spherical(float distance, float horizontal, float vertical) {
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
@ -16,6 +17,17 @@ namespace Passer.LinearAlgebra {
|
|||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Spherical FromVector3(Vector3 v) {
|
||||||
|
float distance = v.magnitude;
|
||||||
|
if (distance == 0.0f)
|
||||||
|
return new Spherical(distance, 0, 0);
|
||||||
|
else {
|
||||||
|
float verticalAngle = (Mathf.PI / 2 - Mathf.Acos(v.y / distance)) * Mathf.Rad2Deg;
|
||||||
|
float horizontalAngle = Mathf.Atan2(v.x, v.z) * Mathf.Rad2Deg;
|
||||||
|
return new Spherical(distance, horizontalAngle, verticalAngle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Vector3 ToVector3() {
|
public Vector3 ToVector3() {
|
||||||
float verticalRad = (UnityEngine.Mathf.PI / 2) - this.direction.vertical * UnityEngine.Mathf.Deg2Rad;
|
float verticalRad = (UnityEngine.Mathf.PI / 2) - this.direction.vertical * UnityEngine.Mathf.Deg2Rad;
|
||||||
float horizontalRad = this.direction.horizontal * UnityEngine.Mathf.Deg2Rad;
|
float horizontalRad = this.direction.horizontal * UnityEngine.Mathf.Deg2Rad;
|
||||||
@ -30,7 +42,6 @@ namespace Passer.LinearAlgebra {
|
|||||||
|
|
||||||
Vector3 v = new Vector3(x, y, z);
|
Vector3 v = new Vector3(x, y, z);
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -134,8 +134,10 @@ namespace Passer.Control.Core {
|
|||||||
this.nextPublishMe = currentTimeMS + this.publishInterval;
|
this.nextPublishMe = currentTimeMS + this.publishInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Thing thing in this.things) {
|
int n = this.things.Count;
|
||||||
if (thing != null && thing.parent == null) // update only root things
|
for (int ix = 0; ix < n; ix++) {
|
||||||
|
Thing thing = this.things[ix];
|
||||||
|
if (thing != null) // && thing.parent == null) // update only root things
|
||||||
thing.Update(currentTimeMS);
|
thing.Update(currentTimeMS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,17 +27,22 @@ namespace Passer.Control.Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void Add(Thing thing, bool invokeEvent = true) {
|
public void Add(Thing thing, bool invokeEvent = true) {
|
||||||
//Console.WriteLine($"added thing [{thing.networkId}/{thing.id}]");
|
Console.WriteLine($"added thing [{thing.networkId}/{thing.id}]");
|
||||||
Thing foundThing = Get(thing.networkId, thing.id);
|
Thing foundThing = Get(thing.networkId, thing.id);
|
||||||
|
|
||||||
if (foundThing == null) {
|
if (foundThing == null) {
|
||||||
// if (thing.id == 0)
|
|
||||||
// thing.id = (byte)(things.Count + 1);
|
|
||||||
things.Add(thing);
|
things.Add(thing);
|
||||||
|
|
||||||
if (invokeEvent)
|
if (invokeEvent)
|
||||||
Thing.InvokeNewThing(thing);
|
Thing.InvokeNewThing(thing);
|
||||||
// Console.Write($"Add thing {ipAddress}:{port}[{networkId}/{thing.id}]");
|
// Console.Write($"Add thing {ipAddress}:{port}[{networkId}/{thing.id}]");
|
||||||
|
} else {
|
||||||
|
if (thing != foundThing) {
|
||||||
|
// should be: find first non-existing id...
|
||||||
|
thing.id = (byte)this.things.Count;
|
||||||
|
things.Add(thing);
|
||||||
|
Console.Write($"Add thing, updated thing id to [{thing.networkId}/{thing.id}]");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
Thing.cs
2
Thing.cs
@ -7,6 +7,7 @@ namespace Passer.Control.Core {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A thing is the basic building block
|
/// A thing is the basic building block
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
public class Thing {
|
public class Thing {
|
||||||
|
|
||||||
#region Types
|
#region Types
|
||||||
@ -126,6 +127,7 @@ namespace Passer.Control.Core {
|
|||||||
public Spherical angularVelocity;
|
public Spherical angularVelocity;
|
||||||
|
|
||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
|
[NonSerialized]
|
||||||
public Unity.Thing component;
|
public Unity.Thing component;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ namespace Passer.Control.Unity {
|
|||||||
public class DistanceSensor : Thing {
|
public class DistanceSensor : Thing {
|
||||||
|
|
||||||
public new Core.DistanceSensor core {
|
public new Core.DistanceSensor core {
|
||||||
get => (Core.DistanceSensor)base.core;
|
get => (Core.DistanceSensor)base.core;
|
||||||
set => base.core = value;
|
set => base.core = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,19 +22,23 @@ namespace Passer.Control.Unity {
|
|||||||
GameObject distanceObj = new("Distance sensor");
|
GameObject distanceObj = new("Distance sensor");
|
||||||
DistanceSensor component = distanceObj.AddComponent<DistanceSensor>();
|
DistanceSensor component = distanceObj.AddComponent<DistanceSensor>();
|
||||||
if (parent != null && parent.component != null)
|
if (parent != null && parent.component != null)
|
||||||
distanceObj.transform.SetParent(parent.component.transform);
|
distanceObj.transform.SetParent(parent.component.transform, false);
|
||||||
|
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator MeasureDistance() {
|
IEnumerator MeasureDistance() {
|
||||||
while (Application.isPlaying) {
|
while (Application.isPlaying) {
|
||||||
if (Physics.Raycast(this.transform.position, this.transform.forward, out RaycastHit hitInfo, 10.0f)) {
|
if (Physics.Raycast(this.transform.position, this.transform.forward, out RaycastHit hitInfo, 2.0f)) {
|
||||||
core.distance = hitInfo.distance;
|
Thing thing = hitInfo.transform.GetComponentInParent<Thing>();
|
||||||
|
if (thing == null) {
|
||||||
// send distance to...
|
Debug.Log($"collision {hitInfo.transform.name} {hitInfo.distance}");
|
||||||
yield return new WaitForSeconds(1);
|
core.distance = hitInfo.distance;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
core.distance = 0;
|
||||||
}
|
}
|
||||||
|
yield return new WaitForSeconds(0.1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ namespace Passer.Control.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void HandleNewThing(Core.Thing thing) {
|
public void HandleNewThing(Core.Thing thing) {
|
||||||
|
site.Add(thing, false);
|
||||||
thingQueue.Enqueue(thing);
|
thingQueue.Enqueue(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +32,6 @@ namespace Passer.Control.Unity {
|
|||||||
thing.CreateComponent();
|
thing.CreateComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ namespace Passer.Control.Unity {
|
|||||||
|
|
||||||
public class Thing : MonoBehaviour {
|
public class Thing : MonoBehaviour {
|
||||||
|
|
||||||
|
[field: SerializeField]
|
||||||
public Core.Thing core {get; set; }
|
public Core.Thing core {get; set; }
|
||||||
|
|
||||||
protected void SetCoreThing(Core.Thing thing) {
|
protected void SetCoreThing(Core.Thing thing) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user