Hey guys, i read the page about the quatrions but i'm not a math genious. I simple want 3 vectors from those 4 numbers which i don't really understand.
Those 3 vectors should have length 1 and have this formation (x, y, z) Here is a picture explaining what i mean. Maybe something like GetVehicleXVector(vehicleid, &Float ![]() GetVehicleYVector(vehicleid, &Float ![]() GetVehicleZVector(vehicleid, &Float ![]() would be nice |
#include <a_samp>
forward Float:QuatTo3x3Matrix(Float:w,Float:x,Float:y,Float:z);
stock Float:QuatTo3x3Matrix(Float:w,Float:x,Float:y,Float:z)
{
new Float:Matrix[3][3];
Matrix[0][0] = 1 - (2*(y*y)) - (2*(z*z)); Matrix[0][1] = (2 * x * y) - (2 * z * w); Matrix[0][2] = (2*x*z)+(2*y*w);
Matrix[1][0] = ( 2*x*y ) + ( 2 * z * w ); Matrix[1][1] = 1 - (2*x*x) - (2* z * z ); Matrix[1][2] = (2*y*z)-(2*x*w);
Matrix[2][0] = ( 2*x*y ) - ( 2 * y * w ); Matrix[2][1] = (2*y* z ) + ( 2 * x * w ); Matrix[2][2] = 1 - (2*(x*x)) - (2*(y*y));
return Matrix;
}
public OnFilterScriptInit()
{
new Float:test[3][3];
test = QuatTo3x3Matrix(0.0,0.0,0.0,0.0);
return 1;
}
//http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/index.htm
and instead of vectors you can use a 3d matrix, i have somewhere some code which converts quads to 3x3 and 4x4 matrix.
(for PAWN ofcourse) |
#include <a_samp>
public OnFilterScriptInit()
{
new Float:test[4][4];
test = setRotate(0.0,0.0,0.0,0.0,0.0,0.0);
return 1;
}
forward Float:setRotate(Float:q_w,Float:q_x,Float:q_y,Float:q_z,Float:q1_x,Float:q1_y,Float:centre_x = 0.0,Float:centre_y = 0.0,Float:centre_z = 0.0);
stock Float:setRotate(Float:q_w,Float:q_x,Float:q_y,Float:q_z,Float:q1_x,Float:q1_y,Float:centre_x = 0.0,Float:centre_y = 0.0,Float:centre_z = 0.0)
{
new Float: sqw = q_w*q_w;
new Float: sqx = q_x*q_x;
new Float: sqy = q_y*q_y;
new Float: sqz = q_z*q_z;
new Float: m00 = sqx - sqy - sqz + sqw; // since sqw + sqx + sqy + sqz =1
new Float: m11 = -sqx + sqy - sqz + sqw;
new Float: m22 = -sqx - sqy + sqz + sqw;
new Float: tmp1 = q_x*q_y;
new Float: tmp2 = q_z*q_w;
new Float: m01 = 2.0 * (tmp1 + tmp2);
new Float: m10 = 2.0 * (tmp1 - tmp2);
tmp1 = q_x*q_z;
tmp2 = q_y*q_w;
new Float: m02 = 2.0 * (tmp1 - tmp2);
new Float: m20 = 2.0 * (tmp1 + tmp2);
tmp1 = q1_y*q_z;
tmp2 = q1_x*q_w;
new Float: m12 = 2.0 * (tmp1 + tmp2);
new Float: m21 = 2.0 * (tmp1 - tmp2);
new Float:a1,Float:a2,Float:a3;
if (centre_x && centre_y && centre_z == 0.0)
{
a1 = a2=a3=0.0;
}
else
{
a1 = centre_x;
a2 = centre_y;
a3 = centre_z;
}
new Float: m03 = a1 - a1 * m00 - a2 * m01 - a3 * m02;
new Float: m13 = a2 - a1 * m10 - a2 * m11 - a3 * m12;
new Float: m23 = a3 - a1 * m20 - a2 * m21 - a3 * m22;
new Float: m31, Float: m32;
new Float: m30 = m31 = m32 = 0.0;
new Float: m33 = 1.0;
new Float: fxfMatrix[4][4];
fxfMatrix[0][0] = m00;
fxfMatrix[0][1] = m01;
fxfMatrix[0][2] = m02;
fxfMatrix[0][3] = m03;
fxfMatrix[1][0] = m10;
fxfMatrix[1][1] = m11;
fxfMatrix[1][2] = m12;
fxfMatrix[1][3] = m13;
fxfMatrix[2][0] = m20;
fxfMatrix[2][1] = m21;
fxfMatrix[2][2] = m22;
fxfMatrix[2][3] = m23;
fxfMatrix[3][0] = m30;
fxfMatrix[3][1] = m31;
fxfMatrix[3][2] = m32;
fxfMatrix[3][3] = m33;
return fxfMatrix;
}
void setRotate(sfquat q,sfvec3f centre) {
double sqw = q.w*q.w;
double sqx = q.x*q.x;
double sqy = q.y*q.y;
double sqz = q.z*q.z;
m00 = sqx - sqy - sqz + sqw; // since sqw + sqx + sqy + sqz =1
m11 = -sqx + sqy - sqz + sqw;
m22 = -sqx - sqy + sqz + sqw;
double tmp1 = q.x*q.y;
double tmp2 = q.z*q.w;
m01 = 2.0 * (tmp1 + tmp2);
m10 = 2.0 * (tmp1 - tmp2);
tmp1 = q.x*q.z;
tmp2 = q.y*q.w;
m02 = 2.0 * (tmp1 - tmp2);
m20 = 2.0 * (tmp1 + tmp2);
tmp1 = q1.y*q.z;
tmp2 = q1.x*q.w;
m12 = 2.0 * (tmp1 + tmp2);
m21 = 2.0 * (tmp1 - tmp2);
double a1,a2,a3;
if (centre == null) {
a1=a2=a3=0;
} else {
a1 = centre.x;
a2 = centre.y;
a3 = centre.z;
}
m03 = a1 - a1 * m00 - a2 * m01 - a3 * m02;
m13 = a2 - a1 * m10 - a2 * m11 - a3 * m12;
m23 = a3 - a1 * m20 - a2 * m21 - a3 * m22;
m30 = m31 = m32 = 0.0;
m33 = 1.0;
}
thank you, that should do. i got a friend who told me that he could rotate a vector pointing downwards (which is simply (0,0,-1)) around with that 4x4 matrix... i hope he can, but unfortunatualy he is very bussy at the moment so that might take some time
those vectors can be used to find offset positions around vehicles and direction vectors for the CreateGravityAffectedObject(model, x, y, z, xspeed, yspeed, zspeed, multiplier) function i am making also those vectors can be used to create speed vectors that go to a specific direction from the vehicle (like the flares i want to make, poping in pairs left and right out of the plane) |
tmp1 = q1.y*q.z; tmp2 = q1.x*q.w;
if (centre_x && centre_y && centre_z == 0.0) { a1 = a2=a3=0.0; } else { a1 = centre_x; a2 = centre_y; a3 = centre_z; } new Float: m03 = a1 - a1 * m00 - a2 * m01 - a3 * m02; new Float: m13 = a2 - a1 * m10 - a2 * m11 - a3 * m12; new Float: m23 = a3 - a1 * m20 - a2 * m21 - a3 * m22;