Attack on Titan Custom Skins
https://aotskins.com/

Understanding the map scripts
https://aotskins.com/viewtopic.php?f=31&t=11383
Page 1 of 1

Author:  Axelztras [ July 11th, 2017, 12:17 am ]
Post subject:  Understanding the map scripts

Hello, I think I'ts time to lay down the real deal when it comes to the map scripts. I've struggled big time trying to learn what each line of code the level editor means. This post is mainly made for programmers(even novice programmers like me).

With this knowledge you're about to learn you can fuse already existing maps, how to rotate maps and move maps, i.e do some repetitive work which lazy people ain't got the time to do.

This is an example of a scipt that describes a stone block.
custom,cuboid,stone1,6,0.45,6,0,1,1,1,1.0,1.0,37.8442,29.22861,-610.459999999999,-0.0001045807,0.9989038,-0.04675767,-0.002234204;

Each line of code ends with a ';', and each code segment is seperated by a ','. From here it's pretty easy to understand which segment denotes what information. You can clearly see where the coordinates are and what textures to use. Each line does also contain information about the tiling and color shading but I haven't really bothered finding that out.

The coordinates are arranged in a x,y,z fashion. HOWEVER! NOTE THAT THE Y AND Z AXIS HAVE BEEN SWAPPED IN LEVEL EDITOR! Most of us are usually referencing Z as the coordinate for height, but in level editor it's the Y-value which denotes height.

--------------------------------------------------------------------------------------------------------
---------------------------------Warning here there be maths---------------------------------------
--------------------------------------------------------------------------------------------------------
When trying to understand the Map scripts the most difficult thing to understand is the last four digits. It should be clear for anyone who is trying to tamper with these values, will have varying results in the rotation of an object. The Last four digits is a quartarnion.

In short a quartarnion is a four dimensional number(hence four values) which encodes information about a rotation around a certain vector. The quartarion takes the following form of:
Q = xi + yj + zk + w
where the variables i,j,k has the following relationship
i^2 = j^2=k^2=ijk=-1
the last four digits in a line of a map script represent variables (x,y,z,w).
w = cos(θ/2)
x,y and z are coordinates in a unitvector V multiplied with a factor of sin(θ/2).
x = Vxsin(θ/2)
y = Vysin(θ/2)
z = Vzsin(θ/2)
The "w" component essentially tells us how many degrees around our unitvector we're gonna rotate and the rest is information about the direction of the unitvector.

How we actually use a quartarion isn't really what we're interested in, the level editor is going to preform that algorithm. What we're going to do is decide how many degrees of rotation around which unitvector. If we wanted to do a 90 degree rotation around the unitvector
V' =[x,y,z] = [0,1,0]
we just construct the quartarion by simply
w = cos(90/2) = sqrt(1/2)
x = V'x*sin(90/2) = 0 * sqrt(1/2) = 0
y = V'y*sin(90/2) = 1 * sqrt(1/2) = sqrt(1/2)
z = V'z*sin(90/2) = 0* sqrt(1/2) = 0
Q = xi + yj + zk + w = 0 + sqrt(1/2)j + 0 +sqrt(1/2)
then eventually parse the numbers and feed it into RC mod remove the i,j,k components and just go for the raw values. in this example the last four digits would be
... 0,0.707,0,0.707;
-------------------------------------------------------------------------------------------------------
------------------------------------------For Programmers------------------------------------------
-------------------------------------------------------------------------------------------------------
The advantages with knowing the rotation and the location every single object in a aottg map, is that you can very simply manipulate it. Once you've managed to figure out to rotate one object, it's not hard to then expand and rotate several objects at once.

who ever has come this far into the post get an internet cookie, GJ!

The next step is trying to build a method that can take an already existing quartarnion rotation and then apply another rotation. Very similar to Matrix multiplication we say that we multiply two Quartarnions. If you have two Quartarnions q and r in the form of
q = q0 + q1i + q2j + q3k
r = r0 + r1i + r2j + r3k

The product of two Quartarnions is
t = q x r = t0 + t1i + t2j + t3k
t0 = r0q0 - r1q1 - r2q2 - r3q3
t1 = r0q1 + r1q0 - r2q3 + r3q2
t2 = r0q2 + r1q3 + r2q0 - r3q1
t3 = r0q3 - r1q2 + r2q1 + r3q0
(for better resolution)https://se.mathworks.com/help/aeroblks/quaternionmultiplication.html
Note that the order matters!
If you were to combine this knowledge with linear transformations on the coordinate vector, you could easily create a program that can rotate any map. I'm not gonna link my code, the best way to learn this is to try it youself.

If you've made it this far into the post then congratulations! You're awesome!

Author:  Sampai [ July 12th, 2017, 6:15 am ]
Post subject:  Re: Understanding the map scripts

Thank you very much for posting this!
I have long struggled with understanding the (seemingly) ridiculous and incomprehensible way the rotation values at the end of the code work. As such, I've either had to approximate rotations with the editor controls or only do 90 degree turns around the x, y, or z axis (but only one :/)
I wrote a little program in Java a while ago to create randomized forests and cities in a few different fashions, I'm hoping the knowledge you've imparted here might help me to make better use of randomized rotation for objects like rocks and trees. Heck, I might even be able to use it to make walls that almost appear to curve!

Personally I would have preferred the rotation values to be three values, a simple angle about the x, y, and z axes, which is basically how the manual rotation in the editor works. Whether it was in degrees, radians, or gradians wouldn't really matter since they're all distinct and fairly easy to identify. I wonder if I could write or find a code that would convert my preferred rotation values to the quarternion system used in the editor...

Author:  Axelztras [ July 12th, 2017, 8:22 am ]
Post subject:  Re: Understanding the map scripts

Sampai wrote:
I wonder if I could write or find a code that would convert my preferred rotation values to the quarternion system used in the editor...


I'm pretty sure I've already explained how to construct a quartarnion.
x = Vx sin(θ/2)
y = Vy sin(θ/2)
z = Vy sin(θ/2)
w = cos(θ/2)
and when you parse the values into the map script

..., x, y, z, w;

It's very important know that the Y-axis and Z-axis has been swapped. so if you were to create a quartarnion that rotates an object around the Z-axis. It's actually around the Y-axis. the Vector "V" MUST be a unitvector, i.e a vector with lenght 1, google "vector normalization".

Author:  Ralphen [ July 12th, 2017, 2:47 pm ]
Post subject:  Re: Understanding the map scripts

Man, you're a goddamn GENIUS ! :D

Author:  Axelztras [ July 12th, 2017, 2:55 pm ]
Post subject:  Re: Understanding the map scripts

Quote:
Man, you're a goddamn GENIUS ! :D

Thank you Ralphen, I do my best
:D

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/