Nuke, tornado/dustdevil, plane particle examples

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

Nuke, tornado/dustdevil, plane particle examples

Post by DK_PETER »

Play with the affectors and change images...

Create these three folders inside a main folder:
texture, scripts, material.

Needs images named: smoke.png and ring_flare.png


Next save each of the scripts below to the scripts folder:

Filename: atombase.particle

Code: Select all

particle_system atombase
{
	quota	2000
	material	pbsmoke
	particle_width	20
	particle_height	20
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Ring
	{
		angle	110.7
		colour	1 1 1 0.0729167
		colour_range_start	1 1 1 0.0729167
		colour_range_end	1 1 1 1
		direction	0 1 0
		emission_rate	183.4
		position	0 0 -500
		velocity	0
		velocity_min	0
		velocity_max	0
		time_to_live	5
		time_to_live_min	5
		time_to_live_max	5
		duration	0
		duration_min	0
		duration_max	0
		repeat_delay	0
		repeat_delay_min	0
		repeat_delay_max	0
		width	165.6
		height	0
		depth	10.17
		inner_width	0.5
		inner_height	0.5
	}
}
Filename: atombase2.particle

Code: Select all

particle_system atombaseblast
{
	quota	2000
	material	pbsmoke
	particle_width	0.001
	particle_height	0.001
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Ring
	{
		angle	11
		colour	1 1 1 0.02
		colour_range_start	1 1 1 0.07
		colour_range_end	1 1 1 1
		direction	0 0 1
		emission_rate	683.4
		position	0 0 -500
		velocity	0
		velocity_min	40
		velocity_max	160
		time_to_live	5
		time_to_live_min	4
		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	665.6
		height	0
		depth	60.17
		inner_width	0.01
		inner_height	0.01
	}
	affector Scaler
	{
		rate	20
	}

}
Filename: atombloom.particle

Code: Select all

particle_system atombloom
{
	quota	1000
	material	pbsmoke
	particle_width	30
	particle_height	30
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Ring
	{
		angle	110.7
		colour	1 1 1 0.0729167
		colour_range_start	1 1 1 1
		colour_range_end	1 1 1 1
		direction	0 -1 -1
		emission_rate	163.4
		position	0 100 -500
		velocity	0
		velocity_min	0
		velocity_max	1
		time_to_live	5
		time_to_live_min	2
		time_to_live_max	5
		duration	0
		duration_min	0
		duration_max	0
		repeat_delay	0
		repeat_delay_min	0
		repeat_delay_max	0
		width	200
		height	100
		depth	15
		inner_width	0.1
		inner_height	0.1
	}

	affector Scaler
	{
		rate	7.049
	}

	affector ColourFader
	{
		red	1
		green	0
		blue	0
		alpha	1
	}

	affector LinearForce
	{
		force_vector	0.1 -0.1 0
		force_application	add
	}
}
Filename: atompillar.particle

Code: Select all

particle_system atompillar
{
	quota	1000
	material	pbringflare
	particle_width	15
	particle_height	15
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Ellipsoid
	{
		angle	110.7
		colour	1 1 1 0.0729167
		colour_range_start  1 1 1 0.0229167
		colour_range_end  1 1 1 0.0022167
		direction	0 1 0
		emission_rate	80
		position	0 10 -400
		velocity	0
		velocity_min	0
		velocity_max	0
		time_to_live	3
		time_to_live_min	2
		time_to_live_max	5
		duration	0
		duration_min	0
		duration_max	0
		repeat_delay	0
		repeat_delay_min	0
		repeat_delay_max	0
		width	4
		height	4
		depth	100
		inner_width	0.1
		inner_height	0.1
	}
}
Filename: atompillar2.particle

Code: Select all

particle_system atompillar2
{
	quota	2000
	material	pbsmoke
	particle_width	15
	particle_height	15
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Ring
	{
		angle	410.7
		colour	1 1 1 0.0729167
		colour_range_start  1 1 1 0.0229167
		colour_range_end  1 1 1 0.0022167
		direction	0 -1 0
		emission_rate	40
		position	0 10 -400
		velocity	0
		velocity_min	3
		velocity_max	8
		time_to_live	5
		time_to_live_min	5
		time_to_live_max	5
		duration	0
		duration_min	0
		duration_max	0
		repeat_delay	0
		repeat_delay_min	0
		repeat_delay_max	0
		width	4
		height	4
		depth	100
		inner_width	0.9
		inner_height	0.9
	}

}

Oooops...Forgot the material script. :-D
Save this in the material folder:

filename: materials.material

Code: Select all

material pbsmoke
{
	technique
	{
		pass
		{
			lighting off
			depth_write off
			scene_blend alpha_blend

			texture_unit
			{
				texture smoke.png
			}
		}
	}
}
material pbringflare
{
	technique
	{
		pass
		{
			lighting off
			depth_write off
			scene_blend add

			texture_unit
			{
				texture ring_flare.png
			}
		}
	}
}
Here's the main code:

Code: Select all

;Small and easy mini nuke example
;By DK_PETER

UsePNGImageDecoder()
UseJPEGImageDecoder()

InitEngine3D()
InitSprite()
InitKeyboard()

Global Dim par.i(6)

OpenWindow(0, 0, 0, 1024, 768, "Nuke", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, #False, 0, 0)

Add3DArchive("scripts", #PB_3DArchive_FileSystem)
Add3DArchive("material", #PB_3DArchive_FileSystem)
Add3DArchive("texture", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, $001821)
MoveCamera(0, 0, 1, 0)
CameraDirection(0, 0, 0, -1)
CreateLight(0, $00FFDB, 0, 1000, 500, #PB_Light_Directional)
CreatePlane(0, 500, 500, 1, 1, 10, 10)
CreateTexture(0, 128, 128)
StartDrawing(TextureOutput(0))
Box(0, 0, 128, 128, $00668B)
For x = 0 To 500
  Plot(Random(127,1), Random(127,1), $00759F)
Next x
StopDrawing()
CreateMaterial(0, TextureID(0))
CreateEntity(0, MeshID(0), MaterialID(0), 0, 0, 0)
ScaleEntity(0, 100, 1, 100)

par(0) = GetScriptParticleEmitter(#PB_Any, "atombase")
par(1) = GetScriptParticleEmitter(#PB_Any, "atompillar")
par(2) = GetScriptParticleEmitter(#PB_Any, "atompillar2")
par(3) = GetScriptParticleEmitter(#PB_Any, "atombloom")
par(4) = GetScriptParticleEmitter(#PB_Any, "atombaseblast")

DisableParticleEmitter(par(0), #True)
DisableParticleEmitter(par(1), #True)
DisableParticleEmitter(par(2), #True)
DisableParticleEmitter(par(3), #True)
DisableParticleEmitter(par(4), #True)

CreateSprite(0, ScreenWidth(), ScreenHeight())
StartDrawing(SpriteOutput(0))
Box(0, 0, ScreenWidth(), ScreenHeight(), $FFFFFF)
StopDrawing()

Begin = ElapsedMilliseconds()

Repeat
  
  Repeat : ev = WindowEvent() : If ev = #PB_Event_CloseWindow : Quit = 1 : EndIf : Until ev = 0
  
  RenderWorld()
  NowValue = ElapsedMilliseconds() - Begin
  Select NowValue
    Case 2000 To 2300
      DisplayTransparentSprite(0, 0, 0, 255, $FFFFFF)
    Case 2301 To 2550
      DisplayTransparentSprite(0, 0, 0, 2550 - NowValue)
    Case 2551 To 2620
      DisableParticleEmitter(par(1), #False)
      DisableParticleEmitter(par(2), #False)
    Case 2621 To 2800
      DisableParticleEmitter(par(0), #False)
    Case 2801 To 3000
      DisableParticleEmitter(par(3), #False)
    Case 6001 To 6200
      DisableParticleEmitter(par(4), #False)
    Case 6600 To 6800
      DisableParticleEmitter(par(0), #True)
      DisableParticleEmitter(par(1), #True)
      DisableParticleEmitter(par(2), #True)
      DisableParticleEmitter(par(3), #True)
  EndSelect
  
  FlipBuffers()
  
  ExamineKeyboard()
  
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Last edited by DK_PETER on Thu Jun 04, 2015 4:08 pm, edited 4 times in total.
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: Nuke

Post by applePi »

thanks DK_PETER, you are the particles master. the after explosion wind are more exact than the start. it is like a violent sand storm. also when we move the camera to position 1000 the scene are more dramatic
line 23: MoveCamera(0, 0, 1, 1000)
i have manipulated your smoke.png almost randomly and i got this:
Image
it gives scary sense
also i have tried this
Image
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Nuke

Post by DK_PETER »

Hi applePi

Yes..You're right. Moving the camera way back enhances the effect. :-)

I've messed with the nuclear bomb idea a bit more without scripting and came up this small animated demo.
Sorry for the messy code. This was made in a jiffy. ;-)

a.jpg, b.jpg, b2.jpg, c.jpg, sun.jpg, ring_flare.png, smoke.png
Images for download here: http://www.purebasic.fr/english/viewtop ... 36&t=62324

Here's the demo code: (Have fun).

(Code edited 12:28)
Added a more fiery bloom and fireblast. It could use two particleemitters more to make the bloom 'fold in' on itself.

Code: Select all

;The Event demo
;Made a small animated nightmare out of it this time.
;By DK_PETER
;Title: The Event

EnableExplicit

UsePNGImageDecoder()
UseJPEGImageDecoder()
UseJPEGImageEncoder()

InitEngine3D()
InitSprite()
InitKeyboard()

Structure _mesh
  id.i
  ms.i
  tx.i[2]
  ma.i[2]
  nod.i
EndStructure

Structure _parData
  id.i
  ma.i
  tx.i
  disabled.i
EndStructure

Structure _SunData
  id.i
  ma.i
  tx.i
  nod.i
  tim.i
  lgt.i
EndStructure

Structure _par
  birds._parData
  Atombase._parData[6]
  AtomBlast._parData[2]
  AtomBloom._parData[7]
  Aftermath._parData
  rocketfire._parData
  groundsmoke._parData[10]
EndStructure

Structure _Sprites
  Blink.i[2]
EndStructure

Global pa._par, grnd._mesh, cloud._mesh, Sun._SunData, rocket._mesh
Global sp._Sprites, BeginEvent.i, bird, Smokecheck.i, Procret.i, ev.i, xsmoke.i, Quit.i = 0

Declare.i SummerTime()
Declare.i NuclearTime()
Declare.i CreateInBetween()
Declare.i CreateLandscape()
Declare.f RandomF(min.f, Max.f, Res.i = 100000)
Declare.i MakeSpritesReady()

Procedure.i Skymaker(Night.i = #False)
  Protected tm.i, color.i, x.i, radinterval.i
  radinterval = 255/32
  If Night = #False 
    color = radinterval * NodePitch(sun\nod)
    CameraBackColor(0, RGB(0, 0, color))
  Else
    CameraBackColor(0, 0)
  EndIf
EndProcedure

Procedure.i NuclearTime()
  Protected x.i
  With grnd
    \tx[1] = LoadTexture(#PB_Any, "b.jpg")
    \ma[1] = CreateMaterial(#PB_Any, TextureID(\tx[1]))
    AddMaterialLayer(\ma[1], TextureID(LoadTexture(#PB_Any, "b2.jpg")), #PB_Material_Color)
    ScaleMaterial(\ma[1], 2,2, 1)
    DisableMaterialLighting(\ma[1], #False)
  EndWith
  
  With cloud
    \tx[1] = LoadTexture(#PB_Any, "c.jpg")
    \ma[1] = CreateMaterial(#PB_Any, TextureID(\tx[0]))
    AddMaterialLayer(\ma[1], TextureID(\tx[1]), #PB_Material_Add)
    ScrollMaterial(\ma[1], 0.01, 0.02, #PB_Material_Animated, 0)
    ScrollMaterial(\ma[1], -0.01, 0.01, #PB_Material_Animated, 1)
  EndWith
  
  With rocket
    \ms = CreateCylinder(#PB_Any, 0.3, 1, 6, 1, 0)
    \tx[0] = CreateTexture(#PB_Any, 10, 10)
    StartDrawing(TextureOutput(\tx[0]))
    DrawingMode(#PB_2DDrawing_Gradient)
    FrontColor($222222)
    BackColor($CCCCCC)
    BoxedGradient(0, 0,  10, 10)
    Box(0, 0, 10, 10)
    StopDrawing()
    \ma[0] = CreateMaterial(#PB_Any, TextureID(\tx[0]))
    \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma[0]), 0, 16, 995)
    RotateEntity(\id, 90, 0, 0, #PB_Absolute)
  EndWith
  
  With pa\rocketfire 
    \tx = CreateTexture(#PB_Any, 20, 20)
    StartDrawing(TextureOutput(\tx))
    DrawingMode(#PB_2DDrawing_Gradient)
    FrontColor($001BFF) : BackColor($00F2FF)
    CircularGradient(10, 10, 8)
    Circle(10, 10, 8)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    \id = CreateParticleEmitter(#PB_Any, 0.2,0.2,0.2,#PB_Particle_Point, 0,16,996)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleSize(\id, 0.5, 0.5)
    ParticleTimeToLive(\id, 0.1, 0.1)
    ParticleVelocity(\id, 0, 0.2)
    ParticleEmissionRate(\id, 60)
    ParticleEmitterDirection(\id, 0, 0, 1)
  EndWith
  
  With pa\Atombase[0]
    \tx = LoadTexture(#PB_Any, "smoke.png")
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_AlphaBlend)
    \id = CreateParticleEmitter(#PB_Any, 1, 1, 1, #PB_Particle_Point, 0, 0, 10)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleColorFader(\id, 0.2, 0.8, 0.5)
    ParticleColorRange(\id, $4B948D, $240BED)
    ParticleEmissionRate(\id, 50)
    ParticleEmitterDirection(\id, -0.7, 0, 0)
    ParticleTimeToLive(\id, 1.2, 1.2)
    ParticleVelocity(\id, 3, 3)
    ParticleSpeedFactor(\id, 0.2)
  EndWith
  
  With pa\Atombase[1]
    \tx = LoadTexture(#PB_Any, "smoke.png")
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_AlphaBlend)
    \id = CreateParticleEmitter(#PB_Any, 1, 1, 1, #PB_Particle_Point, 0, 0, 10)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleColorFader(\id, 0.2, 0.8, 0.5)
    ParticleColorRange(\id, $4B948D, $240BED)
    ParticleEmissionRate(\id, 50)
    ParticleEmitterDirection(\id, 0.7, 0, 0)
    ParticleTimeToLive(\id, 1.2, 1.2)
    ParticleVelocity(\id, 3, 3)
    ParticleSpeedFactor(\id, 0.2)
  EndWith
  
  With pa\Atombase[2]
    \tx = LoadTexture(#PB_Any, "ring_flare.png")
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    \id = CreateParticleEmitter(#PB_Any, 1, 1, 1, #PB_Particle_Point, 0,0, 9)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleColorFader(\id, 0.2, 0.8, 0.5)
    ParticleColorRange(\id, $4B948D, $240BED)
    ParticleEmissionRate(\id, 100)
    ParticleSize(\id, 30, 30)
    ParticleEmitterDirection(\id, 0, 1, 0)
    ParticleTimeToLive(\id, 1.1, 1.1)
    ParticleVelocity(\id, 10, 10)
    ParticleSpeedFactor(\id, 0.4)
  EndWith
  
  With pa\AtomBloom[0]
    \tx = LoadTexture(#PB_Any, "smoke.png")
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_AlphaBlend)
    \id = CreateParticleEmitter(#PB_Any, 1, 1, 1, #PB_Particle_Point, 0, 70, 13)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleColorFader(\id, 0.2, 0.8, 0.5)
    ParticleColorRange(\id, $4B948D, $240BED)
    ParticleEmissionRate(\id, 50)
    ParticleEmitterDirection(\id, -0.7, -0.017, 0)
    ParticleTimeToLive(\id, 1.5, 1.5)
    ParticleVelocity(\id, 4, 4)
    ParticleSpeedFactor(\id, 0.3)
  EndWith
  
  With pa\AtomBloom[1]
    \tx = LoadTexture(#PB_Any, "smoke.png")
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_AlphaBlend)
    \id = CreateParticleEmitter(#PB_Any, 1, 1, 1, #PB_Particle_Point, 0, 70, 13)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleColorFader(\id, 0.2, 0.8, 0.5)
    ParticleColorRange(\id, $4B948D, $240BED)
    ParticleEmissionRate(\id, 50)
    ParticleEmitterDirection(\id, 0.7, -0.017, 0)
    ParticleTimeToLive(\id, 1.5, 1.5)
    ParticleVelocity(\id, 4, 4)
    ParticleSpeedFactor(\id, 0.3)
  EndWith
  
  With pa\AtomBloom[2]
    \tx = CreateTexture(#PB_Any, 20, 20)
    StartDrawing(TextureOutput(\tx))
    DrawingMode(#PB_2DDrawing_Gradient)
    FrontColor($0056D4) : BackColor($05C4C3)
    CircularGradient(10, 10, 8)
    Circle(10, 10, 8)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    \id = CreateParticleEmitter(#PB_Any, 1, 1.03, 5, #PB_Particle_Point, 0, 70, 12.96)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleSize(\id, 21, 21)
    ParticleEmissionRate(\id, 25)
    ParticleEmitterDirection(\id, -0.7, -0.054, 0)
    ParticleTimeToLive(\id, 1.5, 1.5)
    ParticleVelocity(\id, 4, 4)
    ParticleSpeedFactor(\id, 0.3)
  EndWith
  
  With pa\AtomBloom[3]
    \tx = CreateTexture(#PB_Any, 20, 20)
    StartDrawing(TextureOutput(\tx))
    DrawingMode(#PB_2DDrawing_Gradient)
    FrontColor($0056D4) : BackColor($05C4C3)
    CircularGradient(10, 10, 8)
    Circle(10, 10, 8)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    \id = CreateParticleEmitter(#PB_Any, 1, 1.03, 5, #PB_Particle_Point, 0, 70, 12.96)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleSize(\id, 21, 21)
    ParticleEmissionRate(\id, 25)
    ParticleEmitterDirection(\id, 0.7, -0.054, 0)
    ParticleTimeToLive(\id, 1.5, 1.5)
    ParticleVelocity(\id, 4, 4)
    ParticleSpeedFactor(\id, 0.3)
  EndWith
  
  With pa\AtomBlast[0]
    \tx = LoadTexture(#PB_Any, "smoke.png")
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_AlphaBlend)
    \id = CreateParticleEmitter(#PB_Any, 30, 30, 1, #PB_Particle_Box, 0, 17, 10)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleSize(\id, 60, 65)
    ParticleEmissionRate(\id, 350)
    ParticleEmitterDirection(\id, 0, 0, 1)
    ParticleTimeToLive(\id, 2.5, 2.5)
    ParticleVelocity(\id, 300, 400)
  EndWith
  
  With pa\AtomBlast[1]
    \tx = CreateTexture(#PB_Any, 20, 20)
    StartDrawing(TextureOutput(\tx))
    DrawingMode(#PB_2DDrawing_Gradient)
    FrontColor($113EE2) : BackColor($11D2E2)
    CircularGradient(10, 10, 8)
    Circle(10, 10, 8)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    \id = CreateParticleEmitter(#PB_Any, 30, 30, 1, #PB_Particle_Box, 0, 27, 10)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleSize(\id, 70, 70)
    ParticleEmissionRate(\id, 350)
    ParticleEmitterDirection(\id, 0, 0, 1)
    ParticleTimeToLive(\id, 2.5, 2.5)
    ParticleVelocity(\id, 100, 200)
  EndWith
  
  With pa\Aftermath
    \tx = CreateTexture(#PB_Any, 20, 20)
    StartDrawing(TextureOutput(\tx))
    DrawingMode(#PB_2DDrawing_Gradient)
    FrontColor($222222)
    BackColor($FFFFFF)
    CircularGradient(10, 10, 8)
    Circle(10, 10, 8)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    \id = CreateParticleEmitter(#PB_Any, 2000, 2000, 2000, #PB_Particle_Box, 0, 500, 500)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleSize(\id, 2, 2)
    ParticleColorRange(\id, $4B948D, $240BED)
    ParticleEmissionRate(\id, 1550)
    ParticleEmitterDirection(\id, 0, -1, 0)
    ParticleTimeToLive(\id, 2, 2)
    ParticleVelocity(\id, 0.2, 1)
  EndWith
  
  For x = 0 To 9
    With pa\groundsmoke[x]
      \tx = LoadTexture(#PB_Any, "smoke.png")
      \ma = CreateMaterial(#PB_Any, TextureID(\tx))
      MaterialBlendingMode(\ma, #PB_Material_AlphaBlend)
      \id = CreateParticleEmitter(#PB_Any, 7, 5, 7, #PB_Particle_Point, RandomF(-500,500), 1, RandomF(-2700,900))
      ParticleMaterial(\id, MaterialID(\ma))
      ParticleSize(\id, 20, 20)
      ParticleEmissionRate(\id, 20)
      ParticleEmitterDirection(\id, 0, 1, 0)
      ParticleTimeToLive(\id, 0.3, 1)
      ParticleVelocity(\id, 0.1, 0.3)
      ParticleSpeedFactor(\id, 0.6)
      DisableParticleEmitter(\id,#True)   : \disabled = #True
    EndWith
  Next x
  
  DisableParticleEmitter(pa\Atombase[0]\id,#True) : pa\Atombase[0]\disabled = #True
  DisableParticleEmitter(pa\Atombase[1]\id,#True) : pa\Atombase[1]\disabled = #True
  DisableParticleEmitter(pa\Atombase[2]\id,#True) : pa\Atombase[2]\disabled = #True
  DisableParticleEmitter(pa\AtomBloom[0]\id,#True): pa\AtomBloom[0]\disabled = #True
  DisableParticleEmitter(pa\AtomBloom[1]\id,#True): pa\AtomBloom[1]\disabled = #True
  DisableParticleEmitter(pa\AtomBloom[2]\id,#True): pa\AtomBloom[2]\disabled = #True
  DisableParticleEmitter(pa\AtomBloom[3]\id,#True): pa\AtomBloom[3]\disabled = #True
  DisableParticleEmitter(pa\AtomBlast[0]\id,#True): pa\AtomBlast[0]\disabled = #True
  DisableParticleEmitter(pa\AtomBlast[1]\id,#True): pa\AtomBlast[1]\disabled = #True
  DisableParticleEmitter(pa\Aftermath\id,#True)   : pa\Aftermath\disabled = #True
  
EndProcedure

Procedure.i SummerTime()
  With grnd
    \tx[0] = LoadTexture(#PB_Any, "a.jpg")
    \ma[0] = CreateMaterial(#PB_Any, TextureID(\tx[0]))
    ScrollMaterial(\ma[0], 0, -0.1, #PB_Material_Animated)
  EndWith
  
  With cloud
    \tx[0] = LoadTexture(#PB_Any, "c.jpg")
    \ma[0] = CreateMaterial(#PB_Any, TextureID(\tx[0]))
    MaterialBlendingMode(\ma[0], #PB_Material_Add)
    AddMaterialLayer(\ma[0], TextureID(\tx[0]), #PB_Material_Color)
    ScrollMaterial(\ma[0], 0.001, 0.002, #PB_Material_Animated, 0)
    ScrollMaterial(\ma[0], -0.001, 0.01, #PB_Material_Animated, 1)
  EndWith
  
  With pa\birds ; Mega simple flocking birds..No details or material switching is required due to distance
                ;other alternatives is multiple particle emitters or sprites.
    \tx = CreateTexture(#PB_Any, 2, 2)
    StartDrawing(TextureOutput(\tx))
    Circle(1,1,1, $7777777)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Replace)
    \id = CreateParticleEmitter(#PB_Any, 800, 0, 800, #PB_Particle_Box, 1500, -220, -4000)
    ParticleEmitterDirection(\id, -1, 0, 0)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleSize(\id, 10, 10)
    ParticleEmissionRate(\id, 20)
    ParticleTimeToLive(\id, 3, 20)
    ParticleVelocity(\id, 0.01, 1)
  EndWith
  DisableParticleEmitter(pa\birds\id, #True) : pa\birds\disabled = #True
EndProcedure

Procedure.i CreateLandscape()
  Protected tx.i
  With grnd
    \ms = CreatePlane(#PB_Any, 500, 500, 1, 1, 3500, 3500)
    \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma[0]), 0, 0, 0)
    ScaleEntity(\id, 100, 100, 100)
  EndWith
  
  With cloud
    \ms = CreatePlane(#PB_Any, 500, 500, 1, 1, 1, 1)
    \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma[0]), 0, 2500, 0)
    ScaleEntity(\id, 150, 100, 150)
    RotateEntity(\id, 180, 0, 0, #PB_Absolute)
  EndWith
  
  With Sun
    \tx = LoadTexture(#PB_Any, "sun.jpg")
    \ma = CreateMaterial(#PB_Any,TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Add)
    SetMaterialColor(\ma, #PB_Material_SelfIlluminationColor, $00BFB4)
    \id = CreateBillboardGroup(#PB_Any, MaterialID(\ma), 1000, 1000, 0, 0, 0)
    AddBillboard(\id, 0, -1000, -5700)
    \nod = CreateNode(#PB_Any, 0, 0, 0)
    \lgt = CreateLight(#PB_Any, $00BFB4, 0, -1000, -5700, #PB_Light_Directional)
    AttachNodeObject(\nod, BillboardGroupID(\id))
    AttachNodeObject(\nod, LightID(\lgt))
  EndWith
  ProcedureReturn #True
EndProcedure

Procedure.i MakeSpritesReady()
  sp\Blink[0] = CreateSprite(#PB_Any, ScreenWidth(), ScreenHeight())
  StartDrawing(SpriteOutput(sp\Blink[0]))
  Box(0, 0, ScreenWidth(), ScreenHeight(), $FFFFFF)
  StopDrawing()
  sp\Blink[1] = CreateSprite(#PB_Any, ScreenWidth(), ScreenHeight())
  StartDrawing(SpriteOutput(sp\Blink[1]))
  Box(0, 0, ScreenWidth(), ScreenHeight(), $0)
  StopDrawing()
EndProcedure

Procedure.i DoSunStuff()
  RotateNode(sun\nod, 0.015, 0, 0, #PB_Relative)
  LightLookAt(sun\lgt, 0, 0, 0)
  If NodePitch(sun\nod) > 2 
    If pa\birds\disabled = #True
      DisableParticleEmitter(pa\birds\id, #False)
      pa\birds\disabled = #False
    EndIf
    Skymaker()
    If ElapsedMilliseconds() - bird > 500
      Select Random(10)
        Case 0 To 3
          ParticleEmitterDirection(pa\birds\id, Randomf(-0.5, -0.1), RandomF(-0.2, 0.2), 0)
        Case 4 To 6
          ParticleEmitterDirection(pa\birds\id, Randomf(-0.5, -0.1), RandomF(-0.2, 0.2), 0)
        Case 7 To 9
          ParticleEmitterDirection(pa\birds\id, Randomf(-0.5, -0.1), RandomF(-0.2, 0.2), 0)
        Default
          ParticleEmitterDirection(pa\birds\id, Randomf(-0.5, -0.1), RandomF(-0.2, 0.2), 0)
      EndSelect
      bird = ElapsedMilliseconds()
    EndIf
  EndIf
EndProcedure

Procedure.f RandomF(min.f, Max.f, Res.i = 100000)
  ProcedureReturn (Min + (Max - Min) * Random(Res) / Res)
EndProcedure


OpenWindow(0, 0, 0, 1024, 768, "The Event", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, #False, 0, 0)

Add3DArchive("texture", #PB_3DArchive_FileSystem)

Procret = SummerTime()
Procret = NuclearTime()
Procret = CreateLandscape()
Procret = MakeSpritesReady()

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 6, 1000)
CameraDirection(0, 0, 0, -1)

BeginEvent = ElapsedMilliseconds()
bird = ElapsedMilliseconds()

Repeat
  
  Repeat : ev = WindowEvent() : If ev = #PB_Event_CloseWindow : Quit = 1 : EndIf : Until ev = 0
  
  RenderWorld()
  
  Select ElapsedMilliseconds() - BeginEvent
    Case 0 To 35000
      Procret = DoSunStuff()
    Case 35100 To 35200
      DisableParticleEmitter(pa\birds\id, #True)
    Case 40000 To 43000 ;Nightmare begins
      MoveEntity(rocket\id, 0, 0, -0.8, #PB_Relative)
      MoveParticleEmitter(pa\rocketfire\id, 0, 0, -0.8, #PB_Relative)
    Case 43300 To 44900
      MoveEntity(rocket\id, 0, -0.01, -0.1, #PB_Relative)
      MoveParticleEmitter(pa\rocketfire\id, 0, -0.01, -0.1, #PB_Relative)
      ScrollMaterial(grnd\ma[0], 0, 0, #PB_Material_Fixed)
      HideParticleEmitter(pa\rocketfire\id, #True)
      HideEntity(rocket\id, #True)
    Case 45000 To 45200
      DisableParticleEmitter(pa\Atombase[0]\id, #False)
      DisableParticleEmitter(pa\Atombase[1]\id, #False)
      DisableParticleEmitter(pa\Atombase[2]\id, #False)
    Case 45300 To 45500
      DisplayTransparentSprite(sp\Blink[0], 0, 0, 255)
    Case 47700 To 55900
      DisableParticleEmitter(pa\AtomBloom[0]\id, #False)
      DisableParticleEmitter(pa\AtomBloom[1]\id, #False)
      DisableParticleEmitter(pa\AtomBloom[2]\id, #False)
      DisableParticleEmitter(pa\AtomBloom[3]\id, #False)
    Case 56000 To 56200
      DisableParticleEmitter(pa\Atombase[0]\id, #True) : pa\Atombase[0]\disabled = #True
      DisableParticleEmitter(pa\Atombase[1]\id, #True) : pa\Atombase[1]\disabled = #True
      DisableParticleEmitter(pa\Atombase[2]\id, #True) : pa\Atombase[2]\disabled = #True
      DisableParticleEmitter(pa\AtomBloom[0]\id, #True): pa\AtomBloom[0]\disabled = #True
      DisableParticleEmitter(pa\AtomBloom[1]\id, #True): pa\AtomBloom[1]\disabled = #True
      DisableParticleEmitter(pa\AtomBloom[2]\id, #True): pa\AtomBloom[0]\disabled = #True
      DisableParticleEmitter(pa\AtomBloom[3]\id, #True): pa\AtomBloom[1]\disabled = #True
      DisableParticleEmitter(pa\AtomBlast[0]\id, #False)  : pa\AtomBlast[0]\disabled = #False
      DisableParticleEmitter(pa\AtomBlast[1]\id, #False)  : pa\AtomBlast[1]\disabled = #False
    Case 56500 To 63000
      HideBillboardGroup(sun\id,#True)
      CameraBackColor(0, 0)
      RotateCamera(0, 0 + Cos(Random(2,1)), 0 + Sin(Random(2,1)), 0,#PB_Absolute)
    Case 63010 To 67200
      RotateCamera(0, Random(3,1), Random(2,1), Random(3,1), #PB_Relative)
    Case 67500 To 68000
      DisplaySprite(sp\Blink[1], 0, 0)
      SetEntityMaterial(cloud\id, MaterialID(cloud\ma[1]))
      SetEntityMaterial(grnd\id, MaterialID(grnd\ma[1]))
      HideParticleEmitter(pa\AtomBlast[0]\id, #True)
      HideParticleEmitter(pa\AtomBlast[1]\id, #True)
    Case 68300 To 69099
      DisplaySprite(sp\Blink[1], 0, 0)
      DisableParticleEmitter(pa\Aftermath\id, #False)
      RotateCamera(0, 0, 0, 0, #PB_Absolute)
    Case 69300 To 71000
      DisplaySprite(sp\Blink[1], 0, 0)
    Case 71200 To 71400
      For xsmoke = 0 To 9
        DisableParticleEmitter(pa\groundsmoke[xsmoke]\id, #False)
      Next xsmoke
      Smokecheck = ElapsedMilliseconds()
    Case 71100 To 105000
      If ElapsedMilliseconds()-Smokecheck > 400
        For xsmoke = 0 To 9
          ParticleEmitterDirection(pa\groundsmoke[xsmoke]\id, randomf(-1,1),1,randomf(-1,1))
        Next xsmoke
        Smokecheck = ElapsedMilliseconds()
        ParticleEmitterDirection(pa\Aftermath\id, randomf(-1,1), -1, randomf(-1,1))
      EndIf
    Case 106000 To 106500
      Quit = 1
  EndSelect
  
  FlipBuffers()
  
  ExamineKeyboard()
  
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

Last edited by DK_PETER on Thu May 28, 2015 10:50 am, edited 1 time in total.
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: Nuke

Post by applePi »

very cool code DK_PETER , a movie using programming code !!. who have not tried it yet will miss many goodies. can be used in a science exhibition, to demonstrate the hazards of nuclear weapons. the flocking birds particles are great. it gives the illusion that they are really a groggy flying birds even they are tiny circles.
i should say also that the paper particles in the fire cracker demo also deserve attention since it is suitable for making a tornado , you may want someday to simulate a tornado or whats called : dust devil:
https://www.youtube.com/watch?v=Mo8561rS13E
https://www.youtube.com/watch?v=EpYDzdI5PMU
i have played with the fire cracker in a low gravity and have used a circle equation for the particles but still not satisfied , i have posted before a tornado example http://purebasic.fr/english/viewtopic.p ... do#p436120 but it does not resemble a real tornado or dust devil at all
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Nuke

Post by DK_PETER »

Hi applePi.

Simulating a dustdevil/tornado is not easy, but here's my first attempt using particles.
It needs some finetuning, but it's certainly doable.

(Edit: Added simple debree to the dustdevil/tornado)

Code: Select all

;Simulate a tornado
;By DK_PETER - idea from applePi - http://purebasic.fr/english/viewtopic.php?f=36&t=58104&p=436136&hilit=tornado#p436120
;This uses two of the images from the animated nuclear example
;test 1 - particles no script

InitEngine3D()
InitSprite()
InitKeyboard()

UseJPEGImageDecoder()
UsePNGImageDecoder()

Structure _par
  id.i
  ma.i
  tx.i
  rotx.f
  incr.i
EndStructure

Structure _mesh
  id.i
  ms.i
  ma.i
  tx.i
EndStructure

Global Dim tor._par(6), Ground._mesh, Clouds._mesh, torpar.i

OpenWindow(0, 0, 0, 1024, 768, "Tornado", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, #False, 0, 0)

Add3DArchive("texture", #PB_3DArchive_FileSystem)

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 0.4, 16)
CameraBackColor(0, $FFA800)
CreateLight(0, $A5FFF7, 500, 2000, 400, #PB_Light_Directional)

With Ground
  \ms = CreatePlane(#PB_Any, 100, 100, 1, 1, 2, 2)
  \tx = LoadTexture(#PB_Any, "a.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  ScrollMaterial(\ma, 0.007, 0, #PB_Material_Animated)
  ScaleMaterial(\ma, 0.3, 0.3)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
EndWith

With clouds
  \tx = LoadTexture(#PB_Any, "c.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialBlendingMode(\ma, #PB_Material_Add)
  AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Color)
  ScrollMaterial(\ma, 0.001, 0.002, #PB_Material_Animated, 0)
  ScrollMaterial(\ma, -0.001, 0.01, #PB_Material_Animated, 1)

  \ms = CreatePlane(#PB_Any, 100, 100, 1, 1, 2, 2)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 500, 0)
  ScaleEntity(\id, 150, 100, 150)
  RotateEntity(\id, 180, 0, 0, #PB_Absolute)
EndWith


With tor(0)
  \tx = CreateTexture(#PB_Any, 10, 10)
  StartDrawing(TextureOutput(\tx))
  Circle(5, 5, 3, $1C1C1F)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialBlendingMode(\ma, #PB_Material_Color)
  \id = CreateParticleEmitter(#PB_Any, 1, 2, 1, #PB_Particle_Box, 0, 0 , 0)
  ParticleMaterial(\id, MaterialID(\ma))
  ParticleEmissionRate(\id, 300)
  ParticleTimeToLive(\id, 0.1, 0.2)
  ParticleVelocity(\id, 0.5, 0.7)
  ParticleEmitterDirection(\id, 1, 0 , 0)
  ParticleSize(\id, 4 , 0.5 )
EndWith

For torpar = 1 To 4
  With tor(torpar)
    \tx = CreateTexture(#PB_Any, 10, 10)
    StartDrawing(TextureOutput(\tx))
    Circle(5, 5, 3, $1C1C1F)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Color)
    \id = CreateParticleEmitter(#PB_Any, 1 * torpar, 2, 1 * torpar, #PB_Particle_Box, 0, 1 * torpar , 0)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleEmissionRate(\id, 500 * torpar)
    ParticleTimeToLive(\id, 0.1, 0.2)
    ParticleVelocity(\id, 0.5, 0.7)
    ParticleEmitterDirection(\id, 1, 0 , 0)
    ParticleSize(\id, 4 , 0.5 )
  EndWith
Next

With tor(5) ;debree
  \tx = CreateTexture(#PB_Any, 10, 10)
  StartDrawing(TextureOutput(\tx))
  Box(0, 0, 10, 10, $ABDFD3)
  StopDrawing()
  \id = CreateParticleEmitter(#PB_Any, 2.9, 0, 2.9, #PB_Particle_Box, 0, 3, 0)
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  ParticleSize(\id, 0.02, 0.06)
  ParticleEmissionRate(\id, 20)
  ParticleVelocity(\id, 0.01, 0.02)
  ParticleTimeToLive(\id, 0.3, 4)
  ParticleSpeedFactor(\id, 0.2)
  ParticleMaterial(\id, MaterialID(\ma))
  \rotx = -1
EndWith

Repeat
  
  Repeat
    ev = WindowEvent()
    If ev = #PB_Event_CloseWindow : Quit = 1 : EndIf
  Until  ev = 0
  
  For torpar = 0 To 5
    With tor(torpar)
      Select \incr
        Case 0
          If tor(torpar)\rotx - 0.01 < -1
            \incr = 1
          Else
            tor(torpar)\rotx - 0.01
          EndIf
        Case 1
          If tor(torpar)\rotx + 0.01 > 1
            \incr = 0
          Else
            tor(torpar)\rotx + 0.01
          EndIf
      EndSelect
      ParticleEmitterDirection(tor(torpar)\id, tor(torpar)\rotx, 0, 0)
    EndWith
  Next torpar
  RenderWorld()
  
  ExamineKeyboard()
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
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.
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Nuke, tornado/dustdevil, plane particle examples

Post by DK_PETER »

For this to work, you also need this texture:

rust.jpg
Images for download here: http://www.purebasic.fr/english/viewtop ... 36&t=62324

Code: Select all

;Simulate a plane (engine fire)

InitEngine3D()
InitSprite()
InitKeyboard()

UseJPEGImageDecoder()
UsePNGImageDecoder()

Structure _par
  id.i
  ma.i
  tx.i
EndStructure

Structure _mesh
  id.i
  ms.i
  ma.i
  tx.i
EndStructure

Structure _plane
  body._mesh
  wing._mesh[2]
  tail._mesh
  engine._mesh[2]
  nose._mesh
EndStructure

Global Dim pa._par(2), Ground._mesh, Clouds._mesh, torpar.i, pl._plane, rust.i

OpenWindow(0, 0, 0, 1024, 768, "Tornado", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, #False, 0, 0)

Add3DArchive("texture", #PB_3DArchive_FileSystem)

rust = LoadImage(#PB_Any, "texture\rust.jpg")

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 50, 16)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, $FFA800)
CreateLight(0, $A5FFF7, 500, 2000, 400, #PB_Light_Directional)

With clouds
  \tx = LoadTexture(#PB_Any, "c.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialBlendingMode(\ma, #PB_Material_Color)
  AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Color)
  AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Add)
  ScrollMaterial(\ma, -0.2, 0, #PB_Material_Animated, 0)
  ScrollMaterial(\ma, -0.4, 0, #PB_Material_Animated, 1)
  ScrollMaterial(\ma, -0.2, 0, #PB_Material_Animated, 2) ;<---duh..forgot to scroll the last layer
  \ms = CreatePlane(#PB_Any, 100, 100, 1, 1, 10, 10)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -200, 0)
  ScaleEntity(\id, 100, 100, 100)
EndWith

With Ground
  \tx = LoadTexture(#PB_Any, "a.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  ScaleMaterial(\ma, 0.5, 0.5, 0)
  ScrollMaterial(\ma, -1.015, 0, #PB_Material_Animated)
  \ms = CreatePlane(#PB_Any, 100, 100, 1, 1, 10, 10)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -800, 0)
  ScaleEntity(\id, 100, 1, 100)
EndWith

With pa(0)
  \tx = CreateTexture(#PB_Any, 10, 10)
  StartDrawing(TextureOutput(\tx))
  DrawingMode(#PB_2DDrawing_Gradient)
  BackColor($00F1E3) : FrontColor($0030FD)
  CircularGradient(5, 5, 3)
  Circle(5, 5, 3)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialBlendingMode(\ma, #PB_Material_Add)
  \id = CreateParticleEmitter(#PB_Any, 0.5, 0.5, 0.5, #PB_Particle_Box, 3, 1.5 , -10)
  ParticleMaterial(\id, MaterialID(\ma))
  ParticleEmissionRate(\id, 100)
  ParticleTimeToLive(\id, 0.1, 0.1)
  ParticleVelocity(\id, 0.2, 0.4)
  ParticleEmitterDirection(\id, 1, 0 , 0)
  ParticleSize(\id, 4 , 1 )
EndWith

With pa(1)
  \tx = CreateTexture(#PB_Any, 10, 10)
  StartDrawing(TextureOutput(\tx))
  DrawingMode(#PB_2DDrawing_Gradient)
  BackColor($00F1E3) : FrontColor($0030FD)
  CircularGradient(5, 5, 3)
  Circle(5, 5, 3)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialBlendingMode(\ma, #PB_Material_Add)
  \id = CreateParticleEmitter(#PB_Any, 0.5, 0.5, 0.5, #PB_Particle_Box, 3, 1.5 , 10)
  ParticleMaterial(\id, MaterialID(\ma))
  ParticleEmissionRate(\id, 100)
  ParticleTimeToLive(\id, 0.1, 0.1)
  ParticleVelocity(\id, 0.2, 0.4)
  ParticleEmitterDirection(\id, 1, 0 , 0)
  ParticleSize(\id, 4 , 1 )
EndWith

;Extremely simple plane 
;Here we go... This is probably more up applePi's alley.
;Normally I use 3D software to sculpt my objects, if it requires details
;but..hey..It's an example :-)

With pl\body
  \tx = LoadTexture(#PB_Any, "rust.jpg")  ;or create texture and draw image. This is easier..
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \ms = CreateCube(#PB_Any, 50)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 3, 0)
  ScaleEntity(\id, 0.5, 0.05, 0.07)
EndWith

With pl\nose
  \tx = CreateTexture(#PB_Any, 40, 40)
  StartDrawing(TextureOutput(\tx))
  Box(0, 0, 40, 10, $E68B00)
  DrawImage(ImageID(rust), 0, 10)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \ms = CreateSphere(#PB_Any, 50, 10, 10)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -15, 3, 0)
  ScaleEntity(\id, 0.1, 0.04, 0.04)
EndWith

With pl\wing[0] ;Shitty wings!!!
  \tx = LoadTexture(#PB_Any, "rust.jpg")  ;or create texture and draw image. This is easier..
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \ms = CreateCube(#PB_Any, 50)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -1, 2, -10)
  ScaleEntity(\id, 0.5, 0.01, 0.07)
  RotateEntity(\id, 0, 55, 0)
EndWith

With pl\wing[1]
  \tx = LoadTexture(#PB_Any, "rust.jpg")  ;or create texture and draw image. This is easier..
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \ms = CreateCube(#PB_Any, 50)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -1, 2, 10)
  ScaleEntity(\id, 0.5, 0.01, 0.07)
  RotateEntity(\id, 0, -55, 0)
EndWith

With pl\engine[0]
  \tx = LoadTexture(#PB_Any, "rust.jpg")  ;or create texture and draw image. This is easier..
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \ms = CreateSphere(#PB_Any, 30, 10, 10)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 1, 10)
  ScaleEntity(\id, 0.09, 0.08, 0.03)
EndWith

With pl\engine[1]
  \tx = LoadTexture(#PB_Any, "rust.jpg")  ;or create texture and draw image. This is easier..
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \ms = CreateSphere(#PB_Any, 30, 10, 10)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 1, -10)
  ScaleEntity(\id, 0.09, 0.08, 0.03)
EndWith

With pl\tail
  \tx = LoadTexture(#PB_Any, "rust.jpg")  ;or create texture and draw image. This is easier..
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \ms = CreateCylinder(#PB_Any, 3, 5, 2, 1, 5)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 10, 6, 0)
  ScaleEntity(\id, 1, 2, 0.3)
EndWith

;Assemble the plane

nod = CreateNode(#PB_Any, 0, 0, 0)
AttachNodeObject(nod, EntityID(pl\body\id))
AttachNodeObject(nod, EntityID(pl\nose\id))
AttachNodeObject(nod, EntityID(pl\wing[0]\id))
AttachNodeObject(nod, EntityID(pl\wing[1]\id))
AttachNodeObject(nod, EntityID(pl\engine[0]\id))
AttachNodeObject(nod, EntityID(pl\engine[1]\id))
AttachNodeObject(nod, EntityID(pl\tail\id))
AttachNodeObject(nod, ParticleEmitterID(pa(0)\id))
AttachNodeObject(nod, ParticleEmitterID(pa(1)\id))

Repeat
 
  Repeat
    ev = WindowEvent()
    If ev = #PB_Event_CloseWindow : Quit = 1 : EndIf
  Until  ev = 0

  RenderWorld()
 
  ExamineKeyboard()
  
  If KeyboardPushed(#PB_Key_Left)
    RotateNode(nod,0, 0, -0.1, #PB_Relative)
  EndIf
  If KeyboardPushed(#PB_Key_Right)
    RotateNode(nod,0, 0, 0.1, #PB_Relative)
  EndIf
  If KeyboardPushed(#PB_Key_Up)
    RotateNode(nod,-0.1, 0, 0, #PB_Relative)
  EndIf
  If KeyboardPushed(#PB_Key_Down)
    RotateNode(nod,0.1, 0, 0, #PB_Relative)
  EndIf
  
  FlipBuffers()
 
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
Last edited by DK_PETER on Thu May 28, 2015 10:52 am, edited 1 time in total.
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: Nuke, tornado/dustdevil, plane particle examples

Post by applePi »

thats very great DK_PETER ; but because the plane are distinguished and contains other ideas such as how to assemble a model using nodes it deserve a new thread alone , for the future users can find it easily.

good you have not used separated material files for the devil dust. wish Comtois add more material functions for easy using the engine . also we can beautifying the devil dust by moving the cam far away. i have played with your code and do MoveParticleEmitter in a small orbit. and choosing the particle size 2.
DK_PETER code with the above slight testing (as said needs some pictures above in folder "texture"

Code: Select all

;Simulate a tornado
;By DK_PETER - idea from applePi - http://purebasic.fr/english/viewtopic.php?f=36&t=58104&p=436136&hilit=tornado#p436120
;This uses two of the images from the animated nuclear example
;test 1 - particles no script

InitEngine3D()
InitSprite()
InitKeyboard()

UseJPEGImageDecoder()
UsePNGImageDecoder()

Structure _par
  id.i
  ma.i
  tx.i
  rotx.f
  incr.i
EndStructure

Structure _mesh
  id.i
  ms.i
  ma.i
  tx.i
EndStructure

Global Dim tor._par(6), Ground._mesh, Clouds._mesh, torpar.i

OpenWindow(0, 0, 0, 1024, 768, "Tornado", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, #False, 0, 0)

Add3DArchive("texture", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 10.4, 100)
CameraLookAt(0,0,0,0)
CameraBackColor(0, $FFA800)
CreateLight(0, $A5FFF7, 500, 2000, 400, #PB_Light_Directional)

With Ground
  \ms = CreatePlane(#PB_Any, 100, 100, 1, 1, 2, 2)
  \tx = LoadTexture(#PB_Any, "a.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  ScrollMaterial(\ma, 0.007, 0, #PB_Material_Animated)
  ScaleMaterial(\ma, 0.3, 0.3)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
EndWith

With clouds
  \tx = LoadTexture(#PB_Any, "c.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialBlendingMode(\ma, #PB_Material_Add)
  AddMaterialLayer(\ma, TextureID(\tx), #PB_Material_Color)
  ScrollMaterial(\ma, 0.001, 0.002, #PB_Material_Animated, 0)
  ScrollMaterial(\ma, -0.001, 0.01, #PB_Material_Animated, 1)

  \ms = CreatePlane(#PB_Any, 100, 100, 1, 1, 2, 2)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 500, 0)
  ScaleEntity(\id, 150, 100, 150)
  RotateEntity(\id, 180, 0, 0, #PB_Absolute)
EndWith


With tor(0)
  \tx = CreateTexture(#PB_Any, 10, 10)
  StartDrawing(TextureOutput(\tx))
  Circle(5, 5, 3, $1C1C1F)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialBlendingMode(\ma, #PB_Material_Color)
  \id = CreateParticleEmitter(#PB_Any, 1, 2, 1, #PB_Particle_Box, 0, 0 , 0)
  ParticleMaterial(\id, MaterialID(\ma))
  ParticleEmissionRate(\id, 300)
  ParticleTimeToLive(\id, 0.1, 0.2)
  ParticleVelocity(\id, 0.5, 0.7)
  ParticleEmitterDirection(\id, 1, 0 , 0)
  ParticleSize(\id, 2 , 0.5 )
EndWith

For torpar = 1 To 4
  With tor(torpar)
    \tx = CreateTexture(#PB_Any, 10, 10)
    StartDrawing(TextureOutput(\tx))
    Circle(5, 5, 3, $1C1C1F)
    StopDrawing()
    \ma = CreateMaterial(#PB_Any, TextureID(\tx))
    MaterialBlendingMode(\ma, #PB_Material_Color)
    \id = CreateParticleEmitter(#PB_Any, 1 * torpar, 2, 1 * torpar, #PB_Particle_Box, 0, 1 * torpar , 0)
    ParticleMaterial(\id, MaterialID(\ma))
    ParticleEmissionRate(\id, 500 * torpar)
    ParticleTimeToLive(\id, 0.1, 0.2)
    ParticleVelocity(\id, 0.5, 0.7)
    ParticleEmitterDirection(\id, 1, 0 , 0)
    ParticleSize(\id, 2 , 0.5 )
  EndWith
Next

With tor(5) ;debree
  \tx = CreateTexture(#PB_Any, 10, 10)
  StartDrawing(TextureOutput(\tx))
  Box(0, 0, 10, 10, $ABDFD3)
  StopDrawing()
  \id = CreateParticleEmitter(#PB_Any, 2.9, 0, 2.9, #PB_Particle_Box, 0, 3, 0)
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  ParticleSize(\id, 0.02, 0.06)
  ParticleEmissionRate(\id, 20)
  ParticleVelocity(\id, 0.01, 0.02)
  ParticleTimeToLive(\id, 0.3, 4)
  ParticleSpeedFactor(\id, 0.2)
  ParticleMaterial(\id, MaterialID(\ma))
  \rotx = -1
EndWith

Repeat
  
  Repeat
    ev = WindowEvent()
    If ev = #PB_Event_CloseWindow : Quit = 1 : EndIf
  Until  ev = 0
  
  For torpar = 0 To 5
    With tor(torpar)
      Select \incr
        Case 0
          If tor(torpar)\rotx - 0.01 < -1
            \incr = 1
          Else
            tor(torpar)\rotx - 0.01
          EndIf
        Case 1
          If tor(torpar)\rotx + 0.01 > 1
            \incr = 0
          Else
            tor(torpar)\rotx + 0.01
          EndIf
      EndSelect
      ParticleEmitterDirection(tor(torpar)\id, tor(torpar)\rotx, 0, 0)
      x.f=x+0.001: If x>=2*#PI:x=0:EndIf
      z.f=z+0.001: If z>=2*#PI:z=0:EndIf
      xx.f=Cos(x)*0.05
      zz.f=Sin(z)*0.05
      MoveParticleEmitter(tor(torpar)\id, xx, 0, zz )
    EndWith
  Next torpar
  RenderWorld()
  
  ExamineKeyboard()
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

Post Reply