Using Blitzterrain (Full version) with Dark Physics.
I adapted the collision example that comes with Blitzterrain to work with Darkphysics.I first tried to setup a rigid body for every sector seperately and it worked well.Then I constructed(adding limbs) one DBPRO object from the sector meshes generated by BT MakeSectorObject and associated a single DP rigid body with it. It worked well(not with PHY MAKE RIGID BODY STATIC Terrain,
but with PHY MAKE RIGID BODY STATIC mesh. Why ??).
But when I try to reposition the terrain I have two problems.
-The DP rigid body does not move.(If I use advanced terrain I can reposition the rigid body).
-the camera behaves as if terrain is still in the original position, although the Blitzterrain is repositioned.
I want to use the repositioning in the context of a continous terrain (not obvious from the example),
I don´t consider this as a BT ´bug´. But I just want some help setting up BlitzTerrain with Dark Physics.
see the this code:
To test: press "d" to make some balls fall on the terrain. (position the camera somewhere over the terrain first).
press "m" to reposition the terrain,
//BLITZ TERRAIN 2.00 EXAMPLE - DBPRO OBJECTS
//CREATED BY KARL HOBLEY (KAEDROHO) http://www.blitzwerks.co.uk
//CODE BELOW MAY BE USED IN COMMERCIAL AND NON COMMERCIAL PROJECTS
//CREATED AND TESTED WITH DBPRO 7.4
//This demo shows how to create DBPro objects with your terrain.
//As BlitzTerrain manages its own vertex buffers, DBPro is unable to get hold of meshdata for collision, etc. Heres how you do it.
//You have to call the command 'BT MakeSectorObject' or 'BT MakePhyObject' Make Phy object makes an object without UVs or normals.
//These commands creates objects for single sectors and positions them at 0,0,0. You must use BT GetSectorPositionXYZ to Position them.
//You must also use BT GetSectorCount and BT GetSectorExcluded to loop through each sector and make sure its not excluded.
//This system will be used for physics and collision.
//PLEASE NOTE: SLOW RENDER SPEEDS IS NOT BECAUSE OF DBPRO IS SLOW. THE SLOW RENDER SPEEDS ARE BECAUSE THIS DEMO IS RENDERING IN WIREFRAME MODE.
//CONTROLS
//ARROWKEYS AND MOUSE - MOVE
// F1 - WIREFRAME ON. F2 - WIREFRAME OFF
//Setup
sync on : sync rate 0 : sync
center text screen width()/2,screen height()/2,"Loading..." : sync : cls
autocam off
phy start
//Load media
global g_HeightmapImgID : global g_TextureImgID : global g_DetailmapImgID
g_HeightmapImgID=1 : g_TextureImgID=2 : g_DetailmapImgID=3
load image "..\Media\heightmap.bmp",g_HeightmapImgID
load image "..\Media\texture.jpg",g_TextureImgID
load image "..\Media\detail.tga",g_DetailmapImgID
//Create terrain
//Make the terrain
global g_TerrainID
g_TerrainID=BT MakeTerrain()
//Set images
BT SetTerrainHeightmap g_TerrainID,g_HeightmapImgID
BT SetTerrainTexture g_TerrainID,g_TextureImgID
BT SetTerrainDetail g_TerrainID,g_DetailmapImgID
//Set some other values
BT SetTerrainScale g_TerrainID,12.0
BT SetTerrainYScale g_TerrainID,2.0
BT SetTerrainSplit g_TerrainID,8
BT SetTerrainDetailTile g_TerrainID,3.0
//LOD
BT SetTerrainLOD g_TerrainID,3 //3 LOD levels
BT SetTerrainLODDistance g_TerrainID,1,1000.0 //LOD Distances start at one and go up to 1 less the LOD level count
BT SetTerrainLODDistance g_TerrainID,2,2000.0
//Smoothing and Quad Rotation
BT SetTerrainSmoothing g_TerrainID,1
BT SetTerrainQuadRotation g_TerrainID,1
//Build
global g_TerrainObjectID
g_TerrainObjectID=1
//This command processes the heightmap and creates all the internal structures for the terrain
BT BuildTerrain g_TerrainID,g_TerrainObjectID
//This command sets the number of sectors get created every call to 'BT ContinueBuild'.
//As we dont need a loading bar, I set this to 0 which makes it create the whole terrain at once
BT SetBuildStep 0
repeat
//This command generates the sectors. It returns the percentage of how much of the terrain it has generated.
//When it has generated the whole terrain it will return -1
progress=BT ContinueBuild()
until progress=-1
//Make objects
LODLevel= 0 //Set this anywhere between 0 and 2
for i=0 to BT GetSectorCount(g_TerrainID,LODLevel)-1
if BT GetSectorExcluded(g_TerrainID,LODLevel,i)=0
BT MakeSectorObject g_TerrainID,LODLevel,i,2
// addition PeterJBE: Constructing a single DBPRO object for making the collision mesh
secx# = BT GetSectorPositionX(g_TerrainID,LODLevel,i)
secy# = BT GetSectorPositionY(g_TerrainID,LODLevel,i)
secz# = BT GetSectorPositionZ(g_TerrainID,LODLevel,i)
MAKE MESH FROM OBJECT 20000, 2
if i = 0
make object 1000,20000
Position Object 1000,0,0,0
else
add limb 1000,i,20000
endif
offset limb 1000,i,secx#,secy#,secz#
rem if i <> 0 then LINK LIMB 1000, 0, i
delete object 2
delete mesh 20000
// end addition PeterJBE
rem exclude object off 2+i //This is so you are able to see the collision meshes. When using these you should not un exclude them!
rem set object wireframe 2+i,1
endif
next i
rem PHY MAKE RIGID BODY STATIC Terrain 1000 // addition PeterJBE: This does work. The balls fall through
hide object 1000
rem set object wireframe 2+i,1
PHY MAKE RIGID BODY STATIC mesh 1000 // addition PeterJBE: Making a single static rigid body
//Setup camera
set camera range 10,10000
rem hide mouse
//Main loop
StartTime=timer()
pressed = 0
op = 0
do
//Camera movement
Elapsedtime#=(timer()-StartTime)/3000.0+Elapsedtime#*0.7
StartTime=timer()
cx#=camera angle x()+mousemovey()/4.0
if cx#>90.0 then cx#=90.0
if cx#<-90.0 then cx#=-90.0
rotate camera cx#,camera angle y()+mousemovex()/4.0,0.0
if upkey() then move camera 1000.0*Elapsedtime#
if downkey() then move camera -1000.0*Elapsedtime#
gheight#=BT GetGroundHeight(g_TerrainID,camera position x(),camera position z())
if camera position y()-40<gheight# then position camera camera position x(),gheight#+40,camera position z()
if inkey$() = "d" // addition PeterJBE: Collision test >>> a number of balls fall on the terrain
make object sphere 10000 + pressed,10
Position object 10000 + pressed, camera position x()+ rnd(50) ,camera position y() +10, camera position z()+20 + rnd(50)
Phy make rigid body dynamic sphere 10000 + pressed
phy set rigid body mass 10000 + pressed,1
pressed = pressed + 1
ENDIF
remstart
addition PeterJBE:
I can reposition an Advanced Terrain associated with a DarkPhysics rigid body(PHY MAKE RIGID BODY STATIC Terrain)
with phy set rigid body position.
I would like to do this with Blitzterrain too, but I can not get it to work.
(I don´t think it is BT problem. I think it has too with setting up the DBPRO object).
(PS: I want to use this in the context of an endless terrain. Moving the terrain down is only for testing purposes,
but it does not seems to work.)
remend
if inkey$() = "m" and op = 0 // addition PeterJBE: Reposition the terrain and the rigid body.
Position Object g_TerrainObjectID,0, -1000,100 // the BT terrain is repositioned but the camera behaves as if terrain was still in the original place.
rem phy delete rigid body 1000
rem Position Object 1000,0, -500,100
phy set rigid body position 1000,0, -1000,100 // this does reposition the collision mesh
op =1
endif
//FPS
text 10,10,str$(screen fps())
//Position mouse
position mouse screen width()/2,screen height()/2
//Update screen
BT SetCurrentCamera 0 //Set current camera to 0 (if the camera has moved/rotated since this command was last called, you must call it again!)
BT UpdateTerrainCull g_TerrainID //Update frustum cullin
BT RenderTerrain g_TerrainID //Render the terrain
phy update
sync
loop
phy end