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