I'm having problems with Ogre and physics when updating the terrain.
The terrain is created using CreateTerrain and AddTerrainTexture. The objects collide perfect with the loaded terrain.
The terrain is then modified using SetTerrainTileHeightAtPoint. After that UpdateTerrain is called. The graphics is updated correct, but objects don't collide with the new terrain. I have also tried to call TerrainPhysicsBody, BuildTerrain and EnableWorldCollisions after the terrain is modified, but it doesn't improve anything.
version 5.30 beta 7 (win7 x64)
In the attached example the terrain can be modified using the space key. The camera is looking from the ground (terrain) looking at the object (the ball). When the terrain is modified the camera angle changes as it should but the object is not affected by the new terrain.
Code: Select all
; ------------------------------------------------------------
;
; PureBasic - Terrain : Terrain Height change
;
; (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
IncludeFile "Screen3DRequester.pb"
#NbSommet = 36
Declare DoTerrainModify(tx, ty, wx.f, wy.f, wz.f, mBrushSizeTerrainSpace.f, height.f)
If InitEngine3D()=0 : End : EndIf
InitSprite()
InitKeyboard()
If Screen3DRequester()=0 : End : EndIf
Add3DArchive("Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Textures/nvidia", #PB_3DArchive_FileSystem)
Add3DArchive("Data/GUI", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
;- Light
light = CreateLight(#PB_Any ,RGB(185, 185, 185), 4000, 1200, 1000, #PB_Light_Directional)
SetLightColor(light, #PB_Light_SpecularColor, RGB(255*0.4, 255*0.4,255*0.4))
LightDirection(light ,0.55, -0.3, -0.75)
AmbientColor(RGB(5, 5,5))
;- Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 500, -50, #PB_Absolute)
CameraRange(0, 1, 0)
;- ball; new
CreateSphere(0, 3) ; new
CreateEntity(0,MeshID(0),#PB_Material_None,0,500,0); new
EntityPhysicBody(0,#PB_Entity_SphereBody) ; new
; terrain definition
SetupTerrains(LightID(Light), 3000, #PB_Terrain_NormalMapping)
; initialize terrain
CreateTerrain(0, 513, 12000, 600, 3, "TerrainHeight", "dat")
; set all texture will be use when terrrain will be constructed
AddTerrainTexture(0, 0, 100, "dirt_grayrocky_diffusespecular.jpg", "dirt_grayrocky_normalheight.jpg")
AddTerrainTexture(0, 1, 30, "grass_green-01_diffusespecular.jpg", "grass_green-01_normalheight.jpg")
AddTerrainTexture(0, 2, 200, "growth_weirdfungus-03_diffusespecular.jpg", "growth_weirdfungus-03_normalheight.jpg")
;- define terrains
DefineTerrainTile(0, 0, 0, "terrain513.png", ty % 2, tx % 2)
BuildTerrain(0)
TerrainPhysicBody(0, 2, 1) ; new
UpdateTerrain(0)
; SkyBox
SkyBox("desert07.jpg")
Repeat
ExamineKeyboard()
MoveCamera(0, EntityX(0), TerrainHeight(0, CameraX(0), CameraZ(0)) + 10, EntityZ(0)-40, #PB_Absolute)
CameraLookAt(0, EntityX(0), EntityY(0),EntityZ(0))
If KeyboardPushed(#PB_Key_Space)
DoTerrainModify(0, 0, EntityX(0),EntityY(0),EntityZ(0), 0.004, 30)
EndIf
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
Procedure DoTerrainModify(tx, ty, wx.f, wy.f, wz.f, mBrushSizeTerrainSpace.f, newheight.f)
terrainSize.f = TerrainTileSize(0, tx, ty) - 1
Pointx.f = TerrainTilePointX(0, tx, ty, wx, wy, wz)
Pointy.f = TerrainTilePointY(0, tx, ty, wx, wy, wz)
startx = (Pointx - mBrushSizeTerrainSpace) * terrainSize
starty = (Pointy - mBrushSizeTerrainSpace) * terrainSize
endx = (Pointx + mBrushSizeTerrainSpace) * terrainSize
endy = (Pointy + mBrushSizeTerrainSpace) * terrainSize
For y = starty To endy
For x = startx To endx
SetTerrainTileHeightAtPoint(0, tx, ty, x, y, newheight)
Next x
Next y
UpdateTerrain(0)
EndProcedure