/* * Rapier bindings are defined here */ #![allow(nonstandard_style)] macro_rules! V_malloc { ($t:ty, $count:expr) => { malloc(size_of::<$t>() * $count) as *mut $t }; } use std::ptr::{self, null}; use std::mem::transmute; use parry3d::shape::{Shape, ShapeType}; use rapier3d::geometry::Ball; use libc::{malloc, free}; #[repr(C)] pub struct BallShape_t { m_fRadius: f32, } pub struct RapierShape_t { m_eType: ShapeType, m_shape: *mut dyn Shape, } pub struct RapierPhysics { } #[unsafe(no_mangle)] pub unsafe extern "C" fn CRapierPhysics_CreateBall( ball: BallShape_t ) -> *mut RapierShape_t { let rapierShape = Ball::new(ball.m_fRadius); let rapierShapeMemory: *mut Ball = V_malloc!(Ball, 1); *rapierShapeMemory = rapierShape; let shape: RapierShape_t = RapierShape_t { m_eType: ShapeType::Ball, m_shape: rapierShapeMemory }; let shapeMemory: *mut RapierShape_t = V_malloc!(RapierShape_t, 1); *shapeMemory = shape; shapeMemory }