Heres my version of Fire...
This version of Fire places Multipul Particles at Each Limb of the Object, and if you move the Object or Limb, then it will reposition the particles to follow, (Useful For Burning Moving Objects Like in the Picture)
This Code Allows you to Control an object thats on Fire with the Mouse, And if This, "Burning" Object Hits Another Object, Then It will set that object on Fire Aswell, (Contagious Fire). The Particles Will Also Fade Away, and then it will Deletes the Old Particles and Images Automatically
`cd "C:Documents and SettingsMichaelDesktopNewtonNDB_v132NDBv_132 Releasedemos"
BurnObject_Setup:
` Attach Fire to an Object Using the [BurnObject()] Function
Type BurningObject_Type
On As integer
Pn As Integer
In As Integer
Limb As Integer
KillSpeed As Integer
n As Float
Emissions As Integer
EndType
Dim BurningObject(1000) As BurningObject_Type
` Return
Obj_Setup:
` Value Storage for Objects.
Type Obj_Type
Object As Integer
Health As Integer
Burn As Integer
BurnPPL As Integer
BurnFreq As Integer
BurnRad As Integer
BurnLife As Integer
BurnKillSpeed As Integer
EndType
Dim Obj(100) As Obj_Type
` Return
` Contagious Fire
`
` By Michael Mihalyfi
` [email protected]
`
set display mode 1024,768,32
sync on
sync rate 0
hide mouse
Color BackDrop 0,0
randomize timer()
Autocam Off
position Camera 0,0,8,-10
` Example: Contagious Fires Using the Mouse, (With Auto BurnOut)
` GoSub BurnObject_Setup
` GoSub Obj_Setup
` Load Image "C:Documents and SettingsMichaelMy DocumentsMy Picturesearthcloudmap.bmp",444
`make object sphere 444,-5000
` texture object 444,444
`load images
`load image "mediafloor.png",999
`NDB_NewtonCreate
`NDB_SetVector 0.0, -50.0, 0.0
`NDB_SetStandardGravity
`gosub MakeFloor
`time# = NDB_GetElapsedTimeInSec()
`time# = NDB_GetElapsedTimeInSec()
` A Fire, Controled By Mouse
` MakeBox(0,0,0,10,10,10,Rnd(360),Rnd(360),Rnd(360),10) : SetObjectBurnProperties(On,1,5,100,10,20,1)
make object cube 1,10
position object 1,0,-5,0
BurnObject(1,1,100,10,20,0)
set global collision on
Do : Control Camera Using ArrowKeys 0,5,5
If Inkey$() = "a" Then Position Camera 0,camera Position x(0),camera Position y(0)+5,camera Position z(0)
If Inkey$() = "z" Then Position Camera 0,camera Position x(0),camera Position y(0)-5,camera Position z(0)
If Inkey$() = "1" Then On = FreeObjectNumber() : Make Object Cube on,10 : Position Object On,Rnd(500)-250,Rnd(10),Rnd(500)-250 : SetObjectBurnProperties(On,1,5,100,10,20,1)
If Inkey$() = "2" Then On = FreeObjectNumber() : Make Object Sphere On,10 : Position Object On,Rnd(500)-250,Rnd(10),Rnd(500)-250 : : SetObjectBurnProperties(On,1,5,500,20,200,32)
` If Inkey$() = "3" Then On = FreeObjectNumber() : MakeRagdoll(Rnd(500)-250,Rnd(20),Rnd(500)-250,10,10) : SetObjectBurnProperties(On,1,5,100,10,20,1)
Position Object 1,Object Position x(1)+MouseMoveX(),Object Position y(1)+MouseMoveZ()/20,Object Position z(1)+(-MouseMoveY())
Ink -1,0
Text 10,10,"1 = Make Flamable Object"
Text 10,30,"2 = Make Missile LandMine"
` Text 10,50,"3 = Make Flamable RagDoll"
Text 10,70,"a = Move Camera Up"
Text 10,90,"z = Move Camera Down"
Text 10,110,"Control Camera Using ArrowKeys"
Text 10,130,"Control Tourch Using Mouse"
Text 10,150,"Control Tourch Using Mouse"
Text 10,150,"Screen FPS = "+Str$(Screen FPS())
`Position Object 444,9999999999999,9999999999,99999999999
On = UpdateBurningObjects()
`Position Object 444,camera Position x(0),camera Position y(0),camera Position z(0)
If On <> 0 Then Delete Object On : Obj(On).Object = 0
` time# = NDB_GetElapsedTimeInSec()
` NDB_NewtonUpdate time#
FastSync : Loop
` Burn Object Commands ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function BurnObject(On,PPL,Freq,Rad,Life,KillSpeed) : ` Burn an Object
` On = Object To Burn
` PPL = Number Of Particles Per Limb, (a Higher Number Will give a Better Effect, But Slower Speeds, (Minimumn 1)
` Freq = Particles Freq
` Life = Particles Life
` KillSpeed = Number Of Particle Emissions to Reduce Each Time Through the Loop, (Allows the Flame to Gradually fade Away), 0 = Flame Perminant
Perform CheckList For Object Limbs On
` Loop for Every Limb of the Object
For Limb = 0 To CheckList Quantity()
BurnLimb(On,Limb,PPL,Freq,Rad,Life,KillSpeed)
Next Limb : Empty CheckList
EndFunction
Function BurnLimb(On,Limb,PPL,Freq,Rad,Life,KillSpeed) : ` Burn an Objects Limb
If Limb = 0 Or Limb Exist(On,Limb) = 1
` Number of Particles Per Limb, (The Higher PPL, The Better the Effect)
For t = 1 to PPL
Freq = Freq+Rnd(10)
Rad = Rad+Rnd(5)
Life = Life+Int(Rnd(50)/200)
Speed# = 0.001*Rnd(100)
Gravity = Rnd(5)-5
Color = RGB(Rnd(80)+40,30,10)
` Randomize the Flames Shade a Little
In = FreeImageNumber()
Ink Color,0
Box 0,0,10,10
Get Image In,0,0,1,1
` Make/Set the Particles
Pn = FreeParticlesNumber()
make particles Pn,In,Freq,Rad
Set Particle life Pn,Life
Set Particle Speed Pn,Speed#
Set particle gravity Pn,Gravity
Set Particle Floor Pn,0
ghost particles On Pn,0
` Add the Particles Into the Dim, (Allows it to be Automatically Repositioned if Object Moved)
For temp = 1 To Array Count(BurningObject())-1
If BurningObject(temp).On = 0 Then nBO = temp : temp = Array Count(BurningObject())-1
Next temp : If nBO = 0 Then nBO = Array Count(BurningObject()) : Add To Stack BurningObject()
BurningObject(nBO).On = On
BurningObject(nBO).Pn = Pn
BurningObject(nBO).In = In
BurningObject(nBO).Limb = Limb
BurningObject(nBO).KillSpeed = KillSpeed
BurningObject(nBO).Emissions = Freq
Next t : EndIf :
EndFunction
` ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function SetObjectBurnProperties(On,FireProofing,PPL,Freq,Rad,Life,KillSpeed) : ` Sets an Object As Flamable
Obj(On).Object = On
Obj(On).Burn = FireProofing
Obj(On).BurnPPL = PPL
Obj(On).BurnFreq = Freq
Obj(On).BurnRad = Rad
Obj(On).BurnLife = Life
Obj(On).BurnKillSpeed = KillSpeed
EndFunction
Function CopyObjectBurnProperties(Parent,Child) : ` Copy the Object Burn Properties to Another Object
Obj(Child).Object = Obj(Parent).Object
Obj(Child).Burn = Obj(Parent).Burn
Obj(Child).BurnPPL = Obj(Parent).BurnPPL
Obj(Child).BurnFreq = Obj(Parent).BurnFreq
Obj(Child).BurnRad = Obj(Parent).BurnRad
Obj(Child).BurnLife = Obj(Parent).BurnLife
Obj(Child).BurnKillSpeed = Obj(Parent).BurnKillSpeed
EndFunction
` ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function UpdateBurningObjects() : ` Update Burning Objects
` Return Value = Object that has Finished Burning, Else Returns 0
` Search the Burning Object Dim
For n = 1 To Array Count(BurningObject())-1
If BurningObject(n).On <> 0
If Particles Exist(BurningObject(n).Pn) = 1
` Reposition the Particles to the Object And Limb Positions
If BurningObject(n).Limb = 0
x# = Object Position x(BurningObject(n).On)
y# = Object Position y(BurningObject(n).On)
z# = Object Position z(BurningObject(n).On)
Else : x# = Limb Position x(BurningObject(n).On,BurningObject(n).Limb)
y# = Limb Position y(BurningObject(n).On,BurningObject(n).Limb)
z# = Limb Position z(BurningObject(n).On,BurningObject(n).Limb) : EndIf
Position Particles BurningObject(n).Pn,x#,y#,z#
` Then Delete the Particles and Images And Empty the Dim Entry Automatically, (Only if the Emisions <= 0)
If BurningObject(n).Emissions-BurningObject(n).KillSpeed <= 0
BurningObject(n).Limb = 0
BurningObject(n).Emissions = 0
BurningObject(n).KillSpeed = 0
If BurningObject(n).Pn => 1 : If Particles Exist(BurningObject(n).Pn) = 1 : Delete Particles BurningObject(n).Pn : BurningObject(n).Pn = 0 : EndIf : EndIf
If BurningObject(n).In => 1 : If Image Exist(BurningObject(n).In) = 1 : Delete Image BurningObject(n).In : BurningObject(n).In = 0 : EndIf : EndIf
If ObjectBurning(BurningObject(n).On) = 0 Then On = BurningObject(n).On : BurningObject(n).On = 0 : ExitFunction On
` Else Reduce Particle Emissions, (Fading Flame), By KillSpeed
Else : BurningObject(n).Emissions = BurningObject(n).Emissions-BurningObject(n).KillSpeed
Set particle Emissions BurningObject(n).Pn,BurningObject(n).Emissions
` Burn Fading The Object
BurningObject(n).n = BurningObject(n).n+0.5
If BurningObject(n).n >100 Then BurningObject(n).n = 100
Fade Object BurningObject(n).On,100-Int(BurningObject(n).n)
` Reduce the Objects Health.
Obj(n).Health = Obj(n).Health-1
EndIf `
` Automatic Fire Spreading Via Touching Objects...
Hit = Object Hit(BurningObject(n).On,0)
If Hit <> 0
nObj = GetObjNumber(Hit)
If nObj <> 0
Obj(nObj).Burn = Obj(nObj).Burn-1
If Obj(nObj).Burn = 0
BurnObject(Hit,Obj(nObj).BurnPPL,Obj(nObj).BurnFreq,Obj(nObj).BurnRad,Obj(nObj).BurnLife,Obj(nObj).BurnKillSpeed)
Hit = Object Hit(BurningObject(n).On,0)
EndIf : EndIf : EndIf : EndIf : EndIf : Next n : ` Next Object Thats on Fire
EndFunction 0
` Burn Object Expressions ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function ObjectBurning(On) : ` Returns a Value of 1 If the Object is Still Burning, Else Returns 0
For n = 1 To Array Count(BurningObject())-1
If BurningObject(n).On = On Then ExitFunction 1
Next n
EndFunction 0
Function LimbBurning(On,Limb) : ` Returns a Value of 1 If the Object Limb is Still Burning, Else Returns 0
For n = 1 To Array Count(BurningObject())-1
If BurningObject(n).On = On And BurningObject(n).Limb = Limb Then ExitFunction 1
Next n
EndFunction 0
` ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
` ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
` Obj Expressions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function FreeObjNumber() : ` Get a Free Obj Number
For n = 1 To Array Count(Obj())-1
If Obj(n).Object = 0 Then ExitFunction n
Next n : Add To Stack Obj() : Inc n,1
EndFunction n
Function GetObjNumber(On) : ` Returns the Objects Dim Number in the Obj Dim
For n = 1 To Array Count(Obj())-1
If Obj(n).Object = On Then ExitFunction n
Next n
EndFunction 0
Function FreeObjectNumber()
Repeat : Inc n,1 : Until Object Exist(n) = 0
EndFunction n
Function FreeParticlesNumber()
Repeat : Inc n,1 : Until Particles Exist(n) = 0
Endfunction n
Function FreeImageNumber()
Repeat : Inc n,1 : Until Image Exist(n) = 0
Endfunction n
remstart
` FUNCTIONS ---------------------------------
`this makes a simple ragdoll, out of seperate objects for each bone. The Newton wrapper also supports
`skinned ragdolls, but this example should show how ragdolls are setup.
function MakeRagdoll( x#, y#, z#, size#, mass# )
`start the ragdoll!
RagDoll = NDB_NewtonCreateRagDoll()
`start the ragdoll
` NDB_NewtonRagDollBegin RagDoll
gube=freeobject()
load object "C:Documents and SettingsMichaelDesktopNewtonNDB_v132NDBv_132 Releasedemosdemo11 - Advanced RagdollMediagubbe.x",gube
position object gube,0,0,0
set object cull gube,0
rem ghost object on gube,4
rem color object gube,RGB(10,10,130)
`make the root bone!
`first make the collision object for the bone, in this case a box!
Col = NDB_NewtonCreateBox( 5.0*size#, 4.5*size#, 1.0*size# )
`now setup the bone itself... first setup a matrix for the bone's orientation
` NDB_BuildMatrix 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
`then put the bone size in temp vector 1
NDB_SetVector 1, 0.0*size#, 4.5*size#, 1.0*size#
`now make the bone!!
Root = NDB_NewtonRagDollAddbone( RagDoll, 0, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
NDB_RagDollBoneSetOffset Root
NDB_RagDollBoneSetDBProData Root, gube, 0
`now make the chest bone!
Col = NDB_NewtonCreateBox( 4.5*size#, 4.5*size#, 3.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 90.0, 0.0, 3.0, 0.0
NDB_SetVector 1, 4.5*size#, 4.5*size#, 3.0*size#
Chest = NDB_NewtonRagDollAddBone( RagDoll, Root, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 90.0, 0.0, 3.0, 0.0
NDB_RagDollBoneSetOffset Chest
NDB_SetVector 1, 0.0,90.0,0.0
NDB_NewtonRagDollBoneSetLimits Chest,10.0,20.0,20.0
NDB_RagDollBoneSetDBProData Chest, gube, 9
`now make the head bone!
Col = NDB_NewtonCreateSphere( 2.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.5, 0.0, 0.0
NDB_SetVector 1, 2.0*size#, 2.0*size#, 2.0*size#
Head = NDB_NewtonRagDollAddBone( RagDoll, Chest, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.5, 0.0, 0.0
NDB_RagDollBoneSetOffset Head
NDB_SetVector 1, 0.0,90.0,0.0
NDB_NewtonRagDollBoneSetLimits Head,10.0,50.0,20.0
NDB_RagDollBoneSetDBProData Head, gube, 16
`now make the left arm bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 4.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, -90.0, 3.5*size#, -3.0*size#, 0.0
NDB_SetVector 1, 3.5*size#, 1.6*size#, 1.6*size#
LArm = NDB_NewtonRagDollAddBone( RagDoll, Chest, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, -90.0, 3.5*size#, -3.0*size#, 0.0
NDB_RagDollBoneSetOffset LArm
NDB_SetVector 1, 90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits LArm,10.0,150.0,30.0
NDB_RagDollBoneSetDBProData LArm, gube, 13
`now make the left arm2 bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 4.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_SetVector 1, 4.0*size#, 1.6*size#, 1.6*size#
LArm2 = NDB_NewtonRagDollAddBone( RagDoll, LArm, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset LArm2
NDB_SetVector 1, 90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits LArm2,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData LArm2, gube, 14
`now make the left Hand bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 2.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_SetVector 1, 2.5*size#, 1.6*size#, 1.6*size#
LHand = NDB_NewtonRagDollAddBone( RagDoll, LArm2, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset LHand
NDB_SetVector 1, 90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits LHand,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData LHand, gube, 15
`now make the right arm bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 4.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 90.0, 3.5*size#, 3.0*size#, 0.0
NDB_SetVector 1, 3.5*size#, 1.6*size#, 1.6*size#
RArm = NDB_NewtonRagDollAddBone( RagDoll, Chest, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 90.0, 3.5*size#, 3.0*size#, 0.0
NDB_RagDollBoneSetOffset RArm
NDB_SetVector 1, -90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits RArm,10.0,150.0,30.0
NDB_RagDollBoneSetDBProData RArm, gube, 10
`now make the right arm2 bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 4.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_SetVector 1, 4.0*size#, 1.6*size#, 1.6*size#
RArm2 = NDB_NewtonRagDollAddBone( RagDoll, RArm, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset RArm2
NDB_SetVector 1, -90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits RArm2,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData RArm2, gube, 11
`now make the Right Hand bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 2.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_SetVector 1, 2.5*size#, 1.6*size#, 1.6*size#
RHand = NDB_NewtonRagDollAddBone( RagDoll, RArm2, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset RHand
NDB_SetVector 1, -90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits RHand,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData RHand, gube, 12
`now make the left leg bone!
Col = NDB_NewtonCreateCapsule( 0.8*size#, 6.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, -90.0, 1.8, -2.5*size#, 0.0
NDB_SetVector 1, 6.0*size#, 1.6*size#, 1.6*size#
LLeg = NDB_NewtonRagDollAddBone( RagDoll, Root, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, -90.0, 1.8, -3.0*size#, 0.0
NDB_RagDollBoneSetOffset LLeg
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits LLeg,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData LLeg, gube, 3
`now make the left leg2 bone!
Col = NDB_NewtonCreateCapsule( 0.8*size#, 6.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.0*size#, 0.0, 0.0
NDB_SetVector 1, 6.0*size#, 1.6*size#, 1.6*size#
LLeg2 = NDB_NewtonRagDollAddBone( RagDoll, LLeg, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.0*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset LLeg2
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits LLeg2,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData LLeg2, gube, 4
`now make the left Foot bone!
Col = NDB_NewtonCreateCapsule( 0.6*size#, 2.5*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 90.0, 0.0, 6.0*size#, 0.0, 0.0
NDB_SetVector 1, 2.5*size#, 1.6*size#, 1.6*size#
LFoot = NDB_NewtonRagDollAddBone( RagDoll, LLeg2, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 90.0, 0.0, 6.0*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset LFoot
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits LFoot,10.0,60.0,10.0
NDB_RagDollBoneSetDBProData LFoot, gube, 5
`now make the right leg bone!
Col = NDB_NewtonCreateCapsule( 0.8*size#, 6.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, -90.0, -1.8, -2.5*size#, 0.0
NDB_SetVector 1, 6.0*size#, 1.6*size#, 1.6*size#
RLeg = NDB_NewtonRagDollAddBone( RagDoll, Root, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, -90.0, -1.8, 3.0*size#, 0.0
NDB_RagDollBoneSetOffset RLeg
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits RLeg,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData RLeg, gube, 6
`now make the right leg2 bone!
Col = NDB_NewtonCreateCapsule( 0.8*size#, 6.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.0*size#, 0.0, 0.0
NDB_SetVector 1, 6.0*size#, 1.6*size#, 1.6*size#
RLeg2 = NDB_NewtonRagDollAddBone( RagDoll, RLeg, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.0*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset RLeg2
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits RLeg2,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData RLeg2, gube, 7
`now make the right Foot bone!
Col = NDB_NewtonCreateCapsule( 0.6*size#, 2.5*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 90.0, 0.0, 6.0*size#, 0.0, 0.0
NDB_SetVector 1, 2.5*size#, 1.6*size#, 1.6*size#
RFoot = NDB_NewtonRagDollAddBone( RagDoll, RLeg2, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 90.0, 0.0, 6.0*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset RFoot
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits RFoot,10.0,60.0,10.0
NDB_RagDollBoneSetDBProData RFoot, gube, 8
`okay, we're done with the ragdoll!
NDB_NewtonRagDollEnd RagDoll
NDB_RagDollSetGravity RagDoll, 1
`NDB_SetVector 1, 0.0,90.0,0.0
`UpvectorJoint=NDB_NewtonConstraintCreateUpVector (gube)
endfunction
`these are based off the fuctions found in the other demos, but have been simplified and
`adjusted for ragdolls.
function MakeBoxBone(sx#,sy#,sz#)
obj = FreeObject()
load object ".mediabox.x", obj
scale object obj, sx#*100.0, sy#*100.0, sz#*100.0
offset limb obj, 0, 0.5, 0.0, 0.0
color = GetColor()
color object obj, color
set object ambience obj, 50
endfunction obj
function MakeSphereBone(s#)
obj = FreeObject()
load object ".mediasphere.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, s#*100.0, s#*100.0, s#*100.0
offset limb obj, 0, 1.0, 0.0, 0.0
endfunction obj
`this makes a capsule shape, which is like a cylinder with rounded ends.
function MakeCapsuleBone(r#,h#)
obj = FreeObject()
load object ".mediacap_mid.x", obj
obj2 = FreeObject()
load object ".mediacap_cap.x", obj2
make mesh from object 1, obj2
delete object obj2
add limb obj, 5, 1
add limb obj, 6, 1
rotate limb obj, 6, 0.0, 180.0, 0.0
color object obj, GetColor()
set object ambience obj, 50
h# = h# - (r#*2)
if h# < 0.0 then h# = 0.0
scale limb obj, 2, h#*100.0, r#*100.0, r#*100.0
scale limb obj, 5, r#*100.0, r#*100.0, r#*100.0
scale limb obj, 6, r#*100.0, r#*100.0, r#*100.0
offset limb obj, 2, h#/2.0, 0.0, 0.0
offset limb obj, 5, h#, 0.0, 0.0
endfunction obj
function FreeObject()
repeat
inc i
if object exist(i)=0 then found=1
until found
endfunction i
function GetColor()
repeat
r = rnd(1)*255
g = rnd(1)*255
b = rnd(1)*255
until r<>0 or g<>0 or b<> 0
color = rgb(r,g,b)
endfunction color
function NeverCalled()
if memblock exist(1) then delete memblock 1
endfunction
function MakeBox(x#,y#,z#,sx#,sy#,sz#,rx#,ry#,rz#,mass#)
Col = NDB_NewtonCreateBox(sx#, sy#, sz#)
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMIBoxSolid mass#, sx#, sy#, sz#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediabox.x", obj
scale object obj, sx#*100.0, sy#*100.0, sz#*100.0
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
color = GetColor()
color object obj, color
set object ambience obj, 50
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeSphere(x#,y#,z#,s#,mass#)
Col = NDB_NewtonCreateSphere( s# )
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix 0.0, 0.0, 0.0, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMISphereSolid mass#, s#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediasphere.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, s#*100.0, s#*100.0, s#*100.0
position object obj, x#, y#, z#
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeCylinder(x#,y#,z#,r#,h#,rx#,ry#,rz#,mass#)
Col = NDB_NewtonCreateCylinder( r#, h# )
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMICylinderSolid mass#, r#, h#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediacylinder.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, h#*100.0, r#*100.0, r#*100.0
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeCapsule(x#,y#,z#,r#,h#,rx#,ry#,rz#,mass#)
Col = NDB_NewtonCreateCapsule( r#, h# )
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMICylinderSolid mass#, r#, h#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediacap_mid.x", obj
obj2 = FreeObject()
load object "mediacap_cap.x", obj2
make mesh from object 1, obj2
delete object obj2
add limb obj, 5, 1
add limb obj, 6, 1
rotate limb obj, 6, 0.0, 180.0, 0.0
color object obj, GetColor()
set object ambience obj, 50
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
h# = h# - (r#*2)
if h# < 0.0 then h# = 0.0
scale limb obj, 2, h#*100.0, r#*100.0, r#*100.0
scale limb obj, 5, r#*100.0, r#*100.0, r#*100.0
scale limb obj, 6, r#*100.0, r#*100.0, r#*100.0
offset limb obj, 5, h#/2.0, 0.0, 0.0
offset limb obj, 6, -h#/2.0, 0.0, 0.0
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeCone(x#,y#,z#,r#,h#,rx#,ry#,rz#,mass#)
Col = NDB_NewtonCreateCone( r#, h# )
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMICylinderSolid mass#, r#, h#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediacone.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, h#*100.0, r#*100.0, r#*100.0
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeConvexHull(file$,x#,y#,z#,rx#,ry#,rz#,mass#)
obj = FreeObject()
load object file$, obj
Col = NDB_NewtonCreateConvexHull( obj )
Body = NDB_NewtonCreateBody(Col)
NDB_CalculateMIBoxSolid mass#, object size x(obj), object size y(obj), object size z(obj)
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetDBProData Body, obj
color object obj, GetColor()
set object ambience obj, 50
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
NDB_BodySetGravity Body, 1
endfunction Body
MakeFloor:
` GROUND OBJECT
` this makes a simple box with mass=0. this makes the object immobile, like a solid ground.
col = NDB_NewtonCreateBox( 1000.0, 10.0, 1000.0 )
Floor = NDB_NewtonCreateBody( col )
NDB_BuildMatrix 0.0, 0.0, 0.0, 0.0, -20.0, 0.0
NDB_NewtonBodySetMAtrix Floor
`now make a visual object to represent the floor onscreen... same size and position as
`the rigid body above.
obj = 567
load object "mediabox.x", obj
position object obj, 0.0, -20.0, 0.0
scale object obj, (1000.0*100.0), (10.0*100.0), (1000.0*100.0)
scale object texture obj, 10.0, 10.0
texture object obj, 1
`this tells the wrapper that if I destroy the Floor rigid body,
`I also want the wrapper to delete the visual object as well.
NDB_NewtonBodySetDestructorCallback Floor
`this command connects a visual object with a rigid body, making them a "pair"
NDB_BodySetDBProData Floor, obj
FloorObj = obj
return
remend
DBPro Version
cd "C:Documents and SettingsMichaelDesktopNewtonNDB_v132NDBv_132 Releasedemos"
BurnObject_Setup:
` Attach Fire to an Object Using the [BurnObject()] Function
Type BurningObject_Type
On As integer
Pn As Integer
In As Integer
Limb As Integer
KillSpeed As Integer
n As Float
Emissions As Integer
EndType
Dim BurningObject(1000) As BurningObject_Type
` Return
Obj_Setup:
` Value Storage for Objects.
Type Obj_Type
Object As Integer
Health As Integer
Burn As Integer
BurnPPL As Integer
BurnFreq As Integer
BurnRad As Integer
BurnLife As Integer
BurnKillSpeed As Integer
EndType
Dim Obj(100) As Obj_Type
` Return
` Contagious Fire
`
` By Michael Mihalyfi
` [email protected]
`
set display mode 1024,768,32
sync on
sync rate 0
hide mouse
Color BackDrop 0,0
randomize timer()
Autocam Off
position Camera 0,0,8,-10
` Example: Contagious Fires Using the Mouse, (With Auto BurnOut)
` GoSub BurnObject_Setup
` GoSub Obj_Setup
Load Image "C:Documents and SettingsMichaelMy DocumentsMy Picturesearthcloudmap.bmp",444
make object sphere 444,-5000
texture object 444,444
`load images
load image "mediafloor.png",999
NDB_NewtonCreate
NDB_SetVector 0.0, -50.0, 0.0
NDB_SetStandardGravity
gosub MakeFloor
time# = NDB_GetElapsedTimeInSec()
time# = NDB_GetElapsedTimeInSec()
` A Fire, Controled By Mouse
` MakeBox(0,0,0,10,10,10,Rnd(360),Rnd(360),Rnd(360),10) : SetObjectBurnProperties(On,1,5,100,10,20,1)
make object cube 1,10
position object 1,0,-5,0
BurnObject(1,1,100,10,20,0)
set global collision on
Do : Control Camera Using ArrowKeys 0,5,5
If Inkey$() = "a" Then Position Camera 0,camera Position x(0),camera Position y(0)+5,camera Position z(0)
If Inkey$() = "z" Then Position Camera 0,camera Position x(0),camera Position y(0)-5,camera Position z(0)
If Inkey$() = "1" Then On = FreeObjectNumber() : MakeBox(Rnd(500)-250,Rnd(10),Rnd(500)-250,10,10,10,Rnd(360),Rnd(360),Rnd(360),10) : SetObjectBurnProperties(On,1,5,100,10,20,1)
If Inkey$() = "2" Then On = FreeObjectNumber() : MakeSphere(Rnd(500)-250,Rnd(20),Rnd(500)-250,5,10) : SetObjectBurnProperties(On,1,5,500,20,200,32)
If Inkey$() = "3" Then On = FreeObjectNumber() : MakeRagdoll(Rnd(500)-250,Rnd(20),Rnd(500)-250,10,10) : SetObjectBurnProperties(On,1,5,100,10,20,1)
Position Object 1,Object Position x(1)+MouseMoveX(),Object Position y(1)+MouseMoveZ()/20,Object Position z(1)+(-MouseMoveY())
Ink -1,0
Text 10,10,"1 = Make Flamable Object"
Text 10,30,"2 = Make Missile LandMine"
Text 10,50,"3 = Make Flamable RagDoll"
Text 10,70,"a = Move Camera Up"
Text 10,90,"z = Move Camera Down"
Text 10,110,"Control Camera Using ArrowKeys"
Text 10,130,"Control Tourch Using Mouse"
Text 10,150,"Control Tourch Using Mouse"
Text 10,150,"Screen FPS = "+Str$(Screen FPS())
Position Object 444,9999999999999,9999999999,99999999999
On = UpdateBurningObjects()
Position Object 444,camera Position x(0),camera Position y(0),camera Position z(0)
If On <> 0 Then Delete Object On : Obj(On).Object = 0
time# = NDB_GetElapsedTimeInSec()
NDB_NewtonUpdate time#
FastSync : Loop
` Burn Object Commands ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function BurnObject(On,PPL,Freq,Rad,Life,KillSpeed) : ` Burn an Object
` On = Object To Burn
` PPL = Number Of Particles Per Limb, (a Higher Number Will give a Better Effect, But Slower Speeds, (Minimumn 1)
` Freq = Particles Freq
` Life = Particles Life
` KillSpeed = Number Of Particle Emissions to Reduce Each Time Through the Loop, (Allows the Flame to Gradually fade Away), 0 = Flame Perminant
Perform CheckList For Object Limbs On
` Loop for Every Limb of the Object
For Limb = 0 To CheckList Quantity()
BurnLimb(On,Limb,PPL,Freq,Rad,Life,KillSpeed)
Next Limb : Empty CheckList
EndFunction
Function BurnLimb(On,Limb,PPL,Freq,Rad,Life,KillSpeed) : ` Burn an Objects Limb
If Limb = 0 Or Limb Exist(On,Limb) = 1
` Number of Particles Per Limb, (The Higher PPL, The Better the Effect)
For t = 1 to PPL
Freq = Freq+Rnd(10)
Rad = Rad+Rnd(5)
Life = Life+Int(Rnd(50)/200)
Speed# = 0.001*Rnd(100)
Gravity = Rnd(5)-5
Color = RGB(Rnd(80)+40,30,10)
` Randomize the Flames Shade a Little
In = FreeImageNumber()
Ink Color,0
Box 0,0,10,10
Get Image In,0,0,1,1
` Make/Set the Particles
Pn = FreeParticlesNumber()
make particles Pn,In,Freq,Rad
Set Particle life Pn,Life
Set Particle Speed Pn,Speed#
Set particle gravity Pn,Gravity
Set Particle Floor Pn,0
ghost particles On Pn,0
` Add the Particles Into the Dim, (Allows it to be Automatically Repositioned if Object Moved)
For temp = 1 To Array Count(BurningObject())-1
If BurningObject(temp).On = 0 Then nBO = temp : temp = Array Count(BurningObject())-1
Next temp : If nBO = 0 Then nBO = Array Count(BurningObject()) : Add To Stack BurningObject()
BurningObject(nBO).On = On
BurningObject(nBO).Pn = Pn
BurningObject(nBO).In = In
BurningObject(nBO).Limb = Limb
BurningObject(nBO).KillSpeed = KillSpeed
BurningObject(nBO).Emissions = Freq
Next t : EndIf :
EndFunction
` ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function SetObjectBurnProperties(On,FireProofing,PPL,Freq,Rad,Life,KillSpeed) : ` Sets an Object As Flamable
Obj(On).Object = On
Obj(On).Burn = FireProofing
Obj(On).BurnPPL = PPL
Obj(On).BurnFreq = Freq
Obj(On).BurnRad = Rad
Obj(On).BurnLife = Life
Obj(On).BurnKillSpeed = KillSpeed
EndFunction
Function CopyObjectBurnProperties(Parent,Child) : ` Copy the Object Burn Properties to Another Object
Obj(Child).Object = Obj(Parent).Object
Obj(Child).Burn = Obj(Parent).Burn
Obj(Child).BurnPPL = Obj(Parent).BurnPPL
Obj(Child).BurnFreq = Obj(Parent).BurnFreq
Obj(Child).BurnRad = Obj(Parent).BurnRad
Obj(Child).BurnLife = Obj(Parent).BurnLife
Obj(Child).BurnKillSpeed = Obj(Parent).BurnKillSpeed
EndFunction
` ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function UpdateBurningObjects() : ` Update Burning Objects
` Return Value = Object that has Finished Burning, Else Returns 0
` Search the Burning Object Dim
For n = 1 To Array Count(BurningObject())-1
If BurningObject(n).On <> 0
If Particles Exist(BurningObject(n).Pn) = 1
` Reposition the Particles to the Object And Limb Positions
If BurningObject(n).Limb = 0
x# = Object Position x(BurningObject(n).On)
y# = Object Position y(BurningObject(n).On)
z# = Object Position z(BurningObject(n).On)
Else : x# = Limb Position x(BurningObject(n).On,BurningObject(n).Limb)
y# = Limb Position y(BurningObject(n).On,BurningObject(n).Limb)
z# = Limb Position z(BurningObject(n).On,BurningObject(n).Limb) : EndIf
Position Particles BurningObject(n).Pn,x#,y#,z#
` Then Delete the Particles and Images And Empty the Dim Entry Automatically, (Only if the Emisions <= 0)
If BurningObject(n).Emissions-BurningObject(n).KillSpeed <= 0
BurningObject(n).Limb = 0
BurningObject(n).Emissions = 0
BurningObject(n).KillSpeed = 0
If BurningObject(n).Pn => 1 : If Particles Exist(BurningObject(n).Pn) = 1 : Delete Particles BurningObject(n).Pn : BurningObject(n).Pn = 0 : EndIf : EndIf
If BurningObject(n).In => 1 : If Image Exist(BurningObject(n).In) = 1 : Delete Image BurningObject(n).In : BurningObject(n).In = 0 : EndIf : EndIf
If ObjectBurning(BurningObject(n).On) = 0 Then On = BurningObject(n).On : BurningObject(n).On = 0 : ExitFunction On
` Else Reduce Particle Emissions, (Fading Flame), By KillSpeed
Else : BurningObject(n).Emissions = BurningObject(n).Emissions-BurningObject(n).KillSpeed
Set particle Emissions BurningObject(n).Pn,BurningObject(n).Emissions
` Burn Fading The Object
BurningObject(n).n = BurningObject(n).n+0.5
If BurningObject(n).n >100 Then BurningObject(n).n = 100
Fade Object BurningObject(n).On,100-Int(BurningObject(n).n)
` Reduce the Objects Health.
Obj(n).Health = Obj(n).Health-1
EndIf `
` Automatic Fire Spreading Via Touching Objects...
Hit = Object Hit(BurningObject(n).On,0)
If Hit <> 0
nObj = GetObjNumber(Hit)
If nObj <> 0
Obj(nObj).Burn = Obj(nObj).Burn-1
If Obj(nObj).Burn = 0
BurnObject(Hit,Obj(nObj).BurnPPL,Obj(nObj).BurnFreq,Obj(nObj).BurnRad,Obj(nObj).BurnLife,Obj(nObj).BurnKillSpeed)
Hit = Object Hit(BurningObject(n).On,0)
EndIf : EndIf : EndIf : EndIf : EndIf : Next n : ` Next Object Thats on Fire
EndFunction 0
` Burn Object Expressions ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function ObjectBurning(On) : ` Returns a Value of 1 If the Object is Still Burning, Else Returns 0
For n = 1 To Array Count(BurningObject())-1
If BurningObject(n).On = On Then ExitFunction 1
Next n
EndFunction 0
Function LimbBurning(On,Limb) : ` Returns a Value of 1 If the Object Limb is Still Burning, Else Returns 0
For n = 1 To Array Count(BurningObject())-1
If BurningObject(n).On = On And BurningObject(n).Limb = Limb Then ExitFunction 1
Next n
EndFunction 0
` ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
` ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
` Obj Expressions ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function FreeObjNumber() : ` Get a Free Obj Number
For n = 1 To Array Count(Obj())-1
If Obj(n).Object = 0 Then ExitFunction n
Next n : Add To Stack Obj() : Inc n,1
EndFunction n
Function GetObjNumber(On) : ` Returns the Objects Dim Number in the Obj Dim
For n = 1 To Array Count(Obj())-1
If Obj(n).Object = On Then ExitFunction n
Next n
EndFunction 0
Function FreeObjectNumber()
Repeat : Inc n,1 : Until Object Exist(n) = 0
EndFunction n
Function FreeParticlesNumber()
Repeat : Inc n,1 : Until Particles Exist(n) = 0
Endfunction n
Function FreeImageNumber()
Repeat : Inc n,1 : Until Image Exist(n) = 0
Endfunction n
` FUNCTIONS ---------------------------------
`this makes a simple ragdoll, out of seperate objects for each bone. The Newton wrapper also supports
`skinned ragdolls, but this example should show how ragdolls are setup.
function MakeRagdoll( x#, y#, z#, size#, mass# )
`start the ragdoll!
RagDoll = NDB_NewtonCreateRagDoll()
`start the ragdoll
` NDB_NewtonRagDollBegin RagDoll
gube=freeobject()
load object "C:Documents and SettingsMichaelDesktopNewtonNDB_v132NDBv_132 Releasedemosdemo11 - Advanced RagdollMediagubbe.x",gube
position object gube,0,0,0
set object cull gube,0
rem ghost object on gube,4
rem color object gube,RGB(10,10,130)
`make the root bone!
`first make the collision object for the bone, in this case a box!
Col = NDB_NewtonCreateBox( 5.0*size#, 4.5*size#, 1.0*size# )
`now setup the bone itself... first setup a matrix for the bone's orientation
` NDB_BuildMatrix 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
`then put the bone size in temp vector 1
NDB_SetVector 1, 0.0*size#, 4.5*size#, 1.0*size#
`now make the bone!!
Root = NDB_NewtonRagDollAddbone( RagDoll, 0, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
NDB_RagDollBoneSetOffset Root
NDB_RagDollBoneSetDBProData Root, gube, 0
`now make the chest bone!
Col = NDB_NewtonCreateBox( 4.5*size#, 4.5*size#, 3.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 90.0, 0.0, 3.0, 0.0
NDB_SetVector 1, 4.5*size#, 4.5*size#, 3.0*size#
Chest = NDB_NewtonRagDollAddBone( RagDoll, Root, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 90.0, 0.0, 3.0, 0.0
NDB_RagDollBoneSetOffset Chest
NDB_SetVector 1, 0.0,90.0,0.0
NDB_NewtonRagDollBoneSetLimits Chest,10.0,20.0,20.0
NDB_RagDollBoneSetDBProData Chest, gube, 9
`now make the head bone!
Col = NDB_NewtonCreateSphere( 2.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.5, 0.0, 0.0
NDB_SetVector 1, 2.0*size#, 2.0*size#, 2.0*size#
Head = NDB_NewtonRagDollAddBone( RagDoll, Chest, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.5, 0.0, 0.0
NDB_RagDollBoneSetOffset Head
NDB_SetVector 1, 0.0,90.0,0.0
NDB_NewtonRagDollBoneSetLimits Head,10.0,50.0,20.0
NDB_RagDollBoneSetDBProData Head, gube, 16
`now make the left arm bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 4.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, -90.0, 3.5*size#, -3.0*size#, 0.0
NDB_SetVector 1, 3.5*size#, 1.6*size#, 1.6*size#
LArm = NDB_NewtonRagDollAddBone( RagDoll, Chest, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, -90.0, 3.5*size#, -3.0*size#, 0.0
NDB_RagDollBoneSetOffset LArm
NDB_SetVector 1, 90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits LArm,10.0,150.0,30.0
NDB_RagDollBoneSetDBProData LArm, gube, 13
`now make the left arm2 bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 4.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_SetVector 1, 4.0*size#, 1.6*size#, 1.6*size#
LArm2 = NDB_NewtonRagDollAddBone( RagDoll, LArm, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset LArm2
NDB_SetVector 1, 90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits LArm2,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData LArm2, gube, 14
`now make the left Hand bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 2.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_SetVector 1, 2.5*size#, 1.6*size#, 1.6*size#
LHand = NDB_NewtonRagDollAddBone( RagDoll, LArm2, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset LHand
NDB_SetVector 1, 90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits LHand,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData LHand, gube, 15
`now make the right arm bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 4.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 90.0, 3.5*size#, 3.0*size#, 0.0
NDB_SetVector 1, 3.5*size#, 1.6*size#, 1.6*size#
RArm = NDB_NewtonRagDollAddBone( RagDoll, Chest, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 90.0, 3.5*size#, 3.0*size#, 0.0
NDB_RagDollBoneSetOffset RArm
NDB_SetVector 1, -90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits RArm,10.0,150.0,30.0
NDB_RagDollBoneSetDBProData RArm, gube, 10
`now make the right arm2 bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 4.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_SetVector 1, 4.0*size#, 1.6*size#, 1.6*size#
RArm2 = NDB_NewtonRagDollAddBone( RagDoll, RArm, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset RArm2
NDB_SetVector 1, -90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits RArm2,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData RArm2, gube, 11
`now make the Right Hand bone!
Col = NDB_NewtonCreateCapsule( 0.7*size#, 2.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_SetVector 1, 2.5*size#, 1.6*size#, 1.6*size#
RHand = NDB_NewtonRagDollAddBone( RagDoll, RArm2, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 3.5*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset RHand
NDB_SetVector 1, -90.0,0.0,0.0
NDB_NewtonRagDollBoneSetLimits RHand,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData RHand, gube, 12
`now make the left leg bone!
Col = NDB_NewtonCreateCapsule( 0.8*size#, 6.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, -90.0, 1.8, -2.5*size#, 0.0
NDB_SetVector 1, 6.0*size#, 1.6*size#, 1.6*size#
LLeg = NDB_NewtonRagDollAddBone( RagDoll, Root, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, -90.0, 1.8, -3.0*size#, 0.0
NDB_RagDollBoneSetOffset LLeg
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits LLeg,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData LLeg, gube, 3
`now make the left leg2 bone!
Col = NDB_NewtonCreateCapsule( 0.8*size#, 6.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.0*size#, 0.0, 0.0
NDB_SetVector 1, 6.0*size#, 1.6*size#, 1.6*size#
LLeg2 = NDB_NewtonRagDollAddBone( RagDoll, LLeg, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.0*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset LLeg2
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits LLeg2,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData LLeg2, gube, 4
`now make the left Foot bone!
Col = NDB_NewtonCreateCapsule( 0.6*size#, 2.5*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 90.0, 0.0, 6.0*size#, 0.0, 0.0
NDB_SetVector 1, 2.5*size#, 1.6*size#, 1.6*size#
LFoot = NDB_NewtonRagDollAddBone( RagDoll, LLeg2, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 90.0, 0.0, 6.0*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset LFoot
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits LFoot,10.0,60.0,10.0
NDB_RagDollBoneSetDBProData LFoot, gube, 5
`now make the right leg bone!
Col = NDB_NewtonCreateCapsule( 0.8*size#, 6.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, -90.0, -1.8, -2.5*size#, 0.0
NDB_SetVector 1, 6.0*size#, 1.6*size#, 1.6*size#
RLeg = NDB_NewtonRagDollAddBone( RagDoll, Root, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, -90.0, -1.8, 3.0*size#, 0.0
NDB_RagDollBoneSetOffset RLeg
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits RLeg,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData RLeg, gube, 6
`now make the right leg2 bone!
Col = NDB_NewtonCreateCapsule( 0.8*size#, 6.0*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.0*size#, 0.0, 0.0
NDB_SetVector 1, 6.0*size#, 1.6*size#, 1.6*size#
RLeg2 = NDB_NewtonRagDollAddBone( RagDoll, RLeg, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 0.0, 0.0, 5.0*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset RLeg2
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits RLeg2,10.0,100.0,10.0
NDB_RagDollBoneSetDBProData RLeg2, gube, 7
`now make the right Foot bone!
Col = NDB_NewtonCreateCapsule( 0.6*size#, 2.5*size# )
`this matrix is a local matrix, in relation to the parent bone!
NDB_BuildMatrix 0.0, 90.0, 0.0, 6.0*size#, 0.0, 0.0
NDB_SetVector 1, 2.5*size#, 1.6*size#, 1.6*size#
RFoot = NDB_NewtonRagDollAddBone( RagDoll, RLeg2, Col, mass#/11.0 )
NDB_BuildMatrix 0.0, 90.0, 0.0, 6.0*size#, 0.0, 0.0
NDB_RagDollBoneSetOffset RFoot
NDB_SetVector 1, 0.0,-90.0,0.0
NDB_NewtonRagDollBoneSetLimits RFoot,10.0,60.0,10.0
NDB_RagDollBoneSetDBProData RFoot, gube, 8
`okay, we're done with the ragdoll!
NDB_NewtonRagDollEnd RagDoll
NDB_RagDollSetGravity RagDoll, 1
`NDB_SetVector 1, 0.0,90.0,0.0
`UpvectorJoint=NDB_NewtonConstraintCreateUpVector (gube)
endfunction
`these are based off the fuctions found in the other demos, but have been simplified and
`adjusted for ragdolls.
function MakeBoxBone(sx#,sy#,sz#)
obj = FreeObject()
load object ".mediabox.x", obj
scale object obj, sx#*100.0, sy#*100.0, sz#*100.0
offset limb obj, 0, 0.5, 0.0, 0.0
color = GetColor()
color object obj, color
set object ambience obj, 50
endfunction obj
function MakeSphereBone(s#)
obj = FreeObject()
load object ".mediasphere.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, s#*100.0, s#*100.0, s#*100.0
offset limb obj, 0, 1.0, 0.0, 0.0
endfunction obj
`this makes a capsule shape, which is like a cylinder with rounded ends.
function MakeCapsuleBone(r#,h#)
obj = FreeObject()
load object ".mediacap_mid.x", obj
obj2 = FreeObject()
load object ".mediacap_cap.x", obj2
make mesh from object 1, obj2
delete object obj2
add limb obj, 5, 1
add limb obj, 6, 1
rotate limb obj, 6, 0.0, 180.0, 0.0
color object obj, GetColor()
set object ambience obj, 50
h# = h# - (r#*2)
if h# < 0.0 then h# = 0.0
scale limb obj, 2, h#*100.0, r#*100.0, r#*100.0
scale limb obj, 5, r#*100.0, r#*100.0, r#*100.0
scale limb obj, 6, r#*100.0, r#*100.0, r#*100.0
offset limb obj, 2, h#/2.0, 0.0, 0.0
offset limb obj, 5, h#, 0.0, 0.0
endfunction obj
function FreeObject()
repeat
inc i
if object exist(i)=0 then found=1
until found
endfunction i
function GetColor()
repeat
r = rnd(1)*255
g = rnd(1)*255
b = rnd(1)*255
until r<>0 or g<>0 or b<> 0
color = rgb(r,g,b)
endfunction color
function NeverCalled()
if memblock exist(1) then delete memblock 1
endfunction
function MakeBox(x#,y#,z#,sx#,sy#,sz#,rx#,ry#,rz#,mass#)
Col = NDB_NewtonCreateBox(sx#, sy#, sz#)
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMIBoxSolid mass#, sx#, sy#, sz#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediabox.x", obj
scale object obj, sx#*100.0, sy#*100.0, sz#*100.0
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
color = GetColor()
color object obj, color
set object ambience obj, 50
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeSphere(x#,y#,z#,s#,mass#)
Col = NDB_NewtonCreateSphere( s# )
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix 0.0, 0.0, 0.0, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMISphereSolid mass#, s#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediasphere.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, s#*100.0, s#*100.0, s#*100.0
position object obj, x#, y#, z#
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeCylinder(x#,y#,z#,r#,h#,rx#,ry#,rz#,mass#)
Col = NDB_NewtonCreateCylinder( r#, h# )
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMICylinderSolid mass#, r#, h#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediacylinder.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, h#*100.0, r#*100.0, r#*100.0
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeCapsule(x#,y#,z#,r#,h#,rx#,ry#,rz#,mass#)
Col = NDB_NewtonCreateCapsule( r#, h# )
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMICylinderSolid mass#, r#, h#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediacap_mid.x", obj
obj2 = FreeObject()
load object "mediacap_cap.x", obj2
make mesh from object 1, obj2
delete object obj2
add limb obj, 5, 1
add limb obj, 6, 1
rotate limb obj, 6, 0.0, 180.0, 0.0
color object obj, GetColor()
set object ambience obj, 50
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
h# = h# - (r#*2)
if h# < 0.0 then h# = 0.0
scale limb obj, 2, h#*100.0, r#*100.0, r#*100.0
scale limb obj, 5, r#*100.0, r#*100.0, r#*100.0
scale limb obj, 6, r#*100.0, r#*100.0, r#*100.0
offset limb obj, 5, h#/2.0, 0.0, 0.0
offset limb obj, 6, -h#/2.0, 0.0, 0.0
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeCone(x#,y#,z#,r#,h#,rx#,ry#,rz#,mass#)
Col = NDB_NewtonCreateCone( r#, h# )
Body = NDB_NewtonCreateBody(Col)
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMICylinderSolid mass#, r#, h#
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
obj = FreeObject()
load object "mediacone.x", obj
color object obj, GetColor()
set object ambience obj, 50
scale object obj, h#*100.0, r#*100.0, r#*100.0
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
NDB_BodySetDBProData Body, obj
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetGravity Body, 1
endfunction Body
function MakeConvexHull(file$,x#,y#,z#,rx#,ry#,rz#,mass#)
obj = FreeObject()
load object file$, obj
Col = NDB_NewtonCreateConvexHull( obj )
Body = NDB_NewtonCreateBody(Col)
NDB_CalculateMIBoxSolid mass#, object size x(obj), object size y(obj), object size z(obj)
NDB_NewtonBodySetMassMatrix Body, mass#
NDB_NewtonReleaseCollision Col
NDB_BuildMatrix rx#, ry#, rz#, x#, y#, z#
NDB_NewtonBodySetMatrix Body
NDB_NewtonBodySetDestructorCallback Body
NDB_BodySetDBProData Body, obj
color object obj, GetColor()
set object ambience obj, 50
position object obj, x#, y#, z#
rotate object obj, rx#, ry#, rz#
NDB_BodySetGravity Body, 1
endfunction Body
MakeFloor:
` GROUND OBJECT
` this makes a simple box with mass=0. this makes the object immobile, like a solid ground.
col = NDB_NewtonCreateBox( 1000.0, 10.0, 1000.0 )
Floor = NDB_NewtonCreateBody( col )
NDB_BuildMatrix 0.0, 0.0, 0.0, 0.0, -20.0, 0.0
NDB_NewtonBodySetMAtrix Floor
`now make a visual object to represent the floor onscreen... same size and position as
`the rigid body above.
obj = 567
load object "mediabox.x", obj
position object obj, 0.0, -20.0, 0.0
scale object obj, (1000.0*100.0), (10.0*100.0), (1000.0*100.0)
scale object texture obj, 10.0, 10.0
texture object obj, 1
`this tells the wrapper that if I destroy the Floor rigid body,
`I also want the wrapper to delete the visual object as well.
NDB_NewtonBodySetDestructorCallback Floor
`this command connects a visual object with a rigid body, making them a "pair"
NDB_BodySetDBProData Floor, obj
FloorObj = obj
return
Newton Version
