Skip to content

Improve QR Code tracking with simple change #12

Open
@aidanwolf

Description

@aidanwolf

The QR Code Tracking sample while positionally accurate struggles to match the rotation of the QR code which may be important to some use cases. You can very easily improve the sample by sampling each corner with the environmental raycast manager. Here is the code:

            for (var i = 0; i < count; i++)
            {
                var pixelCoord = new Vector2Int(
                    Mathf.RoundToInt(uvs[i].x * intrinsics.Resolution.x),
                    Mathf.RoundToInt(uvs[i].y * intrinsics.Resolution.y)
                );
                
                var r = PassthroughCameraUtils.ScreenPointToRayInWorld(_passthroughCameraEye, pixelCoord);
                if (!envRaycastManager || !envRaycastManager.Raycast(r, out var cornerHitInfo))
                {
                    tempCorners[i] = r.origin + r.direction * distance;
                } 
                else {
                    tempCorners[i] = cornerHitInfo.point;
                }
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions