use crate::sys::*;
pub unsafe trait AsIntersectContext {
type Ext;
fn as_context(&self) -> &IntersectContext;
fn as_mut_context(&mut self) -> &mut IntersectContext;
fn as_context_ptr(&self) -> *const IntersectContext {
self.as_context() as *const IntersectContext
}
fn as_mut_context_ptr(&mut self) -> *mut IntersectContext {
self.as_mut_context() as *mut IntersectContext
}
fn as_extended(&self) -> Option<&Self::Ext>;
fn as_mut_extended(&mut self) -> Option<&mut Self::Ext>;
}
pub type IntersectContext = RTCIntersectContext;
impl IntersectContext {
pub fn coherent() -> IntersectContext {
IntersectContext::new(RTCIntersectContextFlags::COHERENT)
}
pub fn incoherent() -> IntersectContext {
IntersectContext::new(RTCIntersectContextFlags::INCOHERENT)
}
pub fn new(flags: RTCIntersectContextFlags) -> IntersectContext {
RTCIntersectContext {
flags,
filter: None,
instID: [u32::MAX; 1],
}
}
pub unsafe fn ext<T>(&self) -> &T {
&(*(self as *const IntersectContext as *const IntersectContextExt<T>)).ext
}
pub unsafe fn ext_mut<T>(&mut self) -> &mut T {
&mut (*(self as *mut IntersectContext as *mut IntersectContextExt<T>)).ext
}
}
unsafe impl AsIntersectContext for IntersectContext {
type Ext = ();
fn as_context(&self) -> &IntersectContext { self }
fn as_mut_context(&mut self) -> &mut IntersectContext { self }
fn as_extended(&self) -> Option<&Self::Ext> { None }
fn as_mut_extended(&mut self) -> Option<&mut Self::Ext> { None }
}
#[repr(C)]
#[derive(Debug)]
pub struct IntersectContextExt<E>
where
E: Sized,
{
pub ctx: IntersectContext,
pub ext: E,
}
impl<E> Clone for IntersectContextExt<E>
where
E: Sized + Clone,
{
fn clone(&self) -> Self {
IntersectContextExt {
ctx: self.ctx,
ext: self.ext.clone(),
}
}
}
impl<E> Copy for IntersectContextExt<E> where E: Sized + Copy {}
unsafe impl<E> AsIntersectContext for IntersectContextExt<E>
where
E: Sized,
{
type Ext = E;
fn as_context(&self) -> &IntersectContext { &self.ctx }
fn as_mut_context(&mut self) -> &mut IntersectContext { &mut self.ctx }
fn as_extended(&self) -> Option<&Self::Ext> { Some(&self.ext) }
fn as_mut_extended(&mut self) -> Option<&mut Self::Ext> { Some(&mut self.ext) }
}
impl<E> IntersectContextExt<E>
where
E: Sized,
{
pub fn new(flags: RTCIntersectContextFlags, extra: E) -> IntersectContextExt<E> {
IntersectContextExt {
ctx: IntersectContext::new(flags),
ext: extra,
}
}
pub fn coherent(extra: E) -> IntersectContextExt<E> {
IntersectContextExt {
ctx: IntersectContext::coherent(),
ext: extra,
}
}
pub fn incoherent(extra: E) -> IntersectContextExt<E> {
IntersectContextExt {
ctx: IntersectContext::incoherent(),
ext: extra,
}
}
}
pub type PointQueryContext = RTCPointQueryContext;
impl PointQueryContext {
pub fn new() -> Self {
const LEVELS: usize = RTC_MAX_INSTANCE_LEVEL_COUNT as usize;
Self {
world2inst: [[0.0; 16]; LEVELS],
inst2world: [[0.0; 16]; LEVELS],
instID: [crate::INVALID_ID; LEVELS],
instStackSize: 0,
}
}
}
impl Default for PointQueryContext {
fn default() -> Self { Self::new() }
}