Thanks Classicll!
They are, apparently, also having a hard time figuring it out over there :)
I was playing around with the traer physics library, which is a brilliant toolbox for all those formulas I always have to look up when I need them.
As I was pondering how to sum and integrate all the different acceleration values from the wiimote, without breaking my CPU, I remembered the addVelocity(x, y, z) method in the traer library and thought it would be as simple as just adding the vectors to a body.
I was a bit surprised to find it work brilliantly! The idea is basically the same as integrating it over and over again. The body just moves in the direction the sum of all the accelerations dictates.
Code:
import traer.physics.*; // great stuff get it at! http://www.cs.princeton.edu/~traer/physics/
/**
* Author: Ricki G
* Test of the Darwinremote library
* mixed with the traer physics library
* the idea is to apply the jittery Wiimote
* readings directly to a particle instead of trying
* to measure the position by interpolation and integration
*/
WiiController wiiController;
Particle p, center;
ParticleSystem physics;
float x0, y0, z0;
float factor = 0.2;
void setup()
{
size( 400, 400, P3D );
background( 0 );
frameRate( 24 );
ellipseMode( CENTER );
noStroke();
wiiController = new WiiController();
physics = new ParticleSystem( 0, 0.1 );
p = physics.makeParticle(1, width * 0.5, height * 0.5, 0 );
center = physics.makeParticle(1, width * 0.5, height * 0.5, 0 );
physics.makeAttraction( center, p, 1000, 10 );
}
void draw()
{
x0 = ( wiiController.acc.x - 129 ) * factor;
y0 = ( wiiController.acc.y - 129 ) * factor;
z0 = ( wiiController.acc.z - 156 ) * factor;
physics.tick();
fill( 0, 50 );
rect( 0, 0, width, height );
center.moveTo( width * 0.5, height * 0.5, 0 );
fill(255);
p.addVelocity(x0, y0, z0);
ellipse( p.position().x(), p.position().y(), 35, 35 );
bounce();
}
void bounce()
{
if(p.position().x() > width || p.position().x() < 0)
{
float tempX = p.velocity().x() * -1;
p.setVelocity(tempX, p.velocity().y(), p.velocity().z());
}
if(p.position().y() > height || p.position().y() < 0)
{
float tempY = p.velocity().y() * -1;
p.setVelocity(p.velocity().x(), tempY, p.velocity().z());
}
}
So this is a start to something that can be tuned to get more meaningful data from the Wiimote.
By the way the WiiController Class is from sojamo.de, also great stuff:)
Ricki