mirror of
https://github.com/mudabbir-ahmad/MAD-Treasure-Hunt.git
synced 2026-10-08 03:00:20 +00:00
Add FOV cone visualization to map screens; refactor geoMath utility for heading and cone calculations
Have FOV config as it's own thing so it's easier to change the size of the FOV triangle without having to change multiple parts of the maths for it. Fov triangle needed because for some reason maps doesn't let us have our own fov ??
This commit is contained in:
1 parent
c4c8fcf91d
commit
1e405bb87f
5 files changed
+64
-84
No files matched your search
+28
-3
@@ -1,9 +1,34 @@
|
||||
import * as geolib from 'geolib';
|
||||
|
||||
// Convert raw Magnetometer {x, y} reading to a 0-360° heading
|
||||
// --- FOV Configuration ---
|
||||
const FOV_DISTANCE = 20; // metres — radius of arc + length of straight edges
|
||||
const FOV_ANGLE = 45; // degrees — total field of view (halved for each side)
|
||||
|
||||
// Convert raw Magnetometer {x, y} reading to a 0-360° heading (0° = north)
|
||||
const toHeading = ({x, y}) => {
|
||||
const angle = Math.atan2(y, x) * (180 / Math.PI);
|
||||
return angle < 0 ? angle + 360 : angle;
|
||||
const heading = 90 - angle;
|
||||
return heading < 0 ? heading + 360 : heading % 360;
|
||||
};
|
||||
|
||||
// Build a pie-shaped FOV sector as polygon coordinates
|
||||
const getFovCone = (location, headingDeg, radiusMeters = FOV_DISTANCE, halfAngle = FOV_ANGLE / 2, arcSegments = 20) => {
|
||||
const origin = {latitude: location.latitude, longitude: location.longitude};
|
||||
const startBearing = headingDeg - halfAngle;
|
||||
const endBearing = headingDeg + halfAngle;
|
||||
const step = (endBearing - startBearing) / arcSegments;
|
||||
|
||||
// Tip of the sector
|
||||
const points = [location];
|
||||
|
||||
// Arc points at radiusMeters distance from origin
|
||||
for (let i = 0; i <= arcSegments; i++) {
|
||||
const bearing = startBearing + step * i;
|
||||
const dest = geolib.computeDestinationPoint(origin, radiusMeters, bearing);
|
||||
points.push({latitude: dest.latitude, longitude: dest.longitude});
|
||||
}
|
||||
|
||||
return points;
|
||||
};
|
||||
|
||||
const isWithinRadius = (playerCoords, cacheCoords, radius) => {
|
||||
@@ -20,5 +45,5 @@ const isLookingAtCache = (playerHeading, playerCoords, cacheCoords, tolerance =
|
||||
return diff <= tolerance || diff >= 360 - tolerance;
|
||||
};
|
||||
|
||||
export { toHeading, isWithinRadius, isLookingAtCache };
|
||||
export { toHeading, getFovCone, isWithinRadius, isLookingAtCache };
|
||||
|
||||
Reference in new issue
Block a user