1use std::os::raw;
2
3use cgmath::Matrix4;
4
5use device::Device;
6use geometry::Geometry;
7use scene::{Scene, CommittedScene};
8use sys::*;
9use {BufferType, Format, GeometryType};
10
11pub struct Instance<'a> {
12 device: &'a Device,
13 pub(crate) handle: RTCGeometry,
14 scene: &'a CommittedScene<'a>,
16}
17
18impl<'a> Instance<'a> {
19 pub fn unanimated(device: &'a Device, scene: &'a CommittedScene) -> Instance<'a> {
20 let h = unsafe { rtcNewGeometry(device.handle, GeometryType::INSTANCE) };
21 unsafe {
22 rtcSetGeometryInstancedScene(h, scene.scene.handle);
23 }
24 Instance {
25 device: device,
26 handle: h,
27 scene: scene,
28 }
29 }
30 pub fn set_transform(&mut self, transform: &Matrix4<f32>) {
31 let mat: &[f32; 16] = transform.as_ref();
32 unsafe {
34 rtcSetGeometryTransform(
35 self.handle,
36 0,
37 Format::FLOAT4X4_COLUMN_MAJOR,
38 mat.as_ptr() as *const raw::c_void,
39 );
40 }
41 }
42}
43
44unsafe impl<'a> Sync for Instance<'a> {}
45