nalgebra/examples/transformation_pointer.rs

26 lines
746 B
Rust
Raw Normal View History

2017-02-13 01:17:09 +08:00
extern crate nalgebra as na;
2018-02-02 19:26:35 +08:00
use na::{Isometry3, Vector3};
2017-02-13 01:17:09 +08:00
fn main() {
let iso = Isometry3::new(Vector3::new(1.0f32, 0.0, 1.0), na::zero());
// Compute the homogeneous coordinates first.
2018-02-02 19:26:35 +08:00
let iso_matrix = iso.to_homogeneous();
let iso_array = iso_matrix.as_slice();
2017-02-13 01:17:09 +08:00
let iso_pointer = iso_array.as_ptr();
/* Then pass the raw pointer to some graphics API. */
unsafe {
2018-02-02 19:26:35 +08:00
assert_eq!(*iso_pointer, 1.0);
assert_eq!(*iso_pointer.offset(5), 1.0);
2017-02-13 01:17:09 +08:00
assert_eq!(*iso_pointer.offset(10), 1.0);
assert_eq!(*iso_pointer.offset(15), 1.0);
assert_eq!(*iso_pointer.offset(12), 1.0);
assert_eq!(*iso_pointer.offset(13), 0.0);
assert_eq!(*iso_pointer.offset(14), 1.0);
}
}