Righty .. heres my little key controlled sphere thingy that I thought might be of use to someone :)
Use the arrow keys to move, space to 'jump'. This could easily be applied to a trimesh perhaps for some kind of physics-powered 3d platform game or similar .. ?? Any offers to do 3d platform game modelling to ... ;)
Ta daaaa!
There does seem to be a problem with the autodisable, although it may be something I'm doing wrong. For seemingly no reason, ODE seems to disable to body sometimes, so I commented out the autodisable detect in the updategeoms and set autodisable to 0 in the 'world' settings.
Use the arrow keys to move, space to 'jump'. This could easily be applied to a trimesh perhaps for some kind of physics-powered 3d platform game or similar .. ?? Any offers to do 3d platform game modelling to ... ;)
; JV-ODE - Key Controlled Sphere Demo ; Code by Jim Williams (VIP3R) ; Arrow key control by Jeff (PsychicParrot) AppTitle "JV-ODE - Key Controlled Sphere Demo" Include "ode.bb" Graphics3D 800,600,0,2 Type ODEGeom Field body Field geom Field mesh Field pivot ; To find direction vectors Field head ; Just a stupid head to show which direction it's going in! Field inair ; To tell if player is on the ground or not!! End Type ; ### Setup ODE Global World=dWorldCreate() Global Space=dHashSpaceCreate(0) Global ContactGroup=dJointGroupCreate(0) dWorldSetAutoDisableFlag(World,0) dWorldSetGravity(World,0,-1,0) dContactSetMode(dContactBounce) dContactSetBounce(0.2) dContactSetMu(48) ; ### Create light Global Light=CreateLight() RotateEntity Light,45,-90,0 LightColor Light,255,255,255 AmbientLight 130,130,130 ; ### Create camera Global Camera=CreateCamera() CameraClsColor Camera,0,0,0 CameraRange Camera,1,1000 PositionEntity Camera,0,20,-50 RotateEntity Camera,30,0,0 ; ### Control vars Global potato#=0 ; y rotation of thingy (rotater,rotato,potato!!) Global fwd_key Global back_key Global left_key Global right_key Global jump_key ; ### Create plane dCreatePlane(Space,0,1,0,0) Plane=CreatePlane() EntityAlpha Plane,0.8 PlaneTexture=CreateTexture(128,128,9) ClsColor 0,200,80 Cls Color 255,255,255 Rect 0,0,64,64,1 Rect 64,64,64,64,1 CopyRect 0,0,128,128,0,0,BackBuffer(),TextureBuffer(PlaneTexture) ScaleTexture PlaneTexture,20,20 EntityTexture Plane,PlaneTexture,0,0 EntityPickMode plane,2 Mirror=CreateMirror() AddObject() ; Add our thingy to the world While Not KeyHit(1) PTime=MilliSecs() ; Update controls c.ODEGeom=First ODEGeom Getkeys(c) movethingy(c) lookforground(c) PointEntity (camera,c\mesh) UpdateGeoms() dSpaceCollide(Space,World,ContactGroup) dWorldQuickStep(World,0.1) dJointGroupEmpty(ContactGroup) PhysicsTime#=MilliSecs()-PTime UpdateWorld RenderWorld Text 0,0,"JV-ODE Version "+dGetVersion() Text 0,15,"Physics Time:"+PhysicsTime Text 0,25,"Player in the air:"+c\inair Flip Wend dJointGroupDestroy(ContactGroup) dSpaceDestroy(Space) dWorldDestroy(World) dCloseODE() End Function getkeys(c.ODEGeom) fwd_key=False back_key=False left_key=False right_key=False jump_key=False If c\inair=False Then ; Only let player control 'thrust' when on the ground If KeyDown(200) Then fwd_key=True If KeyDown(208) Then back_key=True EndIf If KeyDown(205) Then left_key=True If KeyDown(203) Then right_key=True If KeyDown(57) Then jump_key=True ;EndIf End Function Function lookforground(c.ODEGeom) If LinePick(EntityX(c\mesh,True),EntityY(c\mesh,True)+1,EntityZ(c\mesh,True),0,-4,0)<>0 Then ; Check for anything 'under' player c\inair=False Else c\inair=True EndIf End Function Function movethingy(c.ODEGeom) If fwd_key=True Then TFormVector 0,0,.8,c\pivot,0 dBodyAddForce(c\body,TFormedX#(),TFormedY#() ,TFormedZ#() ) EndIf If back_key=True Then TFormVector 0,0,-.8,c\pivot,0 dBodyAddForce(c\body,TFormedX#(),TFormedY#() ,TFormedZ#() ) EndIf If left_key=True Then potato=potato-2 End If If right_key=True Then potato=potato+2 End If If jump_key=True And c\inair=False Then dBodyAddForce(c\body,0,16 ,0) End If End function Function AddObject() xp=Rand(-8,8) zp=Rand(-8,8) ode.ODEGeom=New ODEGeom ode\body=dBodyCreate(World) dBodySetRotation(ode\body,0,0,0) dBodySetPosition(ode\body,xp,30,zp) dBodySetAutoDisableFlag(ode\body,1) ode\geom=dCreateSphere(Space,3) dGeomSetBody(ode\geom,ode\body) ode\mesh=CreateSphere() ScaleMesh ode\mesh,3,3,3 EntityColor ode\mesh,Rand(255),Rand(255),Rand(255) EntityAlpha ode\mesh,1 EntityShininess ode\mesh,0.7 ode\head=CreateCube() ScaleMesh ode\head,1.5,1.5,1.5 ode\pivot=CreatePivot() ; Create pivot to get direction vectors End Function Function UpdateGeoms() For ode.ODEGeom=Each ODEGeom ;If dBodyIsEnabled(ode\body) RotateEntity ode\mesh,dGeomGetPitch#(ode\geom),dGeomGetYaw#(ode\geom),dGeomGetRoll#(ode\geom) PositionEntity ode\mesh,dGeomGetPositionX#(ode\geom),dGeomGetPositionY#(ode\geom),dGeomGetPositionZ#(ode\geom) PositionEntity ode\pivot,dGeomGetPositionX#(ode\geom),dGeomGetPositionY#(ode\geom),dGeomGetPositionZ#(ode\geom) PositionEntity ode\head,dGeomGetPositionX#(ode\geom),dGeomGetPositionY#(ode\geom)+4.5,dGeomGetPositionZ#(ode\geom) RotateEntity ode\pivot,0,potato#,0 RotateEntity ode\head,0,potato#,0 ;End If Next End Function
Ta daaaa!
There does seem to be a problem with the autodisable, although it may be something I'm doing wrong. For seemingly no reason, ODE seems to disable to body sometimes, so I commented out the autodisable detect in the updategeoms and set autodisable to 0 in the 'world' settings.