Jump to content
5mpower

How to recognize coordinates of 4 corners of screenshot

Recommended Posts

So i take a screenshot in Arma 3 and i need to know coordinates (x,y) of every corner of screenshot. Are there any command to return at least coordinate of one corner?

Share this post


Link to post
Share on other sites
20 hours ago, stanhope said:

With [0,0], [0,1], [1,0],[1,1]

since it is in screen coordinates the coordinates are as follows:

TOP LEFT: [safeZoneX, safeZoneY]
TOP RIGHT: [safeZoneX + safeZoneW, safeZoneY]
BOTTOM LEFT: [safeZoneX, safeZoneY + safeZoneH]
BOTTOM RIGHT: [safeZoneX + safeZoneW, safeZoneY + safeZoneH]

And in case you are running a triple monitor setup replace safeZoneX with safeZoneXAbs and safeZoneW with safeZoneWAbs

  • Like 2

Share this post


Link to post
Share on other sites
On 3/12/2021 at 8:19 PM, 7erra said:

since it is in screen coordinates the coordinates are as follows:


TOP LEFT: [safeZoneX, safeZoneY]
TOP RIGHT: [safeZoneX + safeZoneW, safeZoneY]
BOTTOM LEFT: [safeZoneX, safeZoneY + safeZoneH]
BOTTOM RIGHT: [safeZoneX + safeZoneW, safeZoneY + safeZoneH]

And in case you are running a triple monitor setup replace safeZoneX with safeZoneXAbs and safeZoneW with safeZoneWAbs

Yep that works, thanks. So also i need to know 4 coordinates of object in screenshot (ex. Tank or smth). So we need to use BoundingBoxReal? By that function we can only recognize Xmin, Ymin, Zmin, Xmax, Ymax, Zmax. How we can get coordinates of all corners of this object? Also there is a trouble that point Xmin, Ymin can be not one point. Picture also includedKZ7rZDoabtc.jpg?size=1170x678&quality=96

Share this post


Link to post
Share on other sites

aa = (0 boundingBoxReal yourVisibleObject);  // nothing new so far


points = [[aa#0#0,aa#0#1,aa#0#2],[aa#0#0,aa#1#1,aa#0#2],[aa#1#0,aa#0#1,aa#0#2],[aa#1#0,aa#1#1,aa#0#2],[aa#0#0,aa#0#1,aa#1#2],[aa#0#0,aa#1#1,aa#1#2],[aa#1#0,aa#0#1,aa#1#2],[aa#1#0,aa#1#1,aa#1#2]];  // you get the 8 edge points of your bounding box, relative to center of object

 

bb = points apply {worldToScreen (yourVisibleObject modelToWorld _x)}; // modelToworld is supposed translating the relative coordinates to world AGL ones. The worldToScreen translates these world coordinates to screen ones...

 

Something is wrong because the result is sometimes out of range [0,1] and that's not OK for the purpose. I don't remember why. There is a note in BIKI (and a remark of 7erra above) referring to safeZone but I don't remember how you can pass [x,y] coming from worldToScreen into a workable screen data, sorry.

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

Something is wrong because the result is sometimes out of range [0,1] and that's not OK for the purpose. I don't remember why. There is a note in BIKI (and a remark of 7erra above) referring to safeZone but I don't remember how you can pass [x,y] coming from worldToScreen into a workable screen data, sorry.

Arma's screen coordinates can be out of the range of [0,1] depending on UI settings. This is a relict from old times where [0,1] referred to a 4:3 monitor on ui scale "Very Large". So safeZoneX (left side of the screen) will be negative, something like -1.234 or sth. But we can translate the screen coordinates to either pixels or percentage:

Percentage:

x = safeZoneX + A * safeZoneW = 0.123 (for example)

Solve for A:

A = (x - safeZoneX)/safeZoneW = (0.123 - safeZoneX)/safeZoneW

 

Similar approach for pixels:

x = safeZoneX + P * pixelW;
P = (x - safeZoneX) / pixelW;

 

Example code (run in 3den) :

findDisplay 313 displayRemoveEventHandler ["MouseMoving", missionNamespace getVariable ["EHID", -1]];
EHID = findDisplay 313 displayAddEventHandler ["MouseMoving",{
	params ["_display", "_xPos", "_yPos"];
	toFixed 5;
	_mp = getMousePosition;
	_mp params ["_xp", "_yp"];
	_mpRel = [
		(_xp - safeZoneX) / safeZoneW,
		(_yp - safeZoneY) / safeZoneH
	];

	_mpPixel = [
		(_xp - safeZoneX) / pixelW,
		(_yp - safeZoneY) / pixelH
	] apply {round _x};
	
	systemChat format ["Absolute: %1 | Relative: %2 | Pixel: %3", _mp, _mpRel, _mpPixel];
}];

 

  • Like 1

Share this post


Link to post
Share on other sites

Yes, thanks. So for an object like 5mPower want:

 

private _box = (0 boundingBoxReal yourVisibleObject);

private _edgePoints = [[_box#0#0,_box#0#1,_box#0#2],[_box#0#0,_box#1#1,_box#0#2],[_box#1#0,_box#0#1,_box#0#2],[_box#1#0,_box#1#1,_box#0#2],[_box#0#0,_box#0#1,_box#1#2],[_box#0#0,_box#1#1,_box#1#2],[_box#1#0,_box#0#1,_box#1#2],[_box#1#0,_box#1#1,_box#1#2]];  // you get the 8 edge points of your bounding box, relative to center of object

 

 private _result = (_edgePoints apply {worldToScreen (yourVisibleObject modelToWorld _x)} apply {[(_x#0 - safeZoneX) / safeZoneW,(_x#1 - safeZoneY) / safeZoneH]});

seems to work!

  • Like 2

Share this post


Link to post
Share on other sites
11 hours ago, pierremgi said:

Yes, thanks. So for an object like 5mPower want:

 

private _box = (0 boundingBoxReal yourVisibleObject);

private _edgePoints = [[_box#0#0,_box#0#1,_box#0#2],[_box#0#0,_box#1#1,_box#0#2],[_box#1#0,_box#0#1,_box#0#2],[_box#1#0,_box#1#1,_box#0#2],[_box#0#0,_box#0#1,_box#1#2],[_box#0#0,_box#1#1,_box#1#2],[_box#1#0,_box#0#1,_box#1#2],[_box#1#0,_box#1#1,_box#1#2]];  // you get the 8 edge points of your bounding box, relative to center of object

 

 private _result = (_edgePoints apply {worldToScreen (yourVisibleObject modelToWorld _x)} apply {[(_x#0 - safeZoneX) / safeZoneW,(_x#1 - safeZoneY) / safeZoneH]});

seems to work!

How we define SafeZoneX, SaveZoneY?. I export data in rpt file. Firstly i export "_edgePoints" in rpt file and get results smth like "[[-0.204747,-0.603099,-0.26893],[-0.204747,0.609368,-0.26893],[0.205475,-0.603099,-0.26893]...". How we can translate it in meters (or pixels from screenshot)?. For better understanding i draw what i want and attach zip with "mission" and script  (called "test.sqf"). Link for zip file below. Sorry for bad coding, im just trying to learn

https://fex.net/ru/s/bscpd1p
For open mission we need to go to "editor" then go to "scenario", "open"  then choise "1111.Altis". To run script i use "execVM "test.sqf";"
tyc3kIVfwBY.jpg?size=1404x579&quality=96

Share this post


Link to post
Share on other sites
14 hours ago, pierremgi said:

Yes, thanks. So for an object like 5mPower want:

 

private _box = (0 boundingBoxReal yourVisibleObject);

private _edgePoints = [[_box#0#0,_box#0#1,_box#0#2],[_box#0#0,_box#1#1,_box#0#2],[_box#1#0,_box#0#1,_box#0#2],[_box#1#0,_box#1#1,_box#0#2],[_box#0#0,_box#0#1,_box#1#2],[_box#0#0,_box#1#1,_box#1#2],[_box#1#0,_box#0#1,_box#1#2],[_box#1#0,_box#1#1,_box#1#2]];  // you get the 8 edge points of your bounding box, relative to center of object

 

 private _result = (_edgePoints apply {worldToScreen (yourVisibleObject modelToWorld _x)} apply {[(_x#0 - safeZoneX) / safeZoneW,(_x#1 - safeZoneY) / safeZoneH]});

seems to work!

Also i check what will be if we export SaveZoneX: this mistake is coming "Error position: <SaveZoneX;"

Share this post


Link to post
Share on other sites
32 minutes ago, pierremgi said:

 

20 hours ago, 7erra said:

Arma's screen coordinates can be out of the range of [0,1] depending on UI settings. This is a relict from old times where [0,1] referred to a 4:3 monitor on ui scale "Very Large". So safeZoneX (left side of the screen) will be negative, something like -1.234 or sth. But we can translate the screen coordinates to either pixels or percentage:

Percentage:


x = safeZoneX + A * safeZoneW = 0.123 (for example)

Solve for A:


A = (x - safeZoneX)/safeZoneW = (0.123 - safeZoneX)/safeZoneW

 

Similar approach for pixels:


x = safeZoneX + P * pixelW;
P = (x - safeZoneX) / pixelW;

 

Example code (run in 3den) :


findDisplay 313 displayRemoveEventHandler ["MouseMoving", missionNamespace getVariable ["EHID", -1]];
EHID = findDisplay 313 displayAddEventHandler ["MouseMoving",{
	params ["_display", "_xPos", "_yPos"];
	toFixed 5;
	_mp = getMousePosition;
	_mp params ["_xp", "_yp"];
	_mpRel = [
		(_xp - safeZoneX) / safeZoneW,
		(_yp - safeZoneY) / safeZoneH
	];

	_mpPixel = [
		(_xp - safeZoneX) / pixelW,
		(_yp - safeZoneY) / pixelH
	] apply {round _x};
	
	systemChat format ["Absolute: %1 | Relative: %2 | Pixel: %3", _mp, _mpRel, _mpPixel];
}];

 

Question about translating position in pixels: So i recieve a results of 4 edge points smth like that  :[-0.712121,-0.409091] (its left top corner fo screenshot). I need that left top corner will be [0,0] and right bottom corner will be [1920,1080]. If i calculate a coefficient of "translating" it will be true? Btw i have this mistake "Error in expression <log [safeZoneX, safeZoneY + safeZoneH]" if try to "diag_log [safeZoneX, safeZoneY + safeZoneH]". Why is that mistake?

Share this post


Link to post
Share on other sites
14 hours ago, 5mpower said:

Question about translating position in pixels: So i recieve a results of 4 edge points smth like that  :[-0.712121,-0.409091] (its left top corner fo screenshot). I need that left top corner will be [0,0] and right bottom corner will be [1920,1080]. If i calculate a coefficient of "translating" it will be true?

PX = (x - safeZoneX) / pixelW

and

PY = (y - safeZoneY) / pixelH

will give you the pixel position where x and y are the UI positions that Arma gives you. but safeZoneX, safeZoneY, pixelW and pixelH are not constant and change with game settings. Theoretically those values stay the same if you don't change the UI settings so you end up with at least 4 coefficients

 

 

15 hours ago, 5mpower said:

Btw i have this mistake "Error in expression <log [safeZoneX, safeZoneY + safeZoneH]" if try to "diag_log [safeZoneX, safeZoneY + safeZoneH]". Why is that mistake?

no errors here? output in rpt is "[-0.454716,1.21441]" (windowed, medium UI size)

Share this post


Link to post
Share on other sites
On 4/1/2021 at 12:37 PM, 7erra said:

PX = (x - safeZoneX) / pixelW

and


PY = (y - safeZoneY) / pixelH

will give you the pixel position where x and y are the UI positions that Arma gives you. but safeZoneX, safeZoneY, pixelW and pixelH are not constant and change with game settings. Theoretically those values stay the same if you don't change the UI settings so you end up with at least 4 coefficients

 

 

no errors here? output in rpt is "[-0.454716,1.21441]" (windowed, medium UI size)

Yep, no more errors, but i get strange results. 
So here is script:
 

_Xrnd = round(random 18) -9;
_Yrnd = round(random 18) -9;
_Dir = random(360);
_Alt = random(5)+ 1500;

camX =(getPos player select 0) + _Xrnd;
camY = (getPos player select 1) + _Yrnd;
camZ = (getPos player select 2) ;


cam = "camera" camCreate  position player;
cam cameraEffect ["internal", "back"];


_configs = "getNumber (_x >> 'scope') >= 2 AND configName _x isKindof 'Tank'" configClasses (configFile >> "CfgVehicles");
_classNames = _configs apply {configName _x};


for [{ _i = 0 }, { _i < 1000 }, { _i = _i + 1 }] do
{

_Xrnd = round(random 18) -9;
_Yrnd = round(random 18) -9;
_Dir = random(360);
_Alt = random(5)+ 1500;


_timeToSkipTo = round(random 6)+9;
_to =  (_timeToSkipTo - daytime + 24 ) % 24;
skipTime _to ;


0 setFog 0;
0 setRain 0;
_vx = camX + 100 ;
_name =(_classNames call BIS_fnc_selectRandom);
_vech =  createVehicle [_name, position player , [], 1000];

//_vech = vehicle player;
_bbr = 0 boundingBoxReal _vech;

_center = boundingCenter _vech;
_p1 = _bbr select 0;
_p2 = _bbr select 1;
_width = abs ((_p2 select 0) - (_p1 select 0));
_length = abs ((_p2 select 1) - (_p1 select 1));
_height = abs ((_p2 select 2) - (_p1 select 2));
_TL = screenToWorld [0,0];
_TR = screenToWorld [0,1];
_BL = screenToWorld [1,0];
_BR = screenToWorld [1,1];
sleep 4;
private _box = (0 boundingBoxReal _vech);
private _edgePoints = [[_box#0#0,_box#0#1,_box#0#2],[_box#0#0,_box#1#1,_box#0#2],[_box#1#0,_box#0#1,_box#0#2],[_box#1#0,_box#1#1,_box#0#2],[_box#0#0,_box#0#1,_box#1#2],[_box#0#0,_box#1#1,_box#1#2],[_box#1#0,_box#0#1,_box#1#2],[_box#1#0,_box#1#1,_box#1#2]];
//PX = (x - safeZoneX) / pixelW;
//PY = (y - safeZoneY) / pixelH;
diag_log _edgePoints;
private _result = (_edgePoints apply {worldToScreen (_vech modelToWorld _x)} apply {[(_x#0 - safeZoneX) / safeZoneW,(_x#1 - safeZoneY) / safeZoneH]});
diag_log _result;
//P = (_box#0#0 - safeZoneX) / pixelW;
//diag_log SafeZoneX;
//diag_log SafeZoneY;
diag_log [safeZoneX, safeZoneY];
diag_log [safeZoneX + safeZoneW, safeZoneY];
diag_log [safeZoneX, safeZoneY + safeZoneH];
diag_log [safeZoneX + safeZoneW, safeZoneY + safeZoneH];
//diag_log P;
_vech setDir _Dir;

camX =(getPos _vech select 0) + _Xrnd;
camY = (getPos _vech select 1) + _Yrnd;
camZ = (getPos _vech select 2) ;
cam camCommit 0;
cam camSetPos [camX, camY, camZ+_Alt];
cam camSetDir  [0, 0, -1];
cam camSetFov 0.05;

cam camCommit 0;
sleep 4;

camX =(getPos _vech select 0) + _Xrnd;
camY = (getPos _vech select 1) + _Yrnd;
camZ = (getPos _vech select 2) ;
cam camCommit 0;
cam camSetPos [camX, camY, camZ+_Alt];
cam camSetDir  [0, 0, -1];
cam camSetFov 0.05;

_vech animateSource ["MainTurret", rad 190];

cam camCommit 0;


screenshot "testFile.png";
screenshot format["%9_az%3_w%1_l%2_x%4_y%5_alt%6_cx%7_cy%8.png", _width, _length, _Dir, _Xrnd, _Yrnd, _Alt, _center select 0, _center select 1, _name ];
profileNamespace setVariable ["TAG_lastPlayerLocation", getPosASL player];
saveProfileNamespace;
sleep 0.1;
deleteVehicle _vech;

};

cam camCommit 6;
cam cameraEffect ["terminate","back"];
camDestroy cam;

Maybe i doing smth wrong, but in rpt file i have this:
 

14:14:01 [[0.674908,-5.88783],[0.674885,-5.79451],[0.655435,-5.88723],[0.655423,-5.79392],[0.674529,-5.90356],[0.674506,-5.80996],[0.655,-5.90295],[0.654987,-5.80936]]
14:14:01 [-0.712121,-0.409091]
14:14:01 [1.71212,-0.409091]
14:14:01 [-0.712121,1.40909]
14:14:01 [1.71212,1.40909]
14:14:01 [-0.712121,-0.409091]
14:14:01 [1.71212,-0.409091]
14:14:01 [-0.712121,1.40909]
14:14:01 [1.71212,1.40909]
14:43:21 [[-0.204747,-0.603099,-0.26893],[-0.204747,0.609368,-0.26893],[0.205475,-0.603099,-0.26893],[0.205475,0.609368,-0.26893],[-0.204747,-0.603099,0.273886],[-0.204747,0.609368,0.273886],[0.205475,-0.603099,0.273886],[0.205475,0.609368,0.273886]]
14:43:21 [-0.712121,-0.409091]
14:43:21 [1.71212,-0.409091]
14:43:21 [-0.712121,1.40909]
14:43:21 [1.71212,1.40909]

 

Share this post


Link to post
Share on other sites

better late than never: why should these results be weird? for example [1.71212,1.40909] seems like a reasonable result for [safeZoneX + safeZoneW, safeZoneY + safeZoneH]?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×