Deprecated: Array and string offset access syntax with curly braces is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Subs.php on line 3825
ODE : sphere-plane collision from tutorial not working

### Author Topic: ODE : sphere-plane collision from tutorial not working  (Read 5133 times)

0 Members and 1 Guest are viewing this topic.

#### Petr Schreiber

• Full Member
• Posts: 183
• User-Rate: +14/-4
##### ODE : sphere-plane collision from tutorial not working
« on: August 27, 2008, 06:06:23 PM »
Hi,

I still did not gave up on ODE under PowerBASIC, but I have some problems.
I translated tutorial:
http://opende.sourceforge.net/mediawiki-1.6.10/index.php/HOWTO_simple_bouncing_sphere

... to PB as following:
Code: [Select]
`#COMPILE EXE#DIM ALL%ODE_DOUBLE = 0#INCLUDE "ODE.INC"GLOBAL world AS DWORDGLOBAL space AS DWORDGLOBAL body AS DWORDGLOBAL geom AS DWORDGLOBAL m AS dMassGLOBAL contactgroup AS DWORDGLOBAL CallBackDebug AS STRINGSUB NearCallback CDECL ( BYVAL aData AS DWORD, BYVAL o1 AS DWORD, BYVAL o2 AS DWORD )  CallBackDebug = "Collision Evaluated"  LOCAL b1, b2 AS DWORD  b1 = dGeomGetBody(o1)  b2 = dGeomGetBody(o2)  LOCAL contact AS dContact  contact.surface.mode = %dContactBounce OR %dContactSoftCFM  ' -- friction parameter  contact.surface.mu = 3.40*10^38' -- %dInfinity ?  ' -- bounce is the amount of "bouncyness".  contact.surface.bounce = 0.9 ' 0 - 1  ' -- 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  LOCAL numc AS LONG  numc = dCollide (o1,o2,1,contact.geom,SIZEOF(dContact))  IF numc THEN    CallBackDebug = CallBackDebug + " *** contact evaluated ( but probably no bounce )***"    LOCAL c AS DWORD    c = dJointCreateContact (world,contactgroup, contact)    dJointAttach (c,b1,b2)  ELSE    CallBackDebug = CallBackDebug + " --- NO CONTACT CREATED ---"  END IFEND SUB' --  simulation loopSUB simLoop ()  LOCAL x, y, z AS SINGLE  LOCAL Position AS SINGLE PTR  ' --  find collisions and add contact joints  dSpaceCollide (space, BYVAL 0,CODEPTR(nearCallback))  ' --  step the simulation  dWorldStep (world,0.01)  ' --  remove all contact joints  dJointGroupEmpty (contactgroup)  ' --  redraw sphere at new location  Position = dGeomGetPosition (geom)  ' --  DRAW  IF Position THEN     x = @Position[0]     y = @Position[1]     z = @Position[2]  END IF  GRAPHIC CLEAR %WHITE  GRAPHIC COLOR %BLACK  GRAPHIC PRINT USING\$("#.## #.## #.##", x, y, z)  GRAPHIC PRINT CallBackDebug  GRAPHIC SCALE (-40, 40)-(40, -40)  ' -- Draw the plane  GRAPHIC WIDTH 2  GRAPHIC LINE (-20, 0)-(20, 0), RGB(255,0,0)  ' -- Draw the ball  GRAPHIC COLOR %RED, -2  GRAPHIC ELLIPSE (x-0.5,z-0.5)-(x+0.5, z+0.5)  GRAPHIC SET POS (x, z)  GRAPHIC PRINT "XZ"'  GRAPHIC COLOR %green'  GRAPHIC ELLIPSE (x-0.5,y-0.5)-(x+0.5, y+0.5)  GRAPHIC COLOR %BLUE, -2  GRAPHIC ELLIPSE (y-0.5,z-0.5)-(y+0.5, z+0.5)  GRAPHIC SET POS (y, z)  GRAPHIC PRINT "YZ"  GRAPHIC REDRAWEND SUBFUNCTION PBMAIN () AS LONG  LOCAL hWin AS DWORD  GRAPHIC WINDOW "Sphere plane collision", 300, 300, 640, 640 TO hWin  GRAPHIC ATTACH hWin, 0, REDRAW  ' --  setup pointers to drawstuff callback functions  dInitODE ()  ' --  create world  world = dWorldCreate ()  space = dHashSpaceCreate (0)  dWorldSetGravity (world, 0, 0, -0.2)  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,30)  ' --  run simulation  LOCAL i AS LONG  FOR i = 1 TO 4000    simLoop()  NEXT  ' -- ' -- dsSimulationLoop (argc,argv,352,288,&fn)  ' --  clean up  dJointGroupDestroy (contactgroup)  dSpaceDestroy (space)  dWorldDestroy (world)  dCloseODE()  GRAPHIC WINDOW ENDEND FUNCTION`
You will notice the sphere falls, when it reaches plane ( which should bounce it ) it just slows down and happily continues with some change in direction
Does anybody has any idea ... why ?

I use latest DLL from here, compiled it in CodeBlocks> click

Petr
« Last Edit: August 27, 2008, 09:57:54 PM by Petr Schreiber »
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com

#### José Roca

• Hero Member
• Posts: 2487
• User-Rate: +204/-0
##### Re: ODE : sphere-plane collision from tutorial not working
« Reply #1 on: August 27, 2008, 07:44:22 PM »

I have no idea, sorry. One thing that I have noticed, although doesn't solve the problem, is that SUB NearCallback should be SUB NearCallback CDECL, because ODE uses the C parameter passing convention.
« Last Edit: August 27, 2008, 09:58:32 PM by José Roca »

#### Petr Schreiber

• Full Member
• Posts: 183
• User-Rate: +14/-4
##### Re: ODE : sphere-plane collision from tutorial not working
« Reply #2 on: August 27, 2008, 09:57:30 PM »
Hi José,

thanks, I corrected the sample now.
I used CDECL in demos before, but seems to not make any difference in this case.

I wanted to do some introduction to ODE for others, but without this fixed it would not make much sense.
I am sure I am missing something basic.

Petr
AMD Sempron 3400+ | 1GB RAM @ 533MHz | GeForce 6200 / GeForce 9500GT | 32bit Windows XP SP3

psch.thinbasic.com