Re: experiment with water
Posted: Thu Jun 05, 2014 9:40 pm
thats certainly big contribution, thanks, we can make niagara water falls simulation .
i'm trying to go around the waterfall, but still can't go around it exactly, the waterfall follow the camera, i will flatten the code to be compatible with my Flat one track only brain
but not now.
use the mouse and keys to try going around, or to have a bath under the waterfall. until it is corrected.
i'm trying to go around the waterfall, but still can't go around it exactly, the waterfall follow the camera, i will flatten the code to be compatible with my Flat one track only brain
use the mouse and keys to try going around, or to have a bath under the waterfall. until it is corrected.
Code: Select all
;First simple try to mimic splashing water....
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
UsePNGImageDecoder()
Add3DArchive("textures",#PB_3DArchive_FileSystem)
Add3DArchive("scripts", #PB_3DArchive_FileSystem)
DeclareModule WaterWorld
Declare.i SetResolution(Width.i, Height.i, FullScreen.i = #False)
Declare.i RunWaterWorld()
EndDeclareModule
Module WaterWorld
;IncludeFile #PB_Compiler_Home + "Examples/3D/Screen3DRequester.pb"
Structure mainVars
Win.i
Scr.i
FS.i
Cam.i
Quit.i
lgt.i
lgt2.i
EndStructure
Structure EntityVars
id.i
mes.i
mat.i
tex.i
EndStructure
Global va.mainVars
Declare.i MakePart()
Declare.i MakePlasticWater()
Global foam1.EntityVars
Global foam2.EntityVars
Global foam3.EntityVars
Global wat.EntityVars
Procedure.i MakePart()
foam1\id = GetScriptParticleEmitter(#PB_Any, "waterfosset")
foam2\id = GetScriptParticleEmitter(#PB_Any, "Watercircles")
foam3\id = GetScriptParticleEmitter(#PB_Any, "waterbounce")
EndProcedure
Procedure.i MakePlasticWater()
Protected extratex.i
extratex = LoadTexture(#PB_Any, "water1.png")
wat\mes = CreatePlane(#PB_Any, 1024, 1024, 10, 10, 1, 1)
wat\tex = LoadTexture(#PB_Any, "bwater.png")
wat\mat = CreateMaterial(#PB_Any, TextureID(wat\tex))
MaterialBlendingMode(wat\mat, #PB_Material_AlphaBlend)
AddMaterialLayer(wat\mat, TextureID(extratex), #PB_Material_Color)
RotateMaterial(wat\mat, -0.01,#PB_Material_Animated,0)
ScrollMaterial(wat\mat, 0.01, -0.01, #PB_Material_Animated, 1)
wat\id = CreateEntity(#PB_Any, MeshID(wat\mes), MaterialID(wat\mat), 0, -30, 0)
ProcedureReturn 0
EndProcedure
Procedure.i SetResolution(Width.i, Height.i, FullScreen.i = #False)
va\FS = FullScreen
Select FullScreen
Case #False ;Windowed
va\Win = OpenWindow(#PB_Any, 0, 0, Width, Height, "WaterWorld", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
va\Scr = OpenWindowedScreen(WindowID(va\Win), 0, 0, Width, Height, #False, 0, 0, #PB_Screen_SmartSynchronization)
Default
va\Scr = OpenScreen(Width, Height, 32, "Waterworld", #PB_Screen_SmartSynchronization, 60)
EndSelect
va\Cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(va\Cam, 0, 55, 150)
va\lgt = CreateLight(#PB_Any, $EEEEEE, 0, 1000, -3000, #PB_Light_Directional)
LightDirection(va\lgt, 1, -1, 0)
EndProcedure
Procedure.i RunWaterWorld()
Protected Quit.i = 0
Protected CameraSpeed = 3
Protected KeyX.f, KeyY.f, MouseX.f, MouseY.f
Parse3DScripts()
ret = MakePart()
ret = MakePlasticWater()
Repeat
;Screen3DEvents()
If ExamineMouse()
MouseX.f = -MouseDeltaX() * CameraSpeed * 0.05
MouseY.f = -MouseDeltaY() * CameraSpeed * 0.05
EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX.f = -CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX.f = CameraSpeed
Else
KeyX.f = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = CameraSpeed
Else
KeyY = 0
EndIf
If va\FS = #False
Repeat
ev = WindowEvent()
If ev = #PB_Event_CloseWindow
Quit = 1
EndIf
Until ev = 0
EndIf
RotateCamera(va\Cam, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (va\Cam, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndProcedure
EndModule
WaterWorld::SetResolution(800, 600, #False)
WaterWorld::RunWaterWorld()
