LeroY Posted September 3, 2017 Share Posted September 3, 2017 Help me, please, as fix convert quartenion to euler angles in .ipl files I'm getting an incorrect turn of the object. But this does not happen with all the objects, but only with a part. function quaternionToEuler(q) q.x = q[1] q.y = q[2] q.z = q[3] q.w = q[4] local sqx = q.x * q.x local sqy = q.y * q.y local sqz = q.z * q.z local sqw = q.w * q.w local unit = sqx + sqy + sqz + sqw local test = (q.x * q.y) + (q.z * q.w) if (test > 0.499999999 * unit) then return {0.0,(2 * math.atan2( q.x, q.w ) * 57.295779513082320876798154814105) % 360,90.0} elseif ( test < -0.499999999 * unit ) then return {0.0,(-2 * math.atan2( q.x, q.w ) * 57.295779513082320876798154814105) % 360,270.0} end return { (math.atan2((2 * q.x * q.w) - (2 * q.y * q.z) , 1 - (2 * sqx) - (2 * sqz)) * 57.295779513082320876798154814105) % 360, (math.atan2((2 * q.y * q.w) - (2 * q.x * q.z) , 1 - (2 * sqy) - (2 * sqz)) * 57.295779513082320876798154814105) % 360, (math.asin(2 * test) * 57.295779513082320876798154814105) % 360 } end Link to comment
AfterAll14 Posted September 4, 2017 Share Posted September 4, 2017 At some point I tried hard to solve GTA quaternions. I implemented all possible formulas, none of it worked correctly in GTA SA. It only works for Z rotation. X and Y rotations are screwed by rockstart itself, I guess specifically to prevent modding. So, I'm afraid there's no solution. Link to comment
LeroY Posted September 4, 2017 Author Share Posted September 4, 2017 1 hour ago, AfterAll14 said: At some point I tried hard to solve GTA quaternions. I implemented all possible formulas, none of it worked correctly in GTA SA. It only works for Z rotation. X and Y rotations are screwed by rockstart itself, I guess specifically to prevent modding. So, I'm afraid there's no solution. can it be possible to somehow translate this function into a reverse action? its author Essle Function to translate angles of Euler into quaternions. Arguments: RotX, RotY, RotZ Return: RotX, RotY, RotZ, RotW function math.quaternion(x, y, z) local c = { math.cos(math.rad(-x)), math.cos(math.rad(-y)), math.cos(math.rad(z)) } local s = { math.sin(math.rad(-x)), math.sin(math.rad(-y)), math.sin(math.rad(z)) } local t = { c[2] * c[3], s[1] * s[2] * s[3] + c[1] * c[3], c[1] * c[2] } return math.drt(1.0 + t[1] - t[2] - t[3], (c[3] * s[1] - c[1] * s[2] * s[3]) - (-s[1] * c[2])), math.drt(1.0 - t[1] + t[2] - t[3], s[2] + (c[1] * s[2] * c[3] + s[1] * s[3])), math.drt(1.0 - t[1] - t[2] + t[3], (s[1] * s[2] * c[3] - c[1] * s[3]) - (c[2] * s[3])), math.drt(1.0 + t[1] + t[2] + t[3]) end function math.drt(a, b) a = math.sqrt(math.max(0.0, a)) * 0.5 return (b and ((b < 0) and -math.abs(a) or math.abs(a)) or a) end Link to comment
LeroY Posted September 4, 2017 Author Share Posted September 4, 2017 In general, it seems just impossible. Just manually re-create the mapping. THE TOPIC IS CLOSED! Link to comment
AfterAll14 Posted September 5, 2017 Share Posted September 5, 2017 I'd suggest you to use this code to get rotations of all objects first, then manually fix the angles of those who have non-zero XY rotations. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now