Commit 37d0a9bd authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

erp5_officejs_drone_capture_flag: fix projection proportionality

See merge request nexedi/erp5!1959
parents 40aad952 3c4eeac8
...@@ -524,14 +524,11 @@ var MapManager = /** @class */ (function () { ...@@ -524,14 +524,11 @@ var MapManager = /** @class */ (function () {
_this.map_info.initial_position.longitude, _this.map_info.initial_position.longitude,
_this.map_info.initial_position.altitude _this.map_info.initial_position.altitude
); );
max = _this.map_info.width; max = Math.max(
if (_this.map_info.depth > max) { _this.map_info.depth,
max = _this.map_info.depth; _this.map_info.height,
} _this.map_info.width
if (_this.map_info.height > max) { );
max = _this.map_info.height;
}
max = max < _this.map_info.depth ? _this.map_info.depth : max;
// Skybox // Skybox
max_sky = (max * 15 < 20000) ? max * 15 : 20000; //skybox scene limit max_sky = (max * 15 < 20000) ? max * 15 : 20000; //skybox scene limit
skybox = BABYLON.MeshBuilder.CreateBox("skyBox", { size: max_sky }, scene); skybox = BABYLON.MeshBuilder.CreateBox("skyBox", { size: max_sky }, scene);
...@@ -558,13 +555,13 @@ var MapManager = /** @class */ (function () { ...@@ -558,13 +555,13 @@ var MapManager = /** @class */ (function () {
largeGroundBottom.renderingGroupId = 1; largeGroundBottom.renderingGroupId = 1;
// Terrain // Terrain
// Give map some margin from the flight limits // Give map some margin from the flight limits
width = _this.map_info.width * 1.10; width = _this.map_info.width * 1.30;
depth = _this.map_info.depth * 1.10; depth = _this.map_info.depth * 1.30;
//height = _this.map_info.height; //height = _this.map_info.height;
terrain = scene.getMeshByName("terrain001"); terrain = scene.getMeshByName("terrain001");
terrain.isVisible = true; terrain.isVisible = true;
terrain.position = BABYLON.Vector3.Zero(); terrain.position = BABYLON.Vector3.Zero();
terrain.scaling = new BABYLON.Vector3(depth / 50000, depth / 50000, terrain.scaling = new BABYLON.Vector3(depth / 50000, _this.map_info.height / 50000,
width / 50000); width / 50000);
// Enemies // Enemies
_this._enemy_list = []; _this._enemy_list = [];
...@@ -697,12 +694,6 @@ var MapManager = /** @class */ (function () { ...@@ -697,12 +694,6 @@ var MapManager = /** @class */ (function () {
MapManager.prototype.latLonDistance = function (c1, c2) { MapManager.prototype.latLonDistance = function (c1, c2) {
return this.mapUtils.latLonDistance(c1, c2); return this.mapUtils.latLonDistance(c1, c2);
}; };
MapManager.prototype.longitudToX = function (lon) {
return this.mapUtils.longitudToX(lon);
};
MapManager.prototype.latitudeToY = function (lat) {
return this.mapUtils.latitudeToY(lat);
};
MapManager.prototype.convertToLocalCoordinates = MapManager.prototype.convertToLocalCoordinates =
function (latitude, longitude, altitude) { function (latitude, longitude, altitude) {
return this.mapUtils.convertToLocalCoordinates( return this.mapUtils.convertToLocalCoordinates(
...@@ -862,12 +853,14 @@ var GameManager = /** @class */ (function () { ...@@ -862,12 +853,14 @@ var GameManager = /** @class */ (function () {
GameManager.prototype._checkDroneOut = function (drone) { GameManager.prototype._checkDroneOut = function (drone) {
if (drone.position) { if (drone.position) {
var map_limit = this._mapManager.getMapInfo().map_size / 2; var map_info = this._mapManager.getMapInfo(),
return (drone.position.z > this._mapManager.getMapInfo().height) || width_limit = map_info.width / 2,
(drone.position.x < -map_limit) || depth_limit = map_info.depth / 2;
(drone.position.x > map_limit) || return (drone.position.z > map_info.height) ||
(drone.position.y < -map_limit) || (drone.position.x < -width_limit) ||
(drone.position.y > map_limit); (drone.position.x > width_limit) ||
(drone.position.y < -depth_limit) ||
(drone.position.y > depth_limit);
} }
}; };
...@@ -1159,7 +1152,12 @@ var GameManager = /** @class */ (function () { ...@@ -1159,7 +1152,12 @@ var GameManager = /** @class */ (function () {
GameManager.prototype._init = function () { GameManager.prototype._init = function () {
var _this = this, canvas, hemi_north, hemi_south, camera, cam_radius, var _this = this, canvas, hemi_north, hemi_south, camera, cam_radius,
on3DmodelsReady, map_size = 900; //GAMEPARAMETERS.map.map_size on3DmodelsReady, mapUtils = new MapUtils(GAMEPARAMETERS.map),
map_size = Math.max(
mapUtils.map_info.depth,
mapUtils.map_info.height,
mapUtils.map_info.width
);
canvas = this._canvas; canvas = this._canvas;
this._delayed_defer_list = []; this._delayed_defer_list = [];
this._dispose(); this._dispose();
...@@ -1196,9 +1194,11 @@ var GameManager = /** @class */ (function () { ...@@ -1196,9 +1194,11 @@ var GameManager = /** @class */ (function () {
this._scene this._scene
); );
hemi_south.intensity = 0.75; hemi_south.intensity = 0.75;
//HARDCODE camera to a hardcoded map_size
//skybox scene limit //skybox scene limit
cam_radius = (map_size * 1.10 < 6000) ? map_size * 1.10 : 6000; cam_radius = Math.min(
1.10 * Math.sqrt(mapUtils.map_info.width * mapUtils.map_info.depth),
6000
);
camera = new BABYLON.ArcRotateCamera("camera", 0, 1.25, cam_radius, camera = new BABYLON.ArcRotateCamera("camera", 0, 1.25, cam_radius,
BABYLON.Vector3.Zero(), this._scene); BABYLON.Vector3.Zero(), this._scene);
camera.wheelPrecision = 10; camera.wheelPrecision = 10;
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1016.21978.22579.46609</string> </value> <value> <string>1017.22735.36044.31948</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1714742387.62</float> <float>1718719762.65</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*jslint nomen: true, indent: 2, maxlen: 80, todo: true, unparam: true */
/******************************* MAP UTILS ************************************/ /******************************* MAP UTILS ************************************/
var MapUtils = /** @class */ (function () { var MapUtils = /** @class */ (function () {
...@@ -7,13 +9,7 @@ var MapUtils = /** @class */ (function () { ...@@ -7,13 +9,7 @@ var MapUtils = /** @class */ (function () {
//** CONSTRUCTOR //** CONSTRUCTOR
function MapUtils(map_param) { function MapUtils(map_param) {
var _this = this, max_width = _this.latLonDistance( var _this = this;
[map_param.min_lat, map_param.min_lon],
[map_param.min_lat, map_param.max_lon]),
max_depth = _this.latLonDistance(
[map_param.min_lat, map_param.min_lon],
[map_param.max_lat, map_param.min_lon]),
map_size = Math.ceil(Math.max(max_width, max_depth));
_this.map_param = {}; _this.map_param = {};
_this.map_param.height = map_param.height; _this.map_param.height = map_param.height;
_this.map_param.start_AMSL = map_param.start_AMSL; _this.map_param.start_AMSL = map_param.start_AMSL;
...@@ -21,15 +17,19 @@ var MapUtils = /** @class */ (function () { ...@@ -21,15 +17,19 @@ var MapUtils = /** @class */ (function () {
_this.map_param.max_lat = map_param.max_lat; _this.map_param.max_lat = map_param.max_lat;
_this.map_param.min_lon = map_param.min_lon; _this.map_param.min_lon = map_param.min_lon;
_this.map_param.max_lon = map_param.max_lon; _this.map_param.max_lon = map_param.max_lon;
_this.map_param.depth = map_size; _this.map_param.depth = _this.latLonDistance(
_this.map_param.width = map_size; [map_param.min_lat, map_param.min_lon],
_this.map_param.map_size = map_size; [map_param.max_lat, map_param.min_lon]
);
_this.map_param.width = _this.latLonDistance(
[map_param.min_lat, map_param.min_lon],
[map_param.min_lat, map_param.max_lon]
);
_this.map_info = { _this.map_info = {
"depth": _this.map_param.depth, "depth": _this.map_param.depth,
"width": _this.map_param.width, "width": _this.map_param.width,
"flag_distance_epsilon": map_param.flag_distance_epsilon || FLAG_EPSILON "flag_distance_epsilon": map_param.flag_distance_epsilon || FLAG_EPSILON
}; };
_this.map_info.map_size = _this.map_param.map_size;
_this.map_info.height = _this.map_param.height; _this.map_info.height = _this.map_param.height;
_this.map_info.start_AMSL = _this.map_param.start_AMSL; _this.map_info.start_AMSL = _this.map_param.start_AMSL;
_this.map_info.min_x = _this.longitudToX(map_param.min_lon); _this.map_info.min_x = _this.longitudToX(map_param.min_lon);
...@@ -50,10 +50,10 @@ var MapUtils = /** @class */ (function () { ...@@ -50,10 +50,10 @@ var MapUtils = /** @class */ (function () {
return R * c; return R * c;
}; };
MapUtils.prototype.longitudToX = function (lon) { MapUtils.prototype.longitudToX = function (lon) {
return (this.map_info.map_size / 360.0) * (180 + lon); return (this.map_info.width / 360.0) * (180 + lon);
}; };
MapUtils.prototype.latitudeToY = function (lat) { MapUtils.prototype.latitudeToY = function (lat) {
return (this.map_info.map_size / 180.0) * (90 - lat); return (this.map_info.depth / 180.0) * (90 - lat);
}; };
MapUtils.prototype.convertToLocalCoordinates = MapUtils.prototype.convertToLocalCoordinates =
function (latitude, longitude, altitude) { function (latitude, longitude, altitude) {
...@@ -61,24 +61,22 @@ var MapUtils = /** @class */ (function () { ...@@ -61,24 +61,22 @@ var MapUtils = /** @class */ (function () {
x = this.longitudToX(longitude), x = this.longitudToX(longitude),
y = this.latitudeToY(latitude); y = this.latitudeToY(latitude);
return { return {
x: ((x - map_info.min_x) / (map_info.max_x - map_info.min_x)) * x: (((x - map_info.min_x) / (map_info.max_x - map_info.min_x)) - 0.5)
1000 - map_info.width / 2, * map_info.width,
y: ((y - map_info.min_y) / (map_info.max_y - map_info.min_y)) * y: (((y - map_info.min_y) / (map_info.max_y - map_info.min_y)) - 0.5)
1000 - map_info.depth / 2, * map_info.depth,
z: altitude z: altitude
}; };
}; };
MapUtils.prototype.convertToGeoCoordinates = function (x, y, z) { MapUtils.prototype.convertToGeoCoordinates = function (x, y, z) {
var lon = x + this.map_info.width / 2, var lon = (x / this.map_info.width) + 0.5,
lat = y + this.map_info.depth / 2; lat = (y / this.map_info.depth) + 0.5;
lon = lon / 1000;
lon = lon * (this.map_info.max_x - this.map_info.min_x) + lon = lon * (this.map_info.max_x - this.map_info.min_x) +
this.map_info.min_x; this.map_info.min_x;
lon = lon / (this.map_info.map_size / 360.0) - 180; lon = lon / (this.map_info.width / 360.0) - 180;
lat = lat / 1000;
lat = lat * (this.map_info.max_y - this.map_info.min_y) + lat = lat * (this.map_info.max_y - this.map_info.min_y) +
this.map_info.min_y; this.map_info.min_y;
lat = 90 - lat / (this.map_info.map_size / 180.0); lat = 90 - lat / (this.map_info.depth / 180.0);
return { return {
latitude: lat, latitude: lat,
longitude: lon, longitude: lon,
...@@ -127,11 +125,11 @@ var MapUtils = /** @class */ (function () { ...@@ -127,11 +125,11 @@ var MapUtils = /** @class */ (function () {
function fillObstacleList(list, min_x, min_y, max_x, max_y) { function fillObstacleList(list, min_x, min_y, max_x, max_y) {
var i, el, result_list = []; var i, el, result_list = [];
for (i = 0; i < list.length; i += 1) { for (i = 0; i < list.length; i += 1) {
el = {"position": el = {
{"x": 0, "y": 0, "z": 0}, "position": {"x": 0, "y": 0, "z": 0},
"scale": "scale": {"x": 0, "y": 0, "z": 0},
{"x": 0, "y": 0, "z": 0}, "type": list[i].type
"type": list[i].type}; };
if (list[i].rotation) { if (list[i].rotation) {
el.rotation = {"x": list[i].rotation.x, "y": list[i].rotation.y, el.rotation = {"x": list[i].rotation.x, "y": list[i].rotation.y,
"z": list[i].rotation.z}; "z": list[i].rotation.z};
...@@ -149,14 +147,18 @@ var MapUtils = /** @class */ (function () { ...@@ -149,14 +147,18 @@ var MapUtils = /** @class */ (function () {
return result_list; return result_list;
} }
return { return {
"flag_list": fillFlagList(template.flag_list, min_x, min_y, max_x, max_y), "flag_list":
"obstacle_list": fillObstacleList(template.obstacle_list, min_x, min_y, max_x, max_y), fillFlagList(template.flag_list, min_x, min_y, max_x, max_y),
"enemy_list": fillEnemyList(template.enemy_list, min_x, min_y, max_x, max_y) "obstacle_list":
fillObstacleList(template.obstacle_list, min_x, min_y, max_x, max_y),
"enemy_list":
fillEnemyList(template.enemy_list, min_x, min_y, max_x, max_y)
}; };
} }
// 4x4 grid // 4x4 grid
var GRID = 4, i, j, map_size = this.map_info.map_size, initial_block, var GRID = 4, i, j, max_width = this.map_info.width,
x1, y1, x2, y2, block_result, index, block_size = map_size / GRID, max_depth = this.map_info.depth, initial_block, x1, y1, x2, y2,
block_result, index, block_size = Math.max(max_width, max_depth) / GRID,
result_map, result_map,
BLOCK_TEMPLATE_LIST = [{ BLOCK_TEMPLATE_LIST = [{
"flag_list": [{"position": "flag_list": [{"position":
...@@ -250,32 +252,37 @@ var MapUtils = /** @class */ (function () { ...@@ -250,32 +252,37 @@ var MapUtils = /** @class */ (function () {
x = Math.floor(seed.quick() * GRID); x = Math.floor(seed.quick() * GRID);
y = Math.floor(seed.quick() * GRID); y = Math.floor(seed.quick() * GRID);
//ensure intial block is in the edge of map //ensure intial block is in the edge of map
} while (x !== 0 && x !== GRID-1 && y !== 0 && y !== GRID-1); } while (x !== 0 && x !== GRID - 1 && y !== 0 && y !== GRID - 1);
return {x: x, y: y}; return {x: x, y: y};
} }
initial_block = getInitialBlock(GRID); initial_block = getInitialBlock(GRID);
function checkConditions(json_map, GRID) { function checkConditions(json_map, GRID) {
if (!json_map) return false; var f, flag, g, n_mountains = 0;
if (!json_map) {
return false;
}
// set ~20% of the blocks with flags // set ~20% of the blocks with flags
if (json_map.flag_list.length !== Math.round(GRID * GRID * 0.2)) return false; if (json_map.flag_list.length !== Math.round(GRID * GRID * 0.2)) {
return false;
}
// limit n_mountains // limit n_mountains
if (json_map.obstacle_list.length > 3) { if (json_map.obstacle_list.length > 3) {
var i, n_mountains = 0; for (g = 0; g < json_map.obstacle_list.length; g += 1) {
for (i = 0; i < json_map.obstacle_list.length; i += 1) { if (json_map.obstacle_list[g].type === "mountain") {
if (json_map.obstacle_list[i].type === "mountain") {
n_mountains += 1; n_mountains += 1;
if (n_mountains > 3) { if (n_mountains > 3) {
return false; return false;
} }
json_map.obstacle_list[i].type = "box"; json_map.obstacle_list[g].type = "box";
} }
} }
} }
var f;
// at least one flag in the oposite side of drones initial position // at least one flag in the oposite side of drones initial position
for (f = 0; f < json_map.flag_list.length; f += 1) { for (f = 0; f < json_map.flag_list.length; f += 1) {
if ((json_map.flag_list[f].position.x * json_map.initial_position.x) < 0 || flag = json_map.flag_list[f];
(json_map.flag_list[f].position.y * json_map.initial_position.y) < 0) { if ((flag.position.x * json_map.initial_position.x) < 0 ||
(flag.position.y * json_map.initial_position.y) < 0) {
return true; return true;
} }
} }
...@@ -284,25 +291,30 @@ var MapUtils = /** @class */ (function () { ...@@ -284,25 +291,30 @@ var MapUtils = /** @class */ (function () {
do { do {
result_map = { result_map = {
"flag_list": [], "flag_list": [],
"initial_position": null,
"obstacle_list": [], "obstacle_list": [],
"enemy_list": [] "enemy_list": []
}; };
for (i = 0; i < GRID; i += 1) { for (i = 0; i < GRID; i += 1) {
for (j = 0; j < GRID; j += 1) { for (j = 0; j < GRID; j += 1) {
index = Math.floor(seed.quick() * BLOCK_TEMPLATE_LIST.length); index = Math.floor(seed.quick() * BLOCK_TEMPLATE_LIST.length);
x1 = block_size * i - map_size / 2; x1 = block_size * i - max_width / 2;
y1 = block_size * j - map_size / 2; y1 = block_size * j - max_depth / 2;
x2 = block_size * i + block_size - map_size / 2; x2 = block_size * i + block_size - max_width / 2;
y2 = block_size * j + block_size - map_size / 2; y2 = block_size * j + block_size - max_depth / 2;
if (initial_block.x === i && initial_block.y === j) { if (initial_block.x === i && initial_block.y === j) {
result_map.initial_position = {x: normalize(50, x1, x2), result_map.initial_position = {x: normalize(50, x1, x2),
y: normalize(50, y1, y2), y: normalize(50, y1, y2),
z: 15 }; z: 15 };
} else { } else {
block_result = fillTemplate(BLOCK_TEMPLATE_LIST[index], x1, y1, x2, y2); block_result =
result_map.flag_list = result_map.flag_list.concat(block_result.flag_list); fillTemplate(BLOCK_TEMPLATE_LIST[index], x1, y1, x2, y2);
result_map.obstacle_list = result_map.obstacle_list.concat(block_result.obstacle_list); result_map.flag_list =
result_map.enemy_list = result_map.enemy_list.concat(block_result.enemy_list); result_map.flag_list.concat(block_result.flag_list);
result_map.obstacle_list =
result_map.obstacle_list.concat(block_result.obstacle_list);
result_map.enemy_list =
result_map.enemy_list.concat(block_result.enemy_list);
} }
} }
} }
...@@ -316,7 +328,7 @@ var MapUtils = /** @class */ (function () { ...@@ -316,7 +328,7 @@ var MapUtils = /** @class */ (function () {
MapUtils.prototype.randomize = function (seed) { MapUtils.prototype.randomize = function (seed) {
//TODO randomize start_ASML, map height, depth and width? //TODO randomize start_ASML, map height, depth and width?
var _this = this, flag_list, obstacle_list, enemy_list, var _this = this, flag_list, obstacle_list, enemy_list,
geo_flag_info, geo_obstacle, geo_enemy, coordinates, geo_flag_info, geo_obstacle, geo_enemy,
random_seed = new Math.seedrandom(seed), random_seed = new Math.seedrandom(seed),
randomized_map = _this.randomizeByBlockTemplates(random_seed); randomized_map = _this.randomizeByBlockTemplates(random_seed);
obstacle_list = randomized_map.obstacle_list; obstacle_list = randomized_map.obstacle_list;
...@@ -346,7 +358,7 @@ var MapUtils = /** @class */ (function () { ...@@ -346,7 +358,7 @@ var MapUtils = /** @class */ (function () {
_this.map_info.flag_list.push(geo_flag_info); _this.map_info.flag_list.push(geo_flag_info);
}); });
obstacle_list.forEach(function (obstacle_info, index) { obstacle_list.forEach(function (obstacle_info, index) {
geo_obstacle = {}; geo_obstacle = {position: null};
Object.assign(geo_obstacle, obstacle_info); Object.assign(geo_obstacle, obstacle_info);
geo_obstacle.position = _this.convertToGeoCoordinates( geo_obstacle.position = _this.convertToGeoCoordinates(
obstacle_info.position.x, obstacle_info.position.x,
...@@ -356,7 +368,7 @@ var MapUtils = /** @class */ (function () { ...@@ -356,7 +368,7 @@ var MapUtils = /** @class */ (function () {
_this.map_info.obstacle_list.push(geo_obstacle); _this.map_info.obstacle_list.push(geo_obstacle);
}); });
enemy_list.forEach(function (enemy_info, index) { enemy_list.forEach(function (enemy_info, index) {
geo_enemy = {}; geo_enemy = {position: null};
Object.assign(geo_enemy, enemy_info); Object.assign(geo_enemy, enemy_info);
geo_enemy.position = _this.convertToGeoCoordinates( geo_enemy.position = _this.convertToGeoCoordinates(
enemy_info.position.x, enemy_info.position.x,
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.57448.22674.29627</string> </value> <value> <string>1017.22488.12960.6280</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1697557365.44</float> <float>1718708011.02</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -44,11 +44,6 @@ ...@@ -44,11 +44,6 @@
<td>//div[contains(text(), 'CONSOLE LOG ENTRIES:')]</td> <td>//div[contains(text(), 'CONSOLE LOG ENTRIES:')]</td>
<td></td> <td></td>
<tr> <tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(text(), 'Simulation finished')]</td>
<td></td>
<tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//div[contains(text(), 'Initial speed: OK')]</td> <td>//div[contains(text(), 'Initial speed: OK')]</td>
...@@ -84,6 +79,11 @@ ...@@ -84,6 +79,11 @@
<td>//div[contains(text(), 'Altitude: OK')]</td> <td>//div[contains(text(), 'Altitude: OK')]</td>
<td></td> <td></td>
<tr> <tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Timeout: OK')]</td>
<td></td>
<tr>
</tbody></table> </tbody></table>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -425,28 +425,140 @@ var DroneManager = /** @class */ (function () { ...@@ -425,28 +425,140 @@ var DroneManager = /** @class */ (function () {
/******************************** MAP UTILIS **********************************/
var MapUtils = /** @class */ (function () {
"use strict";
var R = 6371e3;
//** CONSTRUCTOR
function MapUtils(map_param) {
var _this = this;
_this.map_param = {};
_this.map_param.height = map_param.height;
_this.map_param.start_AMSL = map_param.start_AMSL;
_this.map_param.min_lat = map_param.min_lat;
_this.map_param.max_lat = map_param.max_lat;
_this.map_param.min_lon = map_param.min_lon;
_this.map_param.max_lon = map_param.max_lon;
_this.map_param.depth = _this.latLonDistance(
[map_param.min_lat, map_param.min_lon],
[map_param.max_lat, map_param.min_lon]
);
_this.map_param.width = _this.latLonDistance(
[map_param.min_lat, map_param.min_lon],
[map_param.min_lat, map_param.max_lon]
);
_this.map_info = {
"depth": _this.map_param.depth,
"width": _this.map_param.width
};
_this.map_info.height = _this.map_param.height;
_this.map_info.start_AMSL = _this.map_param.start_AMSL;
_this.map_info.min_x = _this.longitudToX(map_param.min_lon);
_this.map_info.min_y = _this.latitudeToY(map_param.min_lat);
_this.map_info.max_x = _this.longitudToX(map_param.max_lon);
_this.map_info.max_y = _this.latitudeToY(map_param.max_lat);
}
MapUtils.prototype.latLonDistance = function (c1, c2) {
var q1 = c1[0] * Math.PI / 180,
q2 = c2[0] * Math.PI / 180,
dq = (c2[0] - c1[0]) * Math.PI / 180,
dl = (c2[1] - c1[1]) * Math.PI / 180,
a = Math.sin(dq / 2) * Math.sin(dq / 2) +
Math.cos(q1) * Math.cos(q2) *
Math.sin(dl / 2) * Math.sin(dl / 2),
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c;
};
MapUtils.prototype.longitudToX = function (lon) {
return (this.map_info.width / 360.0) * (180 + lon);
};
MapUtils.prototype.latitudeToY = function (lat) {
return (this.map_info.depth / 180.0) * (90 - lat);
};
MapUtils.prototype.convertToLocalCoordinates =
function (latitude, longitude, altitude) {
var map_info = this.map_info,
x = this.longitudToX(longitude),
y = this.latitudeToY(latitude);
return {
x: (((x - map_info.min_x) / (map_info.max_x - map_info.min_x)) - 0.5)
* map_info.width,
y: (((y - map_info.min_y) / (map_info.max_y - map_info.min_y)) - 0.5)
* map_info.depth,
z: altitude
};
};
MapUtils.prototype.convertToGeoCoordinates = function (x, y, z) {
var lon = (x / this.map_info.width) + 0.5,
lat = (y / this.map_info.depth) + 0.5;
lon = lon * (this.map_info.max_x - this.map_info.min_x) +
this.map_info.min_x;
lon = lon / (this.map_info.width / 360.0) - 180;
lat = lat * (this.map_info.max_y - this.map_info.min_y) +
this.map_info.min_y;
lat = 90 - lat / (this.map_info.depth / 180.0);
return {
latitude: lat,
longitude: lon,
altitude: z
};
};
return MapUtils;
}());
/******************************************************************************/
/******************************** MAP MANAGER *********************************/ /******************************** MAP MANAGER *********************************/
var MapManager = /** @class */ (function () { var MapManager = /** @class */ (function () {
"use strict"; "use strict";
//default square map
var MAP_HEIGHT = 700,
START_AMSL = 595,
MIN_LAT = 45.6419,
MAX_LAT = 45.65,
MIN_LON = 14.265,
MAX_LON = 14.2766,
MAP = {
"height": MAP_HEIGHT,
"start_AMSL": START_AMSL,
"min_lat": MIN_LAT,
"max_lat": MAX_LAT,
"min_lon": MIN_LON,
"max_lon": MAX_LON
};
//** CONSTRUCTOR //** CONSTRUCTOR
function MapManager(scene) { function MapManager(scene, map_param, initial_position) {
var _this = this, max_sky, skybox, skyboxMat, largeGroundMat, var _this = this, max_sky, skybox, skyboxMat, largeGroundMat,
largeGroundBottom, width, depth, terrain, max; largeGroundBottom, width, depth, terrain, max;
this.setMapInfo(GAMEPARAMETERS.map, GAMEPARAMETERS.initialPosition); if (!map_param) {
max = _this.map_info.width; // Use default map base parameters
if (_this.map_info.depth > max) { map_param = MAP;
max = _this.map_info.depth; }
} _this.mapUtils = new MapUtils(map_param);
if (_this.map_info.height > max) { _this.map_info = map_param;
max = _this.map_info.height; Object.assign(_this.map_info, _this.mapUtils.map_info);
} _this.map_info.initial_position = _this.mapUtils.convertToLocalCoordinates(
max = max < _this.map_info.depth ? _this.map_info.depth : max; initial_position.latitude,
initial_position.longitude,
initial_position.altitude
);
max = Math.max(
_this.map_info.depth,
_this.map_info.height,
_this.map_info.width
);
// Skybox // Skybox
max_sky = (max * 10 < 20000) ? max * 10 : 20000; max_sky = (max * 15 < 20000) ? max * 15 : 20000; //skybox scene limit
skybox = BABYLON.Mesh.CreateBox("skyBox", max_sky, scene); skybox = BABYLON.MeshBuilder.CreateBox("skyBox", { size: max_sky }, scene);
skybox.infiniteDistance = true;
skybox.renderingGroupId = 0;
skyboxMat = new BABYLON.StandardMaterial("skybox", scene); skyboxMat = new BABYLON.StandardMaterial("skybox", scene);
skyboxMat.backFaceCulling = false; skyboxMat.backFaceCulling = false;
skyboxMat.disableLighting = true; skyboxMat.disableLighting = true;
...@@ -455,6 +567,12 @@ var MapManager = /** @class */ (function () { ...@@ -455,6 +567,12 @@ var MapManager = /** @class */ (function () {
skyboxMat.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE; skyboxMat.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
skyboxMat.infiniteDistance = true; skyboxMat.infiniteDistance = true;
skybox.material = skyboxMat; skybox.material = skyboxMat;
skybox.infiniteDistance = true;
skyboxMat.disableLighting = true;
skyboxMat.reflectionTexture = new BABYLON.CubeTexture("./assets/skybox/sky",
scene);
skyboxMat.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
skybox.renderingGroupId = 0;
// Plane from bottom // Plane from bottom
largeGroundMat = new BABYLON.StandardMaterial("largeGroundMat", scene); largeGroundMat = new BABYLON.StandardMaterial("largeGroundMat", scene);
largeGroundMat.specularColor = BABYLON.Color3.Black(); largeGroundMat.specularColor = BABYLON.Color3.Black();
...@@ -465,92 +583,34 @@ var MapManager = /** @class */ (function () { ...@@ -465,92 +583,34 @@ var MapManager = /** @class */ (function () {
largeGroundBottom.rotation.x = -Math.PI / 2; largeGroundBottom.rotation.x = -Math.PI / 2;
largeGroundBottom.rotation.y = Math.PI; largeGroundBottom.rotation.y = Math.PI;
largeGroundBottom.material = largeGroundMat; largeGroundBottom.material = largeGroundMat;
// Camera largeGroundBottom.renderingGroupId = 1;
scene.activeCamera.upperRadiusLimit = max * 4;
// Terrain // Terrain
// Give map some margin from the flight limits // Give map some margin from the flight limits
width = _this.map_info.width * 1.10; width = _this.map_info.width * 1.30;
depth = _this.map_info.depth * 1.10; depth = _this.map_info.depth * 1.30;
//height = _this.map_info.height; //height = _this.map_info.height;
terrain = scene.getMeshByName("terrain001"); terrain = scene.getMeshByName("terrain001");
terrain.isVisible = true; terrain.isVisible = true;
terrain.position = BABYLON.Vector3.Zero(); terrain.position = BABYLON.Vector3.Zero();
terrain.scaling = new BABYLON.Vector3(depth / 50000, depth / 50000, terrain.scaling = new BABYLON.Vector3(depth / 50000, _this.map_info.height / 50000,
width / 50000); width / 50000);
} }
MapManager.prototype.setMapInfo = function (map_dict, initial_position) {
var max_width = this.latLonDistance([map_dict.min_lat, map_dict.min_lon],
[map_dict.min_lat, map_dict.max_lon]),
max_height = this.latLonDistance([map_dict.min_lat, map_dict.min_lon],
[map_dict.max_lat, map_dict.min_lon]),
map_size = Math.ceil(Math.max(max_width, max_height));
this.map_info = {
"depth": map_size,
"height": map_dict.height,
"width": map_size,
"map_size": map_size,
"start_AMSL": map_dict.start_AMSL
};
this.map_info.min_x = this.longitudToX(map_dict.min_lon);
this.map_info.min_y = this.latitudeToY(map_dict.min_lat);
this.map_info.max_x = this.longitudToX(map_dict.max_lon);
this.map_info.max_y = this.latitudeToY(map_dict.max_lat);
this.map_info.initial_position = this.convertToLocalCoordinates(
initial_position.latitude,
initial_position.longitude,
initial_position.altitude
);
};
MapManager.prototype.getMapInfo = function () { MapManager.prototype.getMapInfo = function () {
return this.map_info; return this.map_info;
}; };
MapManager.prototype.longitudToX = function (lon) {
return (this.map_info.map_size / 360.0) * (180 + lon);
};
MapManager.prototype.latitudeToY = function (lat) {
return (this.map_info.map_size / 180.0) * (90 - lat);
};
MapManager.prototype.latLonDistance = function (c1, c2) { MapManager.prototype.latLonDistance = function (c1, c2) {
var R = 6371e3, return this.mapUtils.latLonDistance(c1, c2);
q1 = c1[0] * Math.PI / 180,
q2 = c2[0] * Math.PI / 180,
dq = (c2[0] - c1[0]) * Math.PI / 180,
dl = (c2[1] - c1[1]) * Math.PI / 180,
a = Math.sin(dq / 2) * Math.sin(dq / 2) +
Math.cos(q1) * Math.cos(q2) *
Math.sin(dl / 2) * Math.sin(dl / 2),
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c;
}; };
MapManager.prototype.convertToLocalCoordinates = MapManager.prototype.convertToLocalCoordinates =
function (latitude, longitude, altitude) { function (latitude, longitude, altitude) {
var map_info = this.map_info, return this.mapUtils.convertToLocalCoordinates(
x = this.longitudToX(longitude), latitude,
y = this.latitudeToY(latitude); longitude,
return { altitude
x: ((x - map_info.min_x) / (map_info.max_x - map_info.min_x)) );
* 1000 - map_info.width / 2,
y: ((y - map_info.min_y) / (map_info.max_y - map_info.min_y))
* 1000 - map_info.depth / 2,
z: altitude
};
}; };
MapManager.prototype.convertToGeoCoordinates = function (x, y, z) { MapManager.prototype.convertToGeoCoordinates = function (x, y, z) {
var lon = x + this.map_info.width / 2, return this.mapUtils.convertToGeoCoordinates(x, y, z);
lat = y + this.map_info.depth / 2;
lon = lon / 1000;
lon = lon * (this.map_info.max_x - this.map_info.min_x) +
this.map_info.min_x;
lon = lon / (this.map_info.map_size / 360.0) - 180;
lat = lat / 1000;
lat = lat * (this.map_info.max_y - this.map_info.min_y) +
this.map_info.min_y;
lat = 90 - lat / (this.map_info.map_size / 180.0);
return {
latitude: lat,
longitude: lon,
altitude: z
};
}; };
return MapManager; return MapManager;
}()); }());
...@@ -856,7 +916,14 @@ var GameManager = /** @class */ (function () { ...@@ -856,7 +916,14 @@ var GameManager = /** @class */ (function () {
}; };
GameManager.prototype._init = function () { GameManager.prototype._init = function () {
var _this = this, canvas, hemi_north, hemi_south, camera, on3DmodelsReady; var _this = this, canvas, hemi_north, hemi_south, camera, cam_radius,
on3DmodelsReady,
mapUtils = new MapUtils(GAMEPARAMETERS.map),
map_size = Math.max(
mapUtils.map_info.depth,
mapUtils.map_info.height,
mapUtils.map_info.width
);
canvas = this._canvas; canvas = this._canvas;
this._delayed_defer_list = []; this._delayed_defer_list = [];
this._dispose(); this._dispose();
...@@ -890,9 +957,15 @@ var GameManager = /** @class */ (function () { ...@@ -890,9 +957,15 @@ var GameManager = /** @class */ (function () {
this._scene this._scene
); );
hemi_south.intensity = 0.75; hemi_south.intensity = 0.75;
camera = new BABYLON.ArcRotateCamera("camera", 0, 1.25, 800, cam_radius = Math.min(
1.10 * Math.sqrt(mapUtils.map_info.width * mapUtils.map_info.depth),
6000
);
camera = new BABYLON.ArcRotateCamera("camera", 0, 1.25, cam_radius,
BABYLON.Vector3.Zero(), this._scene); BABYLON.Vector3.Zero(), this._scene);
camera.wheelPrecision = 10; camera.wheelPrecision = 10;
//zoom out limit
camera.upperRadiusLimit = map_size * 10;
//changed for event handling //changed for event handling
//camera.attachControl(this._scene.getEngine().getRenderingCanvas()); //orig //camera.attachControl(this._scene.getEngine().getRenderingCanvas()); //orig
camera.attachControl(canvas, true); camera.attachControl(canvas, true);
...@@ -911,8 +984,9 @@ var GameManager = /** @class */ (function () { ...@@ -911,8 +984,9 @@ var GameManager = /** @class */ (function () {
ctx._map_swapped = true; ctx._map_swapped = true;
} }
// Init the map // Init the map
_this._mapManager = new MapManager(ctx._scene); _this._mapManager = new MapManager(ctx._scene, GAMEPARAMETERS.map,
ctx._spawnDrones(_this._mapManager.map_info.initial_position, GAMEPARAMETERS.initialPosition);
ctx._spawnDrones(_this._mapManager.getMapInfo().initial_position,
GAMEPARAMETERS.droneList, ctx); GAMEPARAMETERS.droneList, ctx);
// Hide the drone prefab // Hide the drone prefab
DroneManager.Prefab.isVisible = false; DroneManager.Prefab.isVisible = false;
......
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1016.21987.28184.16844</string> </value> <value> <string>1017.22776.49981.4147</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1714742619.34</float> <float>1718722284.77</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -54,11 +54,6 @@ ...@@ -54,11 +54,6 @@
<td>//div[contains(text(), 'CONSOLE LOG ENTRIES:')]</td> <td>//div[contains(text(), 'CONSOLE LOG ENTRIES:')]</td>
<td></td> <td></td>
<tr> <tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(text(), 'Simulation finished')]</td>
<td></td>
<tr>
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//div[contains(text(), 'Initial speed: OK')]</td> <td>//div[contains(text(), 'Initial speed: OK')]</td>
...@@ -94,6 +89,11 @@ ...@@ -94,6 +89,11 @@
<td>//div[contains(text(), 'Altitude: OK')]</td> <td>//div[contains(text(), 'Altitude: OK')]</td>
<td></td> <td></td>
<tr> <tr>
<tr>
<td>assertElementPresent</td>
<td>//div[contains(text(), 'Timeout: OK')]</td>
<td></td>
<tr>
</tbody></table> </tbody></table>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment