trogdor - sorry it took so long, I have been working 7 days a week
In the PhysX world (and ODE for that matter) objects have properties that define the way they interact with other objects
PhysX sets default properties that work well in many cases, stacked objects is one area where it doesn't work so well.
The key to controlling stacked objects, and other situations where you want the default PhysX properties to work differently
is to set up a 'material' for the objects to use. Be sure to read about materials in the PhysX docs.
Here is your code with a 'resting' material defined, and then applied when you set up the dynamic objects by assigning the material to use.
hope this helps!
` Advanced Terrain System - Example 1
` sky textures from - SkyMatter
` heightmap created by - David Smith ( infiniteloop@optushome.com.au )
` terrain base texture - generated from Advanced Terrain System Plus
` demo by - TGC
` set up display and camera
sync on
backdrop on
autocam off
set camera range 0.5, 30000
hide mouse
phy start
phy make material 1, "resting"
phy set material restitution 1, 0.1
phy set skin width 0.1
phy set material dynamic friction 1, 1.0
phy build material 1
` movement
g_fSpeed# = 0.05
g_fTurn# = 0.3
` set the directory to media
set dir "media"
` load base and detail texture
load image "texture.bmp", 1
load image "detail.tga", 2
make object terrain 1 ` create the terrain object
set terrain heightmap 1, "map.bmp" ` set the heightmap
set terrain scale 1, 3, 0.6, 3 ` set the scale
set terrain split 1, 16 ` split value by 16 * 16
set terrain tiling 1, 4 ` detail map tiling
set terrain light 1, 1, -0.25, 0, 1, 1, 0.78, 0.5 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture 1, 1, 2 ` base and detail texture
build terrain 1 ` finally build the terrain
phy make rigid body static terrain 1
` load our skybox
load object "skybox2.x", 200
set object light 200, 0
set object texture 200, 3, 1
position object 200, 1000, 2000, 4000
scale object 200, 30000, 30000, 30000
` reset the directory
set dir ".."
barrell1=2
make object cylinder barrell1, 5
scale object barrell1, 100,150,100
Position Object barrell1, 323.0,get terrain ground height(1,323.0,521.0), 521.0
phy make rigid body dynamic box barrell1
for i = 1 to 8
for ii = 1 to 5
barrell2=freeObject()
clone object barrell2,barrell1
color object barrell2,rgb(rnd(255),rnd(255),rnd(255))
scale object barrell2, 100,150,100
`Yrotate object barrell2,rnd(360)
Position Object barrell2, 323.0+(ii*7),get terrain ground height(1, 323.0+(ii*7),521.0)+(i*8), 521.0
phy make rigid body dynamic box barrell2,1
next ii
next i
` position the camera
position camera 344,23,470
` main program loop
do
` handle user input and show some stats
gosub userInput
gosub information
` get the height of the terrain at the current camera position
a# = get terrain ground height( 1, camera position x( ), camera position z( ) )
` now position the camera slightly above the terrain
position camera camera position x( ), a# + 3, camera position z()
` let the terrain handle some internal work
update terrain
phy update
` final screen update
sync
loop
userInput:
` simple mouse and keyboard movement
` move around with arrow keys
control camera using arrowkeys 0, g_fSpeed#, g_fTurn#
` store old camera angle
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
` store new camera angle
CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )
` rotate camera
yrotate camera curveangle ( CameraAngleY#, OldCamAngleY#, 24 )
xrotate camera curveangle ( CameraAngleX#, OldCamAngleX#, 24 )
` speed up movement
if inkey$ ( ) = "+"
if g_fSpeed# < 1000
g_fSpeed# = g_fSpeed# + 0.01
endif
endif
` slow down movement
if inkey$ ( ) = "-"
if g_fSpeed# > 0.002
g_fSpeed# = g_fSpeed# - 0.001
endif
endif
return
information:
` show some information
` start printing at top of screen
set cursor 0, 0
` show frame rate
print "fps = " + str$ ( screen fps ( ) )
print ""
` current camera position
print ""
print "x = " + str$ ( camera position x ( ) )
print "y = " + str$ ( camera position y ( ) )
print "z = " + str$ ( camera position z ( ) )
print ""
` finally the polygon count
print "polygon count = " + str$ ( statistic ( 1 ) )
print ""
return
Function freeObject()
Repeat
Inc i
Until (Object Exist(i) = 0 and i<>255)
EndFunction i