A scuba diver's surprise

Everything related to 3D programming
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

A scuba diver's surprise

Post by DK_PETER »

Wel...Again it requires the entire project to run..
It contains the following:
Mesh folder: sub.mesh - futuristic submarine or spacecraft. You may use it freely.
sound folder:
engine.wav, submerged.wav and a piece of lovely music provided for educational purposes only.
texture folder:
fish animation, bubbles, Hyperia and merk. (all jpg files)

Project: Get it here:
https://www.dropbox.com/s/rmynpupfh4c04 ... R.zip?dl=0

Have fun.


If you're interested in code only - here it is:

Scripts:
Filename: mat.material

Code: Select all

material plankmat1
{
	technique
	{
		pass
		{
			lighting off
			depth_write off
			scene_blend add
			texture_unit
			{
				texture Hyperia_l.jpg
			}
		}
	}
}
material plankmat2
{
	technique
	{
		pass
		{
			lighting off
			depth_write off
			scene_blend add
			texture_unit
			{
				texture Hyperia_r.jpg
			}
		}
	}
}
material bubble
{
	technique
	{
		pass
		{
			lighting off
			depth_write off
			scene_blend add
			texture_unit
			{
				texture bubble.jpg
			}
		}
	}
}
material "subwin"
{
	technique subwin_technique
	{
		pass subwin_standard
		{
			ambient 0.105882 0.172549 0.596078 1
			diffuse 1 1 1 1
			specular 1 1 1 1 153
			emissive 0 0 0 1
		}
	}
}
material "subhullmat"
{
	technique subhullmat_technique
	{
		pass subhullmat_standard
		{
			ambient 0.2 0.2 0.2 1
			diffuse 1 1 1 1
			specular 1 1 1 1 91.8
			emissive 0.3 0.3 0.8 1

			texture_unit subhullmat_Diffuse#0
			{
				texture hull.jpg
				tex_coord_set 0
				colour_op modulate
				scale 50 50
				scroll -0.45 0.45
			}
		}
	}
}
Script:
filename: par.particle

Code: Select all

particle_system plank1
{
	quota	40000
	material	plankmat1
	particle_width	0.1
	particle_height	0.1
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Box
	{
		angle	180
		colour	1 1 1 1
		colour_range_start	1 1 1 1
		colour_range_end	1 1 1 1
		direction	0 0 -1
		emission_rate	1000
		position	0 0 -100
		velocity	0.1
		velocity_min	0.1
		velocity_max	3
		time_to_live	10
		time_to_live_min	10
		time_to_live_max	15
		duration	0
		duration_min	0
		duration_max	0
		repeat_delay	0
		repeat_delay_min	0
		repeat_delay_max	0
		width	300
		height	300
		depth	200
	}

	affector LinearForce
	{
		force_vector	0 -0.002 -0.001
		force_application	add
	}
}
particle_system plank2
{
	quota	40000
	material	plankmat2
	particle_width	0.1
	particle_height	0.1
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Box
	{
		angle	180
		colour	0.510417 0.546392 0.5 1
		colour_range_start	0.510417 0.546392 1 1
		colour_range_end	1 1 1 1
		direction	0.2 0.1 -0.3
		emission_rate	1000
		position	0 0 0
		velocity	0.1
		velocity_min	0.1
		velocity_max	3
		time_to_live	10
		time_to_live_min	10
		time_to_live_max	15
		duration	0
		duration_min	0
		duration_max	0
		repeat_delay	0
		repeat_delay_min	0
		repeat_delay_max	0
		width	300
		height	300
		depth	200
	}

	affector LinearForce
	{
		force_vector	0 -0.004 -0.002
		force_application	add
	}
}
particle_system bubbles
{
	quota	10000
	material	bubble
	particle_width	0.5
	particle_height	0.5
	cull_each	true
	renderer	billboard
	billboard_type	point

	emitter Box
	{
		angle	180
		colour	1 1 1 1
		colour_range_start  1 1 1 1
		colour_range_end  1 1 1 1
		direction	0 0 1
		emission_rate	275.9
		position	0 0 0
		velocity	1
		velocity_min	1
		velocity_max	4
		time_to_live	2
		time_to_live_min  2
		time_to_live_max  10
		duration	0
		duration_min	0
		duration_max	0
		repeat_delay	0
		repeat_delay_min  0
		repeat_delay_max  0
		width	1
		height	1
		depth	10
	}

	affector LinearForce
	{
		force_vector	0 1 -0.7
		force_application  add
	}

	affector Scaler
	{
		rate  1.3
	}
}
Code:

Code: Select all

;------------------------------------------------
; Yet another mish mash
;------------------------------------------------
; By DK_PETER
;------------------------------------------------
; Scuba divers's surprise.
;------------------------------------------------
; Works here using Windows 7 and 10
; Music is NOT mine and provided for educational purposes.
; Add your own music and enhance the experience with music
; that suits your own taste. :-)
;------------------------------------------------
; Problems running this?
; Try OpenGL as subsystem
; Update drivers as needed.
; Try changing Add3DArchive paths
; Try it without sound.
; Or simply try something else than this demo :-)
;------------------------------------------------
UseJPEGImageDecoder()
UseOGGSoundDecoder()

DeclareModule _uboat
  Global  SoundAvailable.i = #True
  Declare.i SetScreen(Width.i = 1024, Height.i = 768, Fullscreen.i = #False)
  Declare.i Run_Demo()
EndDeclareModule

Module _uboat
  
  Structure Vector3
    x.f
    y.f
    z.f
  EndStructure
  
  Structure _par
    Id.i
    im.i[8]
    tx.i[8]
    ma.i[8]
    no.i
    nu.i
    dx.f
    dz.f
  EndStructure
  
  Structure _object
    id.i
    ma.i
    ms.i
    tx.i[2]
    no.i
  EndStructure
  
  
  Structure _Sounds
    base.i
    engine.i
    mus.i
    no.i
  EndStructure
  
  
  Declare.i MakeScene()
  Declare.f RandomF(min.f, Max.f, SeedVal.i = #PB_Ignore)
  Declare.i Looper(num.i)
  
  
  Global u._object, sn._Sounds, ca._object, win.i = -1, scr.i = 0, fs.i = #False
  Global shim._object, bub._object
  
  Global Dim plank._par(2), Dim fish._par(4), elap_fish.i, Kill.i = #False, Quit.i = #False
  
  Procedure.i SetScreen(Width.i = 1024, Height.i = 768, Fullscreen.i = #False)
    fs = Fullscreen
    Select fs
      Case #False
        Win = OpenWindow(#PB_Any, 0, 0, Width, Height, "A scuba diver's surprise - DK_PETER", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
        scr = OpenWindowedScreen(WindowID(win), 0, 0, Width, Height)
      Default
        scr = OpenScreen(Width, Height, 32, "A scuba diver's surprise by DK_PETER", #PB_Screen_SmartSynchronization)
    EndSelect
    If scr <> 0
      Add3DArchive("texture", #PB_3DArchive_FileSystem)  ;PLACE THIS CODE AT THE SAME LOCATION
      Add3DArchive("script" , #PB_3DArchive_FileSystem)  ;AS THESE FOLDERS
      Add3DArchive("sound"  ,#PB_3DArchive_FileSystem)   ;
      Add3DArchive("mesh", #PB_3DArchive_FileSystem)
      Parse3DScripts()
      CreateCamera(0, 0, 0, 100, 100)
      CameraRange(0, 0.5, 500)
      ProcedureReturn #True
    Else
      ProcedureReturn #False
    EndIf
  EndProcedure
  
  
  Procedure.i Run_Demo()
    Protected ret.i, lg.i
    
    ret = MakeScene()
    
    elap_fish = ElapsedMilliseconds()
    
    ret = CreateThread(@Looper(),1)
    
    Repeat
      
      If fs = #False
        Repeat
          ev = WindowEvent()
          If ev = #PB_Event_CloseWindow : Quit = #True : EndIf
        Until ev = 0
      EndIf
      RotateNode(u\no, 0, -0.3, 0, #PB_Relative)
      If IsNode(sn\no) > 0
        SoundListenerLocate(0, 0, 0)
      EndIf
      RenderWorld()
      
      ExamineKeyboard()
      
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = #True
    Kill = #True
    End
  EndProcedure
  
  Procedure.i Looper(num.i)
    Repeat
      If ElapsedMilliseconds() - elap_fish > 50
        For x = 0 To 4
          If fish(x)\nu + 1 > 7
            fish(x)\nu = 0
          Else
            fish(x)\nu + 1
          EndIf
          If kill = #False
            ParticleMaterial(fish(x)\Id, MaterialID(fish(x)\ma[fish(x)\nu]))
          Else
            Break
          EndIf
        Next x
        elap_fish = ElapsedMilliseconds()
      EndIf
    Until Kill = #True
  EndProcedure
  
  Procedure.i MakeScene()
    Protected x.i, y.i
    
    With ca
      \tx[0] = LoadTexture(#PB_Any, "bk2.jpg")
      \tx[1] = CopyTexture(\tx[0], #PB_Any)
      \ma = CreateMaterial(#PB_Any, TextureID(\tx[0]))
      MaterialBlendingMode(\ma, #PB_Material_Add)
      AddMaterialLayer(\ma, TextureID(\tx[1]), #PB_Material_Modulate)
      RotateMaterial(\ma, 90, #PB_Material_Fixed,1)
      ScrollMaterial(\ma, 0.06, -0.06, #PB_Material_Animated,0)
      ScrollMaterial(\ma, -0.06, 0.06, #PB_Material_Animated,1)
      ScaleMaterial(\ma, 2, 2, 0)
      ScaleMaterial(\ma, 4, 4, 1)
      MaterialCullingMode(\ma, #PB_Material_NoCulling)
      SetMaterialColor(\ma, #PB_Material_SelfIlluminationColor, $D74700)
      \ms = CreateCube(#PB_Any, 4)
      TransformMesh(\ms, 0, 0, 0, 100, 100, 100, 0, 0, 0)
      UpdateMeshBoundingBox(\ms)
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, -40.05)
      RotateEntity(\id, 90, 0, -90)
    EndWith
    
    plank(0)\Id = GetScriptParticleEmitter(#PB_Any, "plank1")
    plank(1)\Id = GetScriptParticleEmitter(#PB_Any, "plank2")
    
    For x = 0 To 4
      fish(x)\dx = Randomf(-1,1) : fish(x)\dz = Randomf(-0.1,0.1) 
      fish(x)\Id = CreateParticleEmitter(#PB_Any, 200, 100, 100, #PB_Particle_Box, randomf(-20,200), 0, randomf(-200,20))
      If fish(x)\dx <= 0 :fish(x)\dx = -1 : Else : fish(x)\dx = 1 : EndIf
      ParticleEmitterDirection(fish(x)\Id, fish(x)\dx, 0, fish(x)\dz)
      For y = 1 To 8
        If fish(x)\dx <= 0
          fish(x)\tx[y-1] = LoadTexture(#PB_Any, "a" + Str(y) + ".BMP")
        Else
          fish(x)\tx[y-1] = LoadTexture(#PB_Any, "b" + Str(y) + ".BMP")
        EndIf
        fish(x)\ma[y-1] = CreateMaterial(#PB_Any, TextureID(fish(x)\tx[y-1]))
        MaterialBlendingMode(fish(x)\ma[y-1], #PB_Material_Add)
        MaterialCullingMode(fish(x)\ma[y-1], #PB_Material_NoCulling)
        SetMaterialAttribute(fish(x)\ma[y-1], #PB_Material_DepthCheck, #True)
      Next y
      ParticleEmissionRate(fish(x)\Id, 10)
      fish(x)\nu = Random(7,1)
      ParticleMaterial(fish(x)\Id, MaterialID(fish(x)\ma[fish(x)\nu]))
      ParticleSize(fish(x)\Id, 2 , 1)
      ParticleTimeToLive(fish(x)\Id, 4, 6)
      ParticleVelocity(fish(x)\Id, 0.02, 0.5)
      ParticleSpeedFactor(fish(x)\Id, 0.3)
    Next x
    
    shim\tx[0] = LoadTexture(#PB_Any, "merk.jpg")
    shim\ma = CreateMaterial(#PB_Any, TextureID(shim\tx[0]))
    shim\tx[1] = CopyTexture(shim\tx[0], #PB_Any)
    MaterialBlendingMode(shim\ma, #PB_Material_Add)
    RotateMaterial(shim\ma, 50, #PB_Material_Fixed)
    AddMaterialLayer(shim\ma, TextureID(shim\tx[1]), #PB_Material_Replace)
    AddMaterialLayer(shim\ma, TextureID(shim\tx[1]), #PB_Material_Modulate)
    RotateMaterial(shim\ma, 180, #PB_Material_Fixed,1)
    ScaleMaterial(shim\ma, 3.2, 3.2, 0)
    ScaleMaterial(shim\ma, 2, 2, 1)
    ScrollMaterial(shim\ma, -0.01, 0,#PB_Material_Animated,0)
    ScrollMaterial(shim\ma, 0.01, 0,#PB_Material_Animated,1)
    ScrollMaterial(shim\ma, -0.01, 0,#PB_Material_Animated,2)
    MaterialCullingMode(shim\ma, #PB_Material_NoCulling)
    shim\ms = CreateCylinder(#PB_Any, 2, 10, 20, 10, #False)
    shim\id = CreateEntity(#PB_Any, MeshID(shim\ms), MaterialID(shim\ma), 0, 0, -460)
    ScaleEntity(shim\id, 150, 35, 2)
    
    ;I Wanted to do a simple sub, which can be used as a starship too. :-)
    u\no = CreateNode(#PB_Any, 0, 0, -140)
    u\ms = LoadMesh(#PB_Any, "sub.mesh")
    u\ma = GetScriptMaterial(#PB_Any, "subwin")
    u\id = CreateEntity(#PB_Any, MeshID(u\ms), #PB_Material_None, -100, 0, 0)
    ScaleEntity(u\id, 10, 10, 10)
    RotateEntity(u\id, 0, 0, -30)
    AttachNodeObject(u\no, EntityID(u\id))
    
    bub\id = GetScriptParticleEmitter(#PB_Any, "bubbles")
    MoveParticleEmitter(bub\id, -100, 3, 34) 
    AttachNodeObject(u\no, ParticleEmitterID(bub\id))
    If SoundAvailable = #True
      sn\engine = LoadSound3D(#PB_Any, "engine.wav")
      If IsSound3D(sn\engine) > 0
        sn\no = CreateNode(#PB_Any, -100, 3, 34)
        AttachNodeObject(sn\no, SoundID3D(sn\engine))
        AttachNodeObject(u\no, NodeID(sn\no))
        SoundVolume3D(sn\engine, 100)
        SoundRange3D(sn\engine, 10, 100)
        PlaySound3D(sn\engine, #PB_Sound3D_Loop)
      EndIf
      sn\base = LoadSound(#PB_Any, "sound\submerged.wav")
      If IsSound(sn\base)
        PlaySound(sn\base, #PB_Sound_Loop)
      EndIf
      sn\mus = LoadSound(#PB_Any,  "sound\Ivan Torrent - Before I Leave This World.ogg")
      If IsSound(sn\mus) > 0
        PlaySound(sn\mus, #PB_Sound_Loop, 50)
      EndIf
    EndIf
    ProcedureReturn #True
  EndProcedure
   
  
  Procedure.f RandomF(min.f, Max.f, SeedVal.i = #PB_Ignore)
    If SeedVal = #PB_Ignore : SeedVal = ElapsedMilliseconds() : EndIf
    ProcedureReturn (Min + (Max - Min) * Random(SeedVal) / SeedVal)
  EndProcedure
  
EndModule

If InitEngine3D(#PB_Engine3D_DebugOutput) = 0
  MessageRequester("Ogre3D error", "Check the ogre3D log file for info")
  End
EndIf
If InitSprite() = 0
  MessageRequester("Screen error", "Unable to open screen")
  End
EndIf
If InitKeyboard() = 0
  MessageRequester("Keyboard error", "Eeeeewwwww!!")
  End
EndIf
If InitSound() = 0
  _uboat::SoundAvailable = #False
EndIf

_uboat::SetScreen(1024, 768, #True) ; Set to #True for WindowedScreen()
_uboat::Run_Demo()
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: A scuba diver's surprise

Post by applePi »

Thanks DK_PETER, this is like a painting with color and sound or say a Documentary video. very enjoyable.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5524
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: A scuba diver's surprise

Post by Kwai chang caine »

Very nice thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply