[SOLVED] I would like Sinbad to stop sliding on the floor:)
Re: I would like Sinbad to stop sliding on the floor:)
Hello. Thank you for your help and remarks. I will continue my learning of OGRE3D and do many tests with PureBasic
➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect.
Re: [SOLVED] I would like Sinbad to stop sliding on the floo
Anytime
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.
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: Select all
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
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.
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.
Re: [SOLVED] I would like Sinbad to stop sliding on the floo
With the CreateWater() function this is not possible.DK_PETER wrote:You have to think tiny..
But I'm convinced. Thank you also for this obvious solution
Code: Select all
SoundListenerLocate(EntityX(Player), EntityY(player), EntityZ(Player))
➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti
Sorry for my bad english and the Dunning–Kruger effect.
Re: [SOLVED] I would like Sinbad to stop sliding on the floo
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:
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
Code: Select all
; CompilerIf Subsystem("OpenGL") = #False
CompilerIf #PB_Compiler_OS = #PB_OS_Windows And Subsystem("OpenGL") = #False
Code: Select all
; 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)
PureBasic IDE wrote:[ERROR] Program aborted. (by external library)
Re: [SOLVED] I would like Sinbad to stop sliding on the floo
That's true. I recommend keeping physics values small, though.falsam wrote:With the CreateWater() function this is not possible.DK_PETER wrote:You have to think tiny..
@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: Select all
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
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.
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.
Re: [SOLVED] I would like Sinbad to stop sliding on the floo
@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:
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: Select all
; 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: Select all
; 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: Select all
; 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: Select all
; sound2 = LoadSound(#PB_Any, #PB_Compiler_Home+"Examples\3D\Data\" + "Roar.ogg") sound2 = LoadSound(#PB_Any, #PB_Compiler_Home+"examples/3d/Data/" + "Roar.ogg")
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.
Re: [SOLVED] I would like Sinbad to stop sliding on the floo
@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.
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: Select all
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
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.
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.
Re: [SOLVED] I would like Sinbad to stop sliding on the floo
@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 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 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:
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: Select all
window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
Code: Select all
ExamineDesktops()
Window = OpenWindow(#PB_Any, 0, 0, DesktopWidth(0), DesktopHeight(0), "", #PB_Window_BorderLess | #PB_Window_Maximize)
- Linux Mint 19.3 'Tricia' x64 with Cinnamon
- MacOS 10.14.6 'Mojave'
- Windows 10 (1809) x64
Code: Select all
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