Compare commits

...

5 Commits

3 changed files with 29 additions and 26 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
#if UNITY_5_3_OR_NEWER #if UNITY_5_3_OR_NEWER
using Vector3Float = UnityEngine.Vector3; //using Vector3Float = UnityEngine.Vector3;
using Vector3 = UnityEngine.Vector3;
#endif #endif
namespace LinearAlgebra { namespace LinearAlgebra {
@ -66,16 +67,16 @@ namespace LinearAlgebra {
public readonly static Spherical forward = new(1, Direction.forward); public readonly static Spherical forward = new(1, Direction.forward);
public static Spherical FromVector3Float(Vector3Float v) { // public static Spherical FromVector3Float(Vector3Float v) {
float distance = v.magnitude; // float distance = v.magnitude;
if (distance == 0.0f) // if (distance == 0.0f)
return Spherical.zero; // return Spherical.zero;
else { // else {
float verticalAngle = (float)((Angle.pi / 2 - Math.Acos(v.y / distance)) * Angle.Rad2Deg); // float verticalAngle = (float)((Angle.pi / 2 - Math.Acos(v.y / distance)) * Angle.Rad2Deg);
float horizontalAngle = (float)Math.Atan2(v.x, v.z) * Angle.Rad2Deg; // float horizontalAngle = (float)Math.Atan2(v.x, v.z) * Angle.Rad2Deg;
return Spherical.Degrees(distance, horizontalAngle, verticalAngle); // return Spherical.Degrees(distance, horizontalAngle, verticalAngle);
} // }
} // }
public static Spherical FromVector3(Vector3 v) { public static Spherical FromVector3(Vector3 v) {
float distance = v.magnitude; float distance = v.magnitude;
@ -88,21 +89,21 @@ namespace LinearAlgebra {
} }
} }
public Vector3Float ToVector3Float() { // public Vector3Float ToVector3Float() {
float verticalRad = (Angle.pi / 2) - this.direction.vertical * Angle.Deg2Rad; // float verticalRad = (Angle.pi / 2) - this.direction.vertical * Angle.Deg2Rad;
float horizontalRad = this.direction.horizontal * Angle.Deg2Rad; // float horizontalRad = this.direction.horizontal * Angle.Deg2Rad;
float cosVertical = (float)Math.Cos(verticalRad); // float cosVertical = (float)Math.Cos(verticalRad);
float sinVertical = (float)Math.Sin(verticalRad); // float sinVertical = (float)Math.Sin(verticalRad);
float cosHorizontal = (float)Math.Cos(horizontalRad); // float cosHorizontal = (float)Math.Cos(horizontalRad);
float sinHorizontal = (float)Math.Sin(horizontalRad); // float sinHorizontal = (float)Math.Sin(horizontalRad);
float x = this.distance * sinVertical * sinHorizontal; // float x = this.distance * sinVertical * sinHorizontal;
float y = this.distance * cosVertical; // float y = this.distance * cosVertical;
float z = this.distance * sinVertical * cosHorizontal; // float z = this.distance * sinVertical * cosHorizontal;
Vector3Float v = new(x, y, z); // Vector3Float v = new(x, y, z);
return v; // return v;
} // }
public Vector3 ToVector3() { public Vector3 ToVector3() {
float verticalRad = (Angle.pi / 2) - this.direction.vertical * Angle.Deg2Rad; float verticalRad = (Angle.pi / 2) - this.direction.vertical * Angle.Deg2Rad;

View File

@ -1,3 +1,4 @@
#if !UNITY_5_6_OR_NEWER
using NUnit.Framework; using NUnit.Framework;
namespace LinearAlgebra.Test { namespace LinearAlgebra.Test {
@ -25,4 +26,5 @@ namespace LinearAlgebra.Test {
Assert.AreEqual(v1.distance, r.distance, "Addition(0,0,0)"); Assert.AreEqual(v1.distance, r.distance, "Addition(0,0,0)");
} }
} }
} }
#endif

View File

@ -24,7 +24,7 @@ namespace RoboidControl {
//thisParticipant = participant; //thisParticipant = participant;
} }
public TouchSensor(Thing parent) : base(parent) { } public TouchSensor(Thing parent, bool invokeEvent = true) : base(parent, (byte)Type.TouchSensor, invokeEvent) { }
public ParticipantUDP thisParticipant; public ParticipantUDP thisParticipant;