It is currently Fri Aug 14, 2020 9:22 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: I would like Sinbad to stop sliding on the floor:)
PostPosted: Sun Jul 19, 2020 10:31 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 21, 2011 9:11 am
Posts: 618
Location: France
Hello. Thank you for your help and remarks. I will continue my learning of OGRE3D and do many tests with PureBasic ;)

_________________

➽ Windows 10 - PB 5.72(x64)

Sorry for my bad english and the Dunning–Kruger effect.


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] I would like Sinbad to stop sliding on the floo
PostPosted: Sun Jul 19, 2020 5:12 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 861
Location: Denmark
Anytime :wink:
On a small note..
Remember PB uses Bullet physics..It doesn't react well to large objects.
You have to think tiny...I've modified your first example (shrunk it considerably) so that
the physics are more to its liking. Massive values is not a good thing.
Hint: Large objects should have values (mass) of ex. 1, while small objects should
have considerably lesser mass. You can use larger mass than '1' but bullet physics
enjoys small values and small objects. :-)

Here's your example - shrunken in size. The default earth-gravity works now.

Code:
EnableExplicit

Global window, ww, wh, event, camera, Material, Mesh, Entity, Sound, Node
Global Player, PlayerSpeed.f, CurrentAnimation.s

CompilerIf Subsystem("OpenGL") = #False
  MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
  End
CompilerEndIf

InitEngine3D(#PB_Engine3D_DebugLog)
InitKeyboard()
InitSprite()

; Window & Screen 3D
window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
ww = WindowWidth (window, #PB_Window_InnerCoordinate)
wh = WindowHeight(window, #PB_Window_InnerCoordinate)

OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Packs\Sinbad.zip", #PB_3DArchive_Zip)
Parse3DScripts()

; Light
CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, 1000)
WorldShadows(#PB_Shadow_Additive)

; Camera
camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera, 0, 0.5, 3)
CameraLookAt(camera, 0, 0, 0)

; Entity
Mesh = CreatePlane(#PB_Any, 10, 10, 1, 1, 5, 5)
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "MRAMOR6X6.jpg")))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
CreateEntityBody(Entity, #PB_Entity_StaticBody, 1, 0, 1)

Mesh = CreateCube(#PB_Any, 0.2)
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "Caisse.png")))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -3, 0.1, 0)
CreateEntityBody(Entity, #PB_Entity_StaticBody, 1, 0, 1)

Entity = CopyEntity(Entity, -1)
MoveEntity(Entity, 3, 0.1, 0)

Mesh = LoadMesh(#PB_Any, "sinbad.mesh")
Player = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 0, 2, 0)
ScaleEntity(Player, 0.1, 0.1, 0.1)
CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 0.02, 1, 1)
EntityAngularFactor(Player, 0, 1, 0)
RotateEntity(Player, 0, 180, 0)

; Sound
Sound = LoadSound3D(#PB_Any, "Siren.ogg")
Node = CreateNode(#PB_Any, -3, 0, 0)
AttachNodeObject(Node, SoundID3D(Sound))
SoundRange3D(Sound, 0.1, 1)
PlaySound3D(Sound, #PB_Sound3D_Loop)

Sound = LoadSound3D(#PB_Any, "Roar.ogg")
Node = CreateNode(#PB_Any, 3, 0, 0)
AttachNodeObject(Node, SoundID3D(Sound))
SoundRange3D(Sound, 0.1, 1)
PlaySound3D(Sound, #PB_Sound3D_Loop)

; Render
While #True
  event = WindowEvent()
  ExamineKeyboard()
 
  If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    Break
  EndIf
 
  If KeyboardPushed (#PB_Key_Up)
    PlayerSpeed = 2
    CurrentAnimation = "RunBase"
  ElseIf KeyboardPushed (#PB_Key_Down)
    PlayerSpeed = -2
    CurrentAnimation = "RunBase"
  Else
    CurrentAnimation = "IdleTop"
    PlayerSpeed = 0
  EndIf
 
  If KeyboardPushed (#PB_Key_Left)
    RotateEntity(Player, 0, 3, 0, #PB_Relative)
    CurrentAnimation = "RunBase"
  ElseIf KeyboardPushed (#PB_Key_Right)
    RotateEntity(Player, 0, -3, 0, #PB_Relative)
    CurrentAnimation = "RunBase"
  EndIf   
 
  If PlayerSpeed
    DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
  EndIf
 
  ;Play animation
  If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
    StartEntityAnimation(Player, CurrentAnimation)
  EndIf
 
  CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 1, 3, 0.5, 0.5, #True)
  ;SoundListenerLocate(CameraX(Camera), CameraY(Camera), CameraZ(Camera)) - better to use the object
  SoundListenerLocate(EntityX(Player), EntityY(player), EntityZ(Player))
 
  RenderWorld()
  FlipBuffers()
Wend


_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] I would like Sinbad to stop sliding on the floo
PostPosted: Mon Jul 20, 2020 2:04 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 21, 2011 9:11 am
Posts: 618
Location: France
DK_PETER wrote:
You have to think tiny..
With the CreateWater() function this is not possible.
But I'm convinced. Thank you also for this obvious solution :oops:
Code:
SoundListenerLocate(EntityX(Player), EntityY(player), EntityZ(Player))

_________________

➽ Windows 10 - PB 5.72(x64)

Sorry for my bad english and the Dunning–Kruger effect.


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] I would like Sinbad to stop sliding on the floo
PostPosted: Mon Jul 20, 2020 2:47 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1750
Location: Germany
Those who want to try falsam's orginal code or DK_PETER's solution on Linux or MacOS should change the following code to make it cross-platform:
Code:
; CompilerIf Subsystem("OpenGL") = #False
CompilerIf #PB_Compiler_OS = #PB_OS_Windows And Subsystem("OpenGL") = #False

Code:
; Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$, #PB_3DArchive_FileSystem)
; Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$+"Textures", #PB_3DArchive_FileSystem)
; Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Packs\Sinbad.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$+"Packs"+#PS$+"Sinbad.zip", #PB_3DArchive_Zip)

Now the examples will also run on Linux (tested on Linux Mint 19.3 x64 with Cinnamon and PB 5.72 x64). However they won't run on MacOS because of an old unfixed bug in LoadSound3D(). Even after commenting out all sound-related commands on MacOS, the examples terminate in line RenderWorld() with
PureBasic IDE wrote:
[ERROR] Program aborted. (by external library)


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] I would like Sinbad to stop sliding on the floo
PostPosted: Mon Jul 20, 2020 8:24 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 861
Location: Denmark
falsam wrote:
DK_PETER wrote:
You have to think tiny..
With the CreateWater() function this is not possible.

That's true. I recommend keeping physics values small, though. :-)

@Shardik
I didn't know there was a problem with 3D sound on Mac and Linux...I've made an alternative solution below.
It uses the normal sound functions to mimic the Sound3D function.

Code:
EnableExplicit
UseOGGSoundDecoder()

Structure V3D
  x.f
  y.f
  z.f
EndStructure

Structure MeasurePoints
  ret.i
  FirstDist.f
  SecondDist.f
  Point1.V3D
  Point2.V3D
  point3.V3D
EndStructure

Declare.f FastDist3D(*pos1.V3D, *pos2.V3D)
Declare.i NewVolume(CurrentDistance.f, MaxDistance.f)

Global window, ww, wh, event, camera, Material, Mesh, Entity, Sound1, Sound2, Node
Global Player, PlayerSpeed.f, CurrentAnimation.s, m.MeasurePoints, LinuxMac.i = #False

CompilerIf Subsystem("OpenGL") = #False
  MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
  End
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows And Subsystem("OpenGL") = #True
  LinuxMac = #False
CompilerElse 
  LinuxMac = #True
CompilerEndIf

InitEngine3D(#PB_Engine3D_DebugLog)
InitKeyboard()
InitSprite()
InitSound()




; Window & Screen 3D
window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
ww = WindowWidth (window, #PB_Window_InnerCoordinate)
wh = WindowHeight(window, #PB_Window_InnerCoordinate)

OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Packs\Sinbad.zip", #PB_3DArchive_Zip)
Parse3DScripts()

; Light
CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, 1000)
WorldShadows(#PB_Shadow_Additive)

; Camera
camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera, 0, 0.5, 3)
CameraLookAt(camera, 0, 0, 0)

; Entity
Mesh = CreatePlane(#PB_Any, 10, 10, 1, 1, 5, 5)
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "MRAMOR6X6.jpg")))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
CreateEntityBody(Entity, #PB_Entity_StaticBody, 1, 0, 1)

Mesh = CreateCube(#PB_Any, 0.2)
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "Caisse.png")))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -3, 0.1, 0)
CreateEntityBody(Entity, #PB_Entity_StaticBody, 1, 0, 1)

Entity = CopyEntity(Entity, -1)
MoveEntity(Entity, 3, 0.1, 0)

Mesh = LoadMesh(#PB_Any, "sinbad.mesh")
Player = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 0, 2, 0)
ScaleEntity(Player, 0.1, 0.1, 0.1)
CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 0.02, 1, 1)
EntityAngularFactor(Player, 0, 1, 0)
RotateEntity(Player, 0, 180, 0)

; Sound
If LinuxMac = #False
  Sound1 = LoadSound3D(#PB_Any, "Siren.ogg")
  Node = CreateNode(#PB_Any, -3, 0, 0)
  AttachNodeObject(Node, SoundID3D(Sound1))
  SoundRange3D(Sound1, 0.1, 1)
  PlaySound3D(Sound1, #PB_Sound3D_Loop)
 
  Sound2 = LoadSound3D(#PB_Any, "Roar.ogg")
  Node = CreateNode(#PB_Any, 3, 0, 0)
  AttachNodeObject(Node, SoundID3D(Sound2))
  SoundRange3D(Sound2, 0.1, 1)
  PlaySound3D(Sound2, #PB_Sound3D_Loop)
 
Else
  Sound1 = LoadSound(#PB_Any, #PB_Compiler_Home+"Examples\3D\Data\" + "Siren.ogg")
  PlaySound(Sound1, #PB_Sound_Loop)
  SoundVolume(Sound1, 0)
  m\Point1\x = -3 : m\Point1\y = 0 : m\Point1\z = 0
  sound2 = LoadSound(#PB_Any, #PB_Compiler_Home+"Examples\3D\Data\" + "Roar.ogg")
  PlaySound(Sound2, #PB_Sound_Loop)
  SoundVolume(Sound2, 0)
  m\Point2\x = 3 : m\Point2\y = 0 : m\Point2\z = 0
EndIf


; Render
While #True
  event = WindowEvent()
  ExamineKeyboard()
 
  If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    Break
  EndIf
 
  If KeyboardPushed (#PB_Key_Up)
    PlayerSpeed = 2
    CurrentAnimation = "RunBase"
  ElseIf KeyboardPushed (#PB_Key_Down)
    PlayerSpeed = -2
    CurrentAnimation = "RunBase"
  Else
    CurrentAnimation = "IdleTop"
    PlayerSpeed = 0
  EndIf
 
  If KeyboardPushed (#PB_Key_Left)
    RotateEntity(Player, 0, 3, 0, #PB_Relative)
    CurrentAnimation = "RunBase"
  ElseIf KeyboardPushed (#PB_Key_Right)
    RotateEntity(Player, 0, -3, 0, #PB_Relative)
    CurrentAnimation = "RunBase"
  EndIf   
 
  If PlayerSpeed
    DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
  EndIf
 
  ;Play animation
  If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
    StartEntityAnimation(Player, CurrentAnimation)
  EndIf
  CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 1, 3, 0.5, 0.5, #True)
  If LinuxMac = #False
    SoundListenerLocate(EntityX(Player), EntityY(player), EntityZ(Player))
  Else
    m\point3\x = EntityX(Player) : m\point3\y = EntityY(Player) : m\point3\z = EntityZ(Player)
    m\FirstDist = FastDist3D(m\Point1, m\point3)
    m\ret = NewVolume(m\FirstDist, 2.5)
    SoundVolume(sound1, m\ret)
    m\secondDist = FastDist3D(m\Point2, m\point3)
    m\ret = NewVolume(m\SecondDist, 2.5)     
    SoundVolume(sound2, m\ret)
  EndIf
  RenderWorld()
  FlipBuffers()
Wend

Procedure.i NewVolume(CurrentDistance.f, MaxDistance.f)
  Protected NewVol = 100 - ((100 / MaxDistance) * CurrentDistance)
  If NewVol < 0 : NewVol = 0 : EndIf
  ProcedureReturn NewVol
EndProcedure

Procedure.f FastDist3D(*pos1.V3D, *pos2.V3D)
  Protected r.V3D
  Protected dist.f
  r\x = *pos1\x - *pos2\x : r\x = r\x * r\x
  r\y = *pos1\y - *pos2\y : r\y = r\y * r\y
  r\z = *pos1\z - *pos2\z : r\z = r\z * r\z
  ProcedureReturn  r\x + r\y + r\z
EndProcedure

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] I would like Sinbad to stop sliding on the floo
PostPosted: Mon Jul 20, 2020 10:37 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1750
Location: Germany
@DK_PETER,

thank you for your modified example which uses normal sound functions when running in Linux or MacOS. I had to do the following changes in your last example:
  • In Linux and MacOS OpenGL is the default - therefore the test for OpenGL as subsystem is only valid in Windows:
    Code:
    ; CompilerIf Subsystem("OpenGL") = #False
    CompilerIf #PB_Compiler_OS = #PB_OS_Windows And Subsystem("OpenGL") = #False
      MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
      End
    CompilerEndIf
  • In Linux and MacOS you have to use a slash ("/") instead of a backslash ("\") as a path separator. The PureBasic constant #PS$ always contains the correct path separator for the current operating system. So to program cross-platform you should always use the constant #PS$ in paths. For Linux you also have to take care of folder and filenames which have to be written exactly in the same upper and lower case characters as in the file system!
    Code:
    ; Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$, #PB_3DArchive_FileSystem)
    ; Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$+"Textures", #PB_3DArchive_FileSystem)
    ; Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Packs\Sinbad.zip", #PB_3DArchive_Zip)
    Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$+"Packs"+#PS$+"Sinbad.zip", #PB_3DArchive_Zip)
  • In LoadSound() for Linux and MacOS you should also use the slash ("/") or #PS$ as path separator:
    Code:
      ; Sound1 = LoadSound(#PB_Any, #PB_Compiler_Home+"Examples\3D\Data\" + "Siren.ogg")
      Sound1 = LoadSound(#PB_Any, #PB_Compiler_Home+"examples/3d/Data/" + "Siren.ogg")
    Code:
      ; sound2 = LoadSound(#PB_Any, #PB_Compiler_Home+"Examples\3D\Data\" + "Roar.ogg")
      sound2 = LoadSound(#PB_Any, #PB_Compiler_Home+"examples/3d/Data/" + "Roar.ogg")

Unfortunately your last example with my above modifications still doesn't run on MacOS 10.15.6 'Catalina' with PB 5.72 x64. The same error in the line RenderWorld() is thrown as in your modified example of my last posting where I simply commented out all sound-related commands:
PureBasic IDE wrote:
[ERROR] Program aborted. (by external library)


Last edited by Shardik on Tue Jul 21, 2020 5:53 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] I would like Sinbad to stop sliding on the floo
PostPosted: Tue Jul 21, 2020 7:58 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 861
Location: Denmark
@Shardik
I'm a pure Windows guy, so I can't test on Linux/mac.
Could you try the following example?
Examine the log and look for hints - try running it without debugger.

Code:
EnableExplicit
UseOGGSoundDecoder()

Structure V3D
  x.f
  y.f
  z.f
EndStructure

Structure MeasurePoints
  ret.i
  FirstDist.f
  SecondDist.f
  Point1.V3D
  Point2.V3D
  point3.V3D
EndStructure

Declare.f FastDist3D(*pos1.V3D, *pos2.V3D)
Declare.i NewVolume(CurrentDistance.f, MaxDistance.f)

Global window, ww, wh, event, camera, Material, Mesh, Entity, Sound1, Sound2, Node
Global Player, PlayerSpeed.f, CurrentAnimation.s, m.MeasurePoints, Quit.i = #False

InitEngine3D(#PB_Engine3D_DebugLog)  ; See if there are any hints to the problem in the DebugLog.
InitKeyboard()
InitSprite()
InitSound()

Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$, #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$+"Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$+"Packs"+#PS$+"Sinbad.zip", #PB_3DArchive_Zip)
Parse3DScripts()

OpenWindow(0, 0, 0, 800, 600, "Windowed Screen", #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)

; Light
CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, 1000)
;WorldShadows(#PB_Shadow_Additive) 

; Camera
camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera, 0, 0.5, 3)
CameraLookAt(camera, 0, 0, 0)

; Entity
Mesh = CreatePlane(#PB_Any, 10, 10, 1, 1, 5, 5)
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "MRAMOR6X6.jpg")))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
CreateEntityBody(Entity, #PB_Entity_StaticBody, 1, 0, 1)

Mesh = CreateCube(#PB_Any, 0.2)
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "Caisse.png")))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -3, 0.1, 0)
CreateEntityBody(Entity, #PB_Entity_StaticBody, 1, 0, 1)

Entity = CopyEntity(Entity, -1)
MoveEntity(Entity, 3, 0.1, 0)

Mesh = LoadMesh(#PB_Any, "sinbad.mesh")
Player = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 0, 2, 0)
ScaleEntity(Player, 0.1, 0.1, 0.1)
CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 0.02, 1, 1)
EntityAngularFactor(Player, 0, 0, 0)
; RotateEntity(Player, 0, 180, 0)

; Sound
Sound1 = LoadSound(#PB_Any, #PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$ + "Siren.ogg")
PlaySound(Sound1, #PB_Sound_Loop)
SoundVolume(Sound1, 0)
m\Point1\x = -3 : m\Point1\y = 0 : m\Point1\z = 0
sound2 = LoadSound(#PB_Any, #PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$ + "Roar.ogg")
PlaySound(Sound2, #PB_Sound_Loop)
SoundVolume(Sound2, 0)
m\Point2\x = 3 : m\Point2\y = 0 : m\Point2\z = 0

; Render
Repeat
  Repeat
    event = WindowEvent()
    If event = #PB_Event_CloseWindow : Quit = #True : EndIf
  Until event = 0
 
  ExamineKeyboard()
 
  If KeyboardPushed (#PB_Key_Up)
    PlayerSpeed = 2
    CurrentAnimation = "RunBase"
  ElseIf KeyboardPushed (#PB_Key_Down)
    PlayerSpeed = -2
    CurrentAnimation = "RunBase"
  Else
    CurrentAnimation = "IdleTop"
    PlayerSpeed = 0
  EndIf
 
  If KeyboardPushed (#PB_Key_Left)
    RotateEntity(Player, 0, 3, 0, #PB_Relative)
    CurrentAnimation = "RunBase"
  ElseIf KeyboardPushed (#PB_Key_Right)
    RotateEntity(Player, 0, -3, 0, #PB_Relative)
    CurrentAnimation = "RunBase"
  EndIf   
 
  If PlayerSpeed
    DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
  EndIf
 
  ;Play animation
  If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
    StartEntityAnimation(Player, CurrentAnimation)
  EndIf
  CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 1, 3, 0.5, 0.5, #True)
 
  m\point3\x = EntityX(Player) : m\point3\y = EntityY(Player) : m\point3\z = EntityZ(Player)
  m\FirstDist = FastDist3D(m\Point1, m\point3)
  m\ret = NewVolume(m\FirstDist, 2.5)
  SoundVolume(sound1, m\ret)
  m\secondDist = FastDist3D(m\Point2, m\point3)
  m\ret = NewVolume(m\SecondDist, 2.5)     
  SoundVolume(sound2, m\ret)
 
  RenderWorld()
 
  FlipBuffers()
 
Until KeyboardPushed(#PB_Key_Escape) Or Quit = #True

Procedure.i NewVolume(CurrentDistance.f, MaxDistance.f)
  Protected NewVol = 100 - ((100 / MaxDistance) * CurrentDistance)
  If NewVol < 0 : NewVol = 0 : EndIf
  ProcedureReturn NewVol
EndProcedure

Procedure.f FastDist3D(*pos1.V3D, *pos2.V3D)
  Protected r.V3D
  Protected dist.f
  r\x = *pos1\x - *pos2\x : r\x = r\x * r\x
  r\y = *pos1\y - *pos2\y : r\y = r\y * r\y
  r\z = *pos1\z - *pos2\z : r\z = r\z * r\z
  ProcedureReturn  r\x + r\y + r\z
EndProcedure

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 10, Intel 6800K, GeForce Gtx 1060, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: [SOLVED] I would like Sinbad to stop sliding on the floo
PostPosted: Wed Jul 22, 2020 9:32 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1750
Location: Germany
@DK_PETER,

thank you for your last example. It is working without problems on MacOS 10.14.6 'Mojave' with PB 5.72 x64. It also gave me the hint for the crash on RenderWorld() in the other two examples on MacOS: in your last example you used a defined size of 800x600 when opening the window. The previous examples used
Code:
window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
which doesn't work correctly on MacOS, i.e. it opens a window with zero width and height. I changed your last but one example to
Code:
ExamineDesktops()
Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "", #PB_Window_BorderLess | #PB_Window_Maximize)
and your example works like a charm on MacOS. This is your complete last but one example with all my modification proposals to run cross-platform. I have tested it successfully with PB 5.72 x64 on these operating systems:
  • Linux Mint 19.3 'Tricia' x64 with Cinnamon
  • MacOS 10.14.6 'Mojave'
  • Windows 10 (1809) x64
Code:
EnableExplicit
UseOGGSoundDecoder()

Structure V3D
  x.f
  y.f
  z.f
EndStructure

Structure MeasurePoints
  ret.i
  FirstDist.f
  SecondDist.f
  Point1.V3D
  Point2.V3D
  point3.V3D
EndStructure

Declare.f FastDist3D(*pos1.V3D, *pos2.V3D)
Declare.i NewVolume(CurrentDistance.f, MaxDistance.f)

Global window, ww, wh, event, camera, Material, Mesh, Entity, Sound1, Sound2, Node
Global Player, PlayerSpeed.f, CurrentAnimation.s, m.MeasurePoints, LinuxMac.i = #False

CompilerIf #PB_Compiler_OS = #PB_OS_Windows And Subsystem("OpenGL") = #False
  MessageRequester("Error", "Please set the Library subsystem to OpenGL from IDE : Compiler... Compiler Options")
  End
CompilerEndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows And Subsystem("OpenGL") = #True
  LinuxMac = #False
CompilerElse
  LinuxMac = #True
CompilerEndIf

InitEngine3D(#PB_Engine3D_DebugLog)
InitKeyboard()
InitSprite()
InitSound()

; Window & Screen 3D
ExamineDesktops()
Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "", #PB_Window_BorderLess | #PB_Window_Maximize)
ww = WindowWidth (window, #PB_Window_InnerCoordinate)
wh = WindowHeight(window, #PB_Window_InnerCoordinate)

OpenWindowedScreen(WindowID(window), 0, 0, ww, wh)
Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$, #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$+"Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home+"examples"+#PS$+"3d"+#PS$+"Data"+#PS$+"Packs"+#PS$+"Sinbad.zip", #PB_3DArchive_Zip)
Parse3DScripts()

; Light
CreateLight(#PB_Any,RGB(255, 218, 185), 500, 1000, 1000)
WorldShadows(#PB_Shadow_Additive)

; Camera
camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(camera, 0, 0.5, 3)
CameraLookAt(camera, 0, 0, 0)

; Entity
Mesh = CreatePlane(#PB_Any, 10, 10, 1, 1, 5, 5)
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "MRAMOR6X6.jpg")))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
CreateEntityBody(Entity, #PB_Entity_StaticBody, 1, 0, 1)

Mesh = CreateCube(#PB_Any, 0.2)
Material = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any, "Caisse.png")))
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material), -3, 0.1, 0)
CreateEntityBody(Entity, #PB_Entity_StaticBody, 1, 0, 1)

Entity = CopyEntity(Entity, -1)
MoveEntity(Entity, 3, 0.1, 0)

Mesh = LoadMesh(#PB_Any, "sinbad.mesh")
Player = CreateEntity(-1, MeshID(Mesh), #PB_Material_None, 0, 2, 0)
ScaleEntity(Player, 0.1, 0.1, 0.1)
CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 0.02, 1, 1)
EntityAngularFactor(Player, 0, 1, 0)
RotateEntity(Player, 0, 180, 0)

; Sound
If LinuxMac = #False
  Sound1 = LoadSound3D(#PB_Any, "Siren.ogg")
  Node = CreateNode(#PB_Any, -3, 0, 0)
  AttachNodeObject(Node, SoundID3D(Sound1))
  SoundRange3D(Sound1, 0.1, 1)
  PlaySound3D(Sound1, #PB_Sound3D_Loop)
 
  Sound2 = LoadSound3D(#PB_Any, "Roar.ogg")
  Node = CreateNode(#PB_Any, 3, 0, 0)
  AttachNodeObject(Node, SoundID3D(Sound2))
  SoundRange3D(Sound2, 0.1, 1)
  PlaySound3D(Sound2, #PB_Sound3D_Loop)
Else
  Sound1 = LoadSound(#PB_Any, #PB_Compiler_Home+"examples/3d/Data/" + "Siren.ogg")
  PlaySound(Sound1, #PB_Sound_Loop)
  SoundVolume(Sound1, 0)
  m\Point1\x = -3 : m\Point1\y = 0 : m\Point1\z = 0
  sound2 = LoadSound(#PB_Any, #PB_Compiler_Home+"examples/3d/Data/" + "Roar.ogg")
  PlaySound(Sound2, #PB_Sound_Loop)
  SoundVolume(Sound2, 0)
  m\Point2\x = 3 : m\Point2\y = 0 : m\Point2\z = 0
EndIf


; Render
While #True
  event = WindowEvent()
  ExamineKeyboard()
 
  If event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
    Break
  EndIf
 
  If KeyboardPushed (#PB_Key_Up)
    PlayerSpeed = 2
    CurrentAnimation = "RunBase"
  ElseIf KeyboardPushed (#PB_Key_Down)
    PlayerSpeed = -2
    CurrentAnimation = "RunBase"
  Else
    CurrentAnimation = "IdleTop"
    PlayerSpeed = 0
  EndIf
 
  If KeyboardPushed (#PB_Key_Left)
    RotateEntity(Player, 0, 3, 0, #PB_Relative)
    CurrentAnimation = "RunBase"
  ElseIf KeyboardPushed (#PB_Key_Right)
    RotateEntity(Player, 0, -3, 0, #PB_Relative)
    CurrentAnimation = "RunBase"
  EndIf   
 
  If PlayerSpeed
    DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
    MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)
  EndIf
 
  ;Play animation
  If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
    StartEntityAnimation(Player, CurrentAnimation)
  EndIf
  CameraFollow(Camera, EntityID(Player), 180, EntityY(Player) + 1, 3, 0.5, 0.5, #True)
  If LinuxMac = #False
    SoundListenerLocate(EntityX(Player), EntityY(player), EntityZ(Player))
  Else
    m\point3\x = EntityX(Player) : m\point3\y = EntityY(Player) : m\point3\z = EntityZ(Player)
    m\FirstDist = FastDist3D(m\Point1, m\point3)
    m\ret = NewVolume(m\FirstDist, 2.5)
    SoundVolume(sound1, m\ret)
    m\secondDist = FastDist3D(m\Point2, m\point3)
    m\ret = NewVolume(m\SecondDist, 2.5)     
    SoundVolume(sound2, m\ret)
  EndIf
  RenderWorld()
  FlipBuffers()
Wend

Procedure.i NewVolume(CurrentDistance.f, MaxDistance.f)
  Protected NewVol = 100 - ((100 / MaxDistance) * CurrentDistance)
  If NewVol < 0 : NewVol = 0 : EndIf
  ProcedureReturn NewVol
EndProcedure

Procedure.f FastDist3D(*pos1.V3D, *pos2.V3D)
  Protected r.V3D
  Protected dist.f
  r\x = *pos1\x - *pos2\x : r\x = r\x * r\x
  r\y = *pos1\y - *pos2\y : r\y = r\y * r\y
  r\z = *pos1\z - *pos2\z : r\z = r\z * r\z
  ProcedureReturn  r\x + r\y + r\z
EndProcedure


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 20 guests


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