svg2aamap

Something else for Armagetron? Goody!
User avatar
dlh
Formerly That OS X Guy
Posts: 2034
Joined: Fri Jan 02, 2004 12:05 am
Contact:

Post by dlh »

ed wrote:Can I ask why all x values are + and all y values are - ?
It makes it very difficult to add spawn points later.
I can look at the image in Inkscape and see I want to later put a spawn point at x=80, y=160 for example.
But this would be in xml x=x y=(max y val - (max y val * 2))-y
or something. All I know is that it's a pain to add multiple spawn/zones afterwards. It kind of limits me to symmetrical maps where I can just y = -y.
But that messes up angles as the whole thing is flipped.
I guess I could just to a search on "y="-" and replace with "y="", but then the map must be symmetrical to be any good to me later.
Waffling now.
It is because Arma has different axis orientation than SVG. The y-axis needs to be flipped.

SVG

Code: Select all

(0, 0)
  | 
  | 
  |
  |
  +----------
AA

Code: Select all

  |  
  |  
  | 
  |
  +----------
(0, 0)

User avatar
Jonathan
A Brave Victim
Posts: 3392
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

You could also not assume a top-down view. :)

User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

Kyle: The newest version of the script is able to do transformations now.
This still doesn't solve the problem that zones aren't recognized as they aren't exported as circles.
They're rendered as walls, and since the code doesn't support arc commands and they're used in circles exported by inkscape they get rendered kind of weird, too :(
There's no place like ::1

User avatar
kyle
Reverse Outside Corner Grinder
Posts: 1830
Joined: Thu Jun 08, 2006 3:33 pm
Location: Indiana, USA, Earth, Milky Way Galaxy, Universe, Multiverse
Contact:

Post by kyle »

i don't know who to quote but about making maps so y is not negative


can you just find the smallest y values and take the absolute value of it and add it to all points also if the smallest x point is not at 0 couldn't you add or subtract in the same way. that would be nice

if those are possible you could also have an option that you center it around the origin; its nice for symmetric stuff

as for the new script it works better i still get some messy stuff but thats because of the zones. it draws the rest correctly.

User avatar
Jonathan
A Brave Victim
Posts: 3392
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

-ct-kyle wrote:i don't know who to quote but about making maps so y is not negative
Doesn't matter. I'd rather see some real arguments as to why non-negative coordinates are so important.
-ct-kyle wrote:can you just find the smallest y values and take the absolute value of it and add it to all points also if the smallest x point is not at 0 couldn't you add or subtract in the same way. that would be nice
If I managed to decode/guess your intentions, you mean subtracting the point consisting of the smallest coordinates from each point. Is that correct?
-ct-kyle wrote:if those are possible you could also have an option that you center it around the origin; its nice for symmetric stuff
Centering makes for the best overall precision in floating-point representations. Don't defeat the purpose (not in all ways) by doing it with low precision though.

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Post by Lucifer »

Ok, here's the deal. Images have their positive y axis oriented downward so the origin is top-left, right? Arma uses a cartesian plane for map coordinates. The result is that if you pass the y-values unmodified (which is perfectly legal!), the map image gets reversed like in a mirror. This is usually not the desired behavior.

So, there are conversions. Which is where y'all are at, I'm just trying to reset the coordinate discussion. :)

The first conversion we've encountered is rendering a map to an image. For that, the mirror image is actually acceptable, although unexpected behavior. To get the expected behavior, this conversion is the best:

y = max(y) - current(y)

Where max(y) is the maximum value of the y coordinate and current(y) is the y coordinate for the point you're currently converting. X values don't change at all! The x axis is already fine. In fact, ideally you'd do your final coordinate conversion after you convert the y coordinates, which nemo had to do on his map previewer to make sure negative x values would appear and that the image would be centered correctly regardless of where you located your origin in relation to the rest of the map. Anyway, this y coordinate conversion isn't mathematically correct because the points are actually moved on the plane, but we're not after mathematical perfection--we're after displaying the image the way the map maker likely visualized it in his head.

So now wrtlprnft is trying to go the other way, he needs to convert y coordinates from an image back to cartesian. This is fun. :) I think he said currently he does 0-y, which is mathematically correct. But it's not consistent with what the previewer does, and it probably needs to be. I figure that a map maker is still wanting to locate the origin at the lower-left corner instead of the upper-left corner, so now the transformation needs to be in reverse.

Actually, I think using the same transformation that's used the other way will work. I.e. y = max(y) - current(y) . Side point: don't get lost in the negative signs, the problem corrects itself.

Finally, the problem of the origin. If you want to use this as your primary way to make maps, you're going to either need a way for the map maker to specify where he wants to locate the origin, or he's going to have to live with only working in the first quadrant. Got any ideas on how to let the map maker locate his origin?

If you allow the origin to be placed at any arbitrary point in the image (or outside the image), then you basically need to do the y-axis conversion mentioned, then you need to add the origin's location in relation to the image's coordinate system. It might be subtract, check your signs on it! (I had to do this in Acme to allow the user to move around on the map :) )

Here's why that transformation is the right one for expected behavior:

To relocate a point in relation to a line on a plane, you just subtract the point's y-coordinate from the line's y-coordinate. It's f(x) - g(x) . For example, if f(x) = x, then f(x) - sin(x) will wrap a sin curve around the line y=x, right? It's the same thing here, however the line we're wanting to relocate around is the line at y=max(g(x) ) , where g(x) is your map (and it's not really a function in spite of me using functional notation). So if y=max(g(x) ) is f(x), and g(x) is the map, you do f(x) - g(x), which is the maximum value of the y-coordinate minues the y coordinate for a point on the map. (sorry, have had a little too many discussions on this topic where we always go through the reasoning from the beginning and always wind up with this solution, can we just jump to this solution now and build from it?)
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

User avatar
kyle
Reverse Outside Corner Grinder
Posts: 1830
Joined: Thu Jun 08, 2006 3:33 pm
Location: Indiana, USA, Earth, Milky Way Galaxy, Universe, Multiverse
Contact:

Post by kyle »

Jonathan wrote:
-ct-kyle wrote:i don't know who to quote but about making maps so y is not negative
Doesn't matter. I'd rather see some real arguments as to why non-negative coordinates are so important.
i was thinking here,because ed likes that for some reason, but then i thought i like more the center at the origin (0,0)
Jonathan wrote:
-ct-kyle wrote:can you just find the smallest y values and take the absolute value of it and add it to all points also if the smallest x point is not at 0 couldn't you add or subtract in the same way. that would be nice
If I managed to decode/guess your intentions, you mean subtracting the point consisting of the smallest coordinates from each point. Is that correct?
yes

User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

Jonathan wrote:I'd rather see some real arguments as to why non-negative coordinates are so important.
Ok. I build my map in inkscape. Using aamap xy conventions.
I know that later, using a text editor, I am going to need to add spawn points and zones.
I can hover my mouse over my desired location and down the bottom it will tell my x=80 y=120 or whatever. So I write this down. I do this for all my spawns and zones. Taking a note of what angles I need for my spawns.
I then convert the svg->aamap and try to add my zones/spawns coordinates/angles.
If the map is a simple one, my coords are still useful with simple calcuations. But if I've used strange shaped arena I noticed the coords shift completely and I've had to recalculate from scratch.
I ended up loading the map into armabell to help work out the points.

Now, I'm not complaining. Just stating problems from a map makers point of view.

One workaround is to build the map, write down the coords, then grab all the map vectors(?) and drag them so they're sitting just on top of the Inkscape document (image?) before saving.
Then when it's converted, the y coords are positive (except for -0, simple fix).
I've only tried this for a simple square map with text scribbled on it, but it worked and was converted unharmed.
I think any strange shape being converted would also be unharmed as long as a square box is drawn around it. It seems to move floating shapes around.

User avatar
Jonathan
A Brave Victim
Posts: 3392
Joined: Thu Feb 03, 2005 12:50 am
Location: Not really lurking anymore

Post by Jonathan »

Lucifer, I don't feel like replying to all that right now. Regarding the consistency with the previewer:
  • I haven't looked at what the previewer does.
  • The top left pixel in, say, a PNG image is merely said to be at the origin because it is the first to be encoded. A sort of native space based on order can be constructed, and it is often used in practice, but …
  • Map makers using this will probably have some SVG editor that can give them useful numbers.
ed, you're losing me. If you take a point in the SVG coordinate system (Armagetron's coordinate system is meaningless at this point), all you have to do is negate the y coordinate (or negate x for that matter, if the converter did that, or even mirror in any direction, although that will get impractical indeed) to put it in the right place in Armagetron.

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Post by Lucifer »

Jonathan, there's probably some missing parts of the conversation anyway. :)

When nemo was making his previewer output svg, we found some api functions that seemed to indicate you could change your origin and orientation of axes. If you can do that, then that's all that needs to be done, right? Except the functions didn't exist in the Ruby bindings for some reason, either one was broken and the other was left out, or something like that.

Now Inkscape has no such limitation. So if it is possible with svg to change the origin and orientation of the y axis, then the map maker could do that and the converter can't do anything about it until that issue is cleared up in the ruby bindings.

Also, the reason for the origin being where it is in most graphics formats is irrelevant. :) But if you want to get technical, it has its root in how CRT's actually work and we've just inherited that in new formats. At this point I don't think there's any good reason to keep doing that, we may as well switch out to a cartesian plane for image files, but now we've got millions of graphics programmers who might object (might not, I don't know).

Personally, I'd like to see arma support different coordinate systems anyway. Philippe was talking about wanting to play on a sphere or inside a cylinder, seems like it would be trivial to add support for "bitmap coordinate systems". :)
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

I'll just note that inkscape starts its coordinate system at the bottom-left and probably does some conversation for saving to SVG, this is why the coordinates are screwed up if you try to place spawn points.
There's no place like ::1

User avatar
ed
Match Winner
Posts: 613
Joined: Mon Feb 13, 2006 12:34 pm
Location: UK

Post by ed »

wrtlprnft wrote:I'll just note that inkscape starts its coordinate system at the bottom-left and probably does some conversation for saving to SVG, this is why the coordinates are screwed up if you try to place spawn points.
If you put a square box around the map in Inkscape and make sure the square is sitting on top of the document like this:
Image
It will produce a map like this:
Image
And xml like this:

Code: Select all

<!DOCTYPE Resource SYSTEM "AATeam/map-0.2.8.0_rc4.dtd">
<Resource type="aamap" name="" version="" author="" category="">
	<Map version="2">
		<World>
			<Field>
				<Wall>
					<Point x="0.0" y="-0.0"/>
					<Point x="250.0" y="-0.0"/>
					<Point x="250.0" y="250.0"/>
					<Point x="0.0" y="250.0"/>
					<Point x="0.0" y="-0.0"/>
					<Point x="0.0" y="-0.0"/>
				</Wall>
				<Wall>
					<Point x="20.0" y="210.0"/>
					<Point x="20.0" y="196.45"/>
					<Point x="20.0" y="185.6"/>
					<Point x="20.0" y="177.15"/>
					<Point x="20.0" y="170.8"/>
					<Point x="20.0" y="166.25"/>
					<Point x="20.0" y="163.2"/>
					<Point x="20.0" y="161.35"/>
					<Point x="20.0" y="160.4"/>
					<Point x="20.0" y="160.05"/>
					<Point x="20.0" y="160.0"/>
					<Point x="20.0" y="180.0"/>
					<Point x="40.0" y="180.0"/>
					<Point x="40.0" y="210.0"/>
					<Point x="40.0" y="160.0"/>
					<Point x="60.0" y="160.0"/>
					<Point x="60.0" y="160.0"/>
				</Wall>
				<Wall>
					<Point x="40.0" y="188.57143"/>
					<Point x="60.0" y="190.0"/>
				</Wall>
				<Wall>
					<Point x="40.0" y="205.71429"/>
					<Point x="60.0" y="210.0"/>
				</Wall>
				<Wall>
					<Point x="70.0" y="200.0"/>
					<Point x="70.0" y="160.0"/>
					<Point x="90.0" y="160.0"/>
				</Wall>
				<Wall>
					<Point x="100.0" y="200.0"/>
					<Point x="100.0" y="150.0"/>
					<Point x="120.0" y="150.0"/>
				</Wall>
				<Wall>
					<Point x="160.0" y="180.0"/>
					<Point x="140.0" y="160.0"/>
					<Point x="160.0" y="150.0"/>
					<Point x="210.0" y="160.0"/>
					<Point x="200.0" y="220.0"/>
					<Point x="160.0" y="180.0"/>
					<Point x="160.0" y="180.0"/>
				</Wall>
				<Wall>
					<Point x="30.0" y="100.0"/>
					<Point x="30.28" y="98.6"/>
					<Point x="31.04" y="94.8"/>
					<Point x="32.16" y="89.2"/>
					<Point x="33.52" y="82.4"/>
					<Point x="35.0" y="75.0"/>
					<Point x="36.48" y="67.6"/>
					<Point x="37.84" y="60.8"/>
					<Point x="38.96" y="55.2"/>
					<Point x="39.72" y="51.4"/>
					<Point x="40.0" y="50.0"/>
					<Point x="40.0" y="80.0"/>
					<Point x="40.84" y="79.16"/>
					<Point x="43.12" y="76.88"/>
					<Point x="46.48" y="73.52"/>
					<Point x="50.56" y="69.44"/>
					<Point x="55.0" y="65.0"/>
					<Point x="59.44" y="60.56"/>
					<Point x="63.52" y="56.48"/>
					<Point x="66.88" y="53.12"/>
					<Point x="69.16" y="50.84"/>
					<Point x="70.0" y="50.0"/>
					<Point x="70.0" y="100.0"/>
				</Wall>
				<Wall>
					<Point x="100.0" y="70.0"/>
					<Point x="70.0" y="60.714286"/>
					<Point x="80.0" y="50.0"/>
					<Point x="120.0" y="50.0"/>
					<Point x="100.0" y="70.0"/>
					<Point x="100.0" y="70.0"/>
				</Wall>
				<Wall>
					<Point x="120.0" y="90.0"/>
					<Point x="120.0" y="70.0"/>
					<Point x="119.88428583" y="70.637142861"/>
					<Point x="119.58857184" y="72.354285728"/>
					<Point x="119.19000081" y="74.860000027"/>
					<Point x="118.76571552" y="77.862857184"/>
					<Point x="118.39285875" y="81.071428625"/>
					<Point x="118.14857328" y="84.194285776"/>
					<Point x="118.11000189" y="86.940000063"/>
					<Point x="118.35428736" y="89.017142912"/>
					<Point x="118.95857247" y="90.134285749"/>
					<Point x="120.0" y="90.0"/>
					<Point x="120.0" y="90.0"/>
				</Wall>
				<Wall>
					<Point x="140.0" y="90.0"/>
					<Point x="120.0" y="86.428571"/>
					<Point x="120.0" y="60.0"/>
				</Wall>
				<Wall>
					<Point x="120.0" y="72.857143"/>
					<Point x="140.0" y="70.0"/>
					<Point x="137.35476" y="89.527636"/>
				</Wall>
				<Wall>
					<Point x="124.3" y="72.242855"/>
					<Point x="140.0" y="50.0"/>
				</Wall>
				<Wall>
					<Point x="150.0" y="100.0"/>
					<Point x="150.0" y="50.0"/>
					<Point x="170.0" y="50.0"/>
				</Wall>
				<Wall>
					<Point x="200.0" y="110.0"/>
					<Point x="190.0" y="50.0"/>
					<Point x="230.0" y="50.0"/>
					<Point x="230.0" y="90.0"/>
					<Point x="200.0" y="110.0"/>
					<Point x="200.0" y="110.0"/>
				</Wall>
			</Field>
		</World>
	</Map>
</Resource>
Exactly as they are needed. You can remove the box later is desired.
Without the box it tends to move stuff around. The resulting code is fine, just moved.

User avatar
kyle
Reverse Outside Corner Grinder
Posts: 1830
Joined: Thu Jun 08, 2006 3:33 pm
Location: Indiana, USA, Earth, Milky Way Galaxy, Universe, Multiverse
Contact:

Post by kyle »

It's not letting me convert
i get this error
There was an error creating your aamap.

Code: Select all

ArgumentError: wrong number of arguments (1 for 2)
/users/home/dharple/web/public/armagetronad/svg2aamap/lib/svg2aamap/element.rb:32:in `point'
/users/home/dharple/web/public/armagetronad/svg2aamap/lib/svg2aamap/element.rb:32:in `points'
/usr/local/lib/ruby/1.8/rexml/encoding.rb:37:in `inject'
/users/home/dharple/web/public/armagetronad/svg2aamap/lib/svg2aamap/element.rb:32:in `points'
/users/home/dharple/web/public/armagetronad/svg2aamap/lib/svg2aamap/element.rb:223:in `to_s'
/users/home/dharple/web/public/armagetronad/svg2aamap/lib/svg2aamap/parser.rb:52:in `map'
/usr/local/lib/ruby/1.8/rexml/encoding.rb:37:in `inject'
/users/home/dharple/web/public/armagetronad/svg2aamap/lib/svg2aamap/parser.rb:52:in `map'
/users/home/dharple/web/public/armagetronad/svg2aamap/svg2aamap.rhtml:13
Attachments
DECA_Nano.zip
I tries many different versions of the map. and all of them failed.
(6.92 KiB) Downloaded 315 times

User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

First of all, in the save dialog, please don't use “Inkscape SVG” as that causes bugs for some reason. Instead use “Plain SVG”.
I've just fixed another bug that caused it to crash with your _a and _B files. If you have a circle in Inkscape, please select it and use Path→Object to Path, as otherwise it gets exported as something using “A” commands which aren't supported. You need to wait for nemo to update his web version, though.
A third issue is that you had a path with just one node in your drawing, which doesn't harm arma or svg2aamap, but the previewer draws weird lines then.

I attached the fixed SVG.
Attachments
DECA_Nano.svg.gz
removed useless path, converted the circle to a path, and saved the whole thing as plain SVG
(1.79 KiB) Downloaded 210 times
There's no place like ::1

User avatar
wrtlprnft
Reverse Outside Corner Grinder
Posts: 1679
Joined: Wed Jan 04, 2006 4:42 am
Location: 0x08048000
Contact:

Post by wrtlprnft »

Ok, new stuff :)

From the SVN log:
Added a somewhat hacky support for spawn points and zones in inkscape.

Any path having an end marker will be interpreted as spawn point, with its first point marking the position and the second point marking the direction.

Any path having a start marker will be interpreted a zone, with the first point marking the center and the second point being on the perimeter of the zone. By default the zone will be a fortress zone, but if the path's stroke color is red (that is, the color named “red”) it will be a deathzone, and if the color is green (that is, the color named “lime”) it will be a winzone.

It is recommended to use arrows as end markers for spawn points and dots as start markers for zones.
Some example files:
  1. The original SVG, and the original SVG exported to PNG
  2. The resulting aamap
  3. The preview
There's no place like ::1

Post Reply