We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Toxiclibs - Spherical Interpolation
Page Index Toggle Pages: 1
Toxiclibs - Spherical Interpolation (Read 823 times)
Toxiclibs - Spherical Interpolation
Oct 6th, 2008, 8:05pm
 
Hi,

I just saw that Toxi added a "Quaternion class with spherical interpolation" to toxi.geom.

I'm trying to make particles move around a sphere.
Everytime I set a new target position, for a particle to go to, the interpolation/motion restarts from the 'poles' of the sphere.

All the documentations I found about quaternions were helpful, but I do not seem to be able to put my head around quaternions still.

here is some code:

Code:

import processing.opengl.*;

import toxi.math.noise.*;
import toxi.math.waves.*;
import toxi.geom.*;
import toxi.math.*;
import toxi.math.conversion.*;
import toxi.geom.util.*;


Vec3D[] shell, target;
Quaternion[] targetQuat;
int numPart = 500;
int radius = 300;

void setup() {
size(1024, 768, OPENGL);
shell = new Vec3D[numPart];
target = new Vec3D[numPart];
targetQuat = new Quaternion[numPart];

for (int i = 0; i < shell.length; i++) {
  shell[i] = new Vec3D().randomVector().scaleSelf(radius);
  target[i] = new Vec3D().randomVector().scaleSelf(radius);
  targetQuat[i] = new Quaternion(0.0f , new
Vec3D().randomVector().scaleSelf(radius));
}
}

void draw() {
background(10);
translate(width/2, height/2);

for (int i = 0; i < shell.length; i++) {
  pushMatrix();
  //JUST VECTOR
  //shell[i].interpolateToSelf(target[i], .01f);

  // QUATERNION
  Quaternion actualQuat = new Quaternion(0.0f, shell[i]);
  Quaternion newQuat = actualQuat.interpolateTo(targetQuat[i], .
01f);
  shell[i].set(newQuat.getValue()[1], newQuat.getValue()[2],
newQuat.getValue()[3]).scaleSelf(radius);

  translate(shell[i].x,shell[i].y,shell[i].z);
  ellipse(0, 0, 5, 5);
  popMatrix();
}
}

void mousePressed(){
for (int i = 0; i < target.length; i++) {
    //JUST VECTOR
    //target[i] = new Vec3D().randomVector().scaleSelf(radius);

    // QUATERNION
    targetQuat[i] = new Quaternion(0.0f , new Vec3D().randomVector().scaleSelf(radius));
}
}


Thanks

//h
Page Index Toggle Pages: 1