psychopy.tools.mathtools.intersectRayOBB

psychopy.tools.mathtools.intersectRayOBB(rayOrig, rayDir, modelMatrix, boundsExtents, dtype=None)[source]

Find the point a ray intersects an oriented bounding box (OBB).

Parameters
  • rayOrig (array_like) – Origin of the ray in space [x, y, z].

  • rayDir (array_like) – Direction vector of the ray [x, y, z], should be normalized.

  • modelMatrix (array_like) – 4x4 model matrix of the object and bounding box.

  • boundsExtents (array_like) – Minimum and maximum extents of the bounding box.

  • dtype (dtype or str, optional) – Data type for computations can either be ‘float32’ or ‘float64’. If out is specified, the data type of out is used and this argument is ignored. If out is not provided, ‘float64’ is used by default.

Returns

Coordinate in world space of the intersection and distance in scene units from rayOrig. Returns None if there is no intersection.

Return type

tuple

Examples

Get the point on an oriented bounding box that the cursor is over and place a 3D stimulus there. The eye location is defined by RigidBodyPose object camera:

# get the mouse position on-screen
mx, my = mouse.getPos()

# find the point which the ray intersects on the box
result = intersectRayOBB(
    camera.pos,
    camera.transformNormal(win.coordToRay((mx, my))),
    myStim.thePose.getModelMatrix(),
    myStim.thePose.bounds.extents)

# if the ray intersects, set the position of the cursor object to it
if result is not None:
    cursorModel.thePose.pos = result[0]
    cursorModel.draw()  # don't draw anything if there is no intersect

Back to top