Project

General

Profile

« Previous | Next » 

Revision 487e1d5e

Added by Leszek Koltunski 2 days ago

  • ID 487e1d5e44d8973c585732d827c10d4d844d7d65
  • Parent ba422188

progress with Ghosts. Still far off...

View differences:

src/main/java/org/distorted/library/helpers/QuatHelper.java
153 153
    ret[3] = r[3]*q[3] - r[2]*q[2] - r[1]*q[1] - r[0]*q[0];
154 154
    }
155 155

  
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
158

  
159
  public static void quatMultiply( float[] ret, Static4D q, float[] r )
160
    {
161
    float q0 = q.get0();
162
    float q1 = q.get1();
163
    float q2 = q.get2();
164
    float q3 = q.get3();
165

  
166
    ret[0] = r[3]*q0 - r[2]*q1 + r[1]*q2 + r[0]*q3;
167
    ret[1] = r[3]*q1 + r[2]*q0 + r[1]*q3 - r[0]*q2;
168
    ret[2] = r[3]*q2 + r[2]*q3 - r[1]*q0 + r[0]*q1;
169
    ret[3] = r[3]*q3 - r[2]*q2 - r[1]*q1 - r[0]*q0;
170
    }
171

  
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
174

  
175
  public static void quatMultiply( float[] ret, float[] q, Static4D r )
176
    {
177
    float r0 = r.get0();
178
    float r1 = r.get1();
179
    float r2 = r.get2();
180
    float r3 = r.get3();
181

  
182
    ret[0] = r3*q[0] - r2*q[1] + r1*q[2] + r0*q[3];
183
    ret[1] = r3*q[1] + r2*q[0] + r1*q[3] - r0*q[2];
184
    ret[2] = r3*q[2] + r2*q[3] - r1*q[0] + r0*q[1];
185
    ret[3] = r3*q[3] - r2*q[2] - r1*q[1] - r0*q[0];
186
    }
187

  
156 188
///////////////////////////////////////////////////////////////////////////////////////////////////
157 189
// ret = (qx,qy,qz,qw)*(rx,ry,rz,rw)
158 190

  
......
274 306
    quat[2] = -quat[2];
275 307
    }
276 308

  
309
///////////////////////////////////////////////////////////////////////////////////////////////////
310
// rotate vec by quat ( i.e. return quat*vector*(quat^-1) )
311

  
312
  public static void rotateVectorByQuat(float[] output, float[] vec, Static4D quat)
313
    {
314
    float[] tmp = new float[4];
315

  
316
    quatMultiply(tmp,quat,vec);
317

  
318
    float x1 = quat.get0();
319
    float y1 = quat.get1();
320
    float z1 = quat.get2();
321
    float w1 = quat.get3();
322
    quat.set(-x1,-y1,-z1,w1);
323

  
324
    quatMultiply(output,tmp,quat);
325

  
326
    float x2 = quat.get0();
327
    float y2 = quat.get1();
328
    float z2 = quat.get2();
329
    float w2 = quat.get3();
330
    quat.set(-x2,-y2,-z2,w2);
331
    }
332

  
277 333
///////////////////////////////////////////////////////////////////////////////////////////////////
278 334
// rotate 'vector' by quat  ( i.e. return quat*vector*(quat^-1) )
279 335

  
......
320 376
      quatMultiply(output,tmp[0],tmp[1],tmp[2],tmp[3],qx,qy,qz,qw);
321 377
      }
322 378

  
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380
// rotate 'vector' by quat^(-1)  ( i.e. return (quat^-1)*vector*quat )
381

  
382
  public static void rotateVectorByInvertedQuat(float[] output, float x, float y, float z, float w, Static4D quat)
383
    {
384
    float[] tmp = new float[4];
385

  
386
    float qx = quat.get0();
387
    float qy = quat.get1();
388
    float qz = quat.get2();
389
    float qw = quat.get3();
390

  
391
    quatMultiply(tmp,-qx,-qy,-qz,qw,x,y,z,w);
392
    quatMultiply(output,tmp[0],tmp[1],tmp[2],tmp[3],qx,qy,qz,qw);
393
    }
394

  
323 395
///////////////////////////////////////////////////////////////////////////////////////////////////
324 396

  
325 397
  public static Static4D quatFromDrag(float dragX, float dragY)

Also available in: Unified diff