Reputation: 11
I am trying to control a moving head camera in a certain direction from my computer. The camera is controlled only by pan (540 degrees) and tilt (280 degrees). The problem is getting the Euler angles to these pan and tilt degrees.
I have a 3d representation of a direction, let's say X Y and Z rotation (Eurler angles).
Now I want to move my (physical!) pan tilt camera in te same direction. But i can't figure out how to translate an xyz vector to pan tilt.
Upvotes: 1
Views: 3497
Reputation: 51845
switch to orthogonal homogenous 4x4 transform matrices
rotation around global world X axis by ang:
double c=cos(ang),s=sin(ang);
double Q[16]=
{
1, 0, 0, 0,
0, c,-s, 0,
0, s, c, 0,
0, 0, 0, 1
};
M=M*Q;
rotation around local camera X axis by ang:
double c=cos(ang),s=sin(ang);
double Q[16]=
{
1, 0, 0, 0,
0, c,-s, 0,
0, s, c, 0,
0, 0, 0, 1
};
M=((M^-1)*Q)^-1;
there are libraries for transform matrices like glm but i prefer my own
here you can see the differences between homogenous (4x4) and normal (3x3+1x3) 3D transform matrices:
Now the driving of camera
so for move forward if d units do this:
x0+=d*Zx;
y0+=d*Zy;
z0+=d*Zz;
for side movement use X vector
for rotations different then around X axis just use different Q matrix
rotation around Y-axis
c, 0, s, 0,
0, 1, 0, 0,
-s, 0, c, 0,
0, 0, 0, 1;
rotation around Z-axis
c,-s, 0, 0,
s, c, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1;
Upvotes: 1