Jump to content

[HELP] Quaternions convert to MTA rotation?


Recommended Posts

Hello guys. I need your help in problem with convert quaternions to MTA rotation! Maybe you know some working formula or some script, which help convert standard GTA mods to MTA?

Example:

ORIGINAL

ID#, DFF Name, Interior#, X-Coord, Y-Coord, Z-Coord, RotationX, RotationY, RotationZ, RotationW, Flags

4816, ROCKLIFF1_LAS, 0, -2139.11, 1739.76, 2.75, 1.32679e-06, 1.32679e-06, -1, 1.76038e-12, -1

How convert in MTA rotation?

Cheers,

Kesha_F1.

Link to comment
  • MTA Team

The rotation you're searching for should be (0|-180|0).

These two functions might help for automatic processing of .ide's:

(Keep in mind that math.toeuler takes w as first parameter, while in .ide's W is the last rotation parameter)

  
-- Return order is w, x, y, z 
function math.toquaternion(x, y, z) 
    x = math.rad(x)/2 
    y = math.rad(y)/2 
    z = math.rad(z)/2 
    return 
        math.cos(x) * math.cos(y) * math.cos(z) - math.sin(x) * math.sin(y) * math.sin(z), 
        math.sin(x) * math.sin(y) * math.cos(z) + math.cos(x) * math.cos(y) * math.sin(z), 
        math.sin(x) * math.cos(y) * math.cos(z) + math.cos(x) * math.sin(y) * math.sin(z), 
        math.cos(x) * math.sin(y) * math.cos(z) - math.sin(x) * math.cos(y) * math.sin(z) 
end 
  
function math.toeuler(w, x, y, z) 
    return  
        math.deg(math.atan2(2*(y*w-x*z), 1-2*y^2-2*z^2)), 
        math.deg(math.asin(2*(x*y+z*w))), 
        math.deg(math.atan2(2*x*w-2*y*z,1-2*x^2-2*z^2)) 
end 
  

Edited by Guest
Link to comment

sbx320, Thank you for answer. :) Check please result of convert to Euler Angles and back! This formula returns completely different values! :cry:

print( "-0.230214, 0.679713, 0.668583, -0.194906" ) 
local w 
local x, y, z = math.toeuler( -0.194906, -0.230214, 0.679713, 0.668583 ) 
w, x, y, z = math.toquaternion(x, y, z) 
print( x .. ", " .. y .. ", " .. z .. ", " .. w ) 

Link to comment

sbx320, Checked the work updated formula. The example above is now working. But some objects receive incorrect values​​.

I guess the formula either incorrect or incomplete. Perhaps in the formula necessary to consider how the object is rotated or negative/positive values quaternion. :?

Link to comment
I had some troubles when I converted ides to MTA objects a few months back. Going to look into that again when I get home. Should totally be solveable.

If we are together, we will solve this complex problem - we will give the community great opportunity to convert maps in GTA to MTA!

P.S. No doubt we'll add you to the list of authors the script.

Link to comment
sbx320 will probably solve it at a C++ level, not Lua.

I understand, then do not need a special converter IPL->MAP or what? :?:

P.S. Possible, the objects are placed askew, if the angle is greater than 180 degrees. Maybe need ingreese check to 360 degrees?

P.P.S. Example with sbx320 formulas:

- Tower correct

- Lights spot not correct

915cf2326342003.jpg

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...