getTerrainInfo: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
mNo edit summary
m (Some wiki formatting)
 
(4 intermediate revisions by 2 users not shown)
Line 4: Line 4:
|version1= 2.10
|version1= 2.10


|branch= dev


|gr1= Diagnostic
|gr1= Diagnostic
Line 12: Line 11:
|s1= [[getTerrainInfo]]
|s1= [[getTerrainInfo]]


|r1= [[Array]] - In format {{hl|[landGridWidth, landGridSize, terrainGridWidth, terrainGridSize, seaLevel]}}:
|r1= [[Array]] in format {{hl|[landGridWidth, landGridSize, terrainGridWidth, terrainGridSize, seaLevel]}}:
* landGridWidth: [[Number]] - width of each land grid, in meters
* landGridWidth: [[Number]] - width of each land grid, in meters
* landGridSize: [[Number]] - number of land grid pixels
* landGridSize: [[Number]] - number of land grid pixels
Line 19: Line 18:
* seaLevel: [[Number]] - sea level without waves. The value is {{hl|0}} if tides are disabled.
* seaLevel: [[Number]] - sea level without waves. The value is {{hl|0}} if tides are disabled.


{{Feature|Informative|
{{Feature|informative|
* The result of {{hl|landGridWidth * landGridSize}} and {{hl|terrainGridWidth * terrainGridSize}} is always equal to the [[worldSize]].
* The result of {{hl|landGridWidth * landGridSize}} and {{hl|terrainGridWidth * terrainGridSize}} is always equal to the [[worldSize]].
* "land grid" is used by the game for object placement (e.g. finding the [[nearestObject]]), dynamic simulation, etc.
* "land grid" is used by the game for object placement (e.g. finding the [[nearestObject]]), dynamic simulation, etc.
Line 26: Line 25:


|x1= <sqf>private _terrainInfo = getTerrainInfo; // Stratis: [32,256,4,2048,0]; Altis: [30,1024,7.5,4096,0] </sqf>
|x1= <sqf>private _terrainInfo = getTerrainInfo; // Stratis: [32,256,4,2048,0]; Altis: [30,1024,7.5,4096,0] </sqf>
|x2= [[File:Terrain grid on Stratis.jpg|thumb|Terrain grid on Stratis]]
|x2= [[File:Terrain grid on Stratis.jpg|thumb|Terrain grid on Stratis]]
<sqf> // Draws a 20x20 terrain grid when clicking on the map
<sqf>
// Each triangle of the terrain is formed by a diagonal that starts from the top-left corner of the cell and ends and the bottom-right corner.
// Draws a 20x20 terrain grid when clicking on the map
// Each triangle of the terrain is formed by a diagonal
// that starts from the top-left corner of the cell and ends at the bottom-right corner.
// The green lines show the cell diagonals  
// The green lines show the cell diagonals  
onMapSingleClick {
onMapSingleClick {
getTerrainInfo params ["", "", "_cellsize", "_resolution"];
getTerrainInfo params ["", "", "_cellsize", "_resolution"];
gridLines = [];
gridLines = [];
_pos apply {floor (_x / _cellsize)} params ["_x0", "_y0"];
_pos apply { floor (_x / _cellsize) } params ["_x0", "_y0"];
for "_x" from ((_x0 - 10) max 0) to ((_x0 + 10) min _resolution) do {
for "_x" from ((_x0 - 10) max 0) to ((_x0 + 10) min _resolution) do
for "_y" from ((_y0 - 10) max 0) to ((_y0 + 10) min _resolution) do {
{
private _p1 = [_x, _y] vectorMultiply _cellsize;   //bottom-left corner
for "_y" from ((_y0 - 10) max 0) to ((_y0 + 10) min _resolution) do
private _p2 = [_x, _y + 1] vectorMultiply _cellsize; //top-left corner
{
private _p3 = [_x + 1, _y] vectorMultiply _cellsize; //bottom-right corner
private _p1 = [_x, _y] vectorMultiply _cellsize; // bottom-left corner
private _p2 = [_x, _y + 1] vectorMultiply _cellsize; // top-left corner
private _p3 = [_x + 1, _y] vectorMultiply _cellsize; // bottom-right corner
// Positions are AGL, and Z value of 0 is already at the terrain surface (except on water surface).  
// Positions are AGL, and Z value of 0 is already at the terrain surface (except on water surface).  
// Just move them up a few centimeters so they're visible.
// Just move them up a few centimeters so they're visible.
Line 44: Line 48:
_p2 set [2, 0.1];
_p2 set [2, 0.1];
_p3 set [2, 0.1];
_p3 set [2, 0.1];
 
gridLines pushBack [_p1, _p2, [1,0,0,1]];
gridLines pushBack [_p1, _p2, [1,0,0,1]];
gridLines pushBack [_p1, _p3, [1,0,0,1]];
gridLines pushBack [_p1, _p3, [1,0,0,1]];
gridLines pushBack [_p2, _p3, [0,1,0,1]];
gridLines pushBack [_p2, _p3, [0,1,0,1]];
};
};
};
};
 
onEachFrame {
onEachFrame {
{
{
drawLine3d _x;
drawLine3D _x;
} forEach gridLines;
} forEach gridLines;
}
}
};
};

Latest revision as of 22:35, 4 May 2024

Hover & click on the images for description

Description

Description:
Returns the terrain heightmap information, as well as sea level offset (due to tides, if available).
Groups:
Diagnostic

Syntax

Syntax:
getTerrainInfo
Return Value:
Array in format [landGridWidth, landGridSize, terrainGridWidth, terrainGridSize, seaLevel]:
  • landGridWidth: Number - width of each land grid, in meters
  • landGridSize: Number - number of land grid pixels
  • terrainGridWidth: Number width of each terrain grid, in meters (also known as "cell size")
  • terrainGridSize: Number - number of terrain grid pixels (also known as "heightmap resolution")
  • seaLevel: Number - sea level without waves. The value is 0 if tides are disabled.
  • The result of landGridWidth * landGridSize and terrainGridWidth * terrainGridSize is always equal to the worldSize.
  • "land grid" is used by the game for object placement (e.g. finding the nearestObject), dynamic simulation, etc.
  • "terrain grid" is the actual terrain, used to display the terrain, calculate terrain height, surface normal, etc.

Examples

Example 1:
private _terrainInfo = getTerrainInfo; // Stratis: [32,256,4,2048,0]; Altis: [30,1024,7.5,4096,0]
Example 2:
Terrain grid on Stratis
// Draws a 20x20 terrain grid when clicking on the map // Each triangle of the terrain is formed by a diagonal // that starts from the top-left corner of the cell and ends at the bottom-right corner. // The green lines show the cell diagonals onMapSingleClick { getTerrainInfo params ["", "", "_cellsize", "_resolution"]; gridLines = []; _pos apply { floor (_x / _cellsize) } params ["_x0", "_y0"]; for "_x" from ((_x0 - 10) max 0) to ((_x0 + 10) min _resolution) do { for "_y" from ((_y0 - 10) max 0) to ((_y0 + 10) min _resolution) do { private _p1 = [_x, _y] vectorMultiply _cellsize; // bottom-left corner private _p2 = [_x, _y + 1] vectorMultiply _cellsize; // top-left corner private _p3 = [_x + 1, _y] vectorMultiply _cellsize; // bottom-right corner // Positions are AGL, and Z value of 0 is already at the terrain surface (except on water surface). // Just move them up a few centimeters so they're visible. _p1 set [2, 0.1]; _p2 set [2, 0.1]; _p3 set [2, 0.1]; gridLines pushBack [_p1, _p2, [1,0,0,1]]; gridLines pushBack [_p1, _p3, [1,0,0,1]]; gridLines pushBack [_p2, _p3, [0,1,0,1]]; }; }; onEachFrame { { drawLine3D _x; } forEach gridLines; } };

Additional Information

See also:
getTerrainHeight setTerrainHeight

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note