angle of rotation using raw data from android phone

edited March 2016 in Library Questions

I recieve rotation vector data from Samsung Galaxy phone using Sensors2OSC app:

https://github.com/SensorApps/Sensors2OSC

I have used toxiclibs to converts the quaternion (ROTATION VECTOR) into a float array consisting of: rotation angle in radians, rotation axis x,y,z.

The box "Eppur si muove", but still need improvement...

import oscP5.*;
import netP5.*;
import toxi.geom.*;

OscP5 oscP5;
NetAddress myRemoteLocation;

float number0 = 0.0;
float number1 = 0.0;
float number2 = 0.0;
float number3 = 0.0;

float[] axis = new float[3];
Quaternion quat = new Quaternion(1, 0, 0, 0);

void setup() {
  size(1200, 600, P3D);
  oscP5 = new OscP5(this, 9000);
}

void draw() {
  background(0);
  lights();

  quat.set(number0, number1, number2, number3);
  axis = quat.toAxisAngle();

  pushMatrix(); 
  translate(width/2, height/2, -100);
  rotate(axis[0], axis[1], axis[2], axis[3]);
  box(330, 200, 40);
  popMatrix();
}

/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {

  if ( theOscMessage.addrPattern().equals("/rotationvector/X") )
    number1 = theOscMessage.get(0).floatValue();
  if ( theOscMessage.addrPattern().equals("/rotationvector/Y") )
    number2 = theOscMessage.get(0).floatValue();
  if ( theOscMessage.addrPattern().equals("/rotationvector/Z") )
    number3 = theOscMessage.get(0).floatValue();
  if ( theOscMessage.addrPattern().equals("/rotationvector/cos") )
    number0 = theOscMessage.get(0).floatValue();
}
Sign In or Register to comment.