07/02/2013, 10:04 PM  #1 
Highroller
Join Date: Jun 2012
Posts: 4,885
Reputation: 1337

Calculating .IPL Quaternion rotations to Euler
Ok, so here is the deal I've been working on a map editor for a while now and have steadily been adding new features a couple of days ago I realized there was no way to reference San Andreas objects and delete them with RemoveBuildingForPlayer() function. That part works fine but I also realize it would now be possible to clone parts of San Andreas into it's own map or remove an object and replace it with a create object that can be retextured. Anyways the main problem with this is calculating the Quaternion rotations in the .IPL files to Euler angles which is done by the following function.
Code:
stock QuaternionToEuler(Float:qX, Float:qY, Float:qZ, Float:qW, &Float:rX, &Float:rY, &Float:rZ) { new Float:sqw, Float:sqx, Float:sqy, Float:sqz; new Float:PI = 3.14159265359; new Float:unit; new Float:test; sqw = qW*qW; sqx = qX*qX; sqy = qY*qY; sqz = qZ*qZ; unit = sqx + sqy + sqz + sqw; // if normalised is one, otherwise is correction factor test = qX*qY + qZ*qW; if (test > 0.499 * unit) { // singularity at north pole rX = 2 * atan2(qX,qW); rZ = PI/2; rY = 0; } else if (test < 0.499*unit) { // singularity at south pole rX = 2 * atan2(qX,qW); rZ = PI/2; rY = 0; } else { rX = atan2(2*qY*qW2*qX*qZ , sqx  sqy  sqz + sqw); rZ = asin(2*test/unit); rY = atan2(2*qX*qW2*qY*qZ , sqx + sqy  sqz + sqw); } } 
07/02/2013, 11:36 PM  #2 
Highroller
Join Date: Jun 2012
Posts: 4,885
Reputation: 1337

Re: Calculating .IPL Quaternion rotations to Euler
Thanks a lot, I'll try using this function here and let you know how it goes!
I'm pretty sure this is what I"m looking for Code:
QuatToEulerZXY(Float:quat_x, Float:quat_y, Float:quat_z, Float:quat_w, &Float:x, &Float:y, &Float:z) { x = asin(2 * ((quat_x * quat_z) + (quat_w * quat_y))); y = atan2(2 * ((quat_y * quat_z) + (quat_w * quat_x)), (quat_w * quat_w)  (quat_x * quat_x)  (quat_y * quat_y) + (quat_z * quat_z)); z = atan2(2 * ((quat_x * quat_y) + (quat_w * quat_z)), (quat_w * quat_w) + (quat_x * quat_x)  (quat_y * quat_y)  (quat_z * quat_z)); return 1; } It would seem the RX and RY need to be swapped for it to work. 
08/02/2013, 04:32 AM  #3 
Highroller
Join Date: Jun 2012
Posts: 4,885
Reputation: 1337

Re: Calculating .IPL Quaternion rotations to Euler
Further testing shows this function does not work 100 percent.

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
[Off] Desafio: Project Euler  FeelLikeASir_  Português/Portuguese  10  10/10/2012 01:25 AM 
Rotations With Quaternion  BlackAtom  Scripting Help  1  23/07/2012 03:28 PM 
Object Rotations  Arrows73  Help Archive  0  18/07/2011 07:22 PM 
[Tool/Web/Other] [PHP] Convert Quaternion from/in Euler Angles?  Programie  Everything and Nothing  0  22/03/2009 03:35 PM 