Re: I would like Sinbad to stop sliding on the floor:)
Posted: Sun Jul 19, 2020 10:31 am
Hello. Thank you for your help and remarks. I will continue my learning of OGRE3D and do many tests with PureBasic 

http://www.purebasic.com
https://www.purebasic.fr/english/
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
With the CreateWater() function this is not possible.DK_PETER wrote:You have to think tiny..
Code: Select all
SoundListenerLocate(EntityX(Player), EntityY(player), EntityZ(Player))
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)
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..
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
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
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)
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)
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
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)
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