/// <summary> /// Gets the normal vector (the direction a surface is pointing) at a given screen-space pixel (i,j). /// The normal can be given relative to the camera or the world. Returns false if outside camera's view frustum. /// </summary> /// <param name="pixel">Pixel coordinates.</param> /// <param name="reference_frame">Reference frame given by the enum sl.REFERENCE_FRAME.</param> /// <param name="cam">Unity Camera used for world-camera space conversion.</param> /// <out>Normal to be filled.</out> /// <returns>True if successful, false otherwise.</returns> public static bool GetNormalAtPixel(sl.ZEDCamera zedCam, Vector2 pixel, sl.REFERENCE_FRAME reference_frame, Camera cam, out Vector3 normal) { normal = Vector3.zero; if (zedCam == null) { return(false); } Vector4 n; bool r = zedCam.GetNormalValue(new Vector3(pixel.x, pixel.y, 0), out n); switch (reference_frame) { case sl.REFERENCE_FRAME.CAMERA: //Relative to the provided camera. normal = n; break; case sl.REFERENCE_FRAME.WORLD: //Relative to the world. normal = cam.transform.TransformDirection(n); break; default: normal = Vector3.zero; break; } return(r); }
/// <summary> /// Launches a grab and update the listeners /// </summary> /// <param name="mode"></param> public void Update(sl.SENSING_MODE mode, bool depth = true, sl.REFERENCE_FRAME reference = sl.REFERENCE_FRAME.CAMERA) { if (!isThreaded) { if (!pauseThread && sl.ZEDCamera.GetInstance().Grab(mode, depth, reference) == sl.ERROR_CODE.SUCCESS) { SendEventGrab(); } } else { Broadcast(); grabParameters.mode = mode; } }
/// <summary> /// Get the Normal vector at a world position (x,y,z). the Normal can be given regarding camera reference or in the world reference. /// </summary> /// <param name="position"> world position</param> /// <param name="reference_frame"> Reference frame given by the enum sl.REFERENCE_FRAME</param> /// <param name="cam"> Unity Camera (to access world to camera transform</param> /// <out> normal vector that will be filled </out> /// <returns> true if success, false otherwie</returns> public static bool GetNormalAtWorldLocation(Vector3 position, sl.REFERENCE_FRAME reference_frame, Camera cam, out Vector3 normal) { Vector4 n; bool r = sl.ZEDCamera.GetInstance().GetNormalValue(cam.WorldToScreenPoint(position), out n); switch (reference_frame) { case sl.REFERENCE_FRAME.CAMERA: normal = n; break; case sl.REFERENCE_FRAME.WORLD: normal = cam.transform.TransformDirection(n); break; default: normal = Vector3.zero; break; } return(r); }
/*********************************************************************************************** ******************** BASIC "GET" FUNCTIONS **************************** ***********************************************************************************************/ /// <summary> /// Get the Normal vector at a given pixel (i,j). the Normal can be given regarding camera reference or in the world reference. /// </summary> /// <param name="pixel"> position of the pixel</param> /// <param name="reference_frame"> Reference frame given by the enum sl.REFERENCE_FRAME</param> /// <param name="cam"> Unity Camera (to access world to camera transform</param> /// <out> normal that will be filled </out> /// <returns> true if success, false otherwie</returns> public static bool GetNormalAtPixel(Vector2 pixel, sl.REFERENCE_FRAME reference_frame, Camera cam, out Vector3 normal) { Vector4 n; bool r = sl.ZEDCamera.GetInstance().GetNormalValue(new Vector3(pixel.x, pixel.y, 0), out n); switch (reference_frame) { case sl.REFERENCE_FRAME.CAMERA: normal = n; break; case sl.REFERENCE_FRAME.WORLD: normal = cam.transform.TransformDirection(n); break; default: normal = Vector3.zero; break; } return(r); }