Right,
well I've managed to clear a nice little afternoon in my diary and I've had the whole afternoon to push on with the Newton physics.
So far, I've got 5 spheres, a terrain object and a lot of trees, several materials set up as well, but they don't do that much.
It was working til I added the trees, but the spheres seem to go straight through them.
I'm just wondering, what are people wanting from the physics engine? I mean, at the moment, its just collision, but are people hoping for more? It may be easier to try and put in from the start than later.
If anyone knows why the spheres go through the trees, please could you look at this code, and say why. Thanks
//Notes
//Scale is equal to 1 unit to a metre. I think this will be fine.
//General Paraphernalia
Set Display Mode 1280,1024,32
Sync On
Backdrop on
Autocam off
Sync
//Types
#Constant Land = 1
#Constant Object1 = 2
#Constant Object2 = 3
#Constant Object3 = 4
#Constant Object4 = 5
#Constant Object5 = 6
`#Constant PlayerObject = 10
Global Dim Trees(300)
Print "Loading Objects!" : Sync
//Lets load all objects
//Land
Load object "Files/dbo/HiPoly_44.dbo",Land
//Load the Dynamic objects
Make Object Sphere Object1, 20
Make Object Sphere Object2, 20
Make Object Sphere Object3, 20
Make Object Sphere Object4, 20
Make Object Sphere Object5, 20
//Load the Static Objects
Load Object "Files/Beech_Tree/Beech_Tree_01.X",100
For Tree = 100 to 400
If Object Exist(Tree) = 0
Clone Object Tree, 100
Endif
Set Object Transparency Tree, 4
`Scale Object Tree, 50, 50, 50
X = Rnd(1000) : Z = Rnd(1000)
Y# = 800 - Intersect Object(1, X, 800, Z, X, -200, Z)
Position Object Tree, X, Y#, Z
Next
Print "Objects Loaded!" : Sync
//A few basic Parameters
Global World_Size_X as float : World_Size_X = 2000.0
Global World_Size_Y as float : World_Size_Y = 2000.0
Global World_Size_Z as float : World_Size_Z = 2000.0
//Newton Startup
NDB_NewtonCreate
//Sets the world size to predefinied limits
NDB_SetVector 1,World_Size_X/-2, World_Size_Y/-2, World_Size_Z/-2
NDB_SetVector 2,World_Size_X/2, World_Size_Y/2, World_Size_Z/2
NDB_NewtonSetWorldSize
NDB_SetVector 0.0, -50.0, 0.0
NDB_SetStandardGravity
Print "Setting Up Materials!" : Sync
//Setup Newton for the objects
//Make the materials
Grass as Integer : Metal as Integer : Wood as Integer
Grass = NDB_NewtonMaterialCreateGroupID()
Metal = NDB_NewtonMaterialCreateGroupID()
Wood = NDB_NewtonMaterialCreateGroupID()
//Set the Properties between two materials
//Mat_1, Mat_2, Collision Flag, Static Friction, Kinetic Friction, Elasticity, Softness
Set_Material_Properties(Grass, Metal, 1, 1.0, 1.0, 0.01, 1.0)
Set_Material_Properties(Metal, Wood, 1, 1.0, 1.0, 0.8, 1.0)
Print "Setting Terrain In Newton!" : Sync
//Terrain
//DB_Number, High Poly as Boolean, X, Y, Z,Material
Make_Newton_Terrain(Land, 1, -500.0, 0.0, -500.0, Grass)
Print "Setting Dynamic Objects In Newton!" : Sync
//Other objects
//Dynamic
//Uses a function to save space - DB_Num, Shape, Rad, Size X, Size Y, Size Z, Mass, X, Y, Z, Material
//Use either rad or size depending on which shape you are using.
//Box wants sizes, Sphere uses rad only, The rest use Rad and Size Y
Object1NDB = Newton_Dynamic_Object(Object1, "Sphere", 10.0, 0.0, 0.0, 0.0, 10.0, 201.0, 395.0, 400.0, Metal)
Object2NDB = Newton_Dynamic_Object(Object2, "Sphere", 10.0, 0.0, 0.0, 0.0, 10.0, 202.0, 375.0, 400.0, Metal)
Object3NDB = Newton_Dynamic_Object(Object3, "Sphere", 10.0, 0.0, 0.0, 0.0, 10.0, 203.0, 255.0, 400.0, Metal)
Object4NDB = Newton_Dynamic_Object(Object4, "Sphere", 10.0, 0.0, 0.0, 0.0, 10.0, 204.0, 235.0, 400.0, Metal)
Object5NDB = Newton_Dynamic_Object(Object5, "Sphere", 10.0, 0.0, 0.0, 0.0, 10.0, 205.0, 215.0, 400.0, Metal)
Print "Setting Static Objects In Newton!" : Sync
//Static
For Tree = 100 to 400
Trees(Tree-100) = Newton_Static_Object(Tree, Object Position X(Tree), Object Position Y(Tree), Object Position Z(Tree), Wood)
Next
Print "Done!" : Sync
//Camera
Position Camera 500,100,500
//Constants, arrays, other values
//Misc
time# = NDB_GetElapsedTimeInSec() //Two calls to prevent huge start value
time# = NDB_GetElapsedTimeInSec()
Position mouse 640,291
Disable Escapekey
//Start Loop
Do
//Misc stuff
Elapsedtime# = NDB_GetElapsedTimeInSec()
//Movement
if upkey() then move camera 1.0
if downkey() then move camera -1.0
if leftkey()
turn camera left 90.0
move camera 10.0 * Elapsedtime#
turn camera right 90.0
endif
if rightkey()
turn camera right 90.0
move camera 10.0 * Elapsedtime#
turn camera left 90.0
endif
xrotate camera -(300-mousey())
yrotate camera -(400-mousex())
//Collision handling
//No need newton does it for me =)
//Sync stuff
NDB_NewtonUpdate Elapsedtime#
Sync
text 0,0,str$(NDB_NewtonBodyGetMaterialGroupID(Object1NDB))`Elapsedtime#)
text 0,10,str$(NDB_GetCollisionBodyToMaterial(Object1NDB,Wood))
Text 0,20,Str$(wood)
If Escapekey() = 1 Then Goto Quit:
//End Loop
Loop
Quit:
NDB_NewtonDestroyAllBodies
End
//Functions
function NeverCalled()
if memblock exist(1) then delete memblock 1
endfunction
//Setup Newton for an object
function Newton_Dynamic_Object(DB_Number as Integer, Shape as String, Rad as Float, Size_X as Float, Size_Y as Float, Size_Z as Float, Mass as Float, X as Float, Y as Float, Z as Float, Material as Integer)
Select Shape
Case "Null"
TempCol = NDB_NewtonCreateNull( )
EndCase
Case "Sphere"
TempCol = NDB_NewtonCreateSphere( Rad ) //Creates the shape for Newton to use
EndCase
Case "Box"
TempCol = NDB_NewtonCreateBox( Size_x, Size_Y, Size_Z )
EndCase
Case "Cylinder"
TempCol = NDB_NewtonCreateCylinder( Rad, Size_Y )
EndCase
Case "Chamfer Cylinder"
TempCol = NDB_NewtonCreateChamferCylinder( Rad, Size_Y )
EndCase
Case "Cone"
TempCol = NDB_NewtonCreateCone( Rad, Size_Y )
EndCase
Case "Convex Hull"
TempCol = NDB_NewtonCreateConvexHull( DB_Number )
EndCase
Case Default
Number = -1
EndCase
EndSelect
If Number = -1
Repeat
Text 0,0, "There is an error with making a Newton Object for Object: " + Str$(Object1) + ": Check the shape."
Text 0,10,"Press Escape to Exit"
Sync
Until Escapekey() = 1
Endif
Number = NDB_NewtonCreateBody( TempCol ) //Makes a rigid body for the Newton Shape
NDB_BuildMatrix 0.0,0.0,0.0, X, Y, Z //Sets position and rotation, roatation first
NDB_NewtonBodySetMatrix Number
NDB_CalculateMISphereSolid Mass, Size
NDB_NewtonBodySetMassMatrix Number, Mass, 0.0, 0.0, 0.0 //Sets mass, can also add dampening for each axis
NDB_BodySetDBProData Number, DB_Number //Links Newton to DBPro
NDB_NewtonBodySetDestructorCallback Number
NDB_BodySetGravity Number, 1
NDB_NewtonBodySetLinearDamping Number, 0.02
NDB_SetVector 0.02, 0.02, 0.02
NDB_NewtonBodySetAngularDamping Number
NDB_NewtonReleaseCollision TempCol
NDB_NewtonBodySetMaterialGroupID Number, Material
Endfunction Number
Function Newton_Static_Object(DB_Number as Integer, X as Float, Y as Float, Z as Float, Material as Integer)
TempCol = NDB_NewtonCreateTreeCollision(DB_Number, 0)
Number = NDB_NewtonCreateBody (TempCol)
NDB_BuildMatrix 0.0,0.0,0.0, X, 800 - Y, Z
NDB_NewtonBodySetMassMatrix Number, 0, 0.0, 0.0, 0.0
NDB_BodySetDBProData Number, DB_Number
NDB_NewtonBodySetDestructorCallback Number
NDB_NewtonBodySetMaterialGroupID Number, Material
NDB_NewtonReleaseCollision TempCol
EndFunction Number
Function Make_Newton_Terrain(DB_Number as Integer, High_Poly_Flag as Boolean, X as Float, Y as Float, Z as Float, Material as Integer)
TempTerCol = NDB_NewtonCreateTreeCollision(DB_Number, High_Poly_Flag)
TerNumber = NDB_NewtonCreateBody (TempTerCol)
NDB_BuildMatrix 0.0,0.0,0.0, X, Y, Z
NDB_BodySetDBProData TerNumber, DB_Number
NDB_NewtonBodySetDestructorCallback TerNumber
NDB_NewtonBodySetMaterialGroupID TerNumber, Material
NDB_NewtonReleaseCollision TempTerCol
EndFunction
Function Set_Material_Properties(Mat_1 as Integer, Mat_2 as Integer, Flag as Boolean, Static_Friction as Float, Kinetic_Friction as Float, Elasticity as Float, Softness as Float)
NDB_NewtonMaterialSetDefaultCollidable Mat_1,Mat_2,Flag
NDB_NewtonMaterialSetDefaultFriction Mat_1,Mat_2, Static_Friction, Kinetic_Friction
NDB_NewtonMaterialSetDefaultElasticity Mat_1, Mat_2, Elasticity
NDB_NewtonMaterialSetDefaultSoftness Mat_1, Mat_2, Softness
NDB_NewtonMaterialSetCollisionCallback Mat_1, Mat_2
EndFunction
All files necessary and code so far are attached.