1 package nl.tudelft.pogamut.unreal.agent.module.shooting.util;
2
3 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
4 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
5 import cz.cuni.amis.pogamut.base3d.worldview.object.Rotation;
6 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
7 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
8
9
10
11
12
13
14
15 public class FacingUtil {
16
17
18
19
20
21 public static final double IS_FACING_ANGLE = 6;
22
23
24
25
26
27
28
29
30
31
32
33 public static boolean isFacing(AgentInfo info, ILocated location) {
34 return isFacing(info, location, IS_FACING_ANGLE);
35 }
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 public static boolean isFacing(AgentInfo info, ILocated location, double angle) {
51 if (info == null || location == null)
52 return false;
53
54 return isFacing(info.getLocation(), info.getRotation(), location.getLocation(), angle);
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 public static boolean isFacing(Location origin, Rotation rotation, Location target, double angle) {
73 if (origin == null || rotation == null || target == null)
74 return false;
75
76 Location directionVector = target.sub(origin).getNormalized();
77 Location agentFaceVector = rotation.toLocation().getNormalized();
78
79 if (Math.acos(directionVector.dot(agentFaceVector)) <= Math.toRadians(angle))
80 return true;
81
82 return false;
83
84 }
85
86
87
88
89
90
91
92
93
94
95
96 public static boolean isFacing(Player player, ILocated location) {
97 return isFacing(player, location, IS_FACING_ANGLE);
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 public static boolean isFacing(Player player, ILocated location, double angle) {
114 if (player == null || location == null)
115 return false;
116
117 return isFacing(player.getLocation(), player.getRotation(), location.getLocation(), angle);
118 }
119
120
121
122
123
124
125
126
127
128
129
130 public static boolean isFacing2D(AgentInfo info, ILocated location) {
131 return isFacing2D(info, location, IS_FACING_ANGLE);
132 }
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 public static boolean isFacing2D(AgentInfo info, ILocated location, double angle) {
148 if (info == null || location == null)
149 return false;
150
151 return isFacing2D(info.getLocation(), info.getRotation(), location.getLocation(), angle);
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170 public static boolean isFacing2D(Location origin, Rotation rotation, Location target, double angle) {
171 if (origin == null || rotation == null || target == null)
172 return false;
173
174 Location directionVector = target.sub(origin).setZ(0).getNormalized();
175 Location agentFaceVector = rotation.toLocation().setZ(0).getNormalized();
176
177 if (Math.acos(directionVector.dot(agentFaceVector)) <= Math.toRadians(angle))
178 return true;
179
180 return false;
181
182 }
183
184
185
186
187
188
189
190
191
192
193
194 public static boolean isFacing2D(Player player, ILocated location) {
195 return isFacing2D(player, location, IS_FACING_ANGLE);
196 }
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 public static boolean isFacing2D(Player player, ILocated location, double angle) {
212 if (player == null || location == null)
213 return false;
214
215 return isFacing2D(player.getLocation(), player.getRotation(), location.getLocation(), angle);
216 }
217
218 }