[Tool] Quaternion Calculator

The place to discuss scripting and game modifications for X Rebirth.

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

Atrocious
Posts: 165
Joined: Mon, 15. May 06, 20:13

[Tool] Quaternion Calculator

Post by Atrocious »

Hey there,

I'm currently not modding X games, but I have done it in the past. One of my mods was "Xenon Hunt". For that mod I needed to place some 3d models onto other 3d models. Like placing a shield generator onto an existing ship model.

This placement required a lot of trial and error and got a bit annoying. Later, I created a small tool that can calculate quaternions (which are used for the rotation of models) to make the process a bit easier.

To be honest, I didn't know much about quaternions when I started the mod and the tool. There might be other ways to do this, but the tool helped me understand and calculate quaternions instead of guessing them, so I thought it may be useful for others here as well. I don't claim that the calculations are error free, but strange enough they seem to give reliable results.

[ external image ]

Download from github (and only from there):
https://github.com/Atropin/QuaternionCa ... r/releases

There is the source code and a compiled exe.

Features:
- It probably works only for left-handed coordinate systems like in X Rebirth. I only tested it with X Rebirth.
- Enter degrees for pitch, yaw and roll
- Change the order for pitch, yaw and roll
- Copy XML to Clipboard, in a format that is used in the game's XML files
- Copy text to clipboard, a shorter version of the output for debug etc
- Hint image has a small example for the coordinate system
- Clear input

It's built in C#, requires .Net framework 4.0 and is Open Source.


{Images posted directly to the forums should not be greater than 640x480 or 100kb, oversize image now linked - Terre}
{Apologies, I updated the image according to rules - Atrocious}
Last edited by Atrocious on Mon, 30. Mar 15, 14:16, edited 1 time in total.
Atrocious
Posts: 165
Joined: Mon, 15. May 06, 20:13

Post by Atrocious »

PS: The following stuff is unrelated to the quaternions, but it may help you find the position on a target model.

When looking for a position to place stuff, I spawned myself a ship, flew towards the location where I wanted to add something and then selected a new target. The following code in the right place will then log the position of the player ship and the target ship. You just have to subtract the values from each other to find the absolute position.

Again, there may be easier ways to do it. This is just how I figured it out.

I had put this into a mod as md/MainMenu.xml addon.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<diff>
		<add sel="//cues">
		<cue name="TargetChangedDebugHandler" instantiate="true">
			<conditions>
				<event_player_changed_target/>
			</conditions>
			<actions>
				<do_if value="event.param.exists">
					<debug_text text="'pos: ' + player.ship.position + ' target: ' + event.param.position"  filter="error" />
				</do_if>
			</actions>
		</cue>  
	</add>
</diff>
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

really thx, lets see if this tool is better than the online calculator i have used till no.. not because i needed, but because i think <quarternion qx="0" qy="0" qz="0" qw="1" /> is cleaner than <rotation yaw="0" pitch="0" roll="0" /> (i have used the latter one in only one case yet because the mentoined online calculator didnt didnt return the correct values, but when i entered a rotation with the same values it worked as desired)
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 ;)
bradines
Posts: 31
Joined: Fri, 27. Mar 15, 20:58

Post by bradines »

Thank You... your a life saver...
User avatar
Litauen
Posts: 193
Joined: Fri, 22. Nov 13, 21:09
xr

Post by Litauen »

Sorry guys, but why <rotation yaw="0" pitch="0" roll="0" /> is not good?

I can yaw, pitch, roll objects in my mind which speedups their placement a lot, but quaternions - why bother?
antoniut
Posts: 198
Joined: Sat, 4. Oct 14, 13:07
x4

Post by antoniut »

Litauen wrote:I can yaw, pitch, roll objects in my mind which speedups their placement a lot, but quaternions - why bother?
Me too. And it works as I expect. :)

http://imgur.com/a/mAGDb#0
User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13489
Joined: Sun, 15. Feb 04, 20:12
x4

Post by euclid »

Nice job Atrocious although I do agree with others here and never saw the advantange of using quaterions rather than the usual orientations.

But I'm still learning ;-)

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
Atrocious
Posts: 165
Joined: Mon, 15. May 06, 20:13

Post by Atrocious »

I have used quaternions in the ship definition files under assets/units, where egosoft has used quaternions as well. It may be possible to use <rotation/> there instead, as UniTrader posted. I actually haven't tried that, because when I found quaternions in the definition files I assumed they needed quaternions to work. As I said, there may be other ways to do it. I just went with the quaternions.
antoniut
Posts: 198
Joined: Sat, 4. Oct 14, 13:07
x4

Post by antoniut »

I imagine that quaternions in files are the result of egosoft devs placing p.e.
turrets in a 3d program and exporting files with a custom plugin that generates the XML files. Correct me if I'm wrong.

But devs have had the delicacy to the modders have an easy way to move things

Quaternions for computers, and other way for humans :)

Return to “X Rebirth - Scripts and Modding”