Question on implementation of Lens.project function

hello,
so after creating my entire panda’s application, i also decided to create a version using Numba. so i need to make changes to my code and convert mostly all to numpy arrays.

I have finished most of the code just stuck at the very final conversion where i project the 3d points using Lens.project:
Panda’s implementation

if intersection_upper:

point_in_camera_space = camera_path.getRelativePoint(self.render, intersection_upper)
#print(point_in_camera_space, intersection_upper)
camera_projected_point = Point2()
if lens.project(point_in_camera_space, camera_projected_point):
   print("camera_projected_point ",camera_projected_point)
   projected_x = (camera_projected_point.x + 1) / 2 * (self.img_width - 1)
   projected_y = (1 - camera_projected_point.y) / 2 * (self.img_height - 1)

now I want to achieve a similar implementation using numba.

          intersection_upper = intersect_plane_numba(intersection_lower, intersection_lower + refracted_ray_dir * 1000, -planeoffset)

          cam_x = intersection_upper[0] - pos[0]
          cam_y = intersection_upper[1] - pos[1]
          cam_z = intersection_upper[2] - pos[2]

          # Apply the rotation matrix
          rotated_cam_x = (rotation[0, 0] * cam_x + rotation[0, 1] * cam_y + rotation[0, 2] * cam_z)
          rotated_cam_y = (rotation[1, 0] * cam_x + rotation[1, 1] * cam_y + rotation[1, 2] * cam_z)
          rotated_cam_z = (rotation[2, 0] * cam_x + rotation[2, 1] * cam_y + rotation[2, 2] * cam_z)
          transformed_points = np.array([rotated_cam_x, rotated_cam_y, rotated_cam_z], dtype = np.float32)
          #print(transformed_points,intersection_upper)

          transformed_points_x = (focal_length * transformed_points[0])/ transformed_points[2]
          normalized_x = (transformed_points_x / (img_width / 2))
          transformed_points_y = (focal_length * transformed_points[1])/ transformed_points[2]
          normalized_y = transformed_points_y / (img_height / 2)
          max_val = max(abs(normalized_x), abs(normalized_y))

          if max_val > 1:
              normalized_x /= max_val
              normalized_y /= max_val  
          print("camera_projected_point ", normalized_x, normalized_y)

however this does not yield the exact same value as the points from Lens.Project function which are in the range of -1,1

lens.project(point_in_camera_space, camera_projected_point):

therefore i wish to know what is the implementation behind lens.project function in Panda3d and what i might be doing wrong.
because my camera_coordinate points are exactly the same as in Panda implemention but only the final points are wrong…

much appreciated in advanced :blush:

The source code is available: