I switched from loading up the objects and running this:
function MakeConvex( Obj, Mass#, xs#, ys#, zs#, xp#, yp#, zp#, xr#, yr#, zr# )
Col = NDB_NewtonCreateConvexHull( Obj ) : Body = NDB_NewtonCreateBody( Col )
NDB_BuildMatrix xr#, yr#, zr#, xp#, yp#, zp#
NDB_NewtonBodySetMatrix Body
NDB_CalculateMIBoxSolid Mass#, xs#, ys#, zs#
NDB_NewtonBodySetMassMatrix Body, Mass#
NDB_NewtonReleaseCollision Col
NDB_BodySetDBProData Body, Obj
NDB_NewtonBodySetDestructorCallback Body : NDB_BodySetGravity Body, 1
NDB_SetVector 1, 1.0, 1.0, 1.0, 1.0
` NDB_SetVector 1, 1.0, 1.0, 10.0, 10.0
NDB_NewtonBodySetFreezeTreshold Body, 1
NDB_NewtonBodySetAutoFreeze Body, 0
endfunction Body
To using the rbd loader.dba found in the Newton Demo06 found in the '\NDBv_132 Release\demos' folder.
Now my program starts up a lot faster, but it randomly freezes. The more objects I put in, the more likely it is to freeze. It also occasionally crashes while loading objects, but as it used to crash a lot more, I'm less worried about that.
I've got 200 objects now; looking to get 400 in.
`constants for collision types
#constant COL_BOX 1
#constant COL_ELLIPSOID 2
#constant COL_CYLINDER 3
#constant COL_CAPSULE 4
#constant COL_CONE 5
#constant COL_HULL 6
`LoadBOD() **VERSION 2.0** this loads a ".bod" (Rigid Body) file created by my Rigid Body Designer tool.
`it automatically loads the visual object, and creates the Newton Rigid Body for it. this function returns
`the index to the RIGID BODY created.
function LoadBOD( filename$, rrx#, rry#, rrz#, ppx#, ppy#, ppz# )
if file exist(filename$) = 0 then close file 1 : exitfunction -1
open to read 1, filename$
for i=1 to 3
read byte 1, st
head$ = head$ + chr$(st)
next i
if head$ <> "bd2" then close file 1 : exitfunction -1
` ==========================================================
` VISUAL OBJECT INFORMATION
` ==========================================================
objectfile$ = LoadBOD_GetString() ` This wasn't returning anything
objectfile$ = "GeoSphere.x"
read float 1, rx#
read float 1, ry#
read float 1, rz#
read float 1, ox#
read float 1, oy#
read float 1, oz#
RemStart
While Inkey$( ) = ""
ClS
Print "Yes", " ", head$, " ", objectfile$
Sync
EndWhile
Wait 250
RemEnd ` Testing
if file exist(objectfile$) = 0 then close file 1 : exitfunction -1
obj = GetNextObject( ) ` The function it used wasn't available, so I used my own
load object objectfile$, obj
set object cull obj,0
rotate object obj, rx#, ry#, rz#
fix object pivot obj
offset limb obj, 0, ox#, oy#, oz#
` ==========================================================
` RIGID BODY PRIMITIVES
` ==========================================================
read byte 1, numprims
dim Cols(numprims)
if numprims > 1
NDB_StartCompoundCollision
endif
for i=1 to numprims
read byte 1, shape
if shape <> COL_HULL
read float 1, sx#
read float 1, sy#
read float 1, sz#
else
read long 1, vcount
`add convex hull here
mem = LoadBOD_FreeMemblock()
make memblock mem, 12 + (vcount * 3 * 4)
write memblock dword mem, 0, 2 : `fvf
write memblock dword mem, 4, 12 : `vertex size
write memblock dword mem, 8, vcount : `number of vertices
offset = 12
for v=1 to vcount
read float 1, in# : write memblock float mem, offset, in# : inc offset, 4
read float 1, in# : write memblock float mem, offset, in# : inc offset, 4
read float 1, in# : write memblock float mem, offset, in# : inc offset, 4
next v
`make the object
mesh = LoadBOD_FreeMesh()
make mesh from memblock mesh, mem
hullobj = GetNextObject( )
make object hullobj, mesh, 0 ` Originally, it referenced '1' for the mesh, but referencing mesh seems to make more sense to me. Neither option has any effect on the stability of the program.
delete mesh mesh
delete memblock mem
endif
read float 1, rx#
read float 1, ry#
read float 1, rz#
read float 1, ox#
read float 1, oy#
read float 1, oz#
`distortion matrix
for j=1 to 16
read float 1, in# : `ignored for now
next j
`collision id
read byte 1, in : `ignored for now
NDB_BuildMatrix rx#, ry#, rz#, ox#, oy#, oz#
select shape
case COL_BOX
Cols(i) = NDB_NewtonCreateBox(sx#, sy#, sz#, 1)
endcase
case COL_ELLIPSOID
Cols(i) = NDB_NewtonCreateSphere(sx#, sy#, sz#, 1)
endcase
case COL_CYLINDER
Cols(i) = NDB_NewtonCreateCylinder( sy#, sx#, 1 )
endcase
case COL_CAPSULE
Cols(i) = NDB_NewtonCreateCapsule( sy#, sx#, 1 )
endcase
case COL_CONE
Cols(i) = NDB_NewtonCreateCone( sy#, sx#, 1 )
endcase
case COL_HULL
Cols(i) = NDB_NewtonCreateConvexHull( hullobj, 1 )
delete object hullobj
hullobj = 0
endcase
` OTHER SHAPES GO HERE
endselect
if numprims > 1
NDB_AddCollisionToArray Cols(i)
endif
next i
if numprims > 1
Collision = NDB_NewtonCreateCompoundCollision()
Body = NDB_NewtonCreateBody( Collision )
else
Body = NDB_NewtonCreateBody( Cols(1) )
endif
` ==========================================================
` OBJECT SETUP DATA
` ==========================================================
read float 1, mass#
read float 1, Ixx#
read float 1, Iyy#
read float 1, Izz#
NDB_NewtonBodySetMassMatrix Body, mass#, Ixx#, Iyy#, Izz#
undim Cols()
NDB_BuildMatrix rrx#, rry#, rrz#, ppx#, ppy#, ppz#
NDB_NewtonBodySetMatrix Body
NDB_BodySetDBProData Body, obj
`set gravity to ON as a default
NDB_BodySetGravity Body, 1
close file 1
RemStart
While Inkey$( ) = ""
ClS
Print Body, " ", Obj
Sync
EndWhile
Wait 250
RemEnd ` Another test thing
endfunction Body
function LoadBOD_GetString()
read byte 1, length
st$ = ""
for i=1 to length
read byte 1, bt
st$ = st$ + chr$(bt)
next i
endfunction st$
function LoadBOD_FreeMemblock()
repeat
inc i
if memblock exist(i)=0 then found=1
until found
endfunction i
function LoadBOD_FreeMesh()
repeat
inc i
if mesh exist(i)=0 then found = 1
until found
endfunction i
Cheese!
Expert Bug-Finder, Horrible at Identifying Them.