forked from Nivekk/KOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirection.cs
81 lines (70 loc) · 2.11 KB
/
Direction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace kOS
{
public class Direction : SpecialValue
{
private Vector3d vector;
public Vector3d Vector
{
get { return vector; }
set
{
vector = value; rotation = Quaternion.LookRotation(value); euler = rotation.eulerAngles;
}
}
private Vector3d euler;
public Vector3d Euler
{
get { return euler; }
set
{
euler = value; rotation = Quaternion.Euler(value);
}
}
private Quaternion rotation;
public Quaternion Rotation
{
get { return rotation; }
set { rotation = value; euler = value.eulerAngles; }
}
public Direction()
{
}
public Direction(Quaternion q)
{
rotation = q;
}
public Direction(Vector3d v3d, bool isEuler)
{
if (isEuler)
{
Euler = v3d;
}
else
{
Vector = v3d;
}
}
public override object GetSuffix(string suffixName)
{
if (suffixName == "PITCH") return (float)euler.x;
if (suffixName == "YAW") return (float)euler.y;
if (suffixName == "ROLL") return (float)euler.z;
return base.GetSuffix(suffixName);
}
public void RedefineUp(Vector3d up)
{
}
public static Direction operator *(Direction a, Direction b) { return new Direction(a.Rotation * b.Rotation); }
public static Direction operator +(Direction a, Direction b) { return new Direction(a.Euler + b.Euler, true); }
public static Direction operator -(Direction a, Direction b) { return new Direction(a.Euler - b.Euler, true); }
public override string ToString()
{
return "R(" + Math.Round(euler.x, 3) + "," + Math.Round(euler.y, 3) + "," + Math.Round(euler.z, 3) + ")";
}
}
}