EDIT: Track'ing auf #True setzen damit man handle erhält. Ansonsten wird keine Rückgabe gemacht und CPU zeit gespart.
Code: Alles auswählen
;
; -------------------------------------------------------------------------------
;
; PureBasic - Irrlicht
;
; Von 0 auf 100 (c) 2008 - TFT
;
; IrrKlangTest
;
; -------------------------------------------------------------------------------
;
; Um die Schwierigkeiten mit Irrlicht zu umgehen. Werde ich mich nun an die
; funktionierende Vorlage von Thalius halten. Auch wenn ich nicht nachvollziehen
; kann warum das eine oder ander nicht functioniert. Die Parts ab 101 sind so
; umgestalt das die Grundstruckture eingehalten wird.
;
;- Includes
XIncludeFile "Irr3DRequester.pb"
;- Defines
; = System =
; Globals
Global Quit.l = #False
Global MouseX.l,MouseY.l,MouseSpeedX.l,MouseSpeedY.l
Global LeftMouseBottonHit.l,RigtMouseBottonHit.l,LeftMouseBottonDown.l,RigtMouseBottonDown.l
Global BottonHitLMB.l,BottonHitRMB.l
; Locals
*MyEvent = 0
x.f=0:y.f=0:z.f=0
irr_fps.l
;= IrrKlang =
Global *music_soundsource.l = #Null ; Pointer to a SoundSource
Global *fx_soundsource.l = #Null ; Pointer to a SoundEffectSource
Global *music_sound.l = #Null ; Pointer to a Sound
Global *fx_sound.l = #Null ; Pointer to a SoundEffect
;= Irrlicht =
; Camera / Action
Global *camera.irr_camera
; Nodes
Global *cube.irr_node
; Textures
Global *CubeTexture.irr_texture
; Animator
Global *irb.irr_animator
; Media
Global *BitmapFont
;- Functions
Procedure InitScene()
;- Init Camera
*camera = IrrAddCamera(0,0,0,0,0,1)
If *camera
IrrSetCameraClipDistance(*camera,100) ; We set this to 10 to save some extra cpu, since our Scene is very small
IrrSetCameraNearValue(*camera,0.1)
Else
ProcedureReturn #False
EndIf
;- Get Media
*BitmapFont = IrrGetFont( "media/bitmapfont.bmp" )
If Not *BitmapFont
ProcedureReturn #False
EndIf
;- Create Cube
*cube=IrrAddCubeSceneNode(2)
If Not *cube
ProcedureReturn #False
EndIf
*CubeTexture = IrrGetTexture( "media/fire.bmp" )
If Not *CubeTexture
ProcedureReturn #False
EndIf
IrrSetNodePosition(*cube,0,0,0)
IrrSetNodeMaterialFlag( *cube, #IRR_EMF_LIGHTING, #IRR_OFF )
IrrSetNodeMaterialTexture( *cube, *CubeTexture, 0 )
IrrSetNodeMaterialFlag( *cube, #IRR_EMF_BACK_FACE_CULLING, #IRR_OFF)
IrrSetNodeMaterialType( *cube, #IRR_EMT_TRANSPARENT_ADD_COLOR)
*irb = IrrAddFlyCircleAnimator(*cube, 0,0,0,10,0.001)
;- Load Sound
*fx_soundsource = IrrKlangAddSound("media/explosion.wav")
If Not *fx_soundsource And *mx_soundsource
ProcedureReturn #False
EndIf
;IrrKlangSSSetDefaultMaxDistance(*fx_soundsource,40.0)
;-
ProcedureReturn #True ; Everything's fine !
EndProcedure
ProcedureC _My_Events(*event.SEvent)
Protected key.l,mouse.l
If *event\EventType = #IRR_EET_KEY_INPUT_EVENT
key.l = *event\KeyEvent\key
Select key
Case #IRR_KEY_ESCAPE ; -> Escape Quits
If *event\KeyEvent\PressedDown
If Quit.l = #False
Quit.l = #True
EndIf
EndIf
Case #IRR_KEY_F12
If *event\KeyEvent\PressedDown
; PLease recheck this - you try to STOP Irrlicht here then reuse its functions
; See Console Window for error and crash at end.
;
; Sidenote: a Eventreceiver has to be created ocne - as every ressource in irrlicht
; It is cashed and doesent need to be loaded again until you free it.
;
; This allows fast levelchanges or dynamic model switching without killing your io or harddrive.
;
; So effectively Irrlicht does NOT need a restart everytime the scene changes. In
; fact it is alot more efficient to just reset the scene.
; *uncommented evil code*
; IrrStop()
; If Irr3DRequester()
; IrrSetWindowCaption("PureBasic - Irrlicht > Von 0 auf 100 (c) 2008 - TFT")
; If InitScene()
; *MyEvent = IrrCreateEventReceiver(@_My_Events())
; IrrSetEventReceiver(*MyEvent)
; Else
; MessageRequester("ERROR!","Unable to inizialise Scene")
; If Quit.l = #False
; Quit.l = #True
; EndIf
; EndIf
; Else
; MessageRequester("ERROR!","Unable to open Irr3DRequester .")
; If Quit.l = #False
; Quit.l = #True
; EndIf
; EndIf
; *end uncomment*
; Stop animator
IrrRemoveAnimator(*cube, *irb)
; Reset Scene
IrrSetNodePosition(*cube,0,0,0)
; and start animator again... uncommented you clearly hear the soudn coming from around you as the box
; is inside our listener ( or surrounds it )
;*irb = IrrAddFlyCircleAnimator(*cube, 0,0,0,10,0.001) <-- uncomment me
EndIf
EndSelect
ElseIf *event\EventType = #IRR_EET_MOUSE_INPUT_EVENT
mouse.l = *event\MouseEvent\event
Select mouse
Case #IRR_EMIE_LMOUSE_PRESSED_DOWN
LeftMouseBottonDown.l=1
Case #IRR_EMIE_RMOUSE_PRESSED_DOWN
RigtMouseBottonDown.l=1
Case #IRR_EMIE_MMOUSE_PRESSED_DOWN
Case #IRR_EMIE_LMOUSE_LEFT_UP
LeftMouseBottonDown.l=0
Case #IRR_EMIE_RMOUSE_LEFT_UP
RigtMouseBottonDown.l=0
Case #IRR_EMIE_MMOUSE_LEFT_UP
Case #IRR_EMIE_MOUSE_MOVED
MouseSpeedX.l=MouseX.l-*event\MouseEvent\x
MouseSpeedY.l=MouseY.l-*event\MouseEvent\y
MouseX.l = *event\MouseEvent\x
MouseY.l = *event\MouseEvent\y
Case #IRR_EMIE_MOUSE_WHEEL
EndSelect
EndIf
ProcedureReturn #False
EndProcedure
Procedure BottonHitControll()
LeftMouseBottonHit=0
If LeftMouseBottonDown.l=1 And BottonHitLMB=0
BottonHitLMB=1
LeftMouseBottonHit=1
ElseIf LeftMouseBottonDown.l=0
BottonHitLMB=0
EndIf
RigtMouseBottonHit=0
If RigtMouseBottonDown.l=1 And BottonHitRMB=0
BottonHitRMB=1
RigtMouseBottonHit=1
ElseIf RigtMouseBottonDown.l=0
BottonHitRMB=0
EndIf
EndProcedure
If Irr3DRequester()
IrrSetWindowCaption("PureBasic - Irrlicht > Von 0 auf 100 (c) 2008 - TFT")
If IrrKlangStart()
If InitScene()
*MyEvent = IrrCreateEventReceiver(@_My_Events())
IrrSetEventReceiver(*MyEvent)
posOnCircle.f = 0;
radius.f = 5;
;- Mainloop
While IrrRunning() And Quit = #False
BottonHitControll()
IrrGetNodePosition(*cube,@x.f,@y.f,@z.f)
; After We know the positions, We need To let irrKlang know about the
; listener position (always position (0,0,0), facing forward in This example)
; And let irrKlang know about our calculated 3D music Position
IrrKlangListenerPosition(0,0,0, 0,0,1, 0,0,0, 0,0,0)
If LeftMouseBottonHit=1
; Play functions have no return value as they only play ;)
IrrKlangPlay3D(*fx_soundsource, x.f,y.f,z.f , #False, #False, #False)
EndIf
irr_fps.l=IrrGetFPS()
IrrBeginScene(0, 0, 55 )
IrrDrawScene()
Irr2DFontDraw ( *BitmapFont,"Position = "+Str(irr_fps.l),4,4,0,0)
IrrEndScene()
Delay(1)
Wend
Else
MessageRequester("ERROR!","Unable to inizialise Scene .")
EndIf
Else
MessageRequester("ERROR!","Unable to inizialise IrrKlang .")
EndIf
EndIf
IrrKlangStop() ; clenaup irrklang
IrrStop() ; clenaup irrlicht
End
Hat imemrnoch paar denkfehler aber langsam denke ich hast dus.