Revision 0e1d3d2e
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/library/main/QuatHelper.java | ||
---|---|---|
108 | 108 |
ret[3] = r[3]*q[3] - r[2]*q[2] - r[1]*q[1] - r[0]*q[0]; |
109 | 109 |
} |
110 | 110 |
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 |
// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw) |
|
113 |
|
|
114 |
public static void quatMultiply( float[] ret, float qx, float qy, float qz, float qw, float rx, float ry, float rz, float rw ) |
|
115 |
{ |
|
116 |
ret[0] = rw*qx - rz*qy + ry*qz + rx*qw; |
|
117 |
ret[1] = rw*qy + rz*qx + ry*qw - rx*qz; |
|
118 |
ret[2] = rw*qz + rz*qw - ry*qx + rx*qy; |
|
119 |
ret[3] = rw*qw - rz*qz - ry*qy - rx*qx; |
|
120 |
} |
|
121 |
|
|
111 | 122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
112 | 123 |
// rotate 'vector' by quat ( i.e. return quat*vector*(quat^-1) ) |
113 | 124 |
|
... | ... | |
138 | 149 |
return quatMultiply(tmp,-qx,-qy,-qz,qw); |
139 | 150 |
} |
140 | 151 |
|
152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
153 |
// rotate (x1,x2,x3,x4) by quat ( i.e. return quat*vector*(quat^-1) ) |
|
154 |
|
|
155 |
public static void rotateVectorByQuat(float[] output, float x, float y, float z, float w, Static4D quat) |
|
156 |
{ |
|
157 |
float[] tmp = new float[4]; |
|
158 |
|
|
159 |
float qx = quat.get0(); |
|
160 |
float qy = quat.get1(); |
|
161 |
float qz = quat.get2(); |
|
162 |
float qw = quat.get3(); |
|
163 |
|
|
164 |
quatMultiply(tmp,qx,qy,qz,qw,x,y,z,w); |
|
165 |
quatMultiply(output,tmp[0],tmp[1],tmp[2],tmp[3],-qx,-qy,-qz,qw); |
|
166 |
} |
|
167 |
|
|
141 | 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
142 | 169 |
// rotate vec by quat ( i.e. return quat*vector*(quat^-1) ) |
143 | 170 |
|
Also available in: Unified diff
Extra API for QuatHelper.