Car physics ?

Advanced game related topics
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Nice :shock:
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Include file for BlitzKODE.dll ( Not all functions defined as I didn't use them yet :D

You can get the DEMO DLL from http://www.lcuriel.arrakis.es/kode/index.htm

Code: Select all

; .f.f.f World Functions
Prototype.l dSetMUP(value.f);:"_KODE_dSetMU@4"
Prototype.l dSetMU2P(value.f);:"_KODE_dSetMU2@4"
Prototype.l dSetBOUNCEP(value.f);:"_KODE_dSetBOUNCE@4"
Prototype.l dSetBOUNCE_VELP(value.f);:"_KODE_dSetBOUNCE_VEL@4"
Prototype.l dSetSLIP1P(value.f);:"_KODE_dSetSLIP1@4"
Prototype.l dSetSLIP2P(value.f);:"_KODE_dSetSLIP2@4"
Prototype.l dSetSOFT_ERPP(value.f);:"_KODE_dSetSOFT_ERP@4"
Prototype.l dSetSOFT_CFMP(value.f);:"_KODE_dSetSOFT_CFM@4"
Prototype.l dSetMOTION1P(value.f);:"_KODE_dSetMOTION1@4"
Prototype.l dSetMOTION2P(value.f);:"_KODE_dSetMOTION2@4"

Prototype.f dBodyGetAngularVelX(body.l);:"_KODE_dBodyGetAngularVelX@4"
Prototype.f dBodyGetAngularVelY(body.l);:"_KODE_dBodyGetAngularVelY@4"
Prototype.f dBodyGetAngularVelZ(body.l);:"_KODE_dBodyGetAngularVelZ@4"
Prototype.l dBodySetAngularVel(body.l, x.f, y.f, z.f);:"_KODE_dBodySetAngularVel@16"
 

;MAXCONTACTS
Prototype.l dSetMaxContactsP(max.l);:"_KODE_dSetMaxContacts@4"
Prototype.l dGetMaxContactsP();:"_KODE_dGetMaxContacts@0"

;MASAS TOTALES
Prototype.l dBodySetBoxMassP(body.l,lx.f,ly.f,lz.f,mass.f);:"_KODE_dBodySetBoxMass@20"
Prototype.l dBodySetSphereMassP(body.l,r.f,mass.f);:"_KODE_dBodySetSphereMass@12"
Prototype.l dBodySetCCylinderMassP(body.l,r.f,h.f,mass.f);:"_KODE_dBodySetCCylinderMass@16"
Prototype.l dBodySetCylinderMassP(body.l,r.f,h.f,mass.f);:"_KODE_dBodySetCylinderMass@16"

;GEOM TRANSFORM
Prototype.l dCreateGeomTransformP(space.l);:"_KODE_dCreateGeomTransform@4"
Prototype.l dGeomTransformSetGeomP(geom.l, geomobj.l);:"_KODE_dGeomTransformSetGeom@8"
Prototype.l dGeomTransformGetGeomP(geom.l);:"_KODE_dGeomTransformGetGeom@4"
Prototype.l dGeomTransformSetCleanupP(geom.l,mode.l);:"_KODE_dGeomTransformSetCleanup@8"
Prototype.l dGeomTransformGetCleanupP(geom.l);:"_KODE_dGeomTransformGetCleanup@4"
Prototype.l dGeomTransformSetInfoP(geom.l,mode.l);:"_KODE_dGeomTransformSetInfo@8"
Prototype.l dGeomTransformGetInfoP(geom.l);:"_KODE_dGeomTransformGetInfo@4"


Prototype.l dWorldCreateP(plane);"_KODE_dWorldCreate@0"
Prototype.l dWorldDestroyP();"_KODE_dWorldDestroy@0"
Prototype.l dWorldSetGravityP(x.f,y.f,z.f);"_KODE_dWorldSetGravity@16"
Prototype.l dWorldSetERPP(erp.f);"_KODE_dWorldSetERP@8"
Prototype.l dWorldSetCFMP(cfm.f);"_KODE_dWorldSetCFM@8"
Prototype.l dWorldSetAutoDisableFlagP(do_auto_disable.l);"_KODE_dWorldSetAutoDisableFlag@8"
Prototype.l dWorldGetAutoDisableFlagP(world);"_KODE_dWorldGetAutoDisableFlag@4"
Prototype.l dWorldSetContactSurfaceLayerP(depth.f);"_KODE_dWorldSetContactSurfaceLayer@4"
Prototype.l dWorldSetQuickStepNumIterationsP(num.l);"_KODE_dWorldSetQuickStepNumIterations@4"

Prototype.l dCloseODEP();"_KODE_dCloseODE@0"
Prototype.l dWorldStepP(stepsize.f);"_KODE_dWorldStep@4"
Prototype.l dWorldQuickStepP(stepsize.f);"_KODE_dWorldQuickStep@4"

; .f.f.f Space Functions
Prototype.l dSimpleSpaceCreateP(space);"_KODE_dSimpleSpaceCreate@4"
Prototype.l dHashSpaceCreateP(space);"_KODE_dHashSpaceCreate@4"
Prototype.l dSpaceDestroyP(space);"_KODE_dSpaceDestroy@4"
Prototype.l dSpaceAddP(space,geom);"_KODE_dSpaceAdd@8"
Prototype.l dSpaceRemoveP(space,geom);"_KODE_dSpaceRemove@8"

; .f.f.f Rigid Body Functions
Prototype.l dBodyCreateP();"_KODE_dBodyCreate@4"
Prototype.l dBodyDestroyP(body);"_KODE_dBodyDestroy@4"
Prototype.l dBodySetPositionP(body,x.f,y.f,z.f);"_KODE_dBodySetPosition@16"
Prototype.l dBodySetRotationP(body,pitch.f,yaw.f,roll.f);"_KODE_dBodySetRotation@16"
Prototype.l dBodySetLinearVelP(body,x.f,y.f,z.f);"_KODE_dBodySetLinearVel@16"
Prototype.l dBodySetAngularVelP(body,x.f,y.f,z.f);"_KODE_dBodySetAngularVel@16"
Prototype.f dBodyGetPositionXP(body);"_KODE_dBodyGetPositionX@4"
Prototype.f dBodyGetPositionYP(body);"_KODE_dBodyGetPositionY@4"
Prototype.f dBodyGetPositionZP(body);"_KODE_dBodyGetPositionZ@4"
Prototype.f dBodyGetPitchP(body);"_KODE_dBodyGetPitch@4"
Prototype.f dBodyGetYawP(body);"_KODE_dBodyGetYaw@4"
Prototype.f dBodyGetRollP(body);"_KODE_dBodyGetRoll@4"
Prototype.f dBodyGetLinearVelXP(body);"_KODE_dBodyGetLinearVelX@4"

;Prototype.l dBodySetBoxMassP(body.l,lx.f,ly.f,lz.f,mass.f);:"_KODE_dBodySetBoxMass@20"
;Prototype.l dBodySetSphereMassP(body.l,r.f,mass.f);:"_KODE_dBodySetSphereMass@12"




Prototype.f dBodyGetLinearVelYP(body);"_KODE_dBodyGetLinearVelY@4"
Prototype.f dBodyGetLinearVelZP(body);"_KODE_dBodyGetLinearVelZ@4"
Prototype.f dBodyGetAngularVelXP(body);"_KODE_dBodyGetAngularVelX@4"
Prototype.f dBodyGetAngularVelYP(body);"_KODE_dBodyGetAngularVelY@4"
Prototype.f dBodyGetAngularVelZP(body);"_KODE_dBodyGetAngularVelZ@4"
Prototype.l dBodySetMassP(body,mass);"_KODE_dBodySetMass@8"
Prototype.l dBodyGetMassP(body,mass);"_KODE_dBodyGetMass@8"
Prototype.l dBodyAddForceP(body,fx.f,fy.f,fz.f);"_KODE_dBodyAddForce@16"
Prototype.l dBodyAddTorqueP(body,fx.f,fy.f,fz.f);"_KODE_dBodyAddTorque@16"
Prototype.l dBodySetForceP(body,x.f,y.f,z.f);"_KODE_dBodySetForce@16"
Prototype.l dBodySetTorqueP(body,x.f,y.f,z.f);"_KODE_dBodySetTorque@16"
Prototype.l dBodyEnableP(body);"_KODE_dBodyEnable@4"
Prototype.l dBodyDisableP(body);"_KODE_dBodyDisable@4"
Prototype.l dBodyIsEnabledP(body);"_KODE_dBodyIsEnabled@4"
Prototype.l dBodySetAutoDisableFlagP(body,doautodisable);"_KODE_dBodySetAutoDisableFlag@8"
Prototype.l dBodyGetAutoDisableFlagP(body);"_KODE_dBodyGetAutoDisableFlag@4"
Prototype.l dBodyGetJointP(body,index);"_KODE_dBodyGetJoint@8"
Prototype.l dBodySetGravityModeP(body,mode);"_KODE_dBodySetGravityMode@8"
Prototype.l dBodyGetGravityModeP(body);"_KODE_dBodyGetGravityMode@4"

; .f.f.f Geom Functions
Prototype.l dGeomDestroyP(geom);"_KODE_dGeomDestroy@4"
Prototype.l dGeomSetBodyP(geom,body);"_KODE_dGeomSetBody@8"
Prototype.l dGeomGetBodyP(geom);"_KODE_dGeomGetBody@4"
Prototype.l dGeomSetPositionP(geom,x.f,y.f,z.f);"_KODE_dGeomSetPosition@16"
Prototype.l dGeomSetRotationP(geom,pitch.f,yaw.f,roll.f);"_KODE_dGeomSetRotation@16"
Prototype.f dGeomGetPositionXP(geom);"_KODE_dGeomGetPositionX@4"
Prototype.f dGeomGetPositionYP(geom);"_KODE_dGeomGetPositionY@4"
Prototype.f dGeomGetPositionZP(geom);"_KODE_dGeomGetPositionZ@4"
Prototype.f dGeomGetPitchP(geom);"_KODE_dGeomGetPitch@4"
Prototype.f dGeomGetYawP(geom);"_KODE_dGeomGetYaw@4"
Prototype.f dGeomGetRollP(geom);"_KODE_dGeomGetRoll@4"
Prototype.l dGeomEnableP(geom);"_KODE_dGeomEnable@4"
Prototype.l dGeomDisableP(geom);"_KODE_dGeomDisable@4"
Prototype.l dGeomIsEnabledP(geom);"_KODE_dGeomIsEnabled@4"
Prototype.l dCreateSphereP(space,radius.f);"_KODE_dCreateSphere@8"
Prototype.l dCreateBoxP(space,lx.f,ly.f,lz.f);"_KODE_dCreateBox@16"
Prototype.l dCreatePlaneP(space,a.f,b.f,c.f,d.f);"_KODE_dCreatePlane@20"
Prototype.l dCreateCylinderP(space,radius.f,length.f);"_KODE_dCreateCylinder@12"
Prototype.l dCreateCCylinderP(space,radius.f,length.f);"_KODE_dCreateCCylinder@12"

; .f.f.f Joint Functions
Prototype.l dJointCreateBallP(world,group);"_KODE_dJointCreateBall@8"
Prototype.l dJointCreateHingeP(world,group);"_KODE_dJointCreateHinge@8"
Prototype.l dJointCreateSliderP(world,group);"_KODE_dJointCreateSlider@8"
Prototype.l dJointCreateUniversalP(world,group);"_KODE_dJointCreateUniversal@8"
Prototype.l dJointCreateHinge2P();"_KODE_dJointCreateHinge2@0"
Prototype.l dJointCreateFixedP(world,group);"_KODE_dJointCreateFixed@8"
Prototype.l dJointCreateAMotorP(world,group);"_KODE_dJointCreateAMotor@8"
Prototype.l dJointDestroyP(joint);"_KODE_dJointDestroy@4"
Prototype.l dJointGroupCreateP(maxsize);"_KODE_dJointGroupCreate@4"
Prototype.l dJointGroupDestroyP(group);"_KODE_dJointGroupDestroy@4"
Prototype.l dJointGroupEmptyP(group);"_KODE_dJointGroupEmpty@4"
Prototype.l dJointAttachP(joint,body1,body2);"_KODE_dJointAttach@12"
Prototype.l dJointSetDataP(joint,jData);"_KODE_dJointSetData@8"
Prototype.l dJointGetDataP(joint);"_KODE_dJointGetData@4"
Prototype.l dJointGetTypeP(joint);"_KODE_dJointGetType@4"
Prototype.l dJointGetBodyP(joint,index);"_KODE_dJointGetBody@8"
Prototype.l dAreConnectedP(body1,body2);"_KODE_dAreConnected@8"
Prototype.l dAreConnectedExcludingP(body1,body2,jointtype);"_KODE_dAreConnectedExcluding@12"
Prototype.l dJointSetBallAnchorP(joint,x.f,y.f,z.f);"_KODE_dJointSetBallAnchor@16"
Prototype.l dJointSetHingeAnchorP(joint,x.f,y.f,z.f);"_KODE_dJointSetHingeAnchor@16"
Prototype.l dJointSetHingeAxisP(joint,x.f,y.f,z.f);"_KODE_dJointSetHingeAxis@16"
Prototype.f dJointGetHingeAngleP(joint);"_KODE_dJointGetHingeAngle@4"
Prototype.f dJointGetHingeAngleRateP(joint);"_KODE_dJointGetHingeAngleRate@4"
Prototype.l dJointSetSliderAxisP(joint,x.f,y.f,z.f);"_KODE_dJointSetSliderAxis@16"
Prototype.f dJointGetSliderPositionP(joint);"_KODE_dJointGetSliderPosition@4"
Prototype.f dJointGetSliderPositionRateP(joint);"_KODE_dJointGetSliderPositionRate@4"
Prototype.l dJointSetUniversalAnchorP(joint,x.f,y.f,z.f);"_KODE_dJointSetUniversalAnchor@16"
Prototype.l dJointSetUniversalAxis1P(joint,x.f,y.f,z.f);"_KODE_dJointSetUniversalAxis1@16"
Prototype.l dJointSetUniversalAxis2P(joint,x.f,y.f,z.f);"_KODE_dJointSetUniversalAxis2@16"
Prototype.l dJointSetHinge2AnchorP(joint,x.f,y.f,z.f);"_KODE_dJointSetHinge2Anchor@16"
Prototype.l dJointSetHinge2Axis1P(joint,x.f,y.f,z.f);"_KODE_dJointSetHinge2Axis1@16"
Prototype.l dJointSetHinge2Axis2P(joint,x.f,y.f,z.f);"_KODE_dJointSetHinge2Axis2@16"
Prototype.f dJointGetHinge2Angle1P(joint);"_KODE_dJointGetHinge2Angle1@4"
Prototype.f dJointGetHinge2Angle1RateP(joint);"_KODE_dJointGetHinge2Angle1Rate@4"
Prototype.f dJointGetHinge2Angle2RateP(joint);"_KODE_dJointGetHinge2Angle2Rate@4"
Prototype.l dJointSetFixedP(joint);"_KODE_dJointSetFixed@4"
Prototype.l dJointSetAMotorModeP(joint,mode);"_KODE_dJointSetAMotorMode@8"
Prototype.l dJointGetAMotorModeP(joint);"_KODE_dJointGetAMotorMode@4"
Prototype.l dJointSetAMotorNumAxesP(joint,num);"_KODE_dJointSetAMotorNumAxes@8"
Prototype.l dJointGetAMotorNumAxesP(joint);"_KODE_dJointGetAMotorNumAxes@4"
Prototype.l dJointSetAMotorAxisP(joint,num,rel,x.f,y.f,z.f);"_KODE_dJointSetAMotorAxis@24"
Prototype.l dJointGetAMotorAxisRelP(joint,num);"_KODE_dJointGetAMotorAxisRel@8"
Prototype.l dJointSetAMotorAngleP(joint,num,angle.f);"_KODE_dJointSetAMotorAngle@12"
Prototype.f dJointGetAMotorAngleP(joint,num);"_KODE_dJointGetAMotorAngle@8"
Prototype.f dJointGetAMotorAngleRateP(joint,num);"_KODE_dJointGetAMotorAngleRate@8"
Prototype.l dJointSetHingeParamP(joint,param,value.f);"_KODE_dJointSetHingeParam@12"
Prototype.l dJointSetSliderParamP(joint,param,value.f);"_KODE_dJointSetSliderParam@12"
Prototype.l dJointSetHinge2ParamP(joint,param,value.f);"_KODE_dJointSetHinge2Param@12"
Prototype.l dJointSetUniversalParamP(joint,param,value.f);"_KODE_dJointSetUniversalParam@12"
Prototype.l dJointSetAMotorParamP(joint,param,value.f);"_KODE_dJointSetAMotorParam@12"
Prototype.f dJointGetHingeParamP(joint,param);"_KODE_dJointGetHingeParam@8"
Prototype.f dJointGetSliderParamP(joint,param);"_KODE_dJointGetSliderParam@8"
Prototype.f dJointGetHinge2ParamP(joint,param);"_KODE_dJointGetHinge2Param@8"
Prototype.f dJointGetUniversalParamP(joint,param);"_KODE_dJointGetUniversalParam@8"
Prototype.f dJointGetAMotorParamP(joint,param);"_KODE_dJointGetAMotorParam@8"
Prototype.l dJointAddHingeTorqueP(joint,torque.f);"_KODE_dJointAddHingeTorque@8"
Prototype.l dJointAddUniversalTorquesP(joint,torque1.f,torque2.f);"_KODE_dJointAddUniversalTorques@12"
Prototype.l dJointAddSliderForceP(joint,force.f);"_KODE_dJointAddSliderForce@8"
Prototype.l dJointAddHinge2TorquesP(joint,torque1.f,torque2.f);"_KODE_dJointAddHinge2Torques@12"
Prototype.l dJointAddAMotorTorquesP(joint,torque0.f,torque1.f,torque2.f);"_KODE_dJointAddAMotorTorques@16"

; .f.f.f Mass Functions
Prototype.l dMassCreateP();"_KODE_dMassCreate@0"
Prototype.l dMassDestroyP(mass);"_KODE_dMassDestroy@4"
Prototype.l dMassSetZeroP(mass);"_KODE_dMassSetZero@4"
Prototype.l dMassSetParametersP(mass,themass.f,cgx.f,cgy.f,cgz.f,I11.f,I22.f,I33.f,I12.f,I13.f,I23.f);"_KODE_dMassSetParameters@44"
Prototype.l dMassSetSphereP(mass,density.f,radius.f);"_KODE_dMassSetSphere@12"
Prototype.l dMassSetSphereTotalP(mass,totalmass.f,radius.f);"_KODE_dMassSetSphereTotal@12"
Prototype.l dMassSetCappedCylinderP(mass,density.f,direction,radius.f,length.f);"_KODE_dMassSetCappedCylinder@20"
Prototype.l dMassSetCappedCylinderTotalP(mass,totalmass.f,direction,radius.f,length.f);"_KODE_dMassSetCappedCylinderTotal@20"
Prototype.l dMassSetCylinderP(mass,density.f,direction,radius.f,length.f);"_KODE_dMassSetCylinder@20"
Prototype.l dMassSetCylinderTotalP(mass,totalmass.f,direction,radius.f,length.f);"_KODE_dMassSetCylinderTotal@20"
Prototype.l dMassSetBoxP(mass,density.f,lx.f,ly.f,lz.f);"_KODE_dMassSetBox@20"
Prototype.l dMassSetBoxTotalP(mass,totalmass.f,lx.f,ly.f,lz.f);"_KODE_dMassSetBoxTotal@20"
Prototype.l dMassAdjustP(mass,newmass.f);"_KODE_dMassAdjust@8"
Prototype.l dMassTranslateP(mass,x.f,y.f,z.f);"_KODE_dMassTranslate@16"
Prototype.l dMassAddP(massa,massb);"_KODE_dMassAdd@8"
Prototype.l dBodyTranslateMassP(body.l, x.f, y.f, z.f);:"_KODE_dBodyTranslateMass@16"

; .f.f.f Collision Detection Functions
Prototype.l dSpaceCollideP(space);"_KODE_dSpaceCollide@4"
Prototype.l dSpaceCollide2P(geom1,geom2);"_KODE_dSpaceCollide2@8"

; .f.f.f Contact Functions P(NEW! Not available in the standard ODE)
Prototype.l dContactSetMaxContactsP(max);"_KODE_dContactSetMaxContacts@4"
Prototype.l dContactGetMaxContactsP();"_KODE_dContactGetMaxContacts@0"
Prototype.l dContactSetModeP(mode);"_KODE_dContactSetMode@4"
Prototype.l dContactGetModeP();"_KODE_dContactGetMode@0"
Prototype.l dContactSetMuP(mu.f);"_KODE_dContactSetMu@4"
Prototype.f dContactGetMuP();"_KODE_dContactGetMu@0"
Prototype.l dContactSetMu2P(mu.f);"_KODE_dContactSetMu2@4"
Prototype.f dContactGetMu2P();"_KODE_dContactGetMu2@0"
Prototype.l dContactSetBounceP(bounce.f);"_KODE_dContactSetBounce@4"
Prototype.f dContactGetBounceP();"_KODE_dContactGetBounce@0"
Prototype.l dContactSetBounceVelP(vel.f);"_KODE_dContactSetBounceVel@4"
Prototype.f dContactGetBounceVelP();"_KODE_dContactGetBounceVel@0"
Prototype.l dContactSetSoftERPP(erp.f);"_KODE_dContactSetSoftERP@4"
Prototype.f dContactGetSoftERPP();"_KODE_dContactGetSoftERP@0"
Prototype.l dContactSetSoftCFMP(cfm.f);"_KODE_dContactSetSoftCFM@4"
Prototype.f dContactGetSoftCFMP();"_KODE_dContactGetSoftCFM@0"
Prototype.l dContactSetMotion1P(motion.f);"_KODE_dContactSetMotion1@4"
Prototype.f dContactGetMotion1P();"_KODE_dContactGetMotion1@0"
Prototype.l dContactSetMotion2P(motion.f);"_KODE_dContactSetMotion2@4"
Prototype.f dContactGetMotion2P();"_KODE_dContactGetMotion2@0"
Prototype.l dContactSetSlip1P(slip.f);"_KODE_dContactSetSlip1@4"
Prototype.f dContactGetSlip1P();"_KODE_dContactGetSlip1@0"
Prototype.l dContactSetSlip2P(slip.f);"_KODE_dContactSetSlip2@4"
Prototype.f dContactGetSlip2P();"_KODE_dContactGetSlip2@0"





  

  DLL=OpenLibrary(#PB_Any, "BlitzKODE.dll")


  If DLL
  
Global    dBodyGetAngularVelX.dBodyGetAngularVelXP = GetFunction(DLL,  "_KODE_dBodyGetAngularVelX@4")
Global    dBodyGetAngularVelY.dBodyGetAngularVelYP = GetFunction(DLL,  "_KODE_dBodyGetAngularVelY@4")
Global    dBodyGetAngularVelZ.dBodyGetAngularVelZP = GetFunction(DLL,  "_KODE_dBodyGetAngularVelZ@4")
Global    dBodySetAngularVel.dBodySetAngularVelP = GetFunction(DLL, "_KODE_dBodySetAngularVel@16")

  
    ;MASAS TOTALES
Global    dBodySetBoxMass.dBodySetBoxMassP = GetFunction(DLL, "_KODE_dBodySetBoxMass@20")
Global    dBodySetSphereMass.dBodySetSphereMassP = GetFunction(DLL, "_KODE_dBodySetSphereMass@12")
Global    dBodySetCCylinderMass.dBodySetCCylinderMassP = GetFunction(DLL, "_KODE_dBodySetCCylinderMass@16")
Global    dBodySetCylinderMass.dBodySetCylinderMassP = GetFunction(DLL, "_KODE_dBodySetCylinderMass@16")

    ;GEOM TRANSFORM
Global    dCreateGeomTransform.dCreateGeomTransformP = GetFunction(DLL, "_KODE_dCreateGeomTransform@4")
Global    dGeomTransformSetGeom.dGeomTransformSetGeomP = GetFunction(DLL, "_KODE_dGeomTransformSetGeom@8")
Global    dGeomTransformGetGeom.dGeomTransformGetGeomP = GetFunction(DLL, "_KODE_dGeomTransformGetGeom@4")
Global    dGeomTransformSetCleanup.dGeomTransformSetCleanupP = GetFunction(DLL, "_KODE_dGeomTransformSetCleanup@8")
Global    dGeomTransformGetCleanup.dGeomTransformGetCleanupP = GetFunction(DLL, "_KODE_dGeomTransformGetCleanup@4")
Global    dGeomTransformSetInfo.dGeomTransformSetInfoP = GetFunction(DLL, "_KODE_dGeomTransformSetInfo@8")
Global    dGeomTransformGetInfo.dGeomTransformGetInfoP = GetFunction(DLL, "_KODE_dGeomTransformGetInfo@4")

      

    dAreConnected = GetFunction(DLL, "_KODE_dAreConnected@8")
    dAreConnectedExcluding = GetFunction(DLL, "_KODE_dAreConnectedExcluding@12")
    dBodyAddForce = GetFunction(DLL, "_KODE_dBodyAddForce@16")
    dBodyAddTorque = GetFunction(DLL, "_KODE_dBodyAddTorque@16")
Global    dBodyCreate.dBodyCreateP = GetFunction(DLL, "_KODE_dBodyCreate@0")
    dBodyDestroy = GetFunction(DLL, "_KODE_dBodyDestroy@4")
    dBodyDisable = GetFunction(DLL, "_KODE_dBodyDisable@4")
Global    dBodyEnable.dBodyEnableP = GetFunction(DLL, "_KODE_dBodyEnable@4")
    dBodyGetAngularVelX = GetFunction(DLL, "_KODE_dBodyGetAngularVelX@4")
    dBodyGetAngularVelY = GetFunction(DLL, "_KODE_dBodyGetAngularVelY@4")
    dBodyGetAngularVelZ = GetFunction(DLL, "_KODE_dBodyGetAngularVelZ@4")
    dBodyGetAutoDisableFlag = GetFunction(DLL, "_KODE_dBodyGetAutoDisableFlag@4")
    dBodyGetGravityMode = GetFunction(DLL, "_KODE_dBodyGetGravityMode@4")
    dBodyGetJoint = GetFunction(DLL, "_KODE_dBodyGetJoint@8")
    dBodyGetLinearVelX = GetFunction(DLL, "_KODE_dBodyGetLinearVelX@4")
    dBodyGetLinearVelY = GetFunction(DLL, "_KODE_dBodyGetLinearVelY@4")
    dBodyGetLinearVelZ = GetFunction(DLL, "_KODE_dBodyGetLinearVelZ@4")
    dBodyGetMass = GetFunction(DLL, "_KODE_dBodyGetMass@8")
Global    dBodySetBoxMass.dBodySetBoxMassP = GetFunction(DLL, "_KODE_dBodySetBoxMass@20")
Global    dBodyGetPitch.dBodyGetPitchP = GetFunction(DLL, "_KODE_dBodyGetPitch@4")
Global    dBodyGetPositionX.dBodyGetPositionXP = GetFunction(DLL, "_KODE_dBodyGetPositionX@4")
Global    dBodyGetPositionY.dBodyGetPositionYP = GetFunction(DLL, "_KODE_dBodyGetPositionY@4")
Global    dBodyGetPositionZ.dBodyGetPositionZP = GetFunction(DLL, "_KODE_dBodyGetPositionZ@4")
Global    dBodyGetRoll.dBodyGetRollP = GetFunction(DLL, "_KODE_dBodyGetRoll@4")
Global    dBodyGetYaw.dBodyGetYawP = GetFunction(DLL, "_KODE_dBodyGetYaw@4")
Global    dBodyIsEnabled.dBodyIsEnabledP = GetFunction(DLL, "_KODE_dBodyIsEnabled@4")
    dBodySetAngularVel = GetFunction(DLL, "_KODE_dBodySetAngularVel@16")
Global    dBodySetAutoDisableFlag.dBodySetAutoDisableFlagP = GetFunction(DLL, "_KODE_dBodySetAutoDisableFlag@8")
    dBodySetForce = GetFunction(DLL, "_KODE_dBodySetForce@16")
    dBodySetGravityMode = GetFunction(DLL, "_KODE_dBodySetGravityMode@8")
    dBodySetLinearVel = GetFunction(DLL, "_KODE_dBodySetLinearVel@16")
    dBodySetMass.dBodySetMassP = GetFunction(DLL, "_KODE_dBodySetMass@8")
Global    dBodySetPosition.dBodySetPositionP = GetFunction(DLL, "_KODE_dBodySetPosition@16")
Global    dBodySetRotation.dBodySetRotationP = GetFunction(DLL, "_KODE_dBodySetRotation@16")
    dBodySetTorque.dBodySetTorqueP = GetFunction(DLL, "_KODE_dBodySetTorque@16")
    dCloseode.dCloseodeP = GetFunction(DLL, "_KODE_dCloseODE@0")
    dContactGetBounce = GetFunction(DLL, "_KODE_dContactGetBounce@0")
    dContactGetBounceVel = GetFunction(DLL, "_KODE_dContactGetBounceVel@0")
    dContactGetMaxContacts = GetFunction(DLL, "_KODE_dContactGetMaxContacts@0")
    dContactGetMode = GetFunction(DLL, "_KODE_dContactGetMode@0")
    dContactGetMotion1 = GetFunction(DLL, "_KODE_dContactGetMotion1@0")
    dContactGetMotion2 = GetFunction(DLL, "_KODE_dContactGetMotion2@0")
    dContactGetMu2 = GetFunction(DLL, "_KODE_dContactGetMu2@0")
    dContactGetMu = GetFunction(DLL, "_KODE_dContactGetMu@0")
    dContactGetSlip1 = GetFunction(DLL, "_KODE_dContactGetSlip1@0")
    dContactGetSlip2 = GetFunction(DLL, "_KODE_dContactGetSlip2@0")
    dContactGetSoftCFM = GetFunction(DLL, "_KODE_dContactGetSoftCFM@0")
    dContactGetSoftERP = GetFunction(DLL, "_KODE_dContactGetSoftERP@0")
    dContactSetBounce.dContactSetBounceP = GetFunction(DLL, "_KODE_dContactSetBounce@4")
    dContactSetBounceVel = GetFunction(DLL, "_KODE_dContactSetBounceVel@4")
    dContactSetMaxContacts = GetFunction(DLL, "_KODE_dContactSetMaxContacts@4")
    dContactSetMode.dContactSetModeP = GetFunction(DLL, "_KODE_dContactSetMode@4")
    dContactSetMotion1 = GetFunction(DLL, "_KODE_dContactSetMotion1@4")
    dContactSetMotion2 = GetFunction(DLL, "_KODE_dContactSetMotion2@4")
    dContactSetMu2 = GetFunction(DLL, "_KODE_dContactSetMu2@4")
    dContactSetMu.dContactSetMuP = GetFunction(DLL, "_KODE_dContactSetMu@4")
    dContactSetSlip1 = GetFunction(DLL, "_KODE_dContactSetSlip1@4")
    dContactSetSlip2 = GetFunction(DLL, "_KODE_dContactSetSlip2@4")
    dContactSetSoftCFM = GetFunction(DLL, "_KODE_dContactSetSoftCFM@4")
    dContactSetSoftERP = GetFunction(DLL, "_KODE_dContactSetSoftERP@4")
Global    dCreateBox.dCreateBoxP = GetFunction(DLL, "_KODE_dCreateBox@16")
Global    dCreateCCylinder.dCreateCCylinderP = GetFunction(DLL, "_KODE_dCreateCCylinder@12")
Global    dCreateCylinder.dCreateCylinderP = GetFunction(DLL, "_KODE_dCreateCylinder@12")
Global    dCreatePlane.dCreatePlaneP = GetFunction(DLL, "_KODE_dCreatePlane@20")
Global    dCreateSphere.dCreateSphereP = GetFunction(DLL, "_KODE_dCreateSphere@8")
Global    dDemoTime.dDemoTimeP = GetFunction(DLL, "_KODE_dDemoTime@0")
    dGeomDestroy = GetFunction(DLL, "_KODE_dGeomDestroy@4")
    dGeomDisable = GetFunction(DLL, "_KODE_dGeomDisable@4")
    dGeomEnable = GetFunction(DLL, "_KODE_dGeomEnable@4")
Global    dGeomGetBody.dGeomGetBodyP = GetFunction(DLL, "_KODE_dGeomGetBody@4")
Global    dGeomGetPitch.dGeomGetPitchP = GetFunction(DLL, "_KODE_dGeomGetPitch@4")
Global    dGeomGetPositionX.dGeomGetPositionXP = GetFunction(DLL, "_KODE_dGeomGetPositionX@4")
Global    dGeomGetPositionY.dGeomGetPositionYP = GetFunction(DLL, "_KODE_dGeomGetPositionY@4")
Global    dGeomGetPositionZ.dGeomGetPositionZP = GetFunction(DLL, "_KODE_dGeomGetPositionZ@4")
Global    dGeomGetRoll.dGeomGetRollP = GetFunction(DLL, "_KODE_dGeomGetRoll@4")
Global    dGeomGetYaw.dGeomGetYawP = GetFunction(DLL, "_KODE_dGeomGetYaw@4")
Global    dGeomIsEnabled.dGeomIsEnabledP = GetFunction(DLL, "_KODE_dGeomIsEnabled@4")
Global    dGeomSetBody.dGeomSetBodyP = GetFunction(DLL, "_KODE_dGeomSetBody@8")
    dGeomSetPosition.dGeomSetPositionP = GetFunction(DLL, "_KODE_dGeomSetPosition@16")
    dGeomSetRotation.dGeomSetRotationP = GetFunction(DLL, "_KODE_dGeomSetRotation@16")
    dGetVersion.dGetVersionP= GetFunction(DLL, "_KODE_dGetVersion@0")
    dHashSpaceCreate.dHashSpaceCreateP = GetFunction(DLL, "_KODE_dHashSpaceCreate@4")
    dJointAddAMotorTorques = GetFunction(DLL, "_KODE_dJointAddAMotorTorques@16")
    dJointAddHinge2Torques = GetFunction(DLL, "_KODE_dJointAddHinge2Torques@12")
    dJointAddHingeTorque = GetFunction(DLL, "_KODE_dJointAddHingeTorque@8")
    dJointAddSliderForce = GetFunction(DLL, "_KODE_dJointAddSliderForce@8")
    dJointAddUniversalTorques = GetFunction(DLL, "_KODE_dJointAddUniversalTorques@12")
Global    dJointAttach.dJointAttachP = GetFunction(DLL, "_KODE_dJointAttach@12")
    dJointCreateAMotor = GetFunction(DLL, "_KODE_dJointCreateAMotor@8")
    dJointCreateBall = GetFunction(DLL, "_KODE_dJointCreateBall@8")
    dJointCreateFixed = GetFunction(DLL, "_KODE_dJointCreateFixed@8")
Global    dJointCreateHinge2.dJointCreateHinge2P = GetFunction(DLL, "_KODE_dJointCreateHinge2@0")
    dJointCreateHinge = GetFunction(DLL, "_KODE_dJointCreateHinge@8")
    dJointCreateSlider = GetFunction(DLL, "_KODE_dJointCreateSlider@8")
    dJointCreateUniversal = GetFunction(DLL, "_KODE_dJointCreateUniversal@8")
    dJointDestroy = GetFunction(DLL, "_KODE_dJointDestroy@4")
    dJointGetAMotorAngle = GetFunction(DLL, "_KODE_dJointGetAMotorAngle@8")
    dJointGetAMotorAngleRate = GetFunction(DLL, "_KODE_dJointGetAMotorAngleRate@8")
    dJointGetAMotorAxisRel = GetFunction(DLL, "_KODE_dJointGetAMotorAxisRel@8")
    dJointGetAMotorMode = GetFunction(DLL, "_KODE_dJointGetAMotorMode@4")
    dJointGetAMotorNumAxes = GetFunction(DLL, "_KODE_dJointGetAMotorNumAxes@4")
    dJointGetAMotorParam = GetFunction(DLL, "_KODE_dJointGetAMotorParam@8")
    dJointGetBody = GetFunction(DLL, "_KODE_dJointGetBody@8")
    dJointGetData = GetFunction(DLL, "_KODE_dJointGetData@4")
Global    dJointGetHinge2Angle1.dJointGetHinge2Angle1P = GetFunction(DLL, "_KODE_dJointGetHinge2Angle1@4")
    dJointGetHinge2Angle1Rate = GetFunction(DLL, "_KODE_dJointGetHinge2Angle1Rate@4")
    dJointGetHinge2Angle2Rate = GetFunction(DLL, "_KODE_dJointGetHinge2Angle2Rate@4")
    dJointGetHinge2Param = GetFunction(DLL, "_KODE_dJointGetHinge2Param@8")
    dJointGetHingeAngle = GetFunction(DLL, "_KODE_dJointGetHingeAngle@4")
    dJointGetHingeAngleRate = GetFunction(DLL, "_KODE_dJointGetHingeAngleRate@4")
    dJointGetHingeParam = GetFunction(DLL, "_KODE_dJointGetHingeParam@8")
    dJointGetSliderParam = GetFunction(DLL, "_KODE_dJointGetSliderParam@8")
    dJointGetSliderPosition = GetFunction(DLL, "_KODE_dJointGetSliderPosition@4")
    dJointGetSliderPositionRate = GetFunction(DLL, "_KODE_dJointGetSliderPositionRate@4")
    dJointGetType = GetFunction(DLL, "_KODE_dJointGetType@4")
    dJointGetUniversalParam = GetFunction(DLL, "_KODE_dJointGetUniversalParam@8")
Global    dJointGroupCreate.dJointGroupCreateP = GetFunction(DLL, "_KODE_dJointGroupCreate@4")
Global    dJointGroupDestroy.dJointGroupDestroyP = GetFunction(DLL, "_KODE_dJointGroupDestroy@4")
Global    dJointGroupEmpty.dJointGroupEmptyP = GetFunction(DLL, "_KODE_dJointGroupEmpty@4")
    dJointSetAMotorAngle = GetFunction(DLL, "_KODE_dJointSetAMotorAngle@12")
    dJointSetAMotorAxis = GetFunction(DLL, "_KODE_dJointSetAMotorAxis@24")
    dJointSetAMotorMode = GetFunction(DLL, "_KODE_dJointSetAMotorMode@8")
    dJointSetAMotorNumAxes = GetFunction(DLL, "_KODE_dJointSetAMotorNumAxes@8")
    dJointSetAMotorParam = GetFunction(DLL, "_KODE_dJointSetAMotorParam@12")
    dJointSetBallAnchor = GetFunction(DLL, "_KODE_dJointSetBallAnchor@16")
    dJointSetData = GetFunction(DLL, "_KODE_dJointSetData@8")
    dJointSetFixed = GetFunction(DLL, "_KODE_dJointSetFixed@4")
Global    dJointSetHinge2Anchor.dJointSetHinge2AnchorP = GetFunction(DLL, "_KODE_dJointSetHinge2Anchor@16")
Global    dJointSetHinge2Axis1.dJointSetHinge2Axis1P = GetFunction(DLL, "_KODE_dJointSetHinge2Axis1@16")
Global    dJointSetHinge2Axis2.dJointSetHinge2Axis2P = GetFunction(DLL, "_KODE_dJointSetHinge2Axis2@16")
Global    dJointSetHinge2Param.dJointSetHinge2ParamP = GetFunction(DLL, "_KODE_dJointSetHinge2Param@12")
    dJointSetHingeAnchor = GetFunction(DLL, "_KODE_dJointSetHingeAnchor@16")
    dJointSetHingeAxis = GetFunction(DLL, "_KODE_dJointSetHingeAxis@16")
    dJointSetHingeParam = GetFunction(DLL, "_KODE_dJointSetHingeParam@12")
    dJointSetSliderAxis = GetFunction(DLL, "_KODE_dJointSetSliderAxis@16")
    dJointSetSliderParam = GetFunction(DLL, "_KODE_dJointSetSliderParam@12")
    dJointSetUniversalAnchor = GetFunction(DLL, "_KODE_dJointSetUniversalAnchor@16")
    dJointSetUniversalAxis1 = GetFunction(DLL, "_KODE_dJointSetUniversalAxis1@16")
    dJointSetUniversalAxis2 = GetFunction(DLL, "_KODE_dJointSetUniversalAxis2@16")
    dJointSetUniversalParam = GetFunction(DLL, "_KODE_dJointSetUniversalParam@12")
    dMassAdd = GetFunction(DLL, "_KODE_dMassAdd@8")
    dMassAdjust = GetFunction(DLL, "_KODE_dMassAdjust@8")
    dMassCreate.dMassCreateP = GetFunction(DLL, "_KODE_dMassCreate@0")
    dMassDestroy.dMassDestroyP = GetFunction(DLL, "_KODE_dMassDestroy@4")
    dMassSetBox = GetFunction(DLL, "_KODE_dMassSetBox@20")
    dMassSetBoxTotal.dMassSetBoxTotalP = GetFunction(DLL, "_KODE_dMassSetBoxTotal@20")
    dMassSetCappedCylinder = GetFunction(DLL, "_KODE_dMassSetCappedCylinder@20")
    dMassSetCappedCylinderTotal = GetFunction(DLL, "_KODE_dMassSetCappedCylinderTotal@20")
    dMassSetCylinder = GetFunction(DLL, "_KODE_dMassSetCylinder@20")
    dMassSetCylinderTotal = GetFunction(DLL, "_KODE_dMassSetCylinderTotal@20")
    dMassSetParameters = GetFunction(DLL, "_KODE_dMassSetParameters@44")
    dMassSetSphere = GetFunction(DLL, "_KODE_dMassSetSphere@12")
    dMassSetSphereTotal.dMassSetSphereTotalP = GetFunction(DLL, "_KODE_dMassSetSphereTotal@12")
    dMassSetZero = GetFunction(DLL, "_KODE_dMassSetZero@4")
    dMassTranslate.dMassTranslateP = GetFunction(DLL, "_KODE_dMassTranslate@16")
    dBodyTranslateMass.dBodyTranslateMassP = GetFunction(DLL, "_KODE_dBodyTranslateMass@16")

    dSimpleSpaceCreate = GetFunction(DLL, "_KODE_dSimpleSpaceCreate@4")
    dSpaceAdd.dSpaceAddP = GetFunction(DLL, "_KODE_dSpaceAdd@8")
    dSpaceCollide2 = GetFunction(DLL, "_KODE_dSpaceCollide2@16")
Global    dSpaceCollide.dSpaceCollideP = GetFunction(DLL, "_KODE_dSpaceCollide@4")
Global    dSpaceDestroy.dSpaceDestroyP = GetFunction(DLL, "_KODE_dSpaceDestroy@4")
    dSpaceRemove = GetFunction(DLL, "_KODE_dSpaceRemove@8")
Global    dWorldCreate.dWorldCreateP = GetFunction(DLL, "_KODE_dWorldCreate@4")
Global    dWorldDestroy.dWorldDestroyP = GetFunction(DLL, "_KODE_dWorldDestroy@0")
    dWorldGetAutoDisableFlag = GetFunction(DLL, "_KODE_dWorldGetAutoDisableFlag@4")
Global    dWorldQuickStep.dWorldQuickStepP = GetFunction(DLL, "_KODE_dWorldQuickStep@4")
Global    dWorldSetAutoDisableFlag.dWorldSetAutoDisableFlagP = GetFunction(DLL, "_KODE_dWorldSetAutoDisableFlag@4")
Global    dWorldSetCFM.dWorldSetCFMP = GetFunction(DLL, "_KODE_dWorldSetCFM@4")
Global    dWorldSetERP.dWorldSetERPP = GetFunction(DLL, "_KODE_dWorldSetERP@4")
Global    dWorldSetGravity.dWorldSetGravityP = GetFunction(DLL, "_KODE_dWorldSetGravity@12")
Global    dWorldStep.dWorldStepP = GetFunction(DLL, "_KODE_dWorldStep@8")
Global    dWorldSetContactSurfaceLayer.dWorldSetContactSurfaceLayerP = GetFunction(DLL, "_KODE_dWorldSetContactSurfaceLayer@4")
Global    dWorldSetQuickStepNumIterations.dWorldSetQuickStepNumIterationsP = GetFunction(DLL, "_KODE_dWorldSetQuickStepNumIterations@4")
Global    dSetMU.dSetMUP = GetFunction(DLL, "_KODE_dSetMU@4")
Global    dSetMU2.dSetMU2P = GetFunction(DLL, "_KODE_dSetMU2@4")
Global    dSetBOUNCE.dSetBOUNCEP = GetFunction(DLL, "_KODE_dSetBOUNCE@4")
Global    dSetBOUNCE_VEL.dSetBOUNCE_VELP = GetFunction(DLL, "_KODE_dSetBOUNCE_VEL@4")
Global    dSetSLIP1.dSetSLIP1P = GetFunction(DLL, "_KODE_dSetSLIP1@4")
Global    dSetSLIP2.dSetSLIP2P = GetFunction(DLL, "_KODE_dSetSLIP2@4")
Global    dSetSOFT_ERP.dSetSOFT_ERPP =  GetFunction(DLL, "_KODE_dSetSOFT_ERP@4")
Global    dSetSOFT_CFM.dSetSOFT_CFMP = GetFunction(DLL, "_KODE_dSetSOFT_CFM@4")
Global    dSetMOTION1.dSetMOTION1P = GetFunction(DLL, "_KODE_dSetMOTION1@4")
Global    dSetMOTION2.dSetMOTION2P = GetFunction(DLL, "_KODE_dSetMOTION2@4")
;MAXCONTACTS
Global    dSetMaxContacts.dSetMaxContactsP = GetFunction(DLL, "_KODE_dSetMaxContacts@4")
Global    dGetMaxContacts.dGetMaxContactsP = GetFunction(DLL, "_KODE_dGetMaxContacts@0")

  Else
    MessageRequester("Error!","Cannot find DLL!")  
  EndIf
  
Last edited by dontmailme on Thu Mar 02, 2006 8:10 pm, edited 1 time in total.
Paid up PB User !
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Thank you very much. I am very tempted to buy K[ODE].... Your code is very usefull.
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

Here is an Example using the KODE Wrapper.

It was converted from some Blitz code written by Jim Williams.

It has a Car, Cylinders, Boxes and Spheres all colliding with each other and the Plane they sit on.

The full KODE Wrapper has many more functions available and includes trimesh collisions which I have tested using the circuit mesh (from OGRE).

KODE demo can be found here http://www.lcuriel.arrakis.es/kode/kodedemo105.zip

Hope it's useful to you.

Link to Media.....

http://www.upload2.com/?cmd=_viewer&fil ... ip&s=1303e

The code ( An example, not supposed to be pretty or efficient! :D )

Code: Select all

;- Constants

IncludeFile  "KODE.pbi"

;### The maximum number of user classes that are supported
Global dMaxUserClasses=4

;### Geometry classes
Global dSphereClass=0
Global dBoxClass=1
Global dCCylinderClass=2
Global dCylinderClass=3
Global dPlaneClass=4
Global dRayClass=5
Global dGeomTransformClass=6
Global dTriMeshClass=7
Global dFirstSpaceClass=8
Global dSimpleSpaceClass=dFirstSpaceClass
Global dHashSpaceClass=9
Global dQuadTreeSpaceClass=10
Global dLastSpaceClass=dQuadTreeSpaceClass
Global dFirstUserClass=11
Global dLastUserClass=dFirstUserClass+dMaxUserClasses-1
Global dGeomNumClasses=dFirstUserClass+dMaxUserClasses

;### Joint types
Global dJointTypeNone=0
Global dJointTypeBall=1
Global dJointTypeHinge=2
Global dJointTypeSlider=3
Global dJointTypeContact=4
Global dJointTypeUniversal=5
Global dJointTypeHinge2=6
Global dJointTypeFixed=7
Global dJointTypeNull=8
Global dJointTypeAMotor=9

;### Motor modes
Global dAMotorUser=0
Global dAMotorEuler=1

;### Joint parameters
Global dParamLoStop=0
Global dParamHiStop=1
Global dParamVel=2
Global dParamFMax=3
Global dParamFudgeFactor=4
Global dParamBounce=5
Global dParamCFM=6
Global dParamStopERP=7
Global dParamStopCFM=8
Global dParamSuspensionERP=9
Global dParamSuspensionCFM=10
Global dParamVel2=$100+2
Global dParamFMax2=$100+3

;### Contact modes
Global dContactMu2=$001
Global dContactFDir1=$002
Global dContactBounce=$004
Global dContactSoftERP=$008
Global dContactSoftCFM=$010
Global dContactMotion1=$020
Global dContactMotion2=$040
Global dContactSlip1=$080
Global dContactSlip2=$100
Global dContactApprox0=$0000
Global dContactApprox1_1=$1000
Global dContactApprox1_2=$2000
Global dContactApprox1=$3000

Global dInfinity.q=340282357000000.0

Global Coast

; ###################################################################################################

If InitEngine3D()

  Add3DArchive("Data"        , #PB_3DArchive_FileSystem)
  
  Parse3DScripts()

  InitSprite()
  InitKeyboard()
  
  win=OpenWindow(#PB_Any, 10,10,800,600,#PB_Window_TitleBar,"Test")
  OpenWindowedScreen(WindowID( win),0,0,800,600,0,0,0)
  
  AmbientColor(RGB(150,150,150))

  Global wheelText.l = LoadTexture(#PB_Any, "TYRES.JPG")
  Global oldtext.l = CreateMaterial(#PB_Any, TextureID(wheelText))
  
  Car1Mesh.l  = LoadMesh(#PB_Any, "Jeep_Body.mesh")
  wheelRmesh = LoadMesh(#PB_Any, "Jeep_WheelR.mesh")
      
  wheelRText.l = LoadTexture(#PB_Any, "jeep_wheel.jpg")
  wheelR.l = CreateMaterial(#PB_Any, TextureID(wheelRtext))
    
  CarEnt=CreateEntity(#PB_Any, MeshID(Car1Mesh), 0)  

  ;-SkyBox
  SkyBox("desert07.jpg")
    
  InitMouse()

  Global CubeMesh.l, SphereMesh.l,CylinderMesh.l
  
  CubeMesh = LoadMesh(#PB_Any, "cube.mesh")
  SphereMesh = LoadMesh(#PB_Any, "sphere.mesh")
  CylinderMesh = LoadMesh(#PB_Any, "cylinder.mesh")

      
EndIf

Declare SetupCar()
Declare UpdateKeys()
Declare UpdateCar()
Declare UpdateCam()
Declare UpdateGeoms()
Declare CreateCube()
Declare CreateCylinder()
Declare CreateSphere()
Declare CreatePlane()

Global CMass.f=200.0			; ### Car Mass
Global WMass.f=14.0			; ### Wheel Mass

Global WorldERP.f=0.6			; ### World Error Correction
Global WorldFriction.f=0.8	; ### World Friction

Global Torque.f=25.0			; ### Joint Torque
Global SuspensionHS.f=0.02	; ### Suspension Hardness/Softness (Higher=Softer - Lower=Harder)

Global Force.f=0
Global Steer.f=0

Global Car
Global CGeom
Global CMesh

Global CarStartY.f=20.0

Global Dim Wheel(4)
Global Dim WGeom(4)
Global Dim WJoint(4)

Structure  ODEGeom
	body.l
	geom.l
	mesh.l
EndStructure 

; ###################################################################################################


;- Setup ODE World Parameters

Global Space.l=dWorldCreate(0)

dWorldSetAutoDisableFlag(1)
dWorldSetGravity(0,-0.98,0)
dWorldSetERP(0.6)
dWorldsetCFM(0.00001)

dWorldSetContactSurfaceLayer(0)
dWorldSetQuickstepNumIterations(20)
dWorldSetAutoDisableFlag(1)
dSetMU(WorldFriction)
dSetBOUNCE(0.01)
dSetBOUNCE_VEL(1)
dSetSOFT_ERP(0.5)
dSetSOFT_CFM(0.00001)
dSetSLIP1(0.001)
dSetSLIP2(0.001)
dSetMaxContacts(10)


;- Create car body

Global NewList ode.ODEGeom()

AddElement(ode())

ode()\body=dBodyCreate()
Car=ode()\body

dBodySetRotation(ode()\body,0.0,0.0,0.0)
dBodySetPosition(ode()\body,0.0,CarStartY-1,0.0)

dBodySetBoxMass(ode()\body, 3, 1, 4, CMass)

;Translate mass doesn't work !
;dBodyTranslateMass(ode()\body, 0.0,-1.0,0.0);:"_KODE_dBodyTranslateMass@16"


ode()\geom=dCreateBox(Space,4,5,8)
CGeom=ode()\geom
dGeomSetBody(ode()\geom,ode()\body)

ode()\mesh=carent
CMesh=ode()\mesh
ScaleEntity(ode()\mesh,2.2,2.2,2.2)

RotateEntity( ode()\mesh,0,0,0)
EntityLocate( ode()\mesh,0,0,0)

; Drop BODY to lower MASS !!!!

DROP=-3
dBodySetPosition(ode()\body, dBodyGetPositionX(ode()\body), dBodyGetPositionY(ode()\body)+DROP , dBodyGetPositionZ(ode()\body) ) ; -2 Drop body to move mass down !!!



;- Create wheels

For count=1 To 4
	AddElement(ode())
	ode()\body=dBodyCreate()
	Wheel(count)=ode()\body
	dBodySetRotation(ode()\body,0.0,0.0,0)
	dBodySetPosition(ode()\body,0.0,0.0,0.0)
	dBodySetSphereMass(ode()\body, 0.7, WMass)

	ode()\geom=dCreateSphere(Space,2)
	WGeom(count)=ode()\geom
	dGeomSetBody(ode()\geom,ode()\body)

	ode()\mesh=CreateEntity(#PB_Any, MeshID(wheelRmesh), 0)
	ScaleEntity( ode()\mesh,2,2,2)
	RotateEntity( ode()\mesh,0.0,0.0,0)
	EntityLocate( ode()\mesh,0.0,0.0,0.0)

Next

ok=dBodySetPosition(Wheel(1), -2.5,CarStartY-3+DROP, 4.0)
ok=dBodySetPosition(Wheel(2), 2.5,CarStartY-3+DROP, 4.0)
ok=dBodySetPosition(Wheel(3), -2.5,CarStartY-3+DROP, -3.5)
ok=dBodySetPosition(Wheel(4), 2.5,CarStartY-3+DROP, -3.5)

; ### Create some objects

RandomSeed( ElapsedMilliseconds())

;- Spheres
For spheres=1 To 20
	AddElement(ode())
	ode()\body=dBodyCreate()
	dBodySetRotation(ode()\body,0.0,0.0,0.0)
	dBodySetPosition(ode()\body, Random(200)-100.1, 300.0 , Random(200)-100.1 )
	ode()\geom=dCreateSphere(Space, 4)
	dGeomSetBody(ode()\geom,ode()\body)
	ode()\mesh=CreateSphere()
	ScaleEntity( ode()\mesh,8,8,8)
	RotateEntity(ode()\mesh,0,0,0)
	EntityLocate( ode()\mesh,20,2,0)
Next

;- Cylinders

For cylinders=1 To 20
	AddElement(ode())
	ode()\body=dBodyCreate()
	dBodySetRotation(ode()\body,0,0.0,0.0)
  x.f=Random(200)-100.1
  y.f=30.0
  z.f=Random(200)-100.1
  	
	dBodySetPosition(ode()\body, x.f, y.f, z.f)
	
	ode()\geom=dCreateCylinder(Space,1,8)
	dGeomSetBody(ode()\geom,ode()\body)
	ode()\mesh=CreateCylinder()
	ScaleEntity( ode()\mesh,2,8,2)
	RotateEntity( ode()\mesh,90,0,0)	; <<< Mesh X-Axis must be rotated 90 degrees to fix cylinder alignment

	EntityLocate( ode()\mesh,0,0,0)
Next


;- Cubes

For cubes=1 To 20
	AddElement(ode())
	ode()\body=dBodyCreate()
	dBodySetRotation(ode()\body,0,0.0,0.0)
  x.f=Random(200)-100.1
  y.f=30.0
  z.f=Random(200)-100.1
  	
	dBodySetPosition(ode()\body, x.f, y.f, z.f)
	
	x=Random(10)
	y=Random(10)
	z=Random(10)
	
	ode()\geom=dCreateBox(Space, x, y, z)
	dGeomSetBody(ode()\geom,ode()\body)
	ode()\mesh=CreateCube()
	ScaleEntity( ode()\mesh,x,y,z)
	
	EntityLocate( ode()\mesh,0,0,0)
Next






Global Light

CreateLight(0, RGB(255,255,255),  100.0, 100, 0)

AmbientColor(RGB(128,128,128))

; ### Create camera

Global Camera

Camera=0
CreateCamera(Camera, 0, 0, 100,100)
CameraRange(Camera,1,10000)
CameraLocate(camera,0,0,10)

; ### Create plane

dCreatePlane(Space,0,1,0,0)

Plane=CreatePlane()


;Mirror=CreateMirror()  ; Not available in PB!



; ;- ### ODE STATIC OBJECT (Blue)
; 
	AddElement(ode())
ode()\geom=dCreateBox(Space,2,8,40)
dGeomSetRotation(ode()\geom,-10,8,4)
dGeomSetPosition(ode()\geom,20,5,40)
ode()\mesh=CreateCube()
ScaleEntity( ode()\mesh,2,8,40)
RotateEntity( ode()\mesh,0,0,0)
EntityLocate( ode()\mesh,0,0,0)
Text.l = LoadTexture(#PB_Any, "BLUE.JPG")
Mat.l = CreateMaterial(#PB_Any, TextureID(Text))
EntityMaterial(ode()\mesh, MaterialID(Mat))

; ;- ### ODE STATIC OBJECT (Red)
; 
AddElement(ode())
ode()\geom=dCreateBox(Space,18,0.2,40)
dGeomSetRotation(ode()\geom,-14,0,0)
dGeomSetPosition(ode()\geom,-20,4.9,40)
ode()\mesh=CreateCube()
ScaleEntity( ode()\mesh,18,0.2,40)
RotateEntity( ode()\mesh,0,0,0)
EntityLocate( ode()\mesh,0,0,0)

; ###################################################################################################


SetupCar()

;ExamineKeyboard()

;- ### Game Loop

Repeat 

  ClearScreen(RGB(0, 0, 0))

	UpdateKeys()

	UpdateCar()

	UpdateGeoms()
	
	dWorldQuickStep(0.06)

	UpdateCam()

	RenderWorld()

  StartDrawing(ScreenOutput())
  
  DrawingMode(1)
  
	DrawText( 0,0,"ODE DEMO Using KODE Wrapper")
	DrawText( 0,15,"Force:"+Str(Force))
	DrawText( 0,30,"Torque:"+Str(Torque))
	DrawText( 640,0,"A - Accelerate")
	DrawText( 640,15,"Z - Brake/Reverse")
 	DrawText( 640,30,"Arrows - Steering")
	DrawText( 640,45,"Space - Reset Car")
	
	StopDrawing()

	FlipBuffers()

Until  GetAsyncKeyState_(#VK_ESCAPE)

;- ### End Game Loop ###

;- Tidy up


dWorldDestroy()
dCloseODE()


End

;- ### End of Main Program ###



;-
;- ### Procedures ###
;-







Procedure SetupCar()

For count=1 To 4
	WJoint(count)=dJointCreateHinge2()
	dJointAttach(WJoint(count),Car ,Wheel(count))
	dJointSetHinge2Anchor(WJoint(count),dBodyGetPositionX(Wheel(count)),dBodyGetPositionY(Wheel(count)),dBodyGetPositionZ(Wheel(count)))
	dJointSetHinge2Axis1(WJoint(count),0,1,0)
	dJointSetHinge2Axis2(WJoint(count),-1,0,0)
	dJointSetHinge2Param(WJoint(count),dParamSuspensionERP,0.8)
	dJointSetHinge2Param(WJoint(count),dParamSuspensionCFM,SuspensionHS)
	If count>2
		dJointSetHinge2Param(WJoint(count),dParamLoStop,0.0)
		dJointSetHinge2Param(WJoint(count),dParamHiStop,0.0)
	EndIf
Next

Force=0

EndProcedure 

; ###################################################################################################

Procedure  UpdateKeys()

coast=1
If GetAsyncKeyState_(#VK_A)<> 0
  coast=0
	Force=Force+0.2
	If Force>60.0 
	  Force=60.0
  EndIf	
EndIf

If GetAsyncKeyState_(#VK_Z)
	Force=Force-0.5
	coast=0
	If Force<-10.0 
	  Force=-10.0
  EndIf	
	If Force>0 
	    Force=Force*0.5
  EndIf  	
EndIf

If coast=1     ; Coasting, so slow a little !!!
    Force=Force*0.95
EndIf

If GetAsyncKeyState_(#VK_RIGHT)
		Steer=0.5
ElseIf GetAsyncKeyState_(#VK_LEFT)
		Steer=-0.5
Else
    Steer=0
EndIf

If GetAsyncKeyState_(#VK_SPACE)
	Force=0
	dBodySetRotation(Car, dGeomGetPitch(CGeom), dGeomGetYaw(CGeom),0.0)
EndIf

EndProcedure

; ###################################################################################################

Procedure  UpdateCar()

For count=1 To 4
	dBodyEnable(Wheel(count))
Next

dBodyEnable(Car)

For count=1 To 4
	dJointSetHinge2Param(WJoint(count),dParamVel2,Force)
	dJointSetHinge2Param(WJoint(count),dParamFMax2, Torque)
Next

For count=1 To 2
	angle.f=Steer-dJointGetHinge2Angle1(WJoint(count))
	dJointSetHinge2Param(WJoint(count),dParamVel , angle)
	dJointSetHinge2Param(WJoint(count),dParamFMax ,200.0)
Next



EndProcedure

; ###################################################################################################
Procedure UpdateCam()

    camangle.f=dGeomGetyaw(CGeom)+90
        

    X.f = EntityX(CMesh) - (25 * -Cos((camangle+180)*(3.14/180)))
    Z.f = EntityZ(CMesh) + (25 * Sin((camangle+180)*(3.14/180)))
    Y.f = EntityY(CMesh) + 5
     
    CameraLocate(0, X.f, Y.f, Z.f)
    
    CameraLookAt(0, EntityX(CMesh), EntityY(CMesh), EntityZ(CMesh)) 



EndProcedure

; ###################################################################################################

Procedure  UpdateGeoms()

ResetList(ode())

While NextElement(ode())
 
  newX.f=dGeomGetpitch(ode()\geom)
  newY.f=dGeomGetyaw(ode()\geom)
  newZ.f=dGeomGetroll(ode()\geom)

	RotateEntity(ode()\mesh, -newY, newX, newZ)
	EntityLocate(ode()\mesh, dGeomGetPositionX(ode()\geom), dGeomGetPositionY(ode()\geom), dGeomGetPositionZ(ode()\geom))
  

Wend

EndProcedure

; ###################################################################################################



Procedure CreateCube() 
        
        Text.l = LoadTexture(#PB_Any, "RED.JPG")

        Mat.l = CreateMaterial(#PB_Any, TextureID(Text))
    
        ent.l=CreateEntity(#PB_Any, MeshID(CubeMesh), MaterialID(mat))

        ProcedureReturn ent.l

EndProcedure

Procedure CreatePlane() 
        
        Text.l = LoadTexture(#PB_Any, "GRASS.JPG")
        Mat.l = CreateMaterial(#PB_Any, TextureID(Text))
        ent.l=CreateEntity(#PB_Any, MeshID(CubeMesh), MaterialID(mat))
        
        ScaleEntity( ent, 3000, 0.1, 3000)  ; Big Enough for a demo !
        
        EntityLocate( ent, 0 ,0, 0)

        ProcedureReturn ent.l

EndProcedure



Procedure CreateCylinder() 

        Text.l = LoadTexture(#PB_Any, "GREEN.JPG")
        
        Mat.l = CreateMaterial(#PB_Any, TextureID(Text))
        
        ent.l=CreateEntity(#PB_Any, MeshID(CylinderMesh), MaterialID(mat))

        ProcedureReturn ent.l
        
EndProcedure

Procedure CreateSphere() 

        Text.l = LoadTexture(#PB_Any, "BLUE.JPG")
        
        Mat.l = CreateMaterial(#PB_Any, TextureID(Text))
    
        ent.l=CreateEntity(#PB_Any, MeshID(SphereMesh), MaterialID(mat))

        ProcedureReturn ent.l
        
EndProcedure
Paid up PB User !
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

You are a genious:
Some things to improve:
1. If you move the mouse outside the window it crashes
2. it would be cool to have such things in a packe beacue pasting it together is work^^
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

Thank you very much for the example! It's awesome and works perfectly! Now we can create great games :)
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Excuse me?.. Having a laughter here ;)
Why would you buy a wrapper, when you can call ODE directly?... HELLO !!

I have made my own "wrapper" it just took a bunch of hours to get things going (specially on some undocumented bits), But its going to be faster than using someones wrapper ;) Since you do it all directly to the ODE library.

It's just me or people is a little ignorant on this subject?, Wrappers are useful on languages that cant do much (example: blitzbasic). You can call ODE directly in PB.

Theres really not much on this wrappers but simple function wrapping and a few matrix to euler and vice versa conversions! (else, use quaternions in your game and no need to calculate anything!).

Plus, no ones a genius for wrapping other's code ;) (Uh, less for selling it..).
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

dagcrack wrote:It's just me or people is a little ignorant on this subject?, Wrappers are useful on languages that cant do much (example: blitzbasic). You can call ODE directly in PB.
Release your wrapper then...
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

"I rather be another ant and sell it at half price, that way they lose their customers, and I gain twice in sales..."

Hmm, Can't remember who said that but its good enough for the purpose.
If you need this so bad, discuss it on private so we can arrange an agreement. Perhaps source-code or dll with a limited licence.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

dagcrack wrote:"I rather be another ant and sell it at half price, that way they lose their customers, and I gain twice in sales..."

Hmm, Can't remember who said that but its good enough for the purpose.
If you need this so bad, discuss it on private so we can arrange an agreement. Perhaps source-code or dll with a limited licence.
No, I can do the wrapper myself (in fact, I already done it, that's quick to do), but if you say that's easy to do, and that everybody is looking for it, you should release your code (or say nothing :))
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

:wink: You see why I'm mad at people selling this...
The hardest thing you'll encounter on this kind of wrapper is the euler conversions if you're not experienced with rotation matrixes ;) - I hope you solved that already. And of course the correct use of a collision callback, if you're not into game dev you will fail at providing the correct occlusion on the callback.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
dontmailme
Enthusiast
Enthusiast
Posts: 537
Joined: Wed Oct 29, 2003 10:35 am

Post by dontmailme »

I bought this as it was cheap, includes a graphical physics editor and there were Blitz examples that could easilly be converted.

Dagcrack, would you please show your code to access ODE natively. This would be the best soluton for PB'ers but at the moment the KODE wrapper solution is the only one which has working code and is posted on this board.

If you could post your native 'wrapper' then I'm sure more PB'ers would get into ODE programming and we'd have many experiences to share.
Paid up PB User !
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Would certainly be nice mr dagcrack =P

Be a pal...
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

I might! but not now.
Because it means polishing the entire thing just for YOU, instead, I must finish some work first :)

I don't ever promise anything anyway... Promises can be blown away with the slightest wind.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Or you can release it and not polish it and let the many interested people polish it as they go?
Post Reply