It is currently Wed Jun 26, 2019 3:49 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Sound3D with Sound2D in stereo
PostPosted: Fri Oct 24, 2014 1:47 pm 
Offline
User
User

Joined: Sun Nov 25, 2012 5:27 pm
Posts: 27
Location: Sweden
Code:
;
; ------------------------------------------------------------
;
;   PureBasic - Sound3D
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;
UseOGGSoundDecoder()
Declare loop()

#CameraSpeed = 3
#deg45=0.707106781

If InitEngine3D() =0 : End: EndIf
If InitSprite() =0   : End: EndIf
If InitKeyboard() =0 : End: EndIf
If InitMouse() =0    : End: EndIf
If InitSound() =0    : End: EndIf
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
If Screen3DRequester() =0 : End: EndIf

Add3DArchive(#PB_Compiler_Home + "examples/3d/Data", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
 
;- Material
GetScriptMaterial(0, "Color/Green")
GetScriptMaterial(1, "Color/Blue")
GetScriptMaterial(2, "Color/Red")
   
;- Mesh
CreateSphere(0, 50)

;- Entity
CreateEntity(0, MeshID(0), MaterialID(0),0,0,0);green
CreateEntity(1, MeshID(0), MaterialID(1),-330,0,0);blue
CreateEntity(2, MeshID(0), MaterialID(2),330,0,0);red

;- Camera 
CreateCamera(0, 0, 0, 100, 100)
AttachEntityObject(0, "", CameraID(0)); [, x, y, z, Pitch, Roll, Yaw])

;- Light
AmbientColor(0)
CreateLight(0, RGB(255, 255, 255), 0, 700, 0)

;- Sky
SkyBox("desert07.jpg")

;- Sound
LoadSound(1, #PB_Compiler_Home + "examples/3d/data/Siren.ogg")   ;blue
PlaySound(1, #PB_Sound3D_Loop,0)

LoadSound(2, #PB_Compiler_Home + "examples/3d/data/Roar.ogg")  ;red
PlaySound(2, #PB_Sound3D_Loop,0)

;- Gui
OpenWindow3D(1, 4, 3, ScreenWidth()-8, ScreenHeight()/8, "",#PB_Window3D_Borderless)
ShowGUI(200, 1)
For a=0 To 13
TextGadget3D(a+1, 10+a*ScreenWidth()/14, 0, 152, ScreenHeight()/8, "")
Next a

EnableExplicit

loop()
End
   
Procedure.f dist_3d(x1.f,y1.f,z1.f,x2.f,y2.f,z2.f)
  ProcedureReturn Sqr((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2))
EndProcedure

Procedure.f vikel_3d(d1.f,d2.f)
  ProcedureReturn d1-d2
EndProcedure

Procedure loop()
  Define.f KeyX, KeyY, MouseX, MouseY
  Define.f d1,d2,v,vol

  Repeat
      Screen3DEvents()     
      If ExamineMouse()
        MouseX  -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY  -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
     
ExamineKeyboard()
KeyX = 0
If KeyboardPushed(#PB_Key_Left) : KeyX = -#CameraSpeed : EndIf
If KeyboardPushed(#PB_Key_Right): KeyX = #CameraSpeed : EndIf
KeyY = 0       
If KeyboardPushed(#PB_Key_Up) : KeyY = -#CameraSpeed :EndIf
If KeyboardPushed(#PB_Key_Down) : KeyY = #CameraSpeed :EndIf
       
      ConvertLocalToWorldPosition(EntityID(0),1,0,0) ;blue
      d1=dist_3d(EntityX(1),EntityY(1),EntityZ(1),EntityX(0),EntityY(0),EntityZ(0))
      d2=dist_3d(EntityX(1),EntityY(1),EntityZ(1),GetX(),GetY(),GetZ())
      v=vikel_3d(d1,d2)     
      SoundPan(1, v*100)
      vol=(500-d1)/5
     
      ConvertLocalToWorldPosition(EntityID(0),0,0,1) ;blue
      d1=dist_3d(EntityX(1),EntityY(1),EntityZ(1),EntityX(0),EntityY(0),EntityZ(0))
      d2=dist_3d(EntityX(1),EntityY(1),EntityZ(1),GetX(),GetY(),GetZ())
      v=vikel_3d(d1,d2)     
      vol-v *20     
      SoundVolume(1, vol)

      ConvertLocalToWorldPosition(EntityID(0),-1,0,0) ;red
      d1=dist_3d(EntityX(2),EntityY(2),EntityZ(2),EntityX(0),EntityY(0),EntityZ(0))
      d2=dist_3d(EntityX(2),EntityY(2),EntityZ(2),GetX(),GetY(),GetZ())
      v=vikel_3d(d1,d2)     
      SoundPan(2, -v*100)
      vol=(500-d1)/5
     
      ConvertLocalToWorldPosition(EntityID(0),0,0,1) ;red
      d1=dist_3d(EntityX(2),EntityY(2),EntityZ(2),EntityX(0),EntityY(0),EntityZ(0))
      d2=dist_3d(EntityX(2),EntityY(2),EntityZ(2),GetX(),GetY(),GetZ())
      v=vikel_3d(d1,d2)   
      vol-v *20         
      SoundVolume(2, vol)
     
      SetGadgetText3D(1, "dist Red"+    #LF$+StrF(d1,2) + #LF$+StrF(d2,2) + #LF$+StrF(vol,2))
      SetGadgetText3D(3, "Angel Red"+    #LF$+StrF(v,5))
      ;SetGadgetText3D(5, "(x,y,z)"+ #LF$+StrF(GetX(),2) + #LF$+StrF(GetY(),2) + #LF$+StrF(GetZ(),2))

      RotateEntity(0, MouseY, MouseX, 0);, #PB_Relative );| #PB_World )
      MoveEntity  (0, KeyX, 0, KeyY,#PB_Local )

      RenderWorld()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape)
EndProcedure


Top
 Profile  
Reply with quote  
 Post subject: Re: Sound3D with Sound2D in stereo
PostPosted: Fri Oct 24, 2014 4:57 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1418
Location: Doubs - France
nice idea, well done.

_________________
Please correct my english
http://purebasic.developpez.com/


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye