
It: Map ("table" and walls), Ball and Players.
As now create realistic Ping-Pong physics? This possible? Thanks...
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...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.
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...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...
Code: Select all
Global phxdll = OpenLibrary (#PB_Any, "nwphx.dll")
If phxdll = 0
MessageRequester ("Fatal error!", "Failed to open nwphx.dll!", #PB_MessageRequester_Ok)
End
EndIf
#newton_license_key = "enter your license key here"
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)
Global phBodyCompoundAddHull.phBodyCompoundAddHullPROC
phBodyCompoundAddHull = GetFunction(phxdll, "_phBodyCompoundAddHull@8")
Prototype.l phBodyCompoundAddBodyPROC( body )
Global phBodyCompoundAddBody.phBodyCompoundAddBodyPROC
phBodyCompoundAddBody = GetFunction(phxdll, "_phBodyCompoundAddBody@4")
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 )
Global phBodyCompoundExAddHull.phBodyCompoundExAddHullPROC
phBodyCompoundExAddHull = GetFunction(phxdll, "_phBodyCompoundExAddHull@12")
Prototype.l phBodyCompoundExAddHullDensPROC( *Vertices, VertexCount, density.f )
Global phBodyCompoundExAddHullDens.phBodyCompoundExAddHullDensPROC
phBodyCompoundExAddHullDens = GetFunction(phxdll, "_phBodyCompoundExAddHullDens@12")
Prototype.l phBodyCompoundExAddBodyPROC( body )
Global phBodyCompoundExAddBody.phBodyCompoundExAddBodyPROC
phBodyCompoundExAddBody = GetFunction(phxdll, "_phBodyCompoundExAddBody@4")
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 )
Global phBodyAddForce.phBodyAddForcePROC
phBodyAddForce = GetFunction(phxdll, "_phBodyAddForce@16")
Prototype.l phBodyAddRelForcePROC( body, fx.f, fy.f, fz.f )
Global phBodyAddRelForce.phBodyAddRelForcePROC
phBodyAddRelForce = GetFunction(phxdll, "_phBodyAddRelForce@16")
Prototype.l phBodyAddForceAtPosPROC( body, fx.f, fy.f, fz.f, x.f, y.f, z.f )
Global phBodyAddForceAtPos.phBodyAddForceAtPosPROC
phBodyAddForceAtPos = GetFunction(phxdll, "_phBodyAddForceAtPos@28")
Prototype.l phBodyAddRelForceAtRelPosPROC( body, fx.f, fy.f, fz.f, x.f, y.f, z.f )
Global phBodyAddRelForceAtRelPos.phBodyAddRelForceAtRelPosPROC
phBodyAddRelForceAtRelPos = GetFunction(phxdll, "_phBodyAddRelForceAtRelPos@28")
Prototype.l phBodyAddImpulsePROC( body, x.f, y.f, z.f, vx.f, vy.f, vz.f )
Global phBodyAddImpulse.phBodyAddImpulsePROC
phBodyAddImpulse = GetFunction(phxdll, "_phBodyAddImpulse@28")
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 )
Global phBodyAddTorque.phBodyAddTorquePROC
phBodyAddTorque = GetFunction(phxdll, "_phBodyAddTorque@16")
Prototype.l phBodyAddRelTorquePROC( body, tx.f, ty.f, tz.f )
Global phBodyAddRelTorque.phBodyAddRelTorquePROC
phBodyAddRelTorque = GetFunction(phxdll, "_phBodyAddRelTorque@16")
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 )
Global phLevelAddFace.phLevelAddFacePROC
phLevelAddFace = GetFunction(phxdll, "_phLevelAddFace@36")
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 )
Global phJointSuspAddTorque.phJointSuspAddTorquePROC
phJointSuspAddTorque = GetFunction(phxdll, "_phJointSuspAddTorque@8")
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 )
Global phJointVehicleAddTire.phJointVehicleAddTirePROC
phJointVehicleAddTire = GetFunction(phxdll, "_phJointVehicleAddTire@56")
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 )
Global phJointVehicleAddTireTorque.phJointVehicleAddTireTorquePROC
phJointVehicleAddTireTorque = GetFunction(phxdll, "_phJointVehicleAddTireTorque@12")
Prototype.f phJointVehicleGetTireOmegaPROC( vehicle, tire )
Global phJointVehicleGetTireOmega.phJointVehicleGetTireOmegaPROC
phJointVehicleGetTireOmega = GetFunction(phxdll, "_phJointVehicleGetTireOmega@8")
Prototype.f phJointVehicleGetTireLoadPROC( vehicle, tire )
Global phJointVehicleGetTireLoad.phJointVehicleGetTireLoadPROC
phJointVehicleGetTireLoad = GetFunction(phxdll, "_phJointVehicleGetTireLoad@8")
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")
Code: Select all
; ---------------------------------------------------- ;
; --- --- ;
; --- 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.
Procedure LevelAddMesh(mesh)
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))
phLevelAddFace(x1,y1,z1,x2,y2,z2,x3,y3,z3)
Next
Next
EndProcedure
Procedure LevelAddTerrain(terrain)
;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()
phLevelAddFace(x1,y1,z1,x2,y2,z2,x3,y3,z3)
;--
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()
phLevelAddFace(x1,y1,z1,x2,y2,z2,x3,y3,z3)
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)
;AddElement(TestList())
;TestList()\Field2 = 1
AddElement(phx())
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)
;AddElement(TestList())
;TestList()\Field2 = 1
AddElement(phx())
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)
;AddElement(TestList())
;TestList()\Field2 = 1
AddElement(phx())
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)
;AddElement(TestList())
;TestList()\Field2 = 1
AddElement(phx())
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)
bbAddMesh(m1,m)
bbFreeEntity(m1)
m1 = bbCreateSphere()
bbScaleMesh(m1,r,r,r)
bbPositionMesh(m1,0,(-h)*0.5,0)
bbAddMesh(m1,m)
bbFreeEntity(m1)
phx()\mesh = m
EndProcedure
; Create pivot and null body
Procedure phxCreateNull(mass.f)
AddElement(phx())
phx()\body = phBodyCreateNull(mass)
phx()\mesh = bbCreatePivot()
EndProcedure
Procedure CompoundAddHull(mesh)
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
phBodyCompoundAddHull(*vbank,nvert)
FreeBank(*vbank)
EndProcedure