How could the rotation of an avatars head and body be determined by a single input value?

29 Views Asked by At

In a virtual reallity environment I want to rotate a head according to the rotation value provided by the camera sensor of a head mounted display. When the head reaches the boundary of its maximum rotation the whole avatar should is rotated to achieve this position.

$ h : 140$° denotes the maximum rotation of head (gray arc)

$ c$ : cameraRotation implies head movement

$ b$ : bodyRotation, the whole character should rotate when the head reached the maximum rotation in ei

$R(b,c) \left\{\begin{matrix} & c-\frac{h}2 & if |c-b| > \frac{h}2 \wedge c-b > 0, \\ & c+\frac{h}2 & if |c-b| > \frac{h}2 \wedge c-b < 0, \\ & c & otherwise \end{matrix}\right.$

This function returns the rotation in degrees of the body and works flawless in a test environment.

enter image description here

The used programming interface clamps the angle into the range $ 360 > r >= 0$.

This causes a jump (rotation by $360-h$°) of the camera rotation when c and b is around 0. enter image description here How could the flip be avoided or compensated (I tried different approaches but can't find a solution)?

Related: https://stackoverflow.com/questions/30654290/how-can-characters-body-be-continously-rotated-when-its-head-is-already-turned

A java applet for testing the algorithm standalone: https://github.com/3dbug/blender/blob/master/HeadCamRot.java