# PureBasic Forum

 It is currently Wed Jun 19, 2013 9:05 pm

 All times are UTC + 1 hour

 Page 1 of 1 [ 12 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Ping-Pong Game (Physics)Posted: Sat Feb 06, 2010 4:17 pm
 User

Joined: Wed Jul 01, 2009 12:59 pm
Posts: 73
I shall create 3D Ping-Pong Game with PureBasic... I created necessary me models (.mesh'es):

It: Map ("table" and walls), Ball and Players.
As now create realistic Ping-Pong physics? This possible? Thanks...

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Sat Feb 06, 2010 4:41 pm

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 1720
Not sure, do you mean gravity?

This should be simple, you only have to consider about deltay - each second you have to add 9.81 (m/s) if you would do the game in vacuum. I believe you also want to calculate the air resistance, which is a fixed value for your ball, let's say R=100.
Now if you have a deltay=-20 (20 pixels upwards), the actual air resistance = 4 (deltaY*deltaY/R), so the vertical speed deltay would change to -6.19 (-20 +4 +9.81). In the next second, deltay is around 4 ( -6.19 +0.38 +9.81), then 13.65 (4 -0.16 + 9.81) and so on. Because of R, the vertical speed can't get higher than a specific value (in our example deltay will never be higher than around 31.32)

Michael

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Sat Feb 06, 2010 8:22 pm

Joined: Tue Nov 13, 2007 12:42 pm
Posts: 1307
Location: Manchester, UK
I think he is meaning the angle of reflection and speed when it hits a surface, including the corners and sides (note that the sides are tapered) and if the bat is moving at the same time.

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Sun Feb 07, 2010 9:02 am

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 1720
Foz wrote:
I think he is meaning the angle of reflection and speed when it hits a surface, including the corners and sides (note that the sides are tapered) and if the bat is moving at the same time.

Could be, but this shouldn't be a big problem, (predefined tables) with sin and cos would allow to "mirror" the angles easily when the ball is hitting a wall...

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Sun Feb 07, 2010 3:39 pm
 User

Joined: Wed Jul 01, 2009 12:59 pm
Posts: 73
What about hitboxes of models? Need to create? I do not know what use commands for crate collisions, ricochets, etc. Can be there is example?

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Mon Feb 08, 2010 11:17 pm

Joined: Tue Jan 02, 2007 8:16 pm
Posts: 4328
Location: Cypress TX
Quote:
Could be, but this shouldn't be a big problem, (predefined tables) with sin and cos would allow to "mirror" the angles easily when the ball is hitting a wall...

Back in my Blitz3D days and before physics engines I used to do this with a little factor I called leverage which was simply a randon decision to add or subtract a small amount from the sine or cosine and that put a new spin on the ball as it were...

That said... sometimes it did not do so well like a steep angle in had an even steeper reflection... I modofied that by checking muse move direction so I would know wheather to add or subtract.

You might also try to integrate one of the engines like BOX. Chipmunk...

_________________
Binarily speaking... it takes 10 to Tango!!!

http://www.bluemesapc.com/

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Tue Feb 09, 2010 9:55 am

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1334
Location: Pas-de-Calais, France
You just have to compare the bounding box of each element in a loop, the "pong" directly linked to the mouse, the ball moving freely each time by a small vector. The direction of the vector is reversed based on the collisions. Easiest collision test does not involve "penetration", if the vector is not too big (its size gives the speed). If the vector is bigger than the size of objects, you should do some harder work

_________________
The Shooting Crew ~> http://www.shootingcrew.com/
Bobble Puzzle, Purebreaker 3 ~> http://djes.free.fr

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Tue Feb 23, 2010 5:39 am
 User

Joined: Fri Jan 08, 2010 2:30 am
Posts: 12
Location: Texas
Please refine the question you are asking. Is the question about programming? Is the question about the math of the physics? If you question is about the math of the physics, then the following may help. The problem should be handled in terms of x component of velocity, y component of velocity and z component of velocity (i.e. compute how much the ball moves for x, y and z separately. (you can solve the problem in X and Z only if you prefer) The gravity acceleration effects Z motion only and is 9.8 m/sec every second as previous commentator stated. The friction of air is a bit tricky. You can't compute that in components, so you need to take the square root of the squares of the velocities Vx, Vy and Vz to compute overall velocity. Then compute the friction force, which will be directly opposite the velocity. The friction force is generally: Force= k * v^2 (where k is perhaps .02, or perhaps .002. (use trial and error to find a suitable friction coefficient. The engineering approach is a bit different, to Wiki may not help you much). This force is then broken into x, y and z components. Then divide each component by the mass of the ball (use metric units please.) to get the rate of change of velocity for each component. The signs (neg vs pos) for the friction and gravity components are pretty easy to mess up in which case the ball will speed up, instead of slowing down.

Define the initial conditions. i.e. assign values to the following:
x initial, y initial, z initial, Vx initial, Vy initial, Vz initial,
Put the computer in a loop here
Compute overall speed = Sqrt(Vx^2+Vy^2+Vz^2)
Compute frictional force overall based on relation force = k * Voverall^2 (k is something like .002, or .00035 Don't recall right now)
Convert frictional force into deceleration. i.e. In General Deceleration = Force/Mass (use metric units)
break deceleration into x, y and z components using sin and cos.
Gravity downward acceleration is always 9.8 m/sec every second in downward direction. This is algebrically added to the Z component of frictional force
; now position, velocity and accelerations are known, for x, y and z directions.
xnew=xold+DeltaTime*VelocityOldx
ynew=yold+DeltaTime*VelocityOldy
znew = ditto
Vx new = Vx old + DeltaTime*Accelerationx
Vy new = Vy old + DeltaTime*Accelerationy
Yz new = ditto
; remark- we have computed the new position, and corresponding velocity compoents
Display your graphic representation here. etc.
Increment your time counter if you are tracking real time. i.e. time = time + TimeIncrement
; get ready for the next increment of the loop
Xold=Xnew
Yold=Ynew
Zold=Znew
Vxold=Vxnew
Vyold=Vynew
Vzold=Vznew
; dont worry about accelerations as these will be computed from equations discussed above,
At this point, check for wall impact- do the bounce thing if needed etc. Angle of impact and angle of departure are equal. This is achieved by setting Vx, Vy and Vz after bounce the same as incomming velocity components but with sign changes. This is true for elastic collisions.
Now loop to the top to do the next increment of time.

That was a bit lengthy. I hope it was helpful. the above method is an engineering solution to this problem, as a clean formula solution of the path of the ball is not possible where air friction is involved.

Regards

StP

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Tue May 11, 2010 4:44 am
 Enthusiast

Joined: Fri Jan 29, 2010 1:05 pm
Posts: 221
Location: Brazil
you'd better get a Physics engine, like Newton wrapper

http://itmbin.nm.ru/newton/newton.zip (the lib)

the includes converted from blitz3d to purebasic:
(name this "nwphx.pbi")
Code:
Global phxdll = OpenLibrary (#PB_Any, "nwphx.dll")
If phxdll = 0
MessageRequester ("Fatal error!", "Failed to open nwphx.dll!", #PB_MessageRequester_Ok)
End
EndIf

Prototype.l phWorldCreatePROC( plane, license_key\$ )
Global phWorldCreate.phWorldCreatePROC
phWorldCreate = GetFunction(phxdll, "_phWorldCreate@8")

Prototype.l phWorldSetGravityPROC( gx.f, gy.f, gz.f )
Global phWorldSetGravity.phWorldSetGravityPROC
phWorldSetGravity = GetFunction(phxdll, "_phWorldSetGravity@12")

Prototype.l phWorldStepPROC( timestep.f )
Global phWorldStep.phWorldStepPROC
phWorldStep = GetFunction(phxdll, "_phWorldStep@4")

Prototype.l phWorldSetSizePROC( x1.f, y1.f, z1.f, x2.f, y2.f, z2.f )
Global phWorldSetSize.phWorldSetSizePROC
phWorldSetSize = GetFunction(phxdll, "_phWorldSetSize@24")

Prototype.l phWorldSetSolverModelPROC( model )
Global phWorldSetSolverModel.phWorldSetSolverModelPROC
phWorldSetSolverModel = GetFunction(phxdll, "_phWorldSetSolverModel@4")

Prototype.l phWorldSetFrictionModelPROC( model )
Global phWorldSetFrictionModel.phWorldSetFrictionModelPROC
phWorldSetFrictionModel = GetFunction(phxdll, "_phWorldSetFrictionModel@4")

Prototype.l phWorldMagnetizePROC( x.f, y.f, z.f, r.f, a0.f, a1.f, a2.f, max.f )
Global phWorldMagnetize.phWorldMagnetizePROC
phWorldMagnetize = GetFunction(phxdll, "_phWorldMagnetize@32")

Prototype.l phWorldDestroyPROC( )
Global phWorldDestroy.phWorldDestroyPROC
phWorldDestroy = GetFunction(phxdll, "_phWorldDestroy@0")

Prototype phMatCreatePROC( )
Global phMatCreate.phMatCreatePROC
phMatCreate = GetFunction(phxdll, "_phMatCreate@0")

Prototype.l phMatSetCollidablePROC( mat1, mat2, IsColl )
Global phMatSetCollidable.phMatSetCollidablePROC
phMatSetCollidable = GetFunction(phxdll, "_phMatSetCollidable@12")

Prototype.l phMatSetFrictionPROC( mat1, mat2, stFric.f, dynFric.f )
Global phMatSetFriction.phMatSetFrictionPROC
phMatSetFriction = GetFunction(phxdll, "_phMatSetFriction@16")

Prototype.l phMatSetElasticityPROC( mat1, mat2, elast.f)
Global phMatSetElasticity.phMatSetElasticityPROC
phMatSetElasticity = GetFunction(phxdll, "_phMatSetElasticity@12")

Prototype.l phMatSetSoftnessPROC( mat1, mat2, soft.f )
Global phMatSetSoftness.phMatSetSoftnessPROC
phMatSetSoftness = GetFunction(phxdll, "_phMatSetSoftness@12")

Prototype.l phMatSetDefCollidablePROC( IsColl )
Global phMatSetDefCollidable.phMatSetDefCollidablePROC
phMatSetDefCollidable = GetFunction(phxdll, "_phMatSetDefCollidable@4")

Prototype.l phMatSetDefFrictionPROC( stFric.f, dynFric.f )
Global phMatSetDefFriction.phMatSetDefFrictionPROC
phMatSetDefFriction = GetFunction(phxdll, "_phMatSetDefFriction@8")

Prototype.l phMatSetDefElasticityPROC( elast.f )
Global phMatSetDefElasticity.phMatSetDefElasticityPROC
phMatSetDefElasticity = GetFunction(phxdll, "_phMatSetDefElasticity@4")

Prototype.l phMatSetDefSoftnessPROC( soft.f )
Global phMatSetDefSoftness.phMatSetDefSoftnessPROC
phMatSetDefSoftness = GetFunction(phxdll, "_phMatSetDefSoftness@4")

Prototype phBodyCreateNullPROC( mass.f )
Global phBodyCreateNull.phBodyCreateNullPROC
phBodyCreateNull = GetFunction(phxdll, "_phBodyCreateNull@4")

Prototype phBodyCreateBoxPROC( dx.f, dy.f, dz.f, mass.f )
Global phBodyCreateBox.phBodyCreateBoxPROC
phBodyCreateBox = GetFunction(phxdll, "_phBodyCreateBox@16")

Prototype phBodyCreateSpherePROC( rx.f, ry.f, rz.f, mass.f )
Global phBodyCreateSphere.phBodyCreateSpherePROC
phBodyCreateSphere = GetFunction(phxdll, "_phBodyCreateSphere@16")

Prototype phBodyCreateCylPROC( r.f, h.f, mass.f )
Global phBodyCreateCyl.phBodyCreateCylPROC
phBodyCreateCyl = GetFunction(phxdll, "_phBodyCreateCyl@12")

Prototype phBodyCreateConePROC( r.f, h.f, mass.f )
Global phBodyCreateCone.phBodyCreateConePROC
phBodyCreateCone = GetFunction(phxdll, "_phBodyCreateCone@12")

Prototype phBodyCreateCapsulePROC( r.f, h.f, mass.f )
Global phBodyCreateCapsule.phBodyCreateCapsulePROC
phBodyCreateCapsule = GetFunction(phxdll, "_phBodyCreateCapsule@12")

Prototype phBodyCreateHullPROC( *Vertices, VertexCount, mass.f )
Global phBodyCreateHull.phBodyCreateHullPROC
phBodyCreateHull = GetFunction(phxdll, "_phBodyCreateHull@12")

Prototype phBodyCreateMeshPROC( *Vertices, VertexCount, mass.f)
Global phBodyCreateMesh.phBodyCreateMeshPROC
phBodyCreateMesh = GetFunction(phxdll, "_phBodyCreateMesh@12")

Prototype.l phBodyCompoundBeginPROC( )
Global phBodyCompoundBegin.phBodyCompoundBeginPROC
phBodyCompoundBegin = GetFunction(phxdll, "_phBodyCompoundBegin@0")

Prototype.l phBodyCompoundAddHullPROC( *Vertices, VertexCount)

Prototype.l phBodyCompoundAddBodyPROC( body )

Prototype phBodyCompoundEndPROC( mass.f )
Global phBodyCompoundEnd.phBodyCompoundEndPROC
phBodyCompoundEnd = GetFunction(phxdll, "_phBodyCompoundEnd@4")

Prototype.l phBodyCompoundExBeginPROC( )
Global phBodyCompoundExBegin.phBodyCompoundExBeginPROC
phBodyCompoundExBegin = GetFunction(phxdll, "_phBodyCompoundExBegin@0")

Prototype.l phBodyCompoundExAddHullPROC( *Vertices, VertexCount, mass.f )

Prototype.l phBodyCompoundExAddHullDensPROC( *Vertices, VertexCount, density.f )

Prototype.l phBodyCompoundExAddBodyPROC( body )

Prototype phBodyCompoundExEndPROC( )
Global phBodyCompoundExEnd.phBodyCompoundExEndPROC
phBodyCompoundExEnd = GetFunction(phxdll, "_phBodyCompoundExEnd@0")

Prototype.l phBodyDestroyPROC( body )
Global phBodyDestroy.phBodyDestroyPROC
phBodyDestroy = GetFunction(phxdll, "_phBodyDestroy@4")

Prototype.l phBodySetMatPROC( body, mat )
Global phBodySetMat.phBodySetMatPROC
phBodySetMat = GetFunction(phxdll, "_phBodySetMat@8")

Prototype phBodyGetMatPROC( body )
Global phBodyGetMat.phBodyGetMatPROC
phBodyGetMat = GetFunction(phxdll, "_phBodyGetMat@4")

Prototype.f phBodyGetXPROC( body )
Global phBodyGetX.phBodyGetXPROC
phBodyGetX = GetFunction(phxdll, "_phBodyGetX@4")

Prototype.f phBodyGetYPROC( body )
Global phBodyGetY.phBodyGetYPROC
phBodyGetY = GetFunction(phxdll, "_phBodyGetY@4")

Prototype.f phBodyGetZPROC( body )
Global phBodyGetZ.phBodyGetZPROC
phBodyGetZ = GetFunction(phxdll, "_phBodyGetZ@4")

Prototype.l phBodySetPosPROC( body, x.f, y.f, z.f )
Global phBodySetPos.phBodySetPosPROC
phBodySetPos = GetFunction(phxdll, "_phBodySetPos@16")

Prototype.f phBodyGetPitchPROC( body )
Global phBodyGetPitch.phBodyGetPitchPROC
phBodyGetPitch = GetFunction(phxdll, "_phBodyGetPitch@4")

Prototype.f phBodyGetYawPROC( body )
Global phBodyGetYaw.phBodyGetYawPROC
phBodyGetYaw = GetFunction(phxdll, "_phBodyGetYaw@4")

Prototype.f phBodyGetRollPROC( body )
Global phBodyGetRoll.phBodyGetRollPROC
phBodyGetRoll = GetFunction(phxdll, "_phBodyGetRoll@4")

Prototype phBodySetRotPROC( body, pitch.f, yaw.f, roll.f )
Global phBodySetRot.phBodySetRotPROC
phBodySetRot = GetFunction(phxdll, "_phBodySetRot@16")

Prototype.f phBodyGetVelXPROC( body )
Global phBodyGetVelX.phBodyGetVelXPROC
phBodyGetVelX = GetFunction(phxdll, "_phBodyGetVelX@4")

Prototype.f phBodyGetVelYPROC( body )
Global phBodyGetVelY.phBodyGetVelYPROC
phBodyGetVelY = GetFunction(phxdll, "_phBodyGetVelY@4")

Prototype.f phBodyGetVelZPROC( body )
Global phBodyGetVelZ.phBodyGetVelZPROC
phBodyGetVelZ = GetFunction(phxdll, "_phBodyGetVelZ@4")

Prototype.l phBodySetVelPROC( body, vx.f, vy.f, vz.f )
Global phBodySetVel.phBodySetVelPROC
phBodySetVel = GetFunction(phxdll, "_phBodySetVel@16")

Prototype.f phBodyGetVelXAtPosPROC( body, x.f, y.f, z.f )
Global phBodyGetVelXAtPos.phBodyGetVelXAtPosPROC
phBodyGetVelXAtPos = GetFunction(phxdll, "_phBodyGetVelXAtPos@16")

Prototype.f phBodyGetVelYAtPosPROC( body, x.f, y.f, z.f )
Global phBodyGetVelYAtPos.phBodyGetVelYAtPosPROC
phBodyGetVelYAtPos = GetFunction(phxdll, "_phBodyGetVelYAtPos@16")

Prototype.f phBodyGetVelZAtPosPROC( body, x.f, y.f, z.f )
Global phBodyGetVelZAtPos.phBodyGetVelZAtPosPROC
phBodyGetVelZAtPos = GetFunction(phxdll, "_phBodyGetVelZAtPos@16")

Prototype.f phBodyGetOmegaXPROC( body )
Global phBodyGetOmegaX.phBodyGetOmegaXPROC
phBodyGetOmegaX = GetFunction(phxdll, "_phBodyGetOmegaX@4")

Prototype.f phBodyGetOmegaYPROC( body )
Global phBodyGetOmegaY.phBodyGetOmegaYPROC
phBodyGetOmegaY = GetFunction(phxdll, "_phBodyGetOmegaY@4")

Prototype.f phBodyGetOmegaZPROC( body )
Global phBodyGetOmegaZ.phBodyGetOmegaZPROC
phBodyGetOmegaZ = GetFunction(phxdll, "_phBodyGetOmegaZ@4")

Prototype.l phBodySetOmegaPROC( body, ox.f, oy.f, oz.f )
Global phBodySetOmega.phBodySetOmegaPROC
phBodySetOmega = GetFunction(phxdll, "_phBodySetOmega@16")

Prototype.l phBodyAddForcePROC( body, fx.f, fy.f, fz.f )

Prototype.l phBodyAddRelForcePROC( body, fx.f, fy.f, fz.f )

Prototype.l phBodyAddForceAtPosPROC( body, fx.f, fy.f, fz.f, x.f, y.f, z.f )

Prototype.l phBodyAddRelForceAtRelPosPROC( body, fx.f, fy.f, fz.f, x.f, y.f, z.f )

Prototype.l phBodyAddImpulsePROC( body, x.f, y.f, z.f, vx.f, vy.f, vz.f )

Prototype.l phBodySetGravityModePROC( body, mode )
Global phBodySetGravityMode.phBodySetGravityModePROC
phBodySetGravityMode = GetFunction(phxdll, "_phBodySetGravityMode@8")

Prototype phBodyGetGravityModePROC( body )
Global phBodyGetGravityMode.phBodyGetGravityModePROC
phBodyGetGravityMode = GetFunction(phxdll, "_phBodyGetGravityMode@4")

Prototype.l phBodySetWaterPROC( body, x.f, y.f, z.f, nx.f, ny.f, nz.f, density.f, lin_damping.f, ang_damping.f )
Global phBodySetWater.phBodySetWaterPROC
phBodySetWater = GetFunction(phxdll, "_phBodySetWater@40")

Prototype.l phBodyDisableWaterPROC( body )
Global phBodyDisableWater.phBodyDisableWaterPROC
phBodyDisableWater = GetFunction(phxdll, "_phBodyDisableWater@4")

Prototype.l phBodyAddTorquePROC( body, tx.f, ty.f, tz.f )

Prototype.l phBodyAddRelTorquePROC( body, tx.f, ty.f, tz.f )

Prototype.l phBodySetDampingPROC( body, linear.f, angular.f)
Global phBodySetDamping.phBodySetDampingPROC
phBodySetDamping = GetFunction(phxdll, "_phBodySetDamping@12")

Prototype.l phBodySetContinuousCollisionModePROC( body, mode )
Global phBodySetContinuousCollisionMode.phBodySetContinuousCollisionModePROC
phBodySetContinuousCollisionMode = GetFunction(phxdll, "_phBodySetContinuousCollisionMode@8")

Prototype phBodyGetContinuousCollisionModePROC( body )
Global phBodyGetContinuousCollisionMode.phBodyGetContinuousCollisionModePROC
phBodyGetContinuousCollisionMode = GetFunction(phxdll, "_phBodyGetContinuousCollisionMode@4")

Prototype.l phBodySetSleepPROC( body, state )
Global phBodySetSleep.phBodySetSleepPROC
phBodySetSleep = GetFunction(phxdll, "_phBodySetSleep@8")

Prototype phBodyGetSleepPROC( body )
Global phBodyGetSleep.phBodyGetSleepPROC
phBodyGetSleep = GetFunction(phxdll, "_phBodyGetSleep@4")

Prototype.l phBodySetAutoSleepPROC( body, state )
Global phBodySetAutoSleep.phBodySetAutoSleepPROC
phBodySetAutoSleep = GetFunction(phxdll, "_phBodySetAutoSleep@8")

Prototype.l phBodySetAutoSleepTresholdPROC( body, vel.f, omega.f, frames)
Global phBodySetAutoSleepTreshold.phBodySetAutoSleepTresholdPROC
phBodySetAutoSleepTreshold = GetFunction(phxdll, "_phWorldCreate@8")

Prototype.l phBodySetDataPROC( body, bdata )
Global phBodySetData.phBodySetDataPROC
phBodySetData = GetFunction(phxdll, "_phBodySetData@8")

Prototype phBodyGetDataPROC( body )
Global phBodyGetData.phBodyGetDataPROC
phBodyGetData = GetFunction(phxdll, "_phBodyGetData@4")

Prototype.l phBodySetEntityPROC( body, ent )
Global phBodySetEntity.phBodySetEntityPROC
phBodySetEntity = GetFunction(phxdll, "_phBodySetEntity@8")

Prototype phBodyGetEntityPROC( body )
Global phBodyGetEntity.phBodyGetEntityPROC
phBodyGetEntity = GetFunction(phxdll, "_phBodyGetEntity@4")

Prototype phBodyGetCollNumPROC( body )
Global phBodyGetCollNum.phBodyGetCollNumPROC
phBodyGetCollNum = GetFunction(phxdll, "_phBodyGetCollNum@4")

Prototype.f phBodyGetCollXPROC( body, coll)
Global phBodyGetCollX.phBodyGetCollXPROC
phBodyGetCollX = GetFunction(phxdll, "_phBodyGetCollX@8")

Prototype.f phBodyGetCollYPROC( body, coll )
Global phBodyGetCollY.phBodyGetCollYPROC
phBodyGetCollY = GetFunction(phxdll, "_phBodyGetCollY@8")

Prototype.f phBodyGetCollZPROC( body, coll )
Global phBodyGetCollZ.phBodyGetCollZPROC
phBodyGetCollZ = GetFunction(phxdll, "_phBodyGetCollZ@8")

Prototype.f phBodyGetCollNXPROC( body, coll )
Global phBodyGetCollNX.phBodyGetCollNXPROC
phBodyGetCollNX = GetFunction(phxdll, "_phBodyGetCollNX@8")

Prototype.f phBodyGetCollNYPROC( body, coll )
Global phBodyGetCollNY.phBodyGetCollNYPROC
phBodyGetCollNY = GetFunction(phxdll, "_phBodyGetCollNY@8")

Prototype.f phBodyGetCollNZPROC( body, coll )
Global phBodyGetCollNZ.phBodyGetCollNZPROC
phBodyGetCollNZ = GetFunction(phxdll, "_phBodyGetCollNZ@8")

Prototype.f phBodyGetCollFXPROC( body, coll )
Global phBodyGetCollFX.phBodyGetCollFXPROC
phBodyGetCollFX = GetFunction(phxdll, "_phBodyGetCollFX@8")

Prototype.f phBodyGetCollFYPROC( body, coll )
Global phBodyGetCollFY.phBodyGetCollFYPROC
phBodyGetCollFY = GetFunction(phxdll, "_phBodyGetCollFY@8")

Prototype.f phBodyGetCollFZPROC( body, coll )
Global phBodyGetCollFZ.phBodyGetCollFZPROC
phBodyGetCollFZ = GetFunction(phxdll, "_phBodyGetCollFZ@8")

Prototype.f phBodyGetCollNVelPROC( body, coll )
Global phBodyGetCollNVel.phBodyGetCollNVelPROC
phBodyGetCollNVel = GetFunction(phxdll, "_phBodyGetCollNVel@8")

Prototype.f phBodyGetCollTVelPROC( body, coll )
Global phBodyGetCollTVel.phBodyGetCollTVelPROC
phBodyGetCollTVel = GetFunction(phxdll, "_phBodyGetCollTVel@8")

Prototype.f phBodyGetCollBVelPROC( body, coll )
Global phBodyGetCollBVel.phBodyGetCollBVelPROC
phBodyGetCollBVel = GetFunction(phxdll, "_phBodyGetCollBVel@8")

Prototype phBodyGetCollBodyPROC( body, coll )
Global phBodyGetCollBody.phBodyGetCollBodyPROC
phBodyGetCollBody = GetFunction(phxdll, "_phBodyGetCollBody@8")

Prototype phBodyIsCollidedWithPROC( body1, body2 )
Global phBodyIsCollidedWith.phBodyIsCollidedWithPROC
phBodyIsCollidedWith = GetFunction(phxdll, "_phBodyIsCollidedWith@8")

Prototype.l phBodySetMassPROC( body, mass.f )
Global phBodySetMass.phBodySetMassPROC
phBodySetMass = GetFunction(phxdll, "_phBodySetMass@8")

Prototype.l phBodySetMassMatrixPROC( body, mass.f, Ixx.f, Iyy.f, Izz.f )
Global phBodySetMassMatrix.phBodySetMassMatrixPROC
phBodySetMassMatrix = GetFunction(phxdll, "_phBodySetMassMatrix@20")

Prototype.f phBodyGetMassPROC( body )
Global phBodyGetMass.phBodyGetMassPROC
phBodyGetMass = GetFunction(phxdll, "_phBodyGetMass@4")

Prototype.f phBodyGetMassIxxPROC( body )
Global phBodyGetMassIxx.phBodyGetMassIxxPROC
phBodyGetMassIxx = GetFunction(phxdll, "_phBodyGetMassIxx@4")

Prototype.f phBodyGetMassIyyPROC( body )
Global phBodyGetMassIyy.phBodyGetMassIyyPROC
phBodyGetMassIyy = GetFunction(phxdll, "_phBodyGetMassIyy@4")

Prototype.f phBodyGetMassIzzPROC( body )
Global phBodyGetMassIzz.phBodyGetMassIzzPROC
phBodyGetMassIzz = GetFunction(phxdll, "_phBodyGetMassIzz@4")

Prototype.l phBodySetMassCentrePROC( body, x.f, y.f, z.f )
Global phBodySetMassCentre.phBodySetMassCentrePROC
phBodySetMassCentre = GetFunction(phxdll, "_phBodySetMassCentre@16")

Prototype.f phBodyGetMassCentreXPROC( body )
Global phBodyGetMassCentreX.phBodyGetMassCentreXPROC
phBodyGetMassCentreX = GetFunction(phxdll, "_phBodyGetMassCentreX@4")

Prototype.f phBodyGetMassCentreYPROC( body )
Global phBodyGetMassCentreY.phBodyGetMassCentreYPROC
phBodyGetMassCentreY = GetFunction(phxdll, "_phBodyGetMassCentreY@4")

Prototype.f phBodyGetMassCentreZPROC( body )
Global phBodyGetMassCentreZ.phBodyGetMassCentreZPROC
phBodyGetMassCentreZ = GetFunction(phxdll, "_phBodyGetMassCentreZ@4")

Prototype.f phBodyGetVolumePROC( body )
Global phBodyGetVolume.phBodyGetVolumePROC
phBodyGetVolume = GetFunction(phxdll, "_phBodyGetVolume@4")

Prototype.l phBodySetRayCastingPROC( body, raycast )
Global phBodySetRayCasting.phBodySetRayCastingPROC
phBodySetRayCasting = GetFunction(phxdll, "_phBodySetRayCasting@8")

Prototype phBodyGetRayCastingPROC( body )
Global phBodyGetRayCasting.phBodyGetRayCastingPROC
phBodyGetRayCasting = GetFunction(phxdll, "_phBodyGetRayCasting@4")

Prototype.l phLevelBuildBeginPROC( )
Global phLevelBuildBegin.phLevelBuildBeginPROC
phLevelBuildBegin = GetFunction(phxdll, "_phLevelBuildBegin@0")

Prototype.l phLevelAddFacePROC( x1.f, y1.f, z1.f, x2.f, y2.f, z2.f, x3.f, y3.f, z3.f )

Prototype phLevelBuildEndPROC( )
Global phLevelBuildEnd.phLevelBuildEndPROC
phLevelBuildEnd = GetFunction(phxdll, "_phLevelBuildEnd@0")

Prototype phTerrainCreatePROC( nSize, CellWidth.f, *height )
Global phTerrainCreate.phTerrainCreatePROC
phTerrainCreate = GetFunction(phxdll, "_phTerrainCreate@12")

Prototype phJointBallCreatePROC( x.f, y.f, z.f, body1, body2 )
Global phJointBallCreate.phJointBallCreatePROC
phJointBallCreate = GetFunction(phxdll, "_phJointBallCreate@20")

Prototype.l phJointBallSetLimitPROC( joint, nx.f, ny.f, nz.f, coneAngle.f, twistAngle.f )
Global phJointBallSetLimit.phJointBallSetLimitPROC
phJointBallSetLimit = GetFunction(phxdll, "_phJointBallSetLimit@24")

Prototype.f phJointBallGetForcePROC( joint )
Global phJointBallGetForce.phJointBallGetForcePROC
phJointBallGetForce = GetFunction(phxdll, "_phJointBallGetForce@4")

Prototype phJointHingeCreatePROC( x.f,y.f, z.f, nx.f, ny.f, nz.f, body1, body2 )
Global phJointHingeCreate.phJointHingeCreatePROC
phJointHingeCreate = GetFunction(phxdll, "_phJointHingeCreate@32")

Prototype.l phJointHingeSetLimitPROC( joint, min.f, max.f )
Global phJointHingeSetLimit.phJointHingeSetLimitPROC
phJointHingeSetLimit = GetFunction(phxdll, "_phJointHingeSetLimit@12")

Prototype.f phJointHingeGetAnglePROC( joint )
Global phJointHingeGetAngle.phJointHingeGetAnglePROC
phJointHingeGetAngle = GetFunction(phxdll, "_phJointHingeGetAngle@4")

Prototype.f phJointHingeGetOmegaPROC( joint )
Global phJointHingeGetOmega.phJointHingeGetOmegaPROC
phJointHingeGetOmega = GetFunction(phxdll, "_phJointHingeGetOmega@4")

Prototype.f phJointHingeGetForcePROC( joint )
Global phJointHingeGetForce.phJointHingeGetForcePROC
phJointHingeGetForce = GetFunction(phxdll, "_phJointHingeGetForce@4")

Prototype phJointSliderCreatePROC( x.f, y.f, z.f, nx.f, ny.f, nz.f, body1, body2 )
Global phJointSliderCreate.phJointSliderCreatePROC
phJointSliderCreate = GetFunction(phxdll, "_phJointSliderCreate@32")

Prototype.l phJointSliderSetLimitPROC( joint, min.f, max.f )
Global phJointSliderSetLimit.phJointSliderSetLimitPROC
phJointSliderSetLimit = GetFunction(phxdll, "_phJointSliderSetLimit@12")

Prototype.f phJointSliderGetPosPROC( joint )
Global phJointSliderGetPos.phJointSliderGetPosPROC
phJointSliderGetPos = GetFunction(phxdll, "_phJointSliderGetPos@4")

Prototype.f phJointSliderGetVelPROC( joint )
Global phJointSliderGetVel.phJointSliderGetVelPROC
phJointSliderGetVel = GetFunction(phxdll, "_phJointSliderGetVel@4")

Prototype.f phJointSliderGetForcePROC( joint )
Global phJointSliderGetForce.phJointSliderGetForcePROC
phJointSliderGetForce = GetFunction(phxdll, "_phJointSliderGetForce@4")

Prototype phJointCorkCreatePROC( x.f, y.f, z.f, nx.f, ny.f, nz.f, body1, body2 )
Global phJointCorkCreate.phJointCorkCreatePROC
phJointCorkCreate = GetFunction(phxdll, "_phJointCorkCreate@32")

Prototype.l phJointCorkSetLimitPROC( min.f, max.f, amin.f, amax.f )
Global phJointCorkSetLimit.phJointCorkSetLimitPROC
phJointCorkSetLimit = GetFunction(phxdll, "_phJointCorkSetLimit@20")

Prototype.f phJointCorkGetPosPROC( joint )
Global phJointCorkGetPos.phJointCorkGetPosPROC
phJointCorkGetPos = GetFunction(phxdll, "_phJointCorkGetPos@4")

Prototype.f phJointCorkGetVelPROC( joint )
Global phJointCorkGetVel.phJointCorkGetVelPROC
phJointCorkGetVel = GetFunction(phxdll, "_phJointCorkGetVel@4")

Prototype.f phJointCorkGetAnglePROC( joint )
Global phJointCorkGetAngle.phJointCorkGetAnglePROC
phJointCorkGetAngle = GetFunction(phxdll, "_phJointCorkGetAngle@4")

Prototype.f phJointCorkGetOmegaPROC( joint )
Global phJointCorkGetOmega.phJointCorkGetOmegaPROC
phJointCorkGetOmega = GetFunction(phxdll, "_phJointCorkGetOmega@4")

Prototype.f phJointCorkGetForcePROC( joint )
Global phJointCorkGetForce.phJointCorkGetForcePROC
phJointCorkGetForce = GetFunction(phxdll, "_phJointCorkGetForce@4")

Prototype phJointUpVectorCreatePROC( nx.f, ny.f, nz.f, body )
Global phJointUpVectorCreate.phJointUpVectorCreatePROC
phJointUpVectorCreate = GetFunction(phxdll, "_phJointUpVectorCreate@16")

Prototype.l phJointUpVectorSetPinPROC( joint, nx.f, ny.f, nz.f )
Global phJointUpVectorSetPin.phJointUpVectorSetPinPROC
phJointUpVectorSetPin = GetFunction(phxdll, "_phJointUpVectorSetPin@16")

Prototype.f phJointUpVectorGetPinXPROC( joint )
Global phJointUpVectorGetPinX.phJointUpVectorGetPinXPROC
phJointUpVectorGetPinX = GetFunction(phxdll, "_phJointUpVectorGetPinX@4")

Prototype.f phJointUpVectorGetPinYPROC( joint )
Global phJointUpVectorGetPinY.phJointUpVectorGetPinYPROC
phJointUpVectorGetPinY = GetFunction(phxdll, "_phJointUpVectorGetPinY@4")

Prototype.f phJointUpVectorGetPinZPROC( joint )
Global phJointUpVectorGetPinZ.phJointUpVectorGetPinZPROC
phJointUpVectorGetPinZ = GetFunction(phxdll, "_phJointUpVectorGetPinZ@4")

Prototype phJointUniversalCreatePROC( x.f, y.f, z.f, mx1.f, ny1.f, nz1.f, nx2.f, ny2.f, nz2.f, body1, body2 )
Global phJointUniversalCreate.phJointUniversalCreatePROC
phJointUniversalCreate = GetFunction(phxdll, "_phJointUniversalCreate@44")

Prototype.f phJointUniversalGetAngle1PROC( joint )
Global phJointUniversalGetAngle1.phJointUniversalGetAngle1PROC
phJointUniversalGetAngle1 = GetFunction(phxdll, "_phJointUniversalGetAngle1@4")

Prototype.f phJointUniversalGetAngle2PROC( joint )
Global phJointUniversalGetAngle2.phJointUniversalGetAngle2PROC
phJointUniversalGetAngle2 = GetFunction(phxdll, "_phJointUniversalGetAngle2@4")

Prototype.f phJointUniversalGetOmega1PROC( joint )
Global phJointUniversalGetOmega1.phJointUniversalGetOmega1PROC
phJointUniversalGetOmega1 = GetFunction(phxdll, "_phJointUniversalGetOmega1@4")

Prototype.f phJointUniversalGetOmega2PROC( joint )
Global phJointUniversalGetOmega2.phJointUniversalGetOmega2PROC
phJointUniversalGetOmega2 = GetFunction(phxdll, "_phJointUniversalGetOmega2@4")

Prototype.f phJointUniversalGetForcePROC( joint )
Global phJointUniversalGetForce.phJointUniversalGetForcePROC
phJointUniversalGetForce = GetFunction(phxdll, "_phJointUniversalGetForce@4")

Prototype.l phJointUniversalSetLimitPROC( joint, min1.f, max1.f, min2.f, max2.f )
Global phJointUniversalSetLimit.phJointUniversalSetLimitPROC
phJointUniversalSetLimit = GetFunction(phxdll, "_phJointUniversalSetLimit@20")

Prototype phJointSpringCreatePROC( x1.f, y1.f, z1.f, x2.f, y2.f, z2.f, strong.f, dampfer.f, body1, body2 )
Global phJointSpringCreate.phJointSpringCreatePROC
phJointSpringCreate = GetFunction(phxdll, "_phJointSpringCreate@40")

Prototype phJointFixedCreatePROC( plane, license_key\$)
Global phJointFixedCreate.phJointFixedCreatePROC
phJointFixedCreate = GetFunction(phxdll, "_phJointFixedCreate@8")

Prototype phJointSuspCreatePROC( x.f, y.f, z.f, nx1.f, ny1.f, nz1.f, nx2.f, ny2.f, nz2.f, k.f, s.f, body1, body2 )
Global phJointSuspCreate.phJointSuspCreatePROC
phJointSuspCreate = GetFunction(phxdll, "_phJointSuspCreate@52")

Prototype.l phJointSuspSetSteerPROC( joint, steer.f )
Global phJointSuspSetSteer.phJointSuspSetSteerPROC
phJointSuspSetSteer = GetFunction(phxdll, "_phJointSuspSetSteer@8")

Prototype.l phJointSuspAddTorquePROC( joint, torque.f )

Prototype.l phJointSuspSetFrictionPROC( joint, min.f, max.f )
Global phJointSuspSetFriction.phJointSuspSetFrictionPROC
phJointSuspSetFriction = GetFunction(phxdll, "_phJointSuspSetFriction@12")

Prototype.l phJointSuspSetLimitPROC( joint, min.f, max.f )
Global phJointSuspSetLimit.phJointSuspSetLimitPROC
phJointSuspSetLimit = GetFunction(phxdll, "_phJointSuspSetLimit@12")

Prototype.f phJointSuspGetPosPROC( joint )
Global phJointSuspGetPos.phJointSuspGetPosPROC
phJointSuspGetPos = GetFunction(phxdll, "_phJointSuspGetPos@4")

Prototype.l phJointDestroyPROC( joint )
Global phJointDestroy.phJointDestroyPROC
phJointDestroy = GetFunction(phxdll, "_phJointDestroy@4")

Prototype.l phJointSetCollisionModePROC( joint, mode )
Global phJointSetCollisionMode.phJointSetCollisionModePROC
phJointSetCollisionMode = GetFunction(phxdll, "_phJointSetCollisionMode@8")

Prototype.l phJointSetStiffnessPROC( joint, stiff.f )
Global phJointSetStiffness.phJointSetStiffnessPROC
phJointSetStiffness = GetFunction(phxdll, "_phJointSetStiffness@8")

Prototype phJointVehicleCreatePROC( upx.f, upy.f, upz.f, body )
Global phJointVehicleCreate.phJointVehicleCreatePROC
phJointVehicleCreate = GetFunction(phxdll, "_phJointVehicleCreate@16")

Prototype phJointVehicleAddTirePROC( vehicle , dx.f, dy.f, dz.f, nx.f, ny.f, nz.f, mass.f, width.f, radius.f, shock.f, spring.f, lenght.f, mat )

Prototype.f phJointVehicleGetTireXPROC( vehicle, tire )
Global phJointVehicleGetTireX.phJointVehicleGetTireXPROC
phJointVehicleGetTireX = GetFunction(phxdll, "_phJointVehicleGetTireX@8")

Prototype.f phJointVehicleGetTireYPROC( pvehicle, tire )
Global phJointVehicleGetTireY.phJointVehicleGetTireYPROC
phJointVehicleGetTireY = GetFunction(phxdll, "_phJointVehicleGetTireY@8")

Prototype.f phJointVehicleGetTireZPROC( vehicle, tire )
Global phJointVehicleGetTireZ.phJointVehicleGetTireZPROC
phJointVehicleGetTireZ = GetFunction(phxdll, "_phJointVehicleGetTireZ@8")

Prototype.f phJointVehicleGetTirePitchPROC( vehicle, tire)
Global phJointVehicleGetTirePitch.phJointVehicleGetTirePitchPROC
phJointVehicleGetTirePitch = GetFunction(phxdll, "_phJointVehicleGetTirePitch@8")

Prototype.f phJointVehicleGetTireYawPROC( vehicle, tire )
Global phJointVehicleGetTireYaw.phJointVehicleGetTireYawPROC
phJointVehicleGetTireYaw = GetFunction(phxdll, "_phJointVehicleGetTireYaw@8")

Prototype.f phJointVehicleGetTireRollPROC( vehicle, tire )
Global phJointVehicleGetTireRoll.phJointVehicleGetTireRollPROC
phJointVehicleGetTireRoll = GetFunction(phxdll, "_phJointVehicleGetTireRoll@8")

Prototype.l phJointVehicleSetTireSteerPROC( vehicle, tire, steer.f )
Global phJointVehicleSetTireSteer.phJointVehicleSetTireSteerPROC
phJointVehicleSetTireSteer = GetFunction(phxdll, "_phJointVehicleSetTireSteer@12")

Prototype.l phJointVehicleAddTireTorquePROC( vehicle, tire, torque.f )

Prototype.f phJointVehicleGetTireOmegaPROC( vehicle, tire )
Global phJointVehicleGetTireOmega.phJointVehicleGetTireOmegaPROC
phJointVehicleGetTireOmega = GetFunction(phxdll, "_phJointVehicleGetTireOmega@8")

Prototype.f phJointVehicleGetTireLoadPROC( vehicle, tire )

Prototype.f phJointVehicleGetTireLateralSpeedPROC( vehicle, tire )
Global phJointVehicleGetTireLateralSpeed.phJointVehicleGetTireLateralSpeedPROC
phJointVehicleGetTireLateralSpeed = GetFunction(phxdll, "_phJointVehicleGetTireLateralSpeed@8")

Prototype.f phJointVehicleGetTireLongitudinalSpeedPROC( vehicle, tire )
Global phJointVehicleGetTireLongitudinalSpeed.phJointVehicleGetTireLongitudinalSpeedPROC
phJointVehicleGetTireLongitudinalSpeed = GetFunction(phxdll, "_phJointVehicleGetTireLongitudinalSpeed@8")

Prototype phJointVehicleGetTireAirPROC( vehicle, tire )
Global phJointVehicleGetTireAir.phJointVehicleGetTireAirPROC
phJointVehicleGetTireAir = GetFunction(phxdll, "_phJointVehicleGetTireAir@8")

Prototype phJointVehicleGetTireGripPROC( vehicle, tire )
Global phJointVehicleGetTireGrip.phJointVehicleGetTireGripPROC
phJointVehicleGetTireGrip = GetFunction(phxdll, "_phJointVehicleGetTireGrip@8")

Prototype phJointVehicleGetTireTractionPROC( vehicle, tire )
Global phJointVehicleGetTireTraction.phJointVehicleGetTireTractionPROC
phJointVehicleGetTireTraction = GetFunction(phxdll, "_phJointVehicleGetTireTraction@8")

Prototype.l phJointVehicleSetTireBrakePROC( vehicle, tire, acc.f, fric.f)
Global phJointVehicleSetTireBrake.phJointVehicleSetTireBrakePROC
phJointVehicleSetTireBrake = GetFunction(phxdll, "_phJointVehicleSetTireBrake@16")

Prototype.l phJointVehicleSetTireSlidingPROC( vehicle, tire, sidevel.f, sidek.f, longvel.f, longk.f)
Global phJointVehicleSetTireSliding.phJointVehicleSetTireSlidingPROC
phJointVehicleSetTireSliding = GetFunction(phxdll, "_phJointVehicleSetTireSliding@24")

Prototype.l phJointVehicleResetPROC( vehicle )
Global phJointVehicleReset.phJointVehicleResetPROC
phJointVehicleReset = GetFunction(phxdll, "_phJointVehicleReset@4")

Prototype phJointDryRollingCreatePROC( body, radius.f, friction.f )
Global phJointDryRollingCreate.phJointDryRollingCreatePROC
phJointDryRollingCreate = GetFunction(phxdll, "_phJointDryRollingCreate@12")

Prototype phJointDryRollingSetFrictionPROC( joint, radius.f, friction.f )
Global phJointDryRollingSetFriction.phJointDryRollingSetFrictionPROC
phJointDryRollingSetFriction = GetFunction(phxdll, "_phJointDryRollingSetFriction@12")

Prototype phJointPlaneCreatePROC( body, x.f, y.f, z.f, nx.f, ny.f, nz.f )
Global phJointPlaneCreate.phJointPlaneCreatePROC
phJointPlaneCreate = GetFunction(phxdll, "_phJointPlaneCreate@28")

Prototype phRayCastPROC( x1.f, y1.f, z1.f, x2.f, y2.f, z2.f )
Global phRayCast.phRayCastPROC
phRayCast = GetFunction(phxdll, "_phRayCast@24")

Prototype.f phRayGetXPROC( )
Global phRayGetX.phRayGetXPROC
phRayGetX = GetFunction(phxdll, "_phRayGetX@0")

Prototype.f phRayGetYPROC( )
Global phRayGetY.phRayGetYPROC
phRayGetY = GetFunction(phxdll, "_phRayGetY@0")

Prototype.f phRayGetZPROC( )
Global phRayGetZ.phRayGetZPROC
phRayGetZ = GetFunction(phxdll, "_phRayGetZ@0")

Prototype.f phRayGetNXPROC( )
Global phRayGetNX.phRayGetNXPROC
phRayGetNX = GetFunction(phxdll, "_phRayGetNX@0")

Prototype.f phRayGetNYPROC( )
Global phRayGetNY.phRayGetNYPROC
phRayGetNY = GetFunction(phxdll, "_phRayGetNY@0")

Prototype.f phRayGetNZPROC( )
Global phRayGetNZ.phRayGetNZPROC
phRayGetNZ = GetFunction(phxdll, "_phRayGetNZ@0")

Prototype phRayGetBodyPROC( )
Global phRayGetBody.phRayGetBodyPROC
phRayGetBody = GetFunction(phxdll, "_phRayGetBody@0")

another include to make your life easier:
(name this "newton.pbi")
Code:
;      ----------------------------------------------------      ;
;       ---                                              ---      ;
;       ---   Some functions simplifying wrapper using   ---      ;
;       ---                                              ---      ;
;      ----------------------------------------------------      ;
;
; NOTE: You can modify all these fucntions as you want
XIncludeFile "nwphx.pbi"

; Macros porting B3d code to PB
Macro CreateBank(size)               : AllocateMemory(size)        : EndMacro
Macro FreeBank(bank)                 : FreeMemory(bank)            : EndMacro
Macro PeekByte(bank, offset)         : PeekB(bank + offset)        : EndMacro
Macro PeekShort(bank, offset)        : PeekW(bank + offset)        : EndMacro
Macro PeekInt(bank, offset)          : PeekL(bank + offset)        : EndMacro
Macro PeekFloat(bank, offset)        : PeekF(bank + offset)        : EndMacro
Macro PokeByte(bank, offset, value)  : PokeB(bank + offset, value) : EndMacro
Macro PokeShort(bank, offset, value) : PokeW(bank + offset, value) : EndMacro
Macro PokeInt(bank, offset, value)   : PokeL(bank + offset, value) : EndMacro
Macro PokeFloat(bank, offset, value) : PokeF(bank + offset, value) : EndMacro

; There is the type for object uniting body and mesh
Structure physx
body.l
mesh.l
EndStructure

Global NewList phx.physx()

; Create body with hull geometry from mesh. Mesh can not be scaled via ScaleEntity.
; Only ScaleMesh is supported.
Procedure BodyCreateHull(mesh,mass.f)
; Obtain surfaces and vertices number
Protected nsurf = bbCountSurfaces(mesh)
Protected nvert = 0
For ns = 1 To nsurf
Protected surf = bbGetSurface(mesh,ns)
nvert = nvert + bbCountVertices(surf)
Next

Protected *vbank = CreateBank(nvert*4*3)
Protected nv = 0
; Poke vertices coordinates to bank
For ns = 1 To nsurf
surf = bbGetSurface(mesh,ns)
nvv = bbCountVertices(surf)
For nvc = 0 To nvv - 1
PokeFloat (*vbank,(nv*12+0),bbVertexX(surf,nvc))
PokeFloat (*vbank,(nv*12+4),bbVertexY(surf,nvc))
PokeFloat (*vbank,(nv*12+8),bbVertexZ(surf,nvc))
nv = nv+1
Next
Next
;call wrapper function
Protected bbb = phBodyCreateHull(*vbank,nvert,mass)
FreeBank (*vbank)
ProcedureReturn bbb
EndProcedure

; Create body with mesh geometry from mesh. Mesh can not be scaled via ScaleEntity.
; Only ScaleMesh is supported. Not recommended to use. It is better to use hulls.
Procedure BodyCreateMesh(mesh,mass.f)
; Obtain surfaces And triangles number
Protected nsurf = bbCountSurfaces(mesh)
Protected nvert = 0
For ns = 1 To nsurf
Protected surf = bbGetSurface(mesh,ns)
nvert = nvert + (bbCountTriangles(surf)*3)
Next

Protected *vbank = CreateBank(nvert*4*3)
Protected nv = 0
; Poke vertices coordinates to bank
For ns = 1 To nsurf
surf = bbGetSurface(mesh,ns)
nvv = bbCountTriangles(surf)
For nvc = 0 To nvv - 1
For t = 0 To 2
If (nv < nvert)
PokeFloat (*vbank,(nv*12+0),bbVertexX(surf,bbTriangleVertex(surf,nvc,t)))
PokeFloat (*vbank,(nv*12+4),bbVertexY(surf,bbTriangleVertex(surf,nvc,t)))
PokeFloat (*vbank,(nv*12+8),bbVertexZ(surf,bbTriangleVertex(surf,nvc,t)))
nv = nv+1
EndIf
Next
Next
Next
Protected bbb = phBodyCreateMesh(*vbank,nvert,mass)
FreeBank (*vbank)
ProcedureReturn bbb
EndProcedure

; Add all triangles from mesh to level.
Protected x1.f,y1.f,z1.f,x2.f,y2.f,z2.f,x3.f,y3.f,z3.f
Protected ns
Protected nsurf = bbCountSurfaces(mesh)
For ns = 1 To nsurf
Protected surf = bbGetSurface(mesh,ns)
Protected nvv = bbCountTriangles(surf)
For nvc = 0 To nvv - 1
x1 = bbVertexX(surf,bbTriangleVertex(surf,nvc,0))
y1 = bbVertexY(surf,bbTriangleVertex(surf,nvc,0))
z1 = bbVertexZ(surf,bbTriangleVertex(surf,nvc,0))

x2 = bbVertexX(surf,bbTriangleVertex(surf,nvc,1))
y2 = bbVertexY(surf,bbTriangleVertex(surf,nvc,1))
z2 = bbVertexZ(surf,bbTriangleVertex(surf,nvc,1))

x3 = bbVertexX(surf,bbTriangleVertex(surf,nvc,2))
y3 = bbVertexY(surf,bbTriangleVertex(surf,nvc,2))
z3 = bbVertexZ(surf,bbTriangleVertex(surf,nvc,2))

Next
Next
EndProcedure

;Stop
Protected ts = bbTerrainSize(terrain)
Protected x1.f, x2.f, x3.f, y.f, y1.f, y2.f, y3.f, z1.f, z2.f, z3.f

For x = 0 To ts
For z = 0 To ts
y = bbTerrainHeight(terrain,x,z)
bbTFormPoint(x,y,z,terrain,0)
x1 = bbTFormedX():y1 = bbTFormedY():z1 = bbTFormedZ()
y = bbTerrainHeight(terrain,x+1,z)
bbTFormPoint(x+1,y,z,terrain,0)
x2 = bbTFormedX():y2 = bbTFormedY():z2 = bbTFormedZ()
y = bbTerrainHeight(terrain,x,z+1)
bbTFormPoint(x,y,z+1,terrain,0)
x3 = bbTFormedX():y3 = bbTFormedY():z3 = bbTFormedZ()
;--
y = bbTerrainHeight(terrain,x,z+1)
bbTFormPoint(x,y,z+1,terrain,0)
x1 = bbTFormedX():y1 = bbTFormedY():z1 = bbTFormedZ()
y = bbTerrainHeight(terrain,x+1,z)
bbTFormPoint(x+1,y,z,terrain,0)
x2 = bbTFormedX():y2 = bbTFormedY():z2 = bbTFormedZ()
y = bbTerrainHeight(terrain,x+1,z+1)
bbTFormPoint(x+1,y,z+1,terrain,0)
x3 = bbTFormedX():y3 = bbTFormedY():z3 = bbTFormedZ()
Next
Next
EndProcedure

; Create body with terrain geometry
; cellsize# is size of one cell of the terrain.
; maxheight# is height of the brightest point (i.e. color is 255)
; when you scale the terrain, scaleX and scaleZ are cellsize, scaleY is maxheight
; I.e. ScaleEntity terrain,cellseize,mexheight,cellsize
Procedure TerrainCreate(terrain,cellsize.f,maxheight.f)
; Poke heightfield to bank
Protected nSize = bbTerrainSize(terrain)
Protected *bank = CreateBank((nSize+1)*(nSize+1)*4)
For z=0 To nSize
For x = 0 To nSize
Protected y.f = bbTerrainHeight(terrain,x,z) * maxheight
PokeFloat(*bank,(z*(nSize+1)+x)*4,y)
Next
Next
; Call wrapper function
Protected body = phTerrainCreate(nSize+1,cellsize,*bank)
FreeBank(*bank)
ProcedureReturn body
EndProcedure

; Step the world and reposition entity to body's position.

Procedure WorldStep(dtime.f,N)
; Step the world
For x=n To 0 Step -1
phWorldStep(dtime)
Next
; position and rotate all meshes as the corresponding bodies
ForEach phx()
bbPositionEntity(phx()\mesh,phBodyGetX(phx()\body),phBodyGetY(phx()\body),phBodyGetZ(phx()\body))
bbRotateEntity(phx()\mesh,phBodyGetPitch(phx()\body),phBodyGetYaw(phx()\body),phBodyGetRoll(phx()\body))
Next
EndProcedure

; Create mesh and body for a box
Procedure phxCreateBox(w.f,h.f,d.f,mass.f)
;TestList()\Field2 = 1
phx()\body = phBodyCreateBox(w,h,d,mass)
phx()\mesh = bbCreateCube()
bbScaleMesh(phx()\mesh,w*0.5,h*0.5,d*0.5)
EndProcedure

; Create mesh and body for a sphere
Procedure phxCreateSphere(rx.f,ry.f,rz.f,mass.f)
;TestList()\Field2 = 1
phx()\body = phBodyCreateSphere(rx,ry,rz,mass)
phx()\mesh = bbCreateSphere()
bbScaleMesh(phx()\mesh,rx,ry,rz)
EndProcedure

; Create mesh and body for a cylinder
Procedure phxCreateCyl(r.f,h.f,mass.f)
;TestList()\Field2 = 1
phx()\body = phBodyCreateCyl(r,h,mass)
phx()\mesh = bbCreateCylinder()
bbScaleMesh(phx()\mesh,r,h*0.5,r)
EndProcedure

; Create mesh and body for a capsule
Procedure phxCreateCapsule(r.f,h.f,mass.f)
;TestList()\Field2 = 1
phx()\body = phBodyCreateCapsule(r,h,mass)
Protected m = bbCreateCylinder()
bbScaleMesh(m,r,h*0.5,r)
Protected m1 = bbCreateSphere()
bbScaleMesh(m1,r,r,r)
bbPositionMesh(m1,0,h*0.5,0)
bbFreeEntity(m1)
m1 = bbCreateSphere()
bbScaleMesh(m1,r,r,r)
bbPositionMesh(m1,0,(-h)*0.5,0)
bbFreeEntity(m1)
phx()\mesh = m
EndProcedure

; Create pivot and null body
Procedure phxCreateNull(mass.f)
phx()\body = phBodyCreateNull(mass)
phx()\mesh = bbCreatePivot()
EndProcedure

Protected nsurf = bbCountSurfaces(mesh)
Protected nvert = 0
For ns = 1 To nsurf
Protected surf = bbGetSurface(mesh,ns)
nvert = nvert + bbCountVertices(surf)
Next
Protected *vbank = CreateBank(nvert*4*3)
nv = 0
For ns = 1 To nsurf
surf = bbGetSurface(mesh,ns)
nvv = bbCountVertices(surf)
For nvc = 0 To nvv - 1
PokeFloat(*vbank,nv*12+0,bbVertexX(surf,nvc))
PokeFloat(*vbank,nv*12+4,bbVertexY(surf,nvc))
PokeFloat(*vbank,nv*12+8,bbVertexZ(surf,nvc))
nv = nv+1
Next
Next
FreeBank(*vbank)
EndProcedure

in your app you just need to "XIncludeFile newton.pbi" and thats it

EDIT: if you'd like to buy it

Last edited by PureLeo on Thu May 13, 2010 5:11 am, edited 1 time in total.

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Wed May 12, 2010 4:19 pm

Joined: Tue Jan 02, 2007 8:16 pm
Posts: 4328
Location: Cypress TX
Majorly KEWL PureLeo!!!

You ROCK!!!

_________________
Binarily speaking... it takes 10 to Tango!!!

http://www.bluemesapc.com/

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Thu May 13, 2010 5:16 am
 Enthusiast

Joined: Fri Jan 29, 2010 1:05 pm
Posts: 221
Location: Brazil
thank you Rook, i hope it's being usefull

oh! but there are some functions that still need convertion depending on your engine...
like bbCreatePivot(), bbCreateCube(), and everything starting with "bb"

(edited last post with store link)

Top

 Post subject: Re: Ping-Pong Game (Physics)Posted: Sun Aug 08, 2010 8:48 pm
 New User

Joined: Sun Aug 01, 2010 3:43 pm
Posts: 1
thx for the wrapper

but a simple pong game does not need such an overhead

what simply need to be implemented is the law of reflection, elastic or unelastic bodycontact
and an increase of speedvector when collision hit with walls

so easy to do it by yourself

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 12 posts ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite