1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
use std::ops::{Add, Deref, DerefMut, Mul, Neg, Sub}; use std::sync::atomic::{AtomicBool, Ordering}; use num_traits::{Float, One, Zero}; use specs::{Component, VecStorage}; use super::InnerTransform3D; pub struct LocalTransform3D<T> { wrapped: InnerTransform3D<T>, dirty: AtomicBool, } impl<T> Component for LocalTransform3D<T> where T: 'static + Sync + Send, { type Storage = VecStorage<Self>; } impl<T> Default for LocalTransform3D<T> where T: Zero + One, { #[inline(always)] fn default() -> Self { LocalTransform3D { wrapped: InnerTransform3D::default(), dirty: AtomicBool::new(true), } } } impl<T> Deref for LocalTransform3D<T> where T: Zero + One, { type Target = InnerTransform3D<T>; #[inline(always)] fn deref(&self) -> &Self::Target { &self.wrapped } } impl<T> DerefMut for LocalTransform3D<T> where T: Zero + One, { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { self.flag(true); &mut self.wrapped } } impl<T> LocalTransform3D<T> where T: Zero + One, { #[inline(always)] pub fn new() -> Self { Self::default() } #[inline(always)] pub fn flag(&self, dirty: bool) { self.dirty.store(dirty, Ordering::SeqCst) } #[inline(always)] pub fn is_dirty(&self) -> bool { self.dirty.load(Ordering::SeqCst) } #[inline(always)] pub fn matrix(&self) -> [T; 16] where T: Float, for<'a, 'b> &'a T: Mul<&'b T, Output = T> + Neg<Output = T> + Add<&'b T, Output = T> + Sub<&'b T, Output = T>, { self.wrapped.matrix() } }