Help PhysX Wrapper

Blitz3D Forums/Blitz3D Userlibs/Help PhysX Wrapper

Yue(Posted 2010) [#1]
Hi, I'm using the library for PhysX Wrapper, a function it has is the creation of a particle system, it would be easier if you speak English, but unfortunately I avail myself of the translator of google, where in some cases is very bad translation of documents.


The following code creates a system of particles, so good, but I need to use a jump through the goto command to restart the particle system, but I'm not.

I would appreciate any assistance.

Graphics3D 640,480,32,2
SetBuffer BackBuffer()
.inicio
SeedRnd MilliSecs ()

Global StarAmount

;Lights
light01=CreateLight()
PositionEntity light01,15,66,15
AmbientLight 255,255,255

;Plane
plane=CreatePlane()
EntityColor plane,0,0,150

;Camera
cam=CreateCamera()
PositionEntity cam,-20,20,-28
RotateEntity cam,0,-40,0


;PX
pxCreateWorld(1, "key")			
pxSetGravity(0,-10,0)		

;Physic cube
cube=CreateCube()
ScaleEntity cube,5,1,5
text02=LoadTexture("..\media\cube.jpg")
EntityTexture cube,text02
cube_body=pxBodyCreateCube(5,1,5,0)	
pxBodySetPosition cube_body,0,15,0	
pxBodySetRotation cube_body,0,0,-30	
pxBodySetCollisionGroup(cube_body, 1)

Global pEmitter = pxParticleCreateEmitter%()
pxParticleEmitSetRadius(pEmitter, 0.5)
pxParticleEmitSetStartSpeed( pEmitter, 3, 5)
pxParticleEmitSetTDAcceleration(pEmitter, 0, 3, 0)
pxParticleEmitSetRandRadius( pEmitter, 3)
pxParticleEmitSetScaleFactor(pEmitter, 3, 0.1)


Repeat ;Main Loop
	
	If KeyHit(200) 
		ClearWorld 
		Goto inicio
	End If 
	
	
n=1-n
If n=1 CreateParticleStar()

 time=MilliSecs ()
pxRenderPhysic(30,0)
pxParticleUpdateEmitter(pEmitter)
pxBodySetEntity(cube,cube_body)
UpdateParticleStar()
New_time=MilliSecs ()-time

UpdateWorld()
RenderWorld()
   frames=frames+1  
   If MilliSecs()-render_time=>1000  fps1=frames : frames=0 : render_time=MilliSecs()  
 Text 10,10,"FPS: "+fps1+"  dll time: "+New_time
  Text 10,20,StarAmount
Flip 

Until KeyHit(1)
End


Type Particle_Star
	Field particle
	Field sprite
End Type

 Function CreateParticleStar()
  ps.Particle_Star = New Particle_Star
 	ps\sprite = LoadSprite("..\media\smoke.jpg",2)
	SpriteViewMode ps\sprite,3
  	ps\particle = pxParticleEmitAddParticle(pEmitter, ps\sprite)
	StarAmount = StarAmount+1
End Function

Function UpdateParticleStar()
	For ps.Particle_Star = Each Particle_Star
		radius# = pxParticleGetradius#(ps\particle)
		ScaleSprite ps\sprite, radius, radius
		If StarAmount>300
			entit = pxParticleEmitDeleteFirstParticle(pEmitter)
			FreeEntity Entit
			Delete ps
			StarAmount = StarAmount - 1
		EndIf
	Next
End Function




FlagDKT(Posted 2010) [#2]
Graphics3D 640,480,32,2
SetBuffer BackBuffer()
.inicio
SeedRnd MilliSecs ()

Global StarAmount

;Lights
light01=CreateLight()
PositionEntity light01,15,66,15
AmbientLight 255,255,255

;Plane
plane=CreatePlane()
EntityColor plane,0,0,150

;Camera
cam=CreateCamera()
PositionEntity cam,-20,20,-28
RotateEntity cam,0,-40,0


;PX
pxCreateWorld(1, "key")			
pxSetGravity(0,-10,0)		

;Physic cube
cube=CreateCube()
ScaleEntity cube,5,1,5
text02=LoadTexture("..\media\cube.jpg")
EntityTexture cube,text02
cube_body=pxBodyCreateCube(5,1,5,0)	
pxBodySetPosition cube_body,0,15,0	
pxBodySetRotation cube_body,0,0,-30	
pxBodySetCollisionGroup(cube_body, 1)

Global pEmitter = pxParticleCreateEmitter%()
pxParticleEmitSetRadius(pEmitter, 0.5)
pxParticleEmitSetStartSpeed( pEmitter, 3, 5)
pxParticleEmitSetTDAcceleration(pEmitter, 0, 3, 0)
pxParticleEmitSetRandRadius( pEmitter, 3)
pxParticleEmitSetScaleFactor(pEmitter, 3, 0.1)

Global theSprite=LoadSprite("..\media\smoke.jpg",2)

Repeat ;Main Loop
	
	If KeyHit(200) 
		clearParticles()
	End If 
	
	
	n=1-n
	If n=1 CreateParticleStar()
		
		time=MilliSecs ()
		pxRenderPhysic(30,0)
		pxParticleUpdateEmitter(pEmitter)
		pxBodySetEntity(cube,cube_body)
		UpdateParticleStar()
		New_time=MilliSecs ()-time
		
		UpdateWorld()
		RenderWorld()
		frames=frames+1  
		If MilliSecs()-render_time=>1000  fps1=frames : frames=0 : render_time=MilliSecs()  
			Text 10,10,"FPS: "+fps1+"  dll time: "+New_time
			Text 10,20,StarAmount
			Flip 
			
		Until KeyHit(1)
		End
		
		
		Type Particle_Star
			Field particle
			Field sprite
		End Type
		
Function CreateParticleStar()
	ps.Particle_Star = New Particle_Star
 	ps\sprite = CopyEntity(theSprite)
	SpriteViewMode ps\sprite,3
  	ps\particle = pxParticleEmitAddParticle(pEmitter, ps\sprite)
	StarAmount = StarAmount+1
End Function

Function UpdateParticleStar()
	For ps.Particle_Star = Each Particle_Star
		radius# = pxParticleGetradius#(ps\particle)
		ScaleSprite ps\sprite, radius, radius
		If StarAmount>300
			entit = pxParticleEmitDeleteFirstParticle(pEmitter)
			FreeEntity Entit
			Delete ps
			StarAmount = StarAmount - 1
		EndIf
	Next
End Function

Function clearParticles()
	For p.Particle_Star=Each Particle_Star
		pxParticleEmitDeleteParticle pEmitter,p\particle
		FreeEntity p\sprite
		StarAmount=0
		Delete p
	Next
End Function


Forget about GOTO instructions, they are bad practice.
Use always functions to create and destroy things.
Don't load a sprite every frame, just copy the one you loaded once.

cheers


Yue(Posted 2010) [#3]
Thank you very much friend, I find it very useful, I am a newbie and always will be because every day have to learn something.


Yue(Posted 2010) [#4]
I can not apply to this.
;========================================================
; Proyecto    : Beta
; Nombre File : Menu_Principal.bb
; Programador : Yue Rexie
; Empresa     : Iris3D -Games Studios- ©
; URL         : http://www.iris3d.tk
; ©           : 2007-2011
;========================================================
; OBJETIVO    : Menu Principal
;========================================================
.Menu_Inicial

;-----------------------------
; Fisica Implementada.
;-----------------------------
pxCreateWorld(0,"t>4a3624l]64dm60]m28d\48mm70UT28")
pxSetGravity (0,-30,0)




Menu = 1
MoveMouse GraphicsHeight()/2+100,GraphicsHeight()/2
CambiandoR = False 




;-----------------------------
; Includes Especiales -S-
;-----------------------------
Include "Includes3\ShadowsSimple.bb"
.Cambiando_Sombra


CreateShadow Calidad
;ShadowRange 1

Global Textura0  = ShadowTexture()



;-----------------------------
; Includes Recursos2
;-----------------------------

Include "Includes\Recursos2.bb"

;-----------------------------
; Escena del Menu.
;-----------------------------

Crear_Menu()

CreateShadowCaster Jeep,0,1
CreateShadowCaster Llanta0,0,1
CreateShadowCaster Llanta1,0,1
CreateShadowCaster Llanta2,0,1
CreateShadowCaster Llanta3,0,1

EntityTexture Casa,Textura0,0,1
;-----------------------------
; Emisor Particulas.
;-----------------------------

Type Particle_Star
Field particle
Field sprite
End Type

Global EmisorP =  pxParticleCreateEmitter()
pxParticleEmitSetRadius(EmisorP, .2)
pxParticleEmitSetStartSpeed( EmisorP, 0,.2)
pxParticleEmitSetTDAcceleration(EmisorP, -1, 2, 0)
pxParticleEmitSetRandRadius( EmisorP, .1)
pxParticleEmitSetScaleFactor(EmisorP, 1, 0.1)

pxParticleEmitSetPosition (EmisorP,-1.7,4.55,6.75)













Repeat 
	
	n=1-n
	If n=1 CreateParticleStar()
	
	
	;PointEntity Camara,Jeep

	;CamaraFalsa()
	
	
	
		
	
	
	
	If Calidad <> -1 UpdateShadows Camara,1.0
		If Calidad = -1 FreeShadows()
		
		
		AntiAlias AAlias 
		UpdateParticleStar()
		pxRenderPhysic(60,0)
		
		
		
		pxParticleUpdateEmitter(EmisorP)
		
		RenderWorld 1.0
	; Funciones
		;DebugShadow
		Menu()
		
	
		
		Text_(0,0,FPS()+ "Memoria Usada : " +StarAmount + " " + Tipo_Pantalla,100,100,0)
	Flip Turbo
	
	
	
	
		
	
	
	
	
	
	
	If CambiandoR = True 
		Goto Cambio_Resolucion
	End If 
	
	
	If CambiandoS = True  
		Eliminar_Menu()
		FreeShadows()
		
		ClearWorld True,True,False 
		clearParticles()   ; Error!!!
		
		
		CambiandoS = False 
		Goto Cambiando_Sombra
	End If 
	
	
	If Nivel = 1 
		Eliminar_Menu()
		FreeShadows()
		clearParticles()
		;ClearWorld True,True,False
		
		Goto Cargando
		
	End If 
	
	
Forever


.Cargando 




;-----------------------------
; Cargando Nivel 1
;-----------------------------
Include "Includes\Recursos3.bb"
Camara = CreateCamera()

Repeat 
	Local Frames#
	Local Iniciando_Nivel#
	Frames = Frames + .5
	If Frames => 13 
		Iniciando_Nivel = Iniciando_Nivel +.5
		Frames = 0
		
		If Iniciando_Nivel > .5
			Iniciando_Nivel = 0
			Goto Primer_Nivel
		End If 
		
	End If 
	
	
	RenderWorld
		
	StartDraw
;	If Frames > 0 And Frames < 4
;		SetColor 255,0,0
;	ElseIf Frames >4 And Frames < 8
;		SetColor 255,255,0
;	ElseIf Frames > 8 And Frames < 13
;		SetColor 0,255,0
;	End If 
	DrawImageEx (Cargando,GraphicsWidth()/2,GraphicsHeight()/2,Frames)
		
	EndDraw
	
	Text 0,0, "Memoria Disponeble :" + AvailVidMem()
	Flip Turbo
		
	Forever
	
	.Primer_Nivel
	ClearWorld True,True,False
	
	Include "Includes\Nivel_1.bb"



The idea is that a change of quality of shadows or screen resolution or the beginning of level playing shadow reboot, and I need the roof particle system is restarted again but I can not do it.




Yue(Posted 2010) [#5]
Hi I have already solved all greatly appreciate those who help me despite my inability to speak and write English.

The case was that playing in my case restarting the amount of particles each time to change.

Changing Shadow Quality
	If CambiandoS = True  
		Eliminar_Menu()
		FreeShadows()
		Delete Each Particle_Star
		ClearWorld True,True,False 
		
		StarAmount = 0 ;<<<<<<<<<<<<<< =)
		
		CambiandoS = False 
		Goto Cambiando_Sombra
	End If