OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Spooner on 22 Aug 2007, 19:49:06

Title: Manually drawing on the map
Post by: Spooner on 22 Aug 2007, 19:49:06
OK, I'm trying to build a simple drawing program to allow MP players to draw free-hand on a map control (Among other things). The specific commands are drawEllipse, drawIcon, drawLine, drawRectangle and drawArrow, but, for the life of me, I can't get anything visible to appear. Has anyone actually managed to manually draw anything on a map control with these commands, because I'm clearly missing something obvious?

I'll make and upload an example mission if anyone thinks that might help, but I'm hoping someone has used at least one of these commands before and can just point me in the direction of an example script.

Don't worry, I don't need any help with recording/managing/broardcasting the drawings...just how to make visible marks on a map ;(
Title: Re: Manually drawing on the map
Post by: ColonelSandersLite on 23 Aug 2007, 09:31:05
I've read a few topics that seem to indicate that nobody knows how to get those to work.  Maybe someone will come around and contradict that, but I have my doubts.
Title: Re: Manually drawing on the map
Post by: Mandoble on 23 Aug 2007, 11:01:57
What you try to do should be quite easy to achieve as Ellipses, Icons, Rectangles and Arrows are already present as marker types.

Lines are a bit more tricky, to draw them, once you have the start and end point do the following:
- Calculate the 2D distance between start and end point
- Calculate angle between start and end point
- Calculate the center position between start and end point
Code: [Select]
_dist2d = sqrt(((_endpos select 0)-(_startpos select 0))^2+((_endpos select 1)-(_startpos select 1))^2);
_ang = ((_endpos select 0)-(_startpos select 0)) atan2 ((_endpos select 1)-(_startpos select 1));
_center = [(_startpos select 0)+sin(_ang)*_dist2d/2,(_startpos select 1)+cos(_ang)*_dist2d/2]

- Now create a marker, rectangle type
- Change its size, use the desired line width in meters and the height being the calculated _dist2d, for example [10, _dist2d]
- Place the new marker in the _center position: "newlinemarker" setMarkerPosLocal _center;
- Change the direction of the new marker to _ang: "newlinemarker" setMarkerDirLocal _ang;
Title: Re: Manually drawing on the map
Post by: Spooner on 23 Aug 2007, 11:23:37
Thanks for the rectangular "line" idea, Mandoble; not something I would have considered (duh!), but I'm sure your suggestion will allow me to do everything I wanted to do. Pity the already implemented drawLine is disabled, broken or just improperly documented, but I suppose the community is used to complicated workarounds.
Title: Re: Manually drawing on the map
Post by: Mandoble on 23 Aug 2007, 11:49:10
More than problably the marker solution is much better than using any working drawXXXX command, as you may move markers at will as well as delete them if needed, change their colors, sizes, angles, positions. But the drawXXXX commands, even working, dont return any object you may handle, alter or delete later. With the markers you have an added advantage as markers may be global or local. You may create something like a PDA where different players may draw different things and the result is shared by everybody. Makers give you also the advantage of using text.
Title: Re: Manually drawing on the map
Post by: Spooner on 23 Aug 2007, 11:58:55
Well, one of the things I'd tried with the drawXXX commands was to redraw them every frame, though it didn't help. This would get over the whole problem of moving and deleting, assuming they were implemented in this way. Who knows, though?

Although markers may be global, I want my shared drawable map to be used in MP which would rather mean I have to manage the transfer of markers myself. No problem though, since I have the framework in place; it was only the actual drawing of the lines that I couldn't work out. The other advantage of manually communicating positions rather than creating dozens of global markers is vastly reduced bandwidth use.

**Edit**

Some slight errors in Mando's (admittedly untested) code, but otherwise worked fine:
Code: [Select]
_markerName = "newlinemarker";
createMarkerLocal [_markerName, _center];
_markerName setMarkerShapeLocal "RECTANGLE";
_markerName setMarkerSizeLocal [2, _dist2d / 2]; // 4m wide line
_markerName setMarkerDirLocal _angle;

The map drawing is working in MP, at least at a basic level, and will be in my SPON Scripts release which is coming very soon... http://www.ofpec.com/forum/index.php?topic=30129.0