资源描述:
《ODE教程by wiki》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、HOWTOsimplebouncingsphere如何制作弹跳球Thispageisunderconstruction!1、Introduction介绍Thisarticledescribeshowtomakeaspherethatfallsontoaplaneandbounces.Thisisaboutassimpleasitgets,butitshowsthegeneralstructureofadynamicsimulationusingODE.本文介绍了如何制作一个落向地面并会弹起的球体。这很容易做到,但是它展示了利用ODE做动力学仿真的基本框架。2、Sampl
2、eCode示例代码ThiscodeiswritteninthestyleoftheODEdemos,andusesdrawstufftoshowthesimulation.这段代码使用ODE风格编写的,利用drawstuff函数(用于绘图)显示仿真过程。Firsttheobjectsforthesimulationmustbedeclared.Youmusthaveaworld,aspacetoputeverythingin,abodywithassociatedgeometryandmass,andajointgrouptostorethecontactjointst
3、hatarecreatedduringacollision.首先,必须声明仿真中用到的物体。你必须得有一个world,一个space来装载所有的东西,一个具有几何形状geometry和质量mass的body,还要有一个用于存放碰撞过程中产生的contactjoints的关节组jointgroup。#include#include//dynamicsandcollisionobjectsstaticdWorldIDworld;staticdSpaceIDspace;staticdBodyIDbody;st
4、aticdGeomIDgeom;staticdMassm;staticdJointGroupIDcontactgroup;Whenthecollisionsystemdetectsthattwoobjectsarecolliding,itcallsthisroutinewhichdeterminesthepointsofcontactandcreatestemporaryjoints.Thesurfaceparametersofthejoint(friction,bouncevelocity,CFM,etc)arealsosethere.当碰撞系统检测到两个物体相互碰撞
5、了,它就会调用下面这个程序来确定碰撞点的位置并创建暂时的碰撞关节。碰撞关节的表面参数(摩擦力,反弹速度,CFM等)也在这里设置。//thisiscalledbydSpaceCollidewhentwoobjectsinspaceare//potentiallycolliding.staticvoidnearCallback(void*data,dGeomIDo1,dGeomIDo2){dBodyIDb1=dGeomGetBody(o1);dBodyIDb2=dGeomGetBody(o2);dContactcontact;contact.surface.mode=dCo
6、ntactBounce
7、dContactSoftCFM;//frictionparameter摩擦参数contact.surface.mu=dInfinity;//bounceistheamountof"bouncyness".Bounce表示弹性度contact.surface.bounce=0.9;//bounce_velistheminimumincomingvelocitytocauseabounce.bounce_vel表示引起回弹的最小入射速度。contact.surface.bounce_vel=0.1;//constraintforcemixingpar
8、ameter.约束力混合参数CFMcontact.surface.soft_cfm=0.001;if(intnumc=dCollide(o1,o2,1,&contact.geom,sizeof(dContact))){dJointIDc=dJointCreateContact(world,contactgroup,&contact);dJointAttach(c,b1,b2);}}Thisfunctioniscalledatthestartofthesimulationtosetupthepointofviewofthecamera.下面