Terrain collisions after modifying terrain

Everything related to 3D programming
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Terrain collisions after modifying terrain

Post by Realizimo »

Hello,

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
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: Terrain collisions after modifying terrain

Post by Bananenfreak »

Terrainphysicsbody isn´t updated after modifying an Terraintile.


EDIT: I modified your code a bit. Now camera is looking from above.
Last time I used Worlddebug() Terrain also got physicsbodylines, but now it gets None Oo
I can´t figure out why...

Code: Select all

; ------------------------------------------------------------
;
;   PureBasic - Terrain : Terrain Height change
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
IncludeFile #PB_Compiler_Home + "Examples\3D\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(#PB_Compiler_Home + "Examples\3D\Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples\3D\Data/Textures/nvidia", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples\3D\Data/GUI", #PB_3DArchive_FileSystem) 
Add3DArchive(#PB_Compiler_Home + "Examples\3D\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)
CameraLookAt(0, 0, 0, 0)
WorldDebug(#PB_World_DebugBody)
;- 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
Image
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: Terrain collisions after modifying terrain

Post by Realizimo »

Ok thanks anyway Bananenfreak.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Terrain collisions after modifying terrain

Post by Comtois »

It's a bug, it should be possible to update terrain's body. Should be fixed for next release.
Please correct my english
http://purebasic.developpez.com/
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: Terrain collisions after modifying terrain

Post by Bananenfreak »

@Alexi:
You said this many times and I answered with this: It´s a small team and not only 3D-side gets attention. Yes, I want much things, too, but they will do their best.
To whine is contraproductive.
Image
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: Terrain collisions after modifying terrain

Post by Realizimo »

Thanks Comtois
I am very glad when it's done.
You and fred do a great job.
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Terrain collisions after modifying terrain

Post by Comtois »

It's done, just call TerrainPhysicBody(0, 2, 1) after UpdateTerrain(0) in DoTerrainModify().
It's done also for entity, call EntityPhysicBody() to change a body (for example after scaling an entity).
Please correct my english
http://purebasic.developpez.com/
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: Terrain collisions after modifying terrain

Post by Realizimo »

Awesome, now I can continue with my project (a cargame)
User avatar
Bananenfreak
Enthusiast
Enthusiast
Posts: 519
Joined: Mon Apr 15, 2013 12:22 pm

Re: Terrain collisions after modifying terrain

Post by Bananenfreak »

Cool, thank you PB-Team :)
Image
Kelebrindae
Enthusiast
Enthusiast
Posts: 151
Joined: Tue Apr 01, 2008 3:23 pm

Re: Terrain collisions after modifying terrain

Post by Kelebrindae »

@Alexi:
You ask much, but give very little.
The statement seems harsh, so please let me explain. I'm sure you're a very competent coder, Alexi, and your posts in the "announcements" section sure are compelling. But I've never seen you post a single line of your own code here.
People have done a lot to help you or answer your questions (Samuel did a lot to help you with shaders, Comtois never fails to answer your questions about meshes, etc..), and yet, though your terrain system seems very advanced and would greatly benefit the community, you don't want to share your knowledge. Oh, so you " brought the library to the limits and above"? Then share the code, show us mere mortals how it's done and help Fred and the Team to get more of the well-deserved public attention they need to make PB bigger.

Believe me, we won't steal your work; We won't run away with it and claim the credits. It'll only encourage us to continue to help you.
Post Reply