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 implsim::{implsimfn, implsim_derive};

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 tcm = rode.gettcmmut(geom).unwrap(); // must care ok_or tcm.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 = 1.0; 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 body = rode.mksphere(format!("ball{:08X}", i), m, r, c); 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 body = rode.mksphere("ballbig".tostring(), 0.1, 1.0, c); rode.getmut(body).expect("fail reg").setpos(p); let dm: dReal = 0.1; let lxyz: dVector3 = [10.0, 10.0, 0.05, 0.0]; let n: 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 body = rode.mkplane("plane".tostring(), dm, &lxyz, &n, col); 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(0.78, 0.78, 0.78)); // .setrot(dMatrix3::fromaxisandangle([0.0, 0.0, 1.0], 0.78)); // .setrot(dMatrix3::new()); // .setrot(dMatrix3::fromQ(dQuaternion::new())); // .setrot(dQuaternion::toR(dQuaternion::new())); // .setquaternion(dMatrix3::toQ(dMatrix3::new())); // .setquaternion(dQuaternion::fromR(dMatrix3::new())); // .setquaternion(dQuaternion::new()); .setquaternion(dQuaternion::fromaxisandangle([1.0, 1.0, 0.0], 0.78)); rode.startcallback(); }

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