Add function to query nodes by distance for spatial queries
This commit is contained in:
@@ -1,3 +1,30 @@
|
|||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn sdxr_query_nodes_by_distance(
|
||||||
|
center_x: f32,
|
||||||
|
center_y: f32,
|
||||||
|
center_z: f32,
|
||||||
|
radius: f32,
|
||||||
|
out_ids: *mut u64,
|
||||||
|
max_count: usize,
|
||||||
|
) -> usize {
|
||||||
|
if !STARTED.load(Ordering::SeqCst) { return 0; }
|
||||||
|
let ctrl = CTRL.lock().unwrap();
|
||||||
|
let mut found = 0;
|
||||||
|
let center = glam::Vec3::new(center_x, center_y, center_z);
|
||||||
|
for (id, node) in ctrl.nodes.iter() {
|
||||||
|
let (_scale, _rot, trans) = node.transform.to_scale_rotation_translation();
|
||||||
|
let pos = glam::Vec3::new(trans.x, trans.y, trans.z);
|
||||||
|
if (pos - center).length() <= radius {
|
||||||
|
if found < max_count {
|
||||||
|
unsafe { *out_ids.add(found) = *id; }
|
||||||
|
found += 1;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
found
|
||||||
|
}
|
||||||
// Rust C-ABI bridge for StardustXR client integration.
|
// Rust C-ABI bridge for StardustXR client integration.
|
||||||
|
|
||||||
mod model_downloader;
|
mod model_downloader;
|
||||||
|
|||||||
Reference in New Issue
Block a user