Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

Pitch, Roll, Yaw using rotateX/Y/Z query

$
0
0

I am trying to represent the orientation of my phone being held upright. I'm using a simple rectangle for starters. I am sending messages over OSC. Each of my 3 values; pitch, roll and yaw (Azimuth) goes from -180degrees to +180degrees.

I am going by the example in the picture below my code, where X is pitch and Y is roll:

When I use just two values, (eg just pitch and roll) the orientation seems to be represented normally. But when I throw the third into the mix, it gets a little wild.

I don't have another device right now to check if it's the phone sensors that are faulty. Looking at the rotateX(and Y and Z) examples, this should work as is. I guess there's something a bit deeper I'm missing?

Thanks

import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
float ZyawValue, XpitchValue, YrollValue;


void setup() {
  size(360, 360, P3D);
  lights();
  noStroke();
  colorMode(RGB, 256); 

  oscP5 = new OscP5(this,34567);
  myRemoteLocation = new NetAddress("192.168.1.7",34567);
}


void draw() {
  background(100);
  rectMode(CENTER);
  fill(51);
  stroke(255);

  pushMatrix();
  translate(width/2, height/2, 0);

    rotateX(radians(XpitchValue));
    rotateY(radians(-YrollValue));
    rotateZ(radians(ZyawValue));     // **Issues**

  rect(0, 0, 50, 100);
  popMatrix();

  textSize(24);
  String gyrStr1 = "X=Roll: " + (int) YrollValue; 
  String gyrStr2 = "Y=Pitch: " + (int) XpitchValue; 
  String gyrStr3 = "Z=Yaw: " + (int) ZyawValue; 
  fill(249, 250, 50);
  text(gyrStr1, (int) (width/6.0) - 40, 50); 
  text(gyrStr2, (int) (width/6.0) - 40, 100); 
  text(gyrStr3, (int) (width/6.0) - 40, 150);   
}



void oscEvent(OscMessage theOscMessage) {

  if(theOscMessage.checkAddrPattern("/orientation/azimuth")==true) { 
    if(theOscMessage.checkTypetag("f")) {
      ZyawValue = theOscMessage.get(0).floatValue();  
      return;
    }  
  }

  if(theOscMessage.checkAddrPattern("/orientation/pitch")==true) { 
    if(theOscMessage.checkTypetag("f")) 
    {
      XpitchValue = theOscMessage.get(0).floatValue();  
      return;
    }  
  } 

  if(theOscMessage.checkAddrPattern("/orientation/roll")==true) { 
    if(theOscMessage.checkTypetag("f")) {
      YrollValue = theOscMessage.get(0).floatValue();
      return;
    }  
  }   
  println("Azimuth: "+ZyawValue+", Pitch: "+XpitchValue+", Roll: "+YrollValue);
}

Screen Shot 2018-03-30 at 21.45.50


Viewing all articles
Browse latest Browse all 2896

Trending Articles