Open Dynamics Engine for Linux 安装笔记

下载

  • Bitbucket上可以下载到最新的版本(截止目前为0.14版)

  • 或者直接用wget下载

wget "https://bitbucket.org/odedevs/ode/downloads/ode-0.14.tar.gz"

编译

假设安装到/usr下

# 解压
tar xf ode-0.14.tar.gz
cd ode-0.14 # 依赖安装
sudo apt install automake -y # 配置
./bootstrap
./configure --prefix=/usr --enable-double-precision --enable-static=PKGS --with-drawstuff=X11 --with-trimesh=opcode --enable-demos --enable-libccd
# --prefix=/usr 安装到/usr下,不加这一项则默认安装到/usr/local下
# --enable-double-precision 启用双精度浮点数
# --enable-static=PKGS 生成静态链接库
# --with-drawstuff=X11 启用极简图形库,基于X11
# --enable-demos 例子啦╮(╯▽╰)╭
# --enable-libccd 碰撞检测库 make # 编译啦╮(╯_╰)╭

安装

sudo make install   # 安装啦

echo '╮(╯▽╰)╭'

注意,由于drawstuff没有默认安装_(:3」∠)_,因此需要手动安装。

sudo mkdir /usr/include/drawstuff
sudo cp ./include/drawstuff/drawstuff.h ./include/drawstuff/version.h /usr/include/drawstuff
sudo cp ./drawstuff/src/.lib/libdrawstuff.a ./drawstuff/src/.lib/libdrawstuff.la /usr/lib # 更新库缓存
sudo ldconfig

使用库

drawstuff在链接时需要同时链接X11、GL、GLU、m这些库,若使用cmake,可以添加这一句:

target_link_libraries(target ode drawstuff X11 GLU GL m)

另外,drawstuff需要贴图,有自带的,位于<ode-0.14>/drawstuff/textures/下。需要自行复制到工程目录下。

测试代码

来源:HOWTO simple bouncing sphere - ODE Wiki

#include <ode/ode.h>
#include <drawstuff/drawstuff.h>
// dynamics and collision objects
static dWorldID world;
static dSpaceID space;
static dBodyID body;
static dGeomID geom;
static dMass m;
static dJointGroupID contactgroup; // this is called by dSpaceCollide when two objects in space are
// potentially colliding.
static void nearCallback (void *data, dGeomID o1, dGeomID o2)
{
dBodyID b1 = dGeomGetBody(o1);
dBodyID b2 = dGeomGetBody(o2);
dContact contact;
contact.surface.mode = dContactBounce | dContactSoftCFM;
// friction parameter
contact.surface.mu = dInfinity;
// bounce is the amount of "bouncyness".
contact.surface.bounce = 0.9;
// bounce_vel is the minimum incoming velocity to cause a bounce
contact.surface.bounce_vel = 0.1;
// constraint force mixing parameter
contact.surface.soft_cfm = 0.001;
if (int numc = dCollide (o1,o2,1,&contact.geom,sizeof(dContact))) {
dJointID c = dJointCreateContact (world,contactgroup,&contact);
dJointAttach (c,b1,b2);
}
} // start simulation - set viewpoint
static void start()
{
static float xyz[3] = {2.0f,-2.0f,1.7600f};
static float hpr[3] = {140.000f,-17.0000f,0.0000f};
dsSetViewpoint (xyz,hpr);
} // simulation loop
static void simLoop (int pause)
{
const dReal *pos;
const dReal *R;
// find collisions and add contact joints
dSpaceCollide (space,0,&nearCallback);
// step the simulation
dWorldQuickStep (world,0.01);
// remove all contact joints
dJointGroupEmpty (contactgroup);
// redraw sphere at new location
pos = dGeomGetPosition (geom);
R = dGeomGetRotation (geom);
dsDrawSphereD( pos, R, dGeomSphereGetRadius (geom));
} int main (int argc, char **argv)
{
// setup pointers to drawstuff callback functions
dsFunctions fn;
fn.version = DS_VERSION;
fn.start = &start;
fn.step = &simLoop;
fn.stop = 0;
fn.command = 0;
fn.path_to_textures = "../textures"; // 注意贴图路径! dInitODE ();
// create world
world = dWorldCreate ();
space = dHashSpaceCreate (0);
dWorldSetGravity (world,0,0,-9.8);
dWorldSetCFM (world,1e-5);
dCreatePlane (space,0,0,1,0);
contactgroup = dJointGroupCreate (0);
// create object
body = dBodyCreate (world);
geom = dCreateSphere (space,0.5);
dMassSetSphere (&m,1,0.5);
dBodySetMass (body,&m);
dGeomSetBody (geom,body);
// set initial position
dBodySetPosition (body,0,0,5);
// run simulation
dsSimulationLoop (argc,argv,320,240,&fn);
// clean up
dJointGroupDestroy (contactgroup);
dSpaceDestroy (space);
dWorldDestroy (world);
dCloseODE();
return 0;
}

Open Dynamics Engine for Linux 安装笔记

References

[1] ODE Wiki, Manual: Install and Use,http://ode-wiki.org/wiki/index.php?title=Manual:_Install_and_Use, 2013-05-05

[2] ODE Wiki, HOWTO simple bouncing sphere, http://ode-wiki.org/wiki/index.php?title=HOWTO_simple_bouncing_sphere, 2012-01-08

[3] 小胖, 在 Ubuntu 14.04 下安装 Open Dynamics Engine (ODE) 0.14, http://czhou.cc/2016/04/29/install-ode-on-ubuntu/, 2016-04-29

上一篇:C语言 宏定义之可变参数


下一篇:9,EasyNetQ-版本化消息