Jump to content
RyanBolder

CtrlSetPosition (x,y)

Recommended Posts

I think this is the first post of this here im sorry if theres already one but i dont think. Im really struggelin' right now. Its a guess game because i dont know how to solve it. My problem is kinda hard i dont know if its even working. I know im crying so lets start: 

Im trying to figure out how i can convert a 2d [x,y] (World position 2D [x,y]) position to [w,h] (width,height) for ctrlSetPosition, so i can use ctrlSetPosition [x,y,x,y] for a line between these two points. I saw a post somewhere here on this forum talking about drawing it was interesting but i cant find it. There was a similar question, but the guy there wanted a source i just want to know how that works if it does.

Edited by RyanBolder
i wrote [h,w] instead of [w,h]
  • Like 1

Share this post


Link to post
Share on other sites
14 minutes ago, Mr H. said:

 

Thank you but this wont help me. I use worldtoscreen for converting the pos [x,y,z] in [x,y]. But i need a way to convert it to [w,h] or basically i need to find a way to use RscLine from pos a to pos b. I can draw pos a to a 2d position to the screen. (btw: pos a and pos b are 3d). I dont know if you can understand what the problem is. What i have so far is ctrlSetPosition[( _posA select 0 ), ( _posA select 1 ),  THIRDPAR, FORTHPAR]

These two parameters are missing THIRDPAR, FORTHPAR. 

I want to do ctrlSetPosition[( _posA select 0 ), ( _posA select 1 ),  ( _posB select 0 ), ( _posB select 1 )] but this doesnt work the 3 parameter is for w and not for x and the 4 parameter is for h not for y

Share this post


Link to post
Share on other sites

@RyanBolder - Why not just get the width and height of the RscLine? If you know A and B, it is pretty simple. Show more of your code so we can understand you better and help further.

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, HazJ said:

@RyanBolder - Why not just get the width and height of the RscLine? If you know A and B, it is pretty simple. Show more of your code so we can understand you better and help further.

 

            _posA = (getPos cursorTarget) vectorAdd [0,0,2];
            _posA = worldToScreen (_visiblPosvector);

            _posB = (getPos cursorTarget) vectorAdd [0,0,0];
            _posB = worldToScreen (_visiblPosvector2);
        
            _ctrl ctrlSetPosition[(_posA select 0 ), (_posA select 1 ), (_posB select 0 ), (_posB select 1 )];

Share this post


Link to post
Share on other sites

More code. Not going to keep asking/helping otherwise. What type of control is it? You maybe able to use this depending on the control type:

https://community.bistudio.com/wiki/ctrlTextWidth

Quote

CT_STATIC 0

CT_EDIT 2

CT_STRUCTURED_TEXT 13

You can also just just add the two variables together unless I am missing something? Besides more code that is.

  • Like 1

Share this post


Link to post
Share on other sites

To be honest. I am confused too. You aren't making much sense. You want to find the width and height between a line but why when you can just return the actual width and height of the control itself?

  • Like 1

Share this post


Link to post
Share on other sites
3 minutes ago, HazJ said:

To be honest. I am confused too. You aren't making much sense. You want to find the width and height between a line but why when you can just return the actual width and height of the control itself?

Ok to clear up a bit, let me give more informations.

I want to draw between two positions like the drawline3d example here: drawLine3D [getPos player, getPos cursorTarget, [1,1,1,1]]; (in this case getposPlayer == positionA && getpos cursortarget == positionB)

but the problem is i cant set the line between positionA and positionB. I only can set it on my screen some where like in the middle and then to the 3d position. But i cant draw it from a 3d position to a 3d position. Might cleared something more hope you understood if you have questions please ask.

  • Confused 1

Share this post


Link to post
Share on other sites
Quote

But i cant draw it from a 3d position to a 3d position

Quote

the problem is i cant set the line between positionA and positionB

Why not just add the elements you want together?

https://community.bistudio.com/wiki/Operators

https://community.bistudio.com/wiki/Math_Commands

The control (ex: RscLine) you made is 2D, not 3D.

  • Like 1

Share this post


Link to post
Share on other sites

@HazJ

This is what i have.

8kaiNLh.jpg

 

But i dont want to draw from a 2d position to a 3d position. I want to draw fully 2d but using 3d positions. This topic is reallly confusing

Share this post


Link to post
Share on other sites
Just now, HazJ said:

Why not just use:

https://community.bistudio.com/wiki/drawLine3D

If you are only creating a line. What is it you are trying to do, your end goal? Explain in plain words. Or draw a picture if it is easier.

Drawline3d isnt that much visible and doesnt show trough walls. Many people have problems because of this, i wrote already a ticket 2 month's ago but nothing in this case has changed. I want to just draw something which is more visible. Drawline3d is sh...

Share this post


Link to post
Share on other sites

I don't think a normal control RscLine can do this.

  • Sad 1

Share this post


Link to post
Share on other sites
4 minutes ago, HazJ said:

I don't think a normal control RscLine can do this.

That hurt's spend so much time with this. Hope many people sees this and maybe we can gather an certain answer. :(

*But i saw a screenshot before doing this. Kinda strange

Share this post


Link to post
Share on other sites
9 minutes ago, HazJ said:

I don't think a normal control RscLine can do this.

I could be wrong. Also... I just tested drawLine3D and it works fine?

nIkfRiW.jpg

 

 

Share this post


Link to post
Share on other sites
3 minutes ago, HazJ said:

I could be wrong. Also... I just tested drawLine3D and it works fine?

nIkfRiW.jpg

 

 

It looks normal if you are in the VR map but if youre on altis and it is bright then it will not be visible like this.

Share this post


Link to post
Share on other sites

I also tested on Stratis and it works fine there too. It isn't too visible in first person I admit but maybe because I used eyePos and default example from Wiki. Dunno. Anyway, maybe someone else can help you further.

  • Thanks 1

Share this post


Link to post
Share on other sites

Maybe draw several 3d lines with a slight offset between them?

Share this post


Link to post
Share on other sites
//Just so it can be tested multiple times, uinamespace is not cleaned up between editor previews
uiNamespace setVariable [ "unitLine", nil ];

addMissionEventHandler [ "Draw3D", {
	disableSerialization;
	
	_posA = worldToScreen ( getPosATL bob_1 vectorAdd[ 0, 0, 2 ] );
	_posB = worldToScreen ( getPosATL bob vectorAdd[ 0, 0, 2 ] );
	
	_ctrl = uiNamespace getVariable "unitline";
	
	if ( isNil "_ctrl" ) then {
		_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 10001 ];
		uiNamespace setVariable [ "unitLine", _ctrl ];
	};
	
	_ctrl ctrlSetPosition [
		_posA select 0,
		_posA select 1,
		( _posB select 0 ) - ( _posA select 0 ),
		( _posB select 1 ) - ( _posA select 1 )
	];
	_ctrl ctrlCommit 0;
}]; 

The width and height are the difference between the screen positions of _posA and _posB.

Where the line is drawn between the units bob and bob_1.

You may want to add a minimum line w/h of pixelW/pixelH and you will need to handle positions that are off screen.

TEST_MISSION

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
On 31.8.2018 at 8:43 AM, Larrow said:

//Just so it can be tested multiple times, uinamespace is not cleaned up between editor previews
uiNamespace setVariable [ "unitLine", nil ];

addMissionEventHandler [ "Draw3D", {
	disableSerialization;
	
	_posA = worldToScreen ( getPosATL bob_1 vectorAdd[ 0, 0, 2 ] );
	_posB = worldToScreen ( getPosATL bob vectorAdd[ 0, 0, 2 ] );
	
	_ctrl = uiNamespace getVariable "unitline";
	
	if ( isNil "_ctrl" ) then {
		_ctrl = findDisplay 46 ctrlCreate [ "RscLine", 10001 ];
		uiNamespace setVariable [ "unitLine", _ctrl ];
	};
	
	_ctrl ctrlSetPosition [
		_posA select 0,
		_posA select 1,
		( _posB select 0 ) - ( _posA select 0 ),
		( _posB select 1 ) - ( _posA select 1 )
	];
	_ctrl ctrlCommit 0;
}]; 

The width and height are the difference between the screen positions of _posA and _posB.

Where the line is drawn between the units bob and bob_1.

You may want to add a minimum line w/h of pixelW/pixelH and you will need to handle positions that are off screen.

TEST_MISSION

Thank you this helps and this is what i needed. Why using the uiNamespace why doesnt it work without?

Share this post


Link to post
Share on other sites

@RyanBolder that's what the comment ontop of th script is about.

 

basically when you do UI stuff using ctrlCreate you need to make sure you clean up after yourself properly because when you use the restart mission functionality arma does not clean up by itself. so without that isNil check and saving the control (line in this case) in the uiNamespace before hand you will get a new line everytime you restart (restart using the restart button in the ESC/Pause menu). they will start stacking up and only the latest one would react to your code.

 

if it's not clear still, jsut remove the parts and see what happens.

  • Like 2

Share this post


Link to post
Share on other sites

+ The control needs to be saved between iterations of the mission event so you can reference it next Draw3D. If you try to save it in missionNamespace (Global Variable) you will get complaints about serialisation because it is a ui element.

  • Like 3

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

×