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

erp5_officejs_drone_capture_flag: fix projection proportionality

Fix projection by not making a square map from non square limits (width != depth).
This way rotation does not result anymore in deformed shapes (it was the case until now because proportionality was not respected between width and depth).
parent 40aad952
...@@ -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);
...@@ -564,7 +561,7 @@ var MapManager = /** @class */ (function () { ...@@ -564,7 +561,7 @@ var MapManager = /** @class */ (function () {
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);
} }
}; };
......
...@@ -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.22488.12960.6280</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>1718705497.6</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -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>
......
...@@ -434,14 +434,11 @@ var MapManager = /** @class */ (function () { ...@@ -434,14 +434,11 @@ var MapManager = /** @class */ (function () {
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); this.setMapInfo(GAMEPARAMETERS.map, GAMEPARAMETERS.initialPosition);
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 * 10 < 20000) ? max * 10 : 20000; max_sky = (max * 10 < 20000) ? max * 10 : 20000;
skybox = BABYLON.Mesh.CreateBox("skyBox", max_sky, scene); skybox = BABYLON.Mesh.CreateBox("skyBox", max_sky, scene);
...@@ -475,20 +472,16 @@ var MapManager = /** @class */ (function () { ...@@ -475,20 +472,16 @@ var MapManager = /** @class */ (function () {
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) { 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 = { this.map_info = {
"depth": map_size, "depth": this.latLonDistance([map_dict.min_lat, map_dict.min_lon],
[map_dict.max_lat, map_dict.min_lon]),
"height": map_dict.height, "height": map_dict.height,
"width": map_size, "width": this.latLonDistance([map_dict.min_lat, map_dict.min_lon],
"map_size": map_size, [map_dict.min_lat, map_dict.max_lon]),
"start_AMSL": map_dict.start_AMSL "start_AMSL": map_dict.start_AMSL
}; };
this.map_info.min_x = this.longitudToX(map_dict.min_lon); this.map_info.min_x = this.longitudToX(map_dict.min_lon);
...@@ -505,10 +498,10 @@ var MapManager = /** @class */ (function () { ...@@ -505,10 +498,10 @@ var MapManager = /** @class */ (function () {
return this.map_info; return this.map_info;
}; };
MapManager.prototype.longitudToX = function (lon) { MapManager.prototype.longitudToX = function (lon) {
return (this.map_info.map_size / 360.0) * (180 + lon); return (this.map_info.width / 360.0) * (180 + lon);
}; };
MapManager.prototype.latitudeToY = function (lat) { MapManager.prototype.latitudeToY = function (lat) {
return (this.map_info.map_size / 180.0) * (90 - lat); return (this.map_info.depth / 180.0) * (90 - lat);
}; };
MapManager.prototype.latLonDistance = function (c1, c2) { MapManager.prototype.latLonDistance = function (c1, c2) {
var R = 6371e3, var R = 6371e3,
...@@ -528,24 +521,22 @@ var MapManager = /** @class */ (function () { ...@@ -528,24 +521,22 @@ var MapManager = /** @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
}; };
}; };
MapManager.prototype.convertToGeoCoordinates = function (x, y, z) { MapManager.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,
......
...@@ -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.22507.46137.47957</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>1718706020.19</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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