ode用的是BSD license, 很亲善, 并且库本身质量还不错, 可以作为正经的用途.
并且API是c风格的,可以很轻松的用于其他语言.
作为熟悉引擎, 先写个最简单的小球下落作为HelloWorld.
结果就像这样:
Mac-mini:ode $ ./a.out
0 0 10
1 0 0 0
0 1 0 0
0 0 1 0
0 0 9.9755
1 0 0 0
0 1 0 0
0 0 1 0
0 0 9.9265
1 0 0 0
0 1 0 0
0 0 1 0
0 0 9.853
1 0 0 0
0 1 0 0
0 0 1 0
0 0 9.755
1 0 0 0
0 1 0 0
0 0 1 0
0 0 9.6325
1 0 0 0
0 1 0 0
0 0 1 0
0 0 9.4855
1 0 0 0
0 1 0 0
0 0 1 0
0 0 9.314
1 0 0 0
0 1 0 0
0 0 1 0
0 0 9.118
1 0 0 0
0 1 0 0
0 0 1 0
0 0 8.8975
1 0 0 0
0 1 0 0
0 0 1 0
0 0 8.6525
1 0 0 0
0 1 0 0
0 0 1 0
0 0 8.383
1 0 0 0
0 1 0 0
0 0 1 0
0 0 8.089
1 0 0 0
0 1 0 0
0 0 1 0
0 0 7.7705
1 0 0 0
0 1 0 0
0 0 1 0
毕竟描画还是自己折腾openGL比较灵活高效,更何况已经写了objloader,至于要读模型文件,旋转平移就行了.
下面是源代码, 不知道为什么, 语法高亮失效了, 难道是我设置的问题?
Mac-mini:ode$ cat basic.d
import std.stdio, ode;
static dWorldID world;
dBodyID ball;
const dReal radius = .2;
const dReal mass = 1.;
static void simLoop(){
dReal* pos;
dReal* r;
pos = dBodyGetPosition(ball);
r = dBodyGetRotation(ball);
writeln(*pos,"\t",*(pos+1),"\t",*(pos+2));
foreach(i;0..3*4) write(*(r+i),((i+1)%4==0)?"\n":"\t");
writeln();
dWorldStep(world, 0.05);
}
void main(){
dInitODE();
world = dWorldCreate();
dWorldSetGravity(world, 0, 0, -9.8);
ball = dBodyCreate(world);
dMass m1;
dMassSetZero(&m1);
dMassSetSphereTotal(&m1, mass, radius);
dBodySetMass(ball, &m1);
dBodySetPosition(ball, 0,0,10);
foreach(i;1..40) simLoop();
dWorldDestroy(world);
dCloseODE();
}
连接的时候注意用g++才行,因为库用到了c++.其他的都交给pkg-config吧