# Camera Position / Camera Angle / Camera Target Position

Ok I have to admit that my math class was like ages ago… but…

How can I calculate the camera target position:

I have XYZ: camera position

I have XYZ: angles in degree

how can I calculate the XYZ of the camera target position assuming that the distance is 1.0f?

Cheers,

First, compute side, up, forward vectors from Euler angles, then translate forward vector with your camera position;
targetPosition = cameraPosition + forward

Here is a code snippet to compute from angles to axis vectors(side, up, forward). Notice that I use yaw, pitch and roll rotation order (RyRxRz). But, a different order of rotations produces different axis vectors, so try out yourself to multiply rotation matrice in different orders. And “Vector3” is simply a struct type of 3D vector.

``````///////////////////////////////////////////////////////////////////////////////
// convert Euler angles(x,y,z) to axis(side, up, forward)
// The order of rotation is Yaw->Pitch->Roll (Ry*Rx*Rz)
// Rx: rotation about X-axis, pitch
// Rz: rotation about Z-axis, roll
//      Ry         Rx          Rz
// |Cy  0 -Sy| |1   0  0| | Cz Sz 0|   |CyCz-SySxSz  CySz+SySxCz  -SyCx|  <- side
// | 0  1   0|*|0  Cx Sx|*|-Sz Cz 0| = |-CxSz        CxCz         Sx   |  <- up
// |Sy  0  Cy| |0 -Sx Cx| |  0  0 1|   |SyCz+CySxSz  SySz-CySxCz  CyCx |  <- forward
///////////////////////////////////////////////////////////////////////////////
void anglesToAxis(const Vector3& angles, Vector3& side, Vector3& up, Vector3& forward)
{
const float DEG2RAD = 3.141593f / 180;
float sx, sy, sz, cx, cy, cz, theta;

// rotation angle about X-axis (pitch)
sx = sinf(theta);
cx = cosf(theta);

// rotation angle about Y-axis (yaw)
sy = sinf(theta);
cy = cosf(theta);

// rotation angle about Z-axis (roll)
sz = sinf(theta);
cz = cosf(theta);

// determine side vector
side = cy*cz - sy*sx*sz;
side = cy*sz + sy*sx*cz;
side = -sy*cx;

// determine up vector
up = -cx*sz;
up = cx*cz;
up = sx;

// determine forward vector
forward = sy*cz + cy*sx*sz;
forward = sy*sz - cy*sx*cz;
forward = cy*cx;
}
``````