'Swimmable' water in terrain

Advanced game related topics
Roger
User
User
Posts: 33
Joined: Thu Feb 16, 2006 1:53 pm

Post by Roger »

Working on it, but you'll find that it's just a modified version of PB's terrain example with a different terrain and a cube added for the water.

At the moment it's a bit of a mess, but as soon as I got it to work I'll make you a nice little, shiny new .zip package containing the code ;)
User avatar
Progi1984
Addict
Addict
Posts: 806
Joined: Fri Feb 25, 2005 1:01 am
Location: France > Rennes
Contact:

Post by Progi1984 »

Hi, i try to work on this point.

I find a blitz3D code http://www.blitzbasic.com/codearcs/code ... ?code=1110
But I don't arrive to transform it in Pure.

Code: Select all

Define.f KeyX, KeyY,KeyXCam, KeyYCam, MouseX, MouseY
Define.l actif
Global actifmesh.s

IncludeFile "Screen3DRequester.pb"
Declare WaterEffect()



Enumeration
  #TrackEntity
  #OgreEntity
  #CubeEntity
  #NinjaEntity
  #SphereEntity
EndEnumeration

actif=#CubeEntity
actifmesh="Cube"

If InitEngine3D()

  Add3DArchive("Data\Skybox.zip", #PB_3DArchive_Zip)
  Add3DArchive("Data\Dragon.zip", #PB_3DArchive_Zip)
 
  Add3DArchive("Data\Ogre\"   , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Circuit\", #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Cube\"   , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Ninja\"  , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Sphere\" , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\"        , #PB_3DArchive_FileSystem)
 
  Parse3DScripts()
 
  InitSprite()
  InitKeyboard()
  InitMouse()
 
  If Screen3DRequester()
 
    AmbientColor(RGB(128,128,128))
       
    EnableWorldPhysics(1)
   
    WorldShadows(#PB_Shadow_Additive)
   
    EnableWorldCollisions(1)

   
    OgreMesh   = LoadMesh(#PB_Any, "OgreHead.mesh")
    TrackMesh  = LoadMesh(#PB_Any, "racingcircuit.mesh")
    CubeMesh   = LoadMesh(#PB_Any, "Cube.mesh")
    SphereMesh = LoadMesh(#PB_Any, "Sphere.mesh")
   
    Text = LoadTexture(#PB_Any, "r2skin.jpg")
    Mat = CreateMaterial(#PB_Any, TextureID(Text))
   
    Steel = LoadTexture(#PB_Any, "RustySteel.jpg")
    SteelMaterial = CreateMaterial(#PB_Any, TextureID(Steel))
   
    DisableDebugger
    CreateEntity(#OgreEntity  , MeshID(OgreMesh), 0, 10, 0, 0)
    CreateEntity(#TrackEntity , MeshID(TrackMesh), 0, 0, 00, 0)
    CreateEntity(#CubeEntity  , MeshID(CubeMesh), MaterialID(Mat), 20, 0, 0)
    CreateEntity(#SphereEntity, MeshID(SphereMesh), MaterialID(SteelMaterial), 0, 0, 0)
    EnableDebugger

    EntityPhysicBody(#TrackEntity, #PB_Entity_StaticBody)
    EntityRenderMode(#TrackEntity, 0)
    EntityRenderMode(#OgreEntity, 0)
    ScaleEntity(#OgreEntity, 0.1, 0.1, 0.1)
    EntityRenderMode(#SphereEntity,0)
    ScaleEntity(#SphereEntity, 0.05, 0.05, 0.05)
    EntityRenderMode(#CubeEntity,0)
    ScaleEntity(#CubeEntity, 0.1, 0.1, 0.1)

    Fog(RGB(50,100,150),1,-100,200)   
    CreateLight(0, RGB(255,255,255),  100.0, 100, 0)
   
    SkyBox("desert07.jpg")
   
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0,0,0,30)
     
    Repeat
      Screen3DEvents()
     
      ClearScreen(RGB(0, 0, 0))
           
      If ExamineKeyboard()
        If KeyboardPushed(#PB_Key_Pad1) Or KeyboardPushed(#PB_Key_1)
          actif=#CubeEntity
          actifmesh="Cube"
        ElseIf KeyboardPushed(#PB_Key_Pad2) Or KeyboardPushed(#PB_Key_2)
          actif=#SphereEntity
          actifmesh="Sphere"
        ElseIf KeyboardPushed(#PB_Key_Pad3) Or KeyboardPushed(#PB_Key_3)
          actif=#OgreEntity
          actifmesh="Ogre"
        EndIf
       
       
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -1
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 1
        Else
          KeyX = 0
        EndIf
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -1
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 1
        Else
          KeyY = 0
        EndIf
       
        If KeyboardPushed(#PB_Key_A)
          KeyXCam = -1
        ElseIf KeyboardPushed(#PB_Key_D)
          KeyXCam = 1
        Else
          KeyXCam = 0
        EndIf
        If KeyboardPushed(#PB_Key_W)
         KeyYCam = -1
        ElseIf KeyboardPushed(#PB_Key_S)
          KeyYCam = 1
        Else
          KeyYCam = 0
        EndIf
             
        If KeyboardPushed(#PB_Key_Space)
          MoveEntity(#OgreEntity, 10, 40, 0)
        EndIf
   
      EndIf
     
      If ExamineMouse()
        MouseX = -MouseDeltaX()/10
        MouseY = -MouseDeltaY()/10
      EndIf
      RotateCamera(0, MouseX, MouseY, 0)
      MoveCamera  (0, KeyXCam, 0, KeyYCam)
      MoveEntity(actif,KeyX, 0, KeyY)
      RenderWorld()
      WaterEffect()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
   
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
 
End

Procedure WaterEffect()
  gw=WindowWidth(0)
  gh=WindowHeight(0)
  CreateSprite(0,gw,gh)
  GrabSprite(0,0,0,gw,gh)
  StartDrawing(ScreenOutput())
    underw_a=(underw_a+4)
    steph.f=gh/32
    mu8.f=gh/60
    If underw_a>359
      underw_a=0
    EndIf
    iiff=Int((gh-4)*100)
    For iif=0 To iiff Step 1
      int.l=Int(underw_a+iif)
      mod=int % 360
      wsin.f=Sin(mod)*mu8
      ClipSprite(0,0,iif, gw,steph+4)
       DisplaySprite(0,0,iif+wsin)
    Next
  StopDrawing()
  FreeSprite(0)
EndProcedure
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Num3 wrote:Here it is!
Get it while it's hot ;)

File:363kb->Water.zip
Tested it with V4 and it crashes, the textures are not loaded.
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Post by LuCiFeR[SD] »

I think it's because the files that came with the ogre beta (Fred released some time ago and it seems to be no longer available from the beta area) are not included with PB4 beta's and alas, I no longer have those files either and it crashes for me to :(. Oh well.
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Hey just put these textures with the correct name's in the data directory :P

Image
Image
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

num3, textures is one thing, how about using animated ones? water moves, ya know... :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

ScrollMaterial(3, 0.0009,0.005, #PB_Material_Animated,1) ;)
Thalius
Enthusiast
Enthusiast
Posts: 711
Joined: Thu Jul 17, 2003 4:15 pm
Contact:

Post by Thalius »

Something maybe to port to PB ...

Reallyreally nice:
http://graphics.cs.lth.se/theses/projects/projgrid/

Thalius
"In 3D there is never enough Time to do Things right,
but there's always enough Time to make them *look* right."
"psssst! i steal signatures... don't tell anyone! ;)"
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Num3 wrote:ScrollMaterial(3, 0.0009,0.005, #PB_Material_Animated,1) ;)
Oh boy.. Oh god.. We are in 2006 did you figure that out? need a calendar!? :lol: :lol:
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
dell_jockey
Enthusiast
Enthusiast
Posts: 767
Joined: Sat Jan 24, 2004 6:56 pm

Post by dell_jockey »

Thalius wrote:Something maybe to port to PB ...

Reallyreally nice:
http://graphics.cs.lth.se/theses/projects/projgrid/

Thalius
Nice reference. Thanks Thalius!
cheers,
dell_jockey
________
http://blog.forex-trading-ideas.com
Post Reply