Move Camera

Discussion in 'HAPTIX' started by Tyler Simpson, Nov 24, 2015.

  1. I would like to be able to programmatically move and rotate the camera viewpoint over TCP/IP through a Matlab API call. I haven't found a way to do this using existing calls, though such a feature must be implemented somewhere to enable head-tracking.
  2. Emo Todorov

    Emo Todorov Administrator Staff Member

    There are indeed internal functions for camera control, used for head tracking as well as moving the free camera with the mouse. But they interact with various other mechanisms that are not easily exposed over a socket API.

    Fortunately there is a workaround. Create a new mocap body in the model and attach a camera to it, by adding this code under the <worldbody> element:

    <boby name="cameramover" mocap="true" pos="0 0 1">
    <camera name="mycamera"/>

    (the names and position/orientation are up to you)

    Enable the new camera from Settings / Render / Camera mode. Now you can move the mocap body via the socket API using mj_set_mocap. Keep in mind though that mj_get_mocap and mj_set_mocap operate on the data arrays for all mocap bodies, and HAPTIX-related models are already using a mocap body for hand tracking. So in order to move the camera without perturbing the hand, call mj_get_mocap, change the data only for the camera-related mocap body you added to the model, and then call mj_set_mocap.