oyk

OYK is ODE (Open Dynamics Engine) bindings for Rust yaw kinetics

ODE * https://github.com/nomissbowling/oyk/blob/master/img/oyk_512x100.png?raw=true

Now this crate is tested on ode-0.16.2 dll version.

ode.dll drawstuff.dll for x64 Windows binary compiled with -DdDOUBLE by mingw

(It may work with VC, or other platforms.)

Requirements

to build dll

in the running directory

Samples

```rust use oyk::colors::; use oyk::ode::;

use std::ffi::{cvoid}; // used by implsimfn use implsim::{implsimfn, implsimderive};

pub struct SimApp { cnt: usize }

impl SimApp {

pub fn objsmut(&mut self, f: bool, s: &str) { let rode = self.supermut(); if f || rode.ismodified(false) { self.cnt = rode.num(); println!("obgs: {} in {}", self.cnt, s); let rode = self.superget(); // must re get let ids = rode.eachid(|key, id| { true }); // lambda may return false for id in ids { if id == 0 as dBodyID { continue; } // skipped by result of eachid let rode = self.supermut(); // must re get match rode.getmut(id) { Err(e) => { println!("{}", e); }, Ok(obg) => { // This is test code using eachid with getmut, but high cost. // Better to use self.supermut().findmut("ballbig".tostring()) if obg.key == "ballbig" { obg.col = [1.0, 0.0, 0.0, 0.8]; } println!("{}: {:018p} {:?}", obg.key, id, obg.col); // gettcmmut must be after accessing to obg members if obg.key == "ballbig" { let geom = obg.geom(); // must assign before gettcmmut let mgm = rode.getmgmmut(geom).unwrap(); // must care okor mgm.gettcm_mut().col = [1.0, 0.0, 0.0, 0.8]; } } } } } }

pub fn objsinfo(&mut self, f: bool, s: &str) { let rode = self.supermut(); if f || rode.ismodified(false) { self.cnt = rode.num(); println!("obgs: {} in {}", self.cnt, s); let rode = self.superget(); // must re get because borrow later self.cnt rode.each(|key, id, obg| { println!("{}: {:018p} {:?}", key, id, obg.col); true }); } }

}

[implsimderive(drawgeom, nearcallback, stop_callback)]

impl Sim for SimApp {

fn drawobjects(&mut self) { self.objsinfo(false, "draw"); // twice (after step) self.supermut().drawobjects(); }

fn startcallback(&mut self) { let rode = self.supermut(); let tdelta = &mut rode.tdelta; *tdelta = 0.002; let m: dReal = 0.8; let r: dReal = 0.2; for i in 0..16 { let c: dVector4 = vec4fromu32(COLORS[i]); let p: dVector3 = [(i%4) as dReal - 1.5, (i/4) as dReal - 1.5, 2.0, 1.0]; let mib = MetaSphere::new(m, r, KRP095, 0, c); let (body, _, _) = rode.creatorm(format!("ball{:08X}", i).asstr(), mib); rode.getmut(body).expect("fail reg").setpos(p); } let c: dVector4 = [1.0, 1.0, 0.0, 0.8]; let p: dVector3 = [0.0, 0.0, 10.0, 1.0]; let mib = MetaSphere::new(0.08 / (125.0 * PIt4), 1.0, KRP095, 0, c); let (body, , _) = rode.creator("ballbig", mib); rode.getmut(body).expect("fail reg").setpos(p);

let mi = MetaBox::new(0.1, [1.0, 1.0, 1.0, 0.0], KRP095, 0, [0.0, 1.0, 1.0, 0.8]); let (body, , _) = rode.creator("boxbig", mi); rode.getmut(body).expect("fail reg").setpos([-5.0, 5.0, 2.0, 1.0]);

let micap0 = MetaCapsule::new(0.001, 0.5, 16.0, KRP080, 0, [0.0, 1.0, 0.0, 0.8]); let (body, _, _) = rode.creator("capsule0", micap0); rode.getmut(body).expect("fail reg").setpos([-8.6, 0.0, 1.5, 1.0]) .setrot(dMatrix3::fromaxisand_angle([1.0, 0.0, 0.0], PIh));

let micyl0 = MetaCylinder::new(0.001, 0.5, 16.0, KRP080, 0, [1.0, 0.0, 1.0, 0.8]); let (body, _, _) = rode.creator("cylinder0", micyl0); rode.getmut(body).expect("fail reg").setpos([0.0, 8.6, 1.5, 1.0]) .setrot(dMatrix3::fromaxisand_angle([0.0, 1.0, 0.0], PIh));

let micap1 = MetaCapsule::new(0.001, 0.5, 16.0, KRP080, 0, [0.0, 0.0, 1.0, 0.8]); let (body, _, _) = rode.creator("capsule1", micap1); rode.getmut(body).expect("fail reg").setpos([8.6, 0.0, 1.5, 1.0]) .setrot(dMatrix3::fromaxisand_angle([1.0, 0.0, 0.0], PIh));

let micyl1 = MetaCylinder::new(0.001, 0.5, 16.0, KRP080, 0, [0.0, 1.0, 1.0, 0.8]); let (body, _, _) = rode.creator("cylinder1", micyl1); rode.getmut(body).expect("fail reg").setpos([0.0, -8.6, 1.5, 1.0]) .setrot(dMatrix3::fromaxisand_angle([0.0, 1.0, 0.0], PIh));

let micmp0 = MetaComposite::new( vec![ MetaBox::new(0.1, [0.5, 0.5, 0.5, 0.0], KRP095, 0, [1.0, 0.0, 0.0, 0.8]), MetaBox::new(0.1, [0.5, 0.5, 0.5, 0.0], KRP095, 0, [0.0, 0.0, 1.0, 0.8]), MetaSphere::new(0.6 / PI, 0.5, KRP095, 0, [0.0, 1.0, 0.0, 0.8]), MetaSphere::new(0.0001, 0.1, KRPnk, 0, [1.0, 0.0, 1.0, 0.8])], vec![QI, QI, QI, QI], vec![ [-0.4, -0.4, -0.4, 1.0], [0.4, 0.4, 0.4, 1.0], [0.0, 0.0, 0.0, 1.0], [0.0, 0.0, 0.0, 1.0]], KRPnk, 0, [1.0, 0.0, 0.0, 0.8]); let (body, _, _) = rode.creatorcomposite("composite0", micmp0); rode.getmut(body).expect("fail reg").setpos([-15.0, -2.0, 2.0, 1.0]) .setquaternion(dQuaternion::fromaxisandangle([0.0, 0.0, 1.0], -PIq3));

let micmp1 = MetaComposite::new( vec![ MetaBox::new(0.1, [0.5, 0.5, 0.5, 0.0], KRP095, 0, [1.0, 0.0, 0.0, 0.8]), MetaBox::new(0.1, [0.5, 0.5, 0.5, 0.0], KRP095, 0, [0.0, 0.0, 1.0, 0.8]), MetaSphere::new(0.6 / PI, 0.5, KRP095, 0, [0.0, 1.0, 0.0, 0.8])], vec![ dQuaternion::fromaxisandangle([-0.707, 0.707, 0.0], PIq), dQuaternion::fromaxisandangle([0.707, -0.707, 0.0], -PIq), dQuaternion::new()], vec![ [-0.4, -0.4, -0.4, 1.0], [0.4, 0.4, 0.4, 1.0], [0.0, 0.0, 0.0, 1.0]], KRP100, 0, [1.0, 0.0, 0.0, 0.8]); let (body, _, _) = rode.creatorcomposite("composite1", micmp1); rode.getmut(body).expect("fail reg").setpos([-15.0, 0.0, 2.0, 1.0]) .setquaternion(dQuaternion::fromaxisandangle([0.0, 0.0, 1.0], -PIq3));

let dm: dReal = 0.1; let lxyz: dVector3 = [10.0, 10.0, 0.05, 0.0]; let norm: dVector4 = [0.0, 0.0, 1.0, 0.0]; let col: dVector4 = vec4fromu32(COLORS[0]); let pos: dVector3 = [-5.0, -5.0, 5.0, 0.0]; let mip = MetaPlane::new(dm, lxyz, norm, KRPnk, 0, col); let (body, , _) = rode.creator("plane", mip); let q = dQuaternion::fromaxisandangle([1.0, 1.0, 0.0], PIq); rode.getmut(body).expect("fail reg").setpos(pos) // .setrot(dMatrix3::fromzaxis([0.7, 0.7, 0.0])); // .setrot(dMatrix3::from2axes([-0.7, 0.7, 0.0], [0.7, 0.7, 0.0])); // .setrot(dMatrix3::fromeulerangles(PIq, PIq, PIq)); // .setrot(dMatrix3::fromaxisandangle([0.0, 0.0, 1.0], PIq)); // .setrot(dMatrix3::new()); // .setrot(dMatrix3::fromQ(dQuaternion::new())); // .setrot(dQuaternion::new().toR()); // .setquaternion(dMatrix3::new().toQ()); // .setquaternion(dQuaternion::fromR(dMatrix3::new())); // .setquaternion(dQuaternion::new()); // .setquaternion(q); .setrot(q.toR());

rode.start_callback(); }

fn stepcallback(&mut self, pause: i32) { self.objsinfo(false, "step"); // twice (before draw) self.supermut().stepcallback(pause); }

fn commandcallback(&mut self, cmd: i32) { match cmd as u8 as char { 'o' => { let k = "ballbig"; match self.supermut().findmut(k.tostring()) { Err(e) => { println!("{}", e); }, Ok(obg) => { println!("{}: {:018p} {:?}", k, obg.body(), obg.col); println!(" pos: {}", obg.posvec()); println!(" rot: {}", obg.rotmat3()); let pos: &mut [dReal] = obg.pos(); // re get mut pos[0] += 0.2; pos[1] += 0.2; pos[2] = 5.0; } } }, 'b' => { self.objsmut(true, "mut"); }, 'a' => { self.objsinfo(true, "cmd"); }, _ => {} } self.supermut().commandcallback(cmd); }

} // impl Sim for SimApp

fn main() { ODE::open(); ODE::sim_loop( 640, 480, // 800, 600, Some(Box::new(SimApp{cnt: 0})), b"./resources"); ODE::close(); } ```

see also

License

MIT License