Time to fly..

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

Time to fly..

Post by DK_PETER »

This is yet another particle test.

To try it out, do the following:

removed:use your own images...

Save this code at the same location as the two folders above.

Code: Select all

InitEngine3D()
InitMouse()
InitKeyboard()
InitSprite()

UseJPEGImageDecoder()
UseJPEGImageEncoder()
UsePNGImageDecoder()

Add3DArchive("textures",#PB_3DArchive_FileSystem)
Add3DArchive("flares",#PB_3DArchive_FileSystem)

DeclareModule _3D_Test
	Structure Mesh_Data
		ent.i
		mesh.i
		tex.i
		mat.i
	EndStructure
	
	Structure Particle_Data
		id.i
		mat.i
		tex.i
	EndStructure
	
	Global Win.i, DefaultCam.i
	;Global NewSun.Mesh_Data 
	Global NewList par.Particle_Data()
	Global Hud.i
	
	Declare   SetUpScreen()
	Declare  CreateNewParticles()
	Declare  ConstructSkyboxTexture(SaveFullName.s, PicSize.i = 1024)
	Declare.i PlotStar(Img.i)
	Declare   Do_Mouse()
	Declare   ConstructHud()
	
EndDeclareModule

Module _3D_Test
	
	Procedure SetUpScreen()
		ExamineDesktops()
		Win = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "Hyperspace", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
		OpenWindowedScreen(WindowID(Win), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0,#PB_Screen_SmartSynchronization)
		DefaultCam = CreateCamera(#PB_Any,0,0,100,100)	
		MoveCamera(DefaultCam,0,0,200)
	EndProcedure
	
	Procedure CreateNewParticles()
		
		num = 1
		
		For x = 0 To 1
			AddElement(par())
			par()\id  = CreateParticleEmitter(#PB_Any,2000,2000,3000,#PB_Particle_Point)
			par()\tex = LoadTexture(#PB_Any,Str(num+x) + ".png")
			par()\mat = CreateMaterial(#PB_Any,TextureID(par()\tex))
			RotateMaterial(par()\mat,270,#PB_Absolute)
			DisableMaterialLighting(par()\mat, 1)
			MaterialBlendingMode(par()\mat, #PB_Material_Add)
			MoveParticleEmitter(par()\id, 0,0.0,#PB_Absolute)
			ParticleMaterial(par()\id, MaterialID(par()\mat))
			ParticleEmissionRate(par()\id,500)
			ParticleTimeToLive(par()\id,6.2,7.8)
			ParticleSize(par()\id,20,20)
			ParticleVelocity(par()\id,0.5,1.0)
			ParticleEmitterDirection(par()\id, 0 , 0 , 1)
		Next
		
	EndProcedure
	
	Procedure ConstructSkyboxTexture(SaveFullName.s, PicSize.i = 1024)
		Protected  Img.i
		img = CreateImage(#PB_Any,PicSize,PicSize,32,0)
		Img = PlotStar(Img)
		SaveImage(Img,SaveFullName + "_FR.jpg",#PB_ImagePlugin_JPEG,8)
		Img = PlotStar(Img)
		SaveImage(Img,SaveFullName + "_BK.jpg",#PB_ImagePlugin_JPEG,8)
		Img = PlotStar(Img)
		SaveImage(Img,SaveFullName + "_UP.jpg",#PB_ImagePlugin_JPEG,8)
		Img = PlotStar(Img)
		SaveImage(Img,SaveFullName + "_DN.jpg",#PB_ImagePlugin_JPEG,8)
		Img = PlotStar(Img)
		SaveImage(Img,SaveFullName + "_LF.jpg",#PB_ImagePlugin_JPEG,8)
		Img = PlotStar(Img)
		SaveImage(Img,SaveFullName + "_RT.jpg",#PB_ImagePlugin_JPEG,8)
		FreeImage(Img)
	EndProcedure
	
	Procedure PlotStar(Img.i)
		Protected cloud.i
		Select Random(400,1)
			Case 1 To 100
				cloud = LoadImage(#PB_Any,"textures\neb1.png")
			Case 101 To 200
				cloud = LoadImage(#PB_Any,"textures\neb2.png")
			Case 201 To 300
				cloud = LoadImage(#PB_Any,"textures\neb3.png")
			Default ;No cloud
		EndSelect
		StartDrawing(ImageOutput(Img))
		DrawingMode(#PB_2DDrawing_Default)
		Box(0,0,ImageWidth(Img),ImageHeight(Img),0)
		For x = 0 To 350
			col = Random(200,80)
			Plot(Random(ImageWidth(Img)-10,6),Random(ImageHeight(Img)-10,6),RGBA(col,col,col,Random(255,80)))
		Next x
		If IsImage(cloud)
			DrawingMode(#PB_2DDrawing_AlphaClip)
			For x = 0 To Random(3,1)
				DrawAlphaImage(ImageID(cloud),Random(ImageWidth(Img)-256,0),Random(ImageHeight(Img)-256,0),Random(50,10))
			Next x
			FreeImage(cloud)
		EndIf
		StopDrawing()
		ProcedureReturn Img
	EndProcedure
	
	Procedure ConstructHud()
		Protected x2.i, x3.i, y2, y3,w.i,h.i
		
		w = ScreenWidth():h = ScreenHeight()
		hud = CreateSprite(#PB_Any, w, h, #PB_Sprite_AlphaBlending)
		x2 = SpriteWidth(Hud) / 4
		x3 = x2 * 3
		y2 = SpriteHeight(Hud)/4
		y3 = y2 * 3
		
		StartDrawing(SpriteOutput(Hud))
		LineXY(0, 0, x2, y2, $ffff40)
		LineXY(x2, y2, x3, y2, $ffff40)
		LineXY(x3, y2, w, 0, $ffff40)
		
		LineXY(0, h, x2, y3, $ffff40)
		LineXY(x2, y3, x3, y3, $ffff40)
		LineXY(x3, y3, w, h, $ffff40)
		
		LineXY(w/2, (h/2)-50, w/2, (h/2)-25, $ffff40)
		LineXY(w/2, (h/2)+50, w/2, (h/2)+25, $ffff40)
		
		LineXY((w/2)-50, h/2, (w/2)-25, h/2, $ffff40)
		LineXY((w/2)+50, h/2, (w/2)+25, h/2, $ffff40)
		StopDrawing()
		TransparentSpriteColor(Hud,0)
		
	EndProcedure
	
	
	Procedure Do_Mouse()
		ExamineMouse()
		mx = -MouseDeltaX()  * 0.05
		my = -MouseDeltaY()  * 0.05
		
		RotateCamera(DefaultCam,my,mx,0,#PB_Relative)
		
	EndProcedure
EndModule

_3D_Test::ConstructSkyboxTexture("textures\Stars",1024)
_3D_Test::SetUpScreen()
_3D_Test::ConstructHud()
_3D_Test::CreateNewParticles()
SkyBox("stars.jpg")

Repeat
	ev = WindowEvent()
	
	_3D_Test::Do_Mouse()
	
	ExamineKeyboard()
	
	elapsed = RenderWorld()
	
	DisplayTransparentSprite(_3D_Test::Hud,0,0)
	FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or ev = #PB_Event_CloseWindow
Best regards
Peter
Last edited by DK_PETER on Sun Aug 10, 2014 5:34 am, 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: Time to fly..

Post by applePi »

this is absolutely fabulous , the example deserves to be in the official release with a new particle folder inside 3D examples. if we direct the space craft so the stars are straying away this can demonstrate the expanding universe, thanks Peter very much, i like especially the golden stars
PS: it seems the stars are attracted to a black hole
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Time to fly..

Post by Demivec »

@DK_PETER: I get an IMA at line 48: 'DefaultCam = CreateCamera(#PB_Any,0,0,100,100)'.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Time to fly..

Post by DK_PETER »

Demivec wrote:@DK_PETER: I get an IMA at line 48: 'DefaultCam = CreateCamera(#PB_Any,0,0,100,100)'.
Hi Demivec.
That's odd. I can't reproduce any IMA. Are you sure, that you've copy/pasted everything?
Line 48 is the 'OpenWindow' line...Unless you've made some changes?
Let me know if the problem persists.

@ApplePI.
I'm extremely glad, that you liked it. :-)

Best regards
Peter
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
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Time to fly..

Post by Demivec »

DK_PETER wrote:
Demivec wrote:@DK_PETER: I get an IMA at line 48: 'DefaultCam = CreateCamera(#PB_Any,0,0,100,100)'.
Hi Demivec.
That's odd. I can't reproduce any IMA. Are you sure, that you've copy/pasted everything?
Line 48 is the 'OpenWindow' line...Unless you've made some changes?
Let me know if the problem persists.
It persists. :cry:


@Edit: removed screenshot
Last edited by Demivec on Sat Aug 10, 2013 7:32 pm, edited 1 time in total.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Time to fly..

Post by davido »

@DK_PETER:

Highly impressive demonstration.
Thank you very much for sharing. :D
DE AA EB
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Time to fly..

Post by DK_PETER »

davido wrote:@DK_PETER:

Highly impressive demonstration.
Thank you very much for sharing. :D
You're welcome ;-)

Best regards
Peter
Last edited by DK_PETER on Sat Aug 10, 2013 8:03 pm, 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.
User avatar
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Time to fly..

Post by Demivec »

DK_PETER wrote:Set the creation of skybox to 512 instead of 1024 or
This change only allowed it to work for me. And yes, I didn't specify a sub-system. I didn't test the modified version you posted as it wasn't necessary after the previous change.

Perhaps my graphics card isn't as powerful as yours.


It is a nice demo. Thanks for your help in getting it to run on my system. :)
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Time to fly..

Post by DK_PETER »

Demivec wrote:
DK_PETER wrote:Set the creation of skybox to 512 instead of 1024 or
This change only allowed it to work for me. And yes, I didn't specify a sub-system. I didn't test the modified version you posted as it wasn't necessary after the previous change.

Perhaps my graphics card isn't as powerful as yours.


It is a nice demo. Thanks for your help in getting it to run on my system. :)
Thanks for the 'thumbs up' and you're welcome. ;-)
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
Demivec
Addict
Addict
Posts: 4282
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Time to fly..

Post by Demivec »

DK_PETER wrote:
Demivec wrote:
DK_PETER wrote:Set the creation of skybox to 512 instead of 1024 or
This change only allowed it to work for me. And yes, I didn't specify a sub-system. I didn't test the modified version you posted as it wasn't necessary after the previous change.

Perhaps my graphics card isn't as powerful as yours.


It is a nice demo. Thanks for your help in getting it to run on my system. :)
Thanks for the 'thumbs up' and you're welcome. ;-)
I have a further report on the odd problem I experienced with trying to run the demo. I had made the recommend change to the size of the skybox that was created by modifying the procedure itself, namely the default value for PicSize. I had neglected to change the value in the actual call itself. I noticed this later and reasoned that since I hadn't change the value in the call itself the default value was never used and it should have failed. Since it succeeded I reverted the changes I made (since they were actually inconsequential) and everything still worked.

I am not sure of the exact cause but I did notice a difference with the now working code and the former attempts (with identical code) that failed. It may have been due to interference from my anti-virus software. The anti-virus software interrupts the run to ask if the screen's keyboard functions be allowed to operate. During the failed attempts it had done this after initially displaying a blank screen first, then asking. In the working attempts it asked first then showed the screen. As a result I would diagnose my problems as being the fault of my anti-virus software.

That concludes this service announcement. I now return you to your regularly scheduled program. :)
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Time to fly..

Post by DK_PETER »

I have a further report on the odd problem I experienced with trying to run the demo. I had made the recommend change to the size of the skybox that was created by modifying the procedure itself, namely the default value for PicSize. I had neglected to change the value in the actual call itself. I noticed this later and reasoned that since I hadn't change the value in the call itself the default value was never used and it should have failed. Since it succeeded I reverted the changes I made (since they were actually inconsequential) and everything still worked.

I am not sure of the exact cause but I did notice a difference with the now working code and the former attempts (with identical code) that failed. It may have been due to interference from my anti-virus software. The anti-virus software interrupts the run to ask if the screen's keyboard functions be allowed to operate. During the failed attempts it had done this after initially displaying a blank screen first, then asking. In the working attempts it asked first then showed the screen. As a result I would diagnose my problems as being the fault of my anti-virus software.

That concludes this service announcement. I now return you to your regularly scheduled program. :)
[/quote]

ROFL!!! Nice update Demivec. Gonna remove the revised code now. :)
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.
Post Reply