Skip to content

cf_draw3d_unproject

Category: draw3d
GitHub: cute_draw3d.h


Turns a 2d point into a 3d ray under the current camera stacks.

void cf_draw3d_unproject(CF_V2 point, CF_V3* origin_out, CF_V3* direction_out);
Parameters Description
point A point in the 2d draw API's world space.
origin_out The ray's origin on the near plane. Can be NULL.
direction_out The ray's normalized direction. Can be NULL.

Remarks

The front half of mouse picking -- convert the mouse with cf_screen_to_world, then cast the returned ray against your own scene representation:

CF_V3 origin, dir;
cf_draw3d_unproject(cf_screen_to_world(cf_v2(cf_mouse_x(), cf_mouse_y())), &origin, &dir);

Works for perspective and orthographic projections alike (orthographic rays share a direction but differ in origin).

cf_draw3d_project
cf_screen_to_world
cf_draw3d_push_projection
cf_draw3d_push_view