Quaternions.

The place to discuss scripting and game modifications for X4: Foundations.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

User avatar
Axeface
Posts: 2974
Joined: Fri, 18. Nov 05, 00:41
x4

Quaternions.

Post by Axeface » Mon, 27. Jul 20, 00:02

I am giving ship modding another try and i've made some progress but ive ran into an issue (surprise). I have my ship working with an engine, turrets etc but I need to rotate some of the components.
I am doing this all manually in the xml and then testing in-game, as exporting component position out of blender just doesnt work (afaik).

How do these quaternions work? Can it even be done manually? I did some tests just randomly changing the quaternion values but it was a real mess. I have turrets that need to be rotated about 30* on the X axis.
The values I am finding in other xmls are crazy values like 1.7320510330969933e-07

Also - while messing around with random values I managed to squash a shield generator on one axis, can these quaternions be used to scale components? (I would love to be able to make the L engines much smaller on my ship).

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7411
Joined: Mon, 15. Dec 03, 18:53
x4

Re: Quaternions.

Post by BlackRain » Mon, 27. Jul 20, 00:51

Axeface wrote:
Mon, 27. Jul 20, 00:02
I am giving ship modding another try and i've made some progress but ive ran into an issue (surprise). I have my ship working with an engine, turrets etc but I need to rotate some of the components.
I am doing this all manually in the xml and then testing in-game, as exporting component position out of blender just doesnt work (afaik).

How do these quaternions work? Can it even be done manually? I did some tests just randomly changing the quaternion values but it was a real mess. I have turrets that need to be rotated about 30* on the X axis.
The values I am finding in other xmls are crazy values like 1.7320510330969933e-07

Also - while messing around with random values I managed to squash a shield generator on one axis, can these quaternions be used to scale components? (I would love to be able to make the L engines much smaller on my ship).
I did a lot of this back in X rebirth and I am trying to recall. Quaternians was definitely one way to move the piece maybe inward or outward or something. Or maybe it was moving it along the same plane but in a different position. I just can't recall honestly. I remember having to do a lot of testing in game to see exactly where each thing was after putting the numbers in.

Imperial Good
Moderator (English)
Moderator (English)
Posts: 4787
Joined: Fri, 21. Dec 18, 18:23
x4

Re: Quaternions.

Post by Imperial Good » Mon, 27. Jul 20, 01:21

I suggest reading the Wikipedia article about them. It does provide the mathematics needed to convert them into human-relatable space.

They are intended for machine or calculation use only. This is because some operations can be executed using fewer clock cycles or mathematical operations on them as well as they are more compact since they do not suffer from problems like gimbal lock when describing rotations. Without a lot of experience with advanced mathematics they will make no sense to humans.

They are technically a type of complex number that has 3 "imaginary" fields on top of the usual 1 real field. Much like conventional complex numbers with 1 imaginary field, each field is perpendicular within multi-dimensional space of the numeric plane from its neighbours. This property means they have properties related to 4 dimensional vectors, which modern computer hardware is optimized to manipulate efficiently. Most humans, such as myself, have problem imagining 4 dimensional structures which is why non-calculated manipulation of them is seemingly impossible.

Max Bain
Posts: 1463
Joined: Wed, 27. Jun 18, 19:05
x3ap

Re: Quaternions.

Post by Max Bain » Mon, 27. Jul 20, 01:22

Quaternions are a different mathematical representation for rotations. For 3d calculations they are often more practical but for us they are more difficult to read.

Instead of quaternions you can also use the rotation tag.

Instead of

Code: Select all

<quaternion qw="-0.32366016388529006" qx="0.018206271709074604" qy="0.005126368367101456" qz="-0.945984328798087"/>
(values are just examples and dont match to each other)

You can write this:

Code: Select all

<rotation pitch="0" yaw="0" roll="0"/>
(in degrees)

Brumbear gave me the hint and I use these only if I rotate something out of blender in the xml file directly.

Btw exporting components positions (and rotations) work perfect if you use the tool and the correct settings:
https://www.nexusmods.com/x4foundations ... t=66174131
XR Ship Pack (adds several ships from XR) Link
Weapon Pack (adds several new weapons) Link
Economy Overhaul (expands the X4 economy with many new buildings) Link
X4 Editor (view stats of objects and make your own mod within a few clicks) Link

User avatar
Axeface
Posts: 2974
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Quaternions.

Post by Axeface » Mon, 27. Jul 20, 02:10

Thank you everyone!
Max Bain wrote:
Mon, 27. Jul 20, 01:22
You can write this:

Code: Select all

<rotation pitch="0" yaw="0" roll="0"/>
(in degrees)
The more you know! Thats so much easier! Got my turrets rotated correctly within a few minutes. Approaching something I might consider good enough for a release now.
Can something similar be done with size/scale?


Max Bain wrote:
Mon, 27. Jul 20, 01:22
Btw exporting components positions (and rotations) work perfect if you use the tool and the correct settings:
https://www.nexusmods.com/x4foundations ... t=66174131
I had seen that before but I think I had an issue with it or it didnt work in blender 2.8. I'll have another look.

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7411
Joined: Mon, 15. Dec 03, 18:53
x4

Re: Quaternions.

Post by BlackRain » Mon, 27. Jul 20, 03:35

Axeface wrote:
Mon, 27. Jul 20, 02:10
Thank you everyone!
Max Bain wrote:
Mon, 27. Jul 20, 01:22
You can write this:

Code: Select all

<rotation pitch="0" yaw="0" roll="0"/>
(in degrees)
The more you know! Thats so much easier! Got my turrets rotated correctly within a few minutes. Approaching something I might consider good enough for a release now.
Can something similar be done with size/scale?


Max Bain wrote:
Mon, 27. Jul 20, 01:22
Btw exporting components positions (and rotations) work perfect if you use the tool and the correct settings:
https://www.nexusmods.com/x4foundations ... t=66174131
I had seen that before but I think I had an issue with it or it didnt work in blender 2.8. I'll have another look.
I completely forgot about that. That is right, I had used the rotation pitch/yaw/roll and removed quaternions. I forgot so much, sigh. That's what happens when you stop doing something for several years.

User avatar
Axeface
Posts: 2974
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Quaternions.

Post by Axeface » Mon, 27. Jul 20, 06:46

BlackRain wrote:
Mon, 27. Jul 20, 03:35
I completely forgot about that. That is right, I had used the rotation pitch/yaw/roll and removed quaternions. I forgot so much, sigh. That's what happens when you stop doing something for several years.
That happens to me overnight (I swear im brain damaged), its why I value tutorials so much, especially visual ones.

And i've made a lot of progress if anyone is interested.
https://steamcommunity.com/sharedfiles/ ... 2179163275
https://steamcommunity.com/sharedfiles/ ... 2179163258
https://steamcommunity.com/sharedfiles/ ... 2179582202
Last edited by Axeface on Mon, 27. Jul 20, 18:04, edited 1 time in total.

BrummBear02
Posts: 308
Joined: Fri, 3. Oct 08, 20:43
x3ap

Re: Quaternions.

Post by BrummBear02 » Mon, 27. Jul 20, 12:47

Axeface wrote:
Mon, 27. Jul 20, 02:10

Can something similar be done with size/scale?
Nah. Not as far as i know. But "rezising" something shouldnt be much of a problem. Is there something specific u want to have bigger or smaller?
Gebt mir einen Spiegel dann schlage ich ihn mit seinem eigenen Gesicht

User avatar
Axeface
Posts: 2974
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Quaternions.

Post by Axeface » Mon, 27. Jul 20, 13:27

BrummBear02 wrote:
Mon, 27. Jul 20, 12:47
Axeface wrote:
Mon, 27. Jul 20, 02:10

Can something similar be done with size/scale?
Nah. Not as far as i know. But "rezising" something shouldnt be much of a problem. Is there something specific u want to have bigger or smaller?
Im making a small L so I wanted to resize the engine as I originally planned to have 3 engines on it - only 1 fits. I've already started remodeling the ship to fit the oversized engine but still i'de like to know if its possible.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Re: Quaternions.

Post by UniTrader » Mon, 27. Jul 20, 20:50

you would need to basically make a resized clone of all engines you want to choose between, and make them compatible with the slots by using a different set of tags (like "engine medim_large component", note the _ because space is a seperator between diffrent tags) than the vanilla ones. An alternative with less work involved would be to use M Engines instead, but a few more of them..
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

User avatar
Axeface
Posts: 2974
Joined: Fri, 18. Nov 05, 00:41
x4

Re: Quaternions.

Post by Axeface » Tue, 28. Jul 20, 05:15

UniTrader wrote:
Mon, 27. Jul 20, 20:50
you would need to basically make a resized clone of all engines you want to choose between, and make them compatible with the slots by using a different set of tags (like "engine medim_large component", note the _ because space is a seperator between diffrent tags) than the vanilla ones. An alternative with less work involved would be to use M Engines instead, but a few more of them..
Thanks for the confirmation. Its a shame its not possible in the xmls like rotation.

BrummBear02
Posts: 308
Joined: Fri, 3. Oct 08, 20:43
x3ap

Re: Quaternions.

Post by BrummBear02 » Tue, 28. Jul 20, 07:02

Axeface wrote:
Tue, 28. Jul 20, 05:15
UniTrader wrote:
Mon, 27. Jul 20, 20:50
you would need to basically make a resized clone of all engines you want to choose between, and make them compatible with the slots by using a different set of tags (like "engine medim_large component", note the _ because space is a seperator between diffrent tags) than the vanilla ones. An alternative with less work involved would be to use M Engines instead, but a few more of them..
Thanks for the confirmation. Its a shame its not possible in the xmls like rotation.
i know that feeling :D on the other hand its really not too much work. one engine takes about 15minutes to copy and resize.
Gebt mir einen Spiegel dann schlage ich ihn mit seinem eigenen Gesicht

DeadAirRT
Posts: 1032
Joined: Fri, 25. Jan 19, 03:26
x4

Re: Quaternions.

Post by DeadAirRT » Wed, 29. Jul 20, 00:27

Not sure if this will help much but this is what I used for gate rotation:

https://www.andre-gaschler.com/rotationconverter/

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13307
Joined: Sun, 15. Feb 04, 20:12
x4

Re: Quaternions.

Post by euclid » Wed, 29. Jul 20, 19:36

That link is a nice find DeadAirRT, thanks :-)

Just my 10 pence on this:

1# Quarternions are normalized, i.e. for q = q_0+q_1+q_2+q_3 we have |q|=1. This explains the sometimes "odd" values (like very small) of some of them.

2# Quarternions are associate with a rotation around an axis by the following expression

q_0 = cos(alpha/2)
q_1 = sin(alpha/2)*cos(beta_x)
q_2 = sin(alpha/2)*cos(beta_y)
q_3 = sin(alpha/2)*cos(beta_z)

where alpha is a simple rotation angle (the value in radians of the angle of rotation) and cos(beta_x), cos(beta_y) and cos(beta_z) are the "direction cosines" locating the axis of rotation (Euler's Theorem).

3# Alternatively we use the Tait–Bryan angles (in terms of flight dynamics):

Roll – \phi: rotation about the X-axis
Pitch – \theta: rotation about the Y-axis
Yaw – \psi: rotation about the Z-axis

where the X-axis points forward, Y-axis to the right and Z-axis downward.

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Re: Quaternions.

Post by UniTrader » Wed, 29. Jul 20, 23:52

euclid wrote:
Wed, 29. Jul 20, 19:36

where the X-axis points forward, Y-axis to the right and Z-axis downward.
Not sure how this affects the other stuff but the convention in X4 and earlier games is
X points Up (up on your monitor; up from the ecliptic; Up of a Ship)
Y points Right (right on your monitoy; East on the Ecliptic; Right of a Ship)
Z points forward (into your monitor; North on the Ecliptic; Front of a Ship)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

Return to “X4: Foundations - Scripts and Modding”