Quaternion offset?

Hi all,

I’ve been fiddling around the the Razer Hydra, a motion controller for PC. It gives me the exact position and rotation of 2 controllers, one for each hand.

I want a calibration routine where there is a gun straight in front of the FPS camera, aiming straight forward, so that the player can position a controller in roughly the same place in the real world and press a button, so that the gun then starts matching the player’s movements.

Currently, I have a system which almost works; the gun is pointing exactly along the controller’s forward axis. Trouble is, to aim the gun forwards, I feel like I have to aim the controller slightly off to the side.

I’d like to apply a rotation offset when the calibration button is pressed, calculated by the difference between the gun’s rotation and the controller’s rotation (both are quaternions).

I thought this sort of thing would work:

Quaternion rotationOffset = Quaternion.FromToRotation(trackedObject.transform.localRotation.eulerAngles, controllerRot.eulerAngles);
// apply the rotation
trackedObject.transform.localRotation = controllerRot * rotOffset;

… but I’m getting strange results. Ideally, as soon as the calibration button is pressed, the gun would not move so long as the controller didn’t move - As it is, the gun snaps to a strange angle.

Does anyone have any ideas?

Cheers, Simon.

FromToRotation takes two vectors not vector based angles so it would appear you parameters should be:

    Quaternion.FromToRotation(trackedObject.transform.forward, controllerRot* Vector3.forward)