Rotation looking through a vector - Help!
in
Programming Questions
•
3 years ago
I've been beating my head on this all day and would greatly appreciate any help. I'm working on an addition to the PeasyCam library that would allow us to look through a xyz point.
So you have two points, the one your looking at (always 0,0,0), and the one you're looking through. I have everything completed except I'm getting stuck on the x,y,z to pitch,yaw,roll conversion. I've read through the forum but my math is just not that strong to understand some of the explanations. This thread is good but I don't understand it. This article is informative, but it doesn't work.
Example problem looks like this.. see the mouseclick area for the offending code.
roll = -1.5707963
yaw = -2.3125612
pitch = -0.31500
My pitch is way off, and my yaw is partly off. So I figure this should be pretty exact - so I'm doing something seriously wrong.
So you have two points, the one your looking at (always 0,0,0), and the one you're looking through. I have everything completed except I'm getting stuck on the x,y,z to pitch,yaw,roll conversion. I've read through the forum but my math is just not that strong to understand some of the explanations. This thread is good but I don't understand it. This article is informative, but it doesn't work.
Example problem looks like this.. see the mouseclick area for the offending code.
- import peasy.PeasyCam; //peasy camera control
- PeasyCam cam;
- float x,y,z;
- void setup() {
- size(600, 500, P3D );
- cam = new PeasyCam(this, 1000);
- cam.setMinimumDistance(150);
- cam.setMaximumDistance(800);
- noStroke();
- }
- void draw() {
- background(0);
- fill(255,0,0);
- sphere(25);
- //converted long/lat for new york city
- x = -73;
- y = -21;
- z = -64;
- pushMatrix();
- translate(x,y,z);
- fill(0,255,0);
- sphere(10);
- popMatrix();
- }
- void mouseClicked() {
- //Need Help Here!!!
- float r = sqrt(x * x + y * y + z * z);
- float roll = -HALF_PI;
- float yaw = -acos(z / r);
- float pitch = atan2(z, x);
- cam.setRotations(pitch,yaw,roll);
- }
roll = -1.5707963
yaw = -2.3125612
pitch = -0.31500
My pitch is way off, and my yaw is partly off. So I figure this should be pretty exact - so I'm doing something seriously wrong.
1
