//Calculates the target pose for the camera in order to appear in front of the marker.
    private Pose GetTargetPose(MarkerBehaviour marker)
    {
        Matrix4x4 m          = marker.GetMatrix();
        Matrix4x4 inverseMat = m.inverse;
        Pose      p          = new Pose();

        p.rotation  = ARucoUnityHelper.GetQuaternion(inverseMat);
        p.position  = marker.transform.position;
        p.position += ARucoUnityHelper.GetPosition(inverseMat);

        return(p);
    }
    //Updates Marker pose data by transforming the "transform matrix" received from open cv.
    //additional rotation can be passed so that the whole world matrix is rotated accordingly.
    //that is useful for AR-Foundation since there the camera view is on landscape mode and needs to be rotated properly
    private void UpdateMarkerPose(Matrix4x4 transformMatrix, Nullable <Vector3> additionalRotation = null)
    {
        //convert from open cv space to unity space
        Matrix4x4 matrixY = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, -1, 1));
        Matrix4x4 matrixZ = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1, 1, -1));
        Matrix4x4 matrixX = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(-90, 0, 0), new Vector3(1, 1, 1));

        currentTransformationMatrix = (matrixY * transformMatrix * matrixZ) * matrixX;

        //apply additional rotation if needed
        Matrix4x4 r = Matrix4x4.Rotate(Quaternion.Euler(additionalRotation.GetValueOrDefault(Vector3.zero)));

        currentTransformationMatrix = r * currentTransformationMatrix;

        //update the current marker pose position,rotation and scale
        currentMarkerPose.position = ARucoUnityHelper.GetPosition(currentTransformationMatrix);
        currentMarkerPose.rotation = ARucoUnityHelper.GetQuaternion(currentTransformationMatrix);
        currentMarkerPose.scale    = ARucoUnityHelper.GetScale(currentTransformationMatrix);
    }
Exemplo n.º 3
0
 protected float GetMarkerDistanceFromCamera(MarkerBehaviour m)
 {
     return(ARucoUnityHelper.GetPosition(m.GetMatrix()).magnitude);
 }