-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoords.cs
More file actions
85 lines (71 loc) · 2.45 KB
/
Coords.cs
File metadata and controls
85 lines (71 loc) · 2.45 KB
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
82
83
84
85
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Coords
{
public float x;
public float y;
public float z;
public Coords(float _X, float _Y)
{
x = _X;
y = _Y;
z = -1;
}
public Coords(float _X, float _Y, float _Z)
{
x = _X;
y = _Y;
z = _Z;
}
public Coords(Vector3 vecpos)
{
x = vecpos.x;
y = vecpos.y;
z = vecpos.z;
}
public override string ToString()
{
return "(" + x + "," + y + "," + z + ")";
}
public Vector3 ToVector()
{
return new Vector3(x, y, z);
}
static public Coords operator +(Coords a, Coords b)
{
return new Coords(a.x + b.x, a.y + b.y, a.z + b.z);
}
static public Coords operator -(Coords a, Coords b)
{
return new Coords(a.x - b.x, a.y - b.y, a.z - b.z);
}
static public void DrawLine(Coords startPoint, Coords endPoint, float width, Color colour)
{
GameObject line = new GameObject("Line_" + startPoint.ToString() + "_" + endPoint.ToString());
LineRenderer lineRenderer = line.AddComponent<LineRenderer>();
lineRenderer.material = new Material(Shader.Find("Unlit/Color"));
lineRenderer.material.color = colour;
lineRenderer.positionCount = 2;
lineRenderer.SetPosition(0, new Vector3(startPoint.x, startPoint.y, startPoint.z));
lineRenderer.SetPosition(1, new Vector3(endPoint.x, endPoint.y, endPoint.z));
lineRenderer.startWidth = width;
lineRenderer.endWidth = width;
}
static public Coords Perp(Coords v)
{
return new Coords(-v.y, v.x);
}
static public void DrawPoint(Coords position, float width, Color colour)
{
GameObject line = new GameObject("Point_" + position.ToString());
LineRenderer lineRenderer = line.AddComponent<LineRenderer>();
lineRenderer.material = new Material(Shader.Find("Unlit/Color"));
lineRenderer.material.color = colour;
lineRenderer.positionCount = 2;
lineRenderer.SetPosition(0, new Vector3(position.x - width / 3.0f, position.y - width / 3.0f, position.z));
lineRenderer.SetPosition(1, new Vector3(position.x + width / 3.0f, position.y + width / 3.0f, position.z));
lineRenderer.startWidth = width;
lineRenderer.endWidth = width;
}
}