File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,3 +47,8 @@ bool ccube_is_bbox_inside(ccube_t cube, bbox_t box);
4747 * Checks if a sphere and a cube are overlapping
4848 */
4949bool ccube_is_sphere_inside (ccube_t cube , csphere_t sphere );
50+
51+ /**
52+ * Checks if two cubes are overlapping
53+ */
54+ bool ccube_is_ccube_inside (ccube_t a , ccube_t b );
Original file line number Diff line number Diff line change @@ -69,3 +69,18 @@ bool ccube_is_sphere_inside(ccube_t cube, csphere_t sphere) {
6969 ccube_clamp_point_within_cube (cube , & closest_to_cube_center );
7070 return csphere_is_point_inside (sphere , closest_to_cube_center );
7171}
72+
73+ bool ccube_is_ccube_inside (ccube_t a , ccube_t b ) {
74+ // cancel out a's rotation so we can treat this like a cube-bbox check
75+ quaternion_t a_rot_reversed = a .rotation ;
76+ quaternion_conjugate (& a_rot_reversed );
77+ vec4_cross_product (& b .rotation , b .rotation , a_rot_reversed );
78+ vec3_rotate_by_quaternion (& b .position , b .position , a .rotation );
79+ a .rotation = VEC4_ZERO ;
80+
81+ // Do the cube-bbox check. We inline it here so we don't have to
82+ // initialize an actual bbox
83+ vec3_t a_closest_b = b .position ;
84+ ccube_clamp_point_within_cube (a , & a_closest_b );
85+ return ccube_is_point_inside (b , a_closest_b );
86+ }
You can’t perform that action at this time.
0 commit comments