Page 1 sur 1

Sindba à la piscine

Publié : mer. 04/avr./2018 17:53
par falsam
Certains d'entres vous connaissent déja ce code que j'ai présenté sur le forum anglais.

Code : Tout sélectionner

EnableExplicit

;Police
Global FontInfo = LoadFont(-1, "Arial", 12)

;Textures
Global MatGround, MatBox, MatBuoy 

;Entities
Global Camera, CameraHeight = 125, Brother, Player, PlayerSpeed, CurrentAnimation.s, Angle = 180, Distance = 500
Global Ground, Box, buoy0, buoy1

;Dust emiter / Emetteur de poussieres
Global NewList Emiters()

;Sprite 
Global Bottom

;Init engine
If Not (InitEngine3D() And InitSprite() And InitKeyboard())
  End
EndIf

OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_BorderLess | #PB_Window_Maximize)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0))

;The elements are in the examples folder of PureBasic
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Water", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/waterworld.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Packs/Sinbad.zip", #PB_3DArchive_Zip)
Parse3DScripts()

KeyboardMode(#PB_Keyboard_International | #PB_Keyboard_AllowSystemKeys)
EnableWorldPhysics(#True)
EnableWorldCollisions(#True)
WorldGravity(-10)

;-[2D] Create ou load sprite
Bottom = CreateSprite(-1, ScreenWidth(), 150, #PB_Sprite_AlphaBlending)

;-[3D] Create ou load 3D element

;-Textures & material
MatGround  = CreateMaterial(-1, TextureID(LoadTexture(-1, "Floor02.jpg")))        ;Ground
ScaleMaterial(MatGround, 0.5, 0.5)
MatBox     = CreateMaterial(-1, TextureID(LoadTexture(-1, "Caisse.png")))         ;Box
MatBuoy    = CreateMaterial(-1, TextureID(LoadTexture(-1, "ogrelogo-small.jpg"))) ;Buoy

;-Camera
Camera = CreateCamera(-1, 0, 0, 100, 100)

;Sky and fog
SkyBox("desert07.jpg")

;-Light and shadow
CreateLight(0, RGB(255, 255, 255), -100, 500, 100)
;WorldShadows(#PB_Shadow_Modulative) ;Fontionne pas
WorldShadows(#PB_Shadow_TextureAdditive, 1000, RGB(0,0,0), 2048)

;-Sea
Sun(0, 10000, 10000, RGB(255, 255, 255))
CreateWater(Camera, 0, 135, 0, 0, #PB_World_WaterLowQuality | #PB_World_WaterSmooth)

;-Ground
Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), -1000, 0, 0)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
EntityRenderMode(Ground, 0)

Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 0, 0, 0)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
EntityRenderMode(Ground, 0)

Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 1000, 0, 0)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
EntityRenderMode(Ground, 0)

Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 1000, 0, 1000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
EntityRenderMode(Ground, 0)

Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 1000, 0, 2000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
EntityRenderMode(Ground, 0)

Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), -1000, 0, 1000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
EntityRenderMode(Ground, 0)

Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), -1000, 0, 2000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
EntityRenderMode(Ground, 0)

Ground = CreateEntity(-1, MeshID(CreateCube(-1, 1)), MaterialID(MatGround), 0, 0, 2000)
ScaleEntity(Ground, 1000, 300, 1000)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
EntityRenderMode(Ground, 0)

;-Box
Box = CreateEntity(-1, MeshID(CreateCube(-1, 100)), MaterialID(MatBox), -500, 200, 0)
CreateEntityBody(Box, #PB_Entity_StaticBody)

;-Player
Player = CreateEntity(-1, MeshID(LoadMesh(#PB_Any, "sinbad.mesh")), #PB_Material_None, 10, 275, -40)
ScaleEntity(Player, 25, 25, 35)
CreateEntityBody(Player, #PB_Entity_ConvexHullBody, 1, 3, 40)
EntityAngularFactor(Player, 0, 1, 0)
RotateEntity(Player, 0, -120, 0)

;-Brother
Brother = CreateEntity(-1, MeshID(LoadMesh(#PB_Any, "sinbad.mesh")), #PB_Material_None, 27, 120, 1000)
ScaleEntity(Brother, 25, 25, 25)
RotateEntity(Brother, -90, 45, 0)

;-Buoy / Bouéée
buoy0 = CreateEntity(-1, MeshID(CreateTorus(-1, 60, 30)), MaterialID(MatBuoy), 0, 140, 700)
buoy1 = CreateEntity(-1, MeshID(CreateTorus(-1, 60, 30)), MaterialID(MatBuoy), 300, 140, 900)
RotateEntity(buoy1, 0, 90, 0)

Repeat
  ;-
  ;-[3D] Rendering
  If ExamineKeyboard()
       
    ;-keyboard events : Distance and move
    If KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Up)
      Distance - 25
    ElseIf KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Down) 
      Distance + 25
    ElseIf KeyboardPushed (#PB_Key_Up)
      PlayerSpeed = 400
      CurrentAnimation = "RunBase"
      Angle = 180
    ElseIf KeyboardPushed (#PB_Key_Down)
      PlayerSpeed = -400
      Angle = 0
      CurrentAnimation = "RunBase"
    Else
      CurrentAnimation = "Dance"
      PlayerSpeed = 0
    EndIf
       
    ;-keyboard events : Rotation around player and turn
    If KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Left)
      Angle - 5
    ElseIf KeyboardPushed(#PB_Key_LeftControl) And KeyboardPushed(#PB_Key_Right)
      Angle + 5
    ElseIf 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   
   
    ;Escape
    If KeyboardReleased(#PB_Key_Escape)
      Break
    EndIf     
  EndIf
 
  DisableEntityBody(Player, #False) ; Wake up entity (BugWare)
  MoveEntity(Player, 0, 0, PlayerSpeed, #PB_Absolute|#PB_Local)     
 
  ;Play animation
  If EntityAnimationStatus(Player, CurrentAnimation) = #PB_EntityAnimation_Stopped
    StartEntityAnimation(Player, CurrentAnimation)
  EndIf
 
  If EntityAnimationStatus(Brother, "IdleTop") = #PB_EntityAnimation_Stopped
    StartEntityAnimation(Brother, "IdleTop")
  EndIf
 
  ;Update buoy, player and friend
  MoveEntity(buoy0, EntityX(buoy0), WaterHeight(Camera, EntityX(buoy0), EntityZ(buoy0)), EntityZ(buoy0), #PB_Absolute)
  MoveEntity(buoy1, EntityX(buoy1), WaterHeight(Camera, EntityX(buoy1), EntityZ(buoy1)), EntityZ(buoy1), #PB_Absolute)
  MoveEntity(Brother, EntityX(Brother), WaterHeight(Camera, EntityX(Brother), EntityZ(Brother)) - 10, EntityZ(Brother), #PB_Absolute)
   
  CameraFollow(Camera, EntityID(Player), Angle, EntityY(Player) + (CameraHeight), Distance, 0.25, 1, #True)
 
  RenderWorld(50)
 
  ;-[2D] Rendering
  StartDrawing(SpriteOutput(Bottom))
  DrawingFont(FontID(FontInfo))
  DrawingMode(#PB_2DDrawing_AlphaChannel)
  Box(0, 0, ScreenWidth(), SpriteWidth(Bottom), RGBA(0, 0, 0, 110))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawText(10, 10, ". : : Help : : .")
  DrawText(10, 40, "Arrow keys - Move player.")
  DrawText(10, 70, "Ctrl + Up / Ctrl + Down  - Distance between camera and player.")
  DrawText(10, 100, "Ctrl + Left ou Ctrl + Right - Turn around the player.")
  StopDrawing()
  DisplayTransparentSprite(Bottom, 0, ScreenHeight() - SpriteHeight(Bottom))
 
  FlipBuffers()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow

Re: Sindba à la piscine

Publié : mer. 04/avr./2018 18:06
par SPH
sans debugguer : purebasic_compilation0.exe a cessé de fonctionner

avec debugguer : invalide acces memory
:arrow: RenderWorld(50)

Re: Sindba à la piscine

Publié : jeu. 05/avr./2018 9:30
par Kwai chang caine
Kif kif bourique pour moi :wink:

Bah non...je connaissais pas encore le marin "simbad" :D

Re: Sindba à la piscine

Publié : jeu. 05/avr./2018 10:22
par falsam
Sur mon pc sous Windows 10 Pro DirectX 9c et 11 ce code fonctionne avec ou sans sous-system OpenGl.

J'ai testé ce code avec un pc sous Windows 10 Family DirectX11 seulement et effectivement que ce soit avec ou sans sous-system OpenGl, le code ne fonctionne pas !!

Re: Sindba à la piscine

Publié : jeu. 05/avr./2018 11:17
par falsam
En supprimant

Code : Tout sélectionner

CreateWater(Camera, 0, 135, 0, 0, #PB_World_WaterLowQuality | #PB_World_WaterSmooth)
et en ajoutant le sous-system OpenGl, le code fonctionne mais ne présente plus aucun intérêt !

Re: Sindba à la piscine

Publié : jeu. 05/avr./2018 17:48
par Patrick88
marche impec windows 10 purebasic 5.60 x64

pat

Re: Sindba à la piscine

Publié : jeu. 05/avr./2018 18:11
par falsam
parce que tu dois avoir Directx 9c en plus de DirectX 11 :wink:

Re: Sindba à la piscine

Publié : jeu. 05/avr./2018 18:51
par Patrick88
DirectX 12

Re: Sindba à la piscine

Publié : ven. 06/avr./2018 9:40
par G-Rom
Ogre fourni un .log qui accompagne l'exe, il explique 95% des erreurs. si on ne le poste pas, on ne peu pas savoir ce qui cloche.
comme j'ai participé au dev de la partie 3D, et que j'étais en majeur partie du temps sur linux, y a pas de raison que le code ne fonctionne pas, ici il fonctionne très bien.

Re: Sindba à la piscine

Publié : ven. 06/avr./2018 10:48
par Kwai chang caine
Bon, j'ai retesté sur une nouvelle machine W10 X64 v5.61 X86 et exactement ce que tu dis FALSAM, hier c'était sous W7 X86 :wink:
Sauf que y'a quand même un petit intérêt de voir HULK de dos 8)
G-Rom a écrit :Ogre fourni un .log qui accompagne l'exe,
Je vais encore gagner une tringle à rideau en posant une question à la con :oops:
"OGRE.exe" il est où dans PB ? inclus dedans ? je l'ai pas trouvé dans l'arborescence PB..et donc à fortiori son LOG :|

Re: Sindba à la piscine

Publié : ven. 06/avr./2018 11:14
par G-Rom
y a pas de question bête. ton .log doit se trouvé là ou ton .pb est.
je viens de vérifié , il faut aussi maintenant ( je ne sais pas depuis combien de temps ) activé le log via

Code : Tout sélectionner

InitEngine3D(#PB_Engine3D_DebugLog)

Re: Sindba à la piscine

Publié : sam. 07/avr./2018 9:04
par Kwai chang caine
Merci beaucoup GRom 8)
Si ça intéresse .....je pourrais donc remonter le LOG OGRE de W7 quand j'aurais la main dessus, si quelqu'un l'a pas fait avant bien sûr :wink: