OYK is ODE (Open Dynamics Engine) bindings for Rust yaw kinetics
* 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.)
to build dll
in the running directory
```rust use oyk::ode::*;
use implsim::{implsimfn, implsim_derive};
pub struct SimApp { cnt: usize }
impl SimApp {
pub fn objsinfo(&mut self, f: bool, s: &str) { let rode = self.superget(); let obgs = &rode.obgs; let l = obgs.len(); if f || (l != self.cnt) { self.cnt = l; println!("obgs: {} in {}", self.cnt, s); let rode = self.superget(); // must re get because borrow later self.cnt for (k, v) in &rode.mbgs { println!("{}: {:018p} {:?}", k, *v, rode.obgs[v].col); // same as below /* match rode.find(k.tostring()) { Err(e) => { println!("{}", e); }, Ok(obg) => { println!("{}: {:018p} {:?}", k, obg.body(), obg.col); } } */ } } }
}
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]; rode.mksphere(format!("ball{:08X}", i), m, r, &c, &p); } let c: dVector4 = [1.0, 1.0, 0.0, 0.8]; let p: dVector3 = [0.0, 0.0, 10.0, 1.0]; rode.mksphere("ballbig".tostring(), 0.1, 1.0, &c, &p); 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; } } }, 'a' => { self.objsinfo(true, "cmd"); }, _ => {} } self.supermut().command_callback(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
MIT License