-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavNode.cs
116 lines (96 loc) · 3.75 KB
/
NavNode.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Copyright (C) 2017 G. Michael Barnes
The file NavNode.cs is part of AGMGSKv8 a port and update of AGXNASKv7 from
MonoGames 3.4 to MonoGames 3.5
AGMGSKv8 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#region Using Statements
using System;
using System.IO; // needed for trace()'s fout
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion
namespace AGMGSKv8 {
/// <summary>
/// A WayPoint or Marker to be used in path following or path finding.
/// Four types of WAYPOINT:
/// <list type="number"> WAYPOINT, a navigatable terrain vertex </list>
/// <list type="number"> PATH, a node in a path (could be the result of A*) </list>
/// <list type="number"> OPEN, a possible node to follow in an A*path</list>
/// <list type="number"> CLOSED, a node that has been evaluated by A* </list>
///
/// 2/14/2012 last update
/// </summary>
public class NavNode : IComparable<NavNode> {
public enum NavNodeEnum { WAYPOINT, PATH, OPEN, CLOSED };
private double distance; // can be used with A* path finding.
private Vector3 translation;
private NavNodeEnum navigatable;
private Vector3 nodeColor;
// constructors
/// <summary>
/// Make a VERTEX NavNode
/// </summary>
/// <param name="pos"> location of WAYPOINT</param>
public NavNode(Vector3 pos) {
translation = pos;
Navigatable = NavNodeEnum.WAYPOINT;
}
/// <summary>
/// Make a WAYPOINT and set its Navigational type
/// </summary>
/// <param name="pos"> location of WAYPOINT</param>
/// <param name="nType"> Navigational type {VERTEX, WAYPOINT, A_STAR, PATH} </param>
public NavNode(Vector3 pos, NavNodeEnum nType) {
translation = pos;
Navigatable = nType;
}
// properties
public Vector3 NodeColor {
get { return nodeColor; }}
public Double Distance {
get { return distance; }
set { distance = value; }
}
/// <summary>
/// When changing the Navigatable type the WAYPOINT's nodeColor is
/// also updated.
/// </summary>
public NavNodeEnum Navigatable {
get { return navigatable; }
set { navigatable = value;
switch (navigatable) {
case NavNodeEnum.WAYPOINT : nodeColor = Color.Yellow.ToVector3(); break; // yellow
case NavNodeEnum.PATH : nodeColor = Color.Blue.ToVector3(); break; // blue
case NavNodeEnum.OPEN : nodeColor = Color.White.ToVector3(); break; // white
case NavNodeEnum.CLOSED : nodeColor = Color.Red.ToVector3(); break; // red
}
}}
public Vector3 Translation {
get { return translation; }
}
// methods
/// <summary>
/// Useful in A* path finding
/// when inserting into an min priority queue open set ordered on distance
/// </summary>
/// <param name="n"> goal node </param>
/// <returns> usual comparison values: -1, 0, 1 </returns>
public int CompareTo(NavNode n) {
if (distance < n.Distance) return -1;
else if (distance > n.Distance) return 1;
else return 0;
}
}
}