Mon premier cube

Généralités sur la programmation 3D
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Mon premier cube

Message par SPH »

Salut,

j'ai un petit probleme d'eclairage. Ou est ce que ca se passe ? :idea:
2eme question : comment mapper chaque face du cube par une texture differente ? :idea:
thx

Code : Tout sélectionner

EnableExplicit

;Scene
Global Camera, Light
Global xx.f=20
Global yy.f=24.8
Global zz.f=31

; Returns a random sign {-1, 1}
Macro RandomSign()
  ( Random(1)*2-1 ) 
EndMacro

;Summary
Declare GameLoad()
Declare RenderGame3D()

GameLoad()

Procedure GameLoad()
  Protected Window, n 
    
  If InitEngine3D() And  InitKeyboard() And InitSprite() And InitMouse() And InitSound()
    Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
    SetWindowColor(Window, 0)
    
    ;-[Screen]
    OpenWindowedScreen(WindowID(Window),0, 0, WindowWidth(Window) , WindowHeight(Window))    
    KeyboardMode(#PB_Keyboard_International)  

    ;-[2D]
    
    ;-[3D]
    Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
        
    ;-Camera
    Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
    CameraBackColor(Camera, RGB(0, 0, 0))
    MoveCamera(Camera, 0, 0, -100)
    CameraLookAt(Camera, 0, 0, 0)
    
    ;-Light
    Light = CreateLight(#PB_Any, RGB(255, 255, 255), 0, 1000, 0, #PB_Light_Point)
    SetLightColor(Light, #PB_Light_SpecularColor, RGB(255, 255, 255))
    SetLightColor(Light, #PB_Light_DiffuseColor, RGB(255, 255, 255))
        
    ;Création de 5000 cubes
    CreateMaterial(0, TextureID(LoadTexture(-1, "glass_Dirt.png")))
    MaterialBlendingMode(0, #PB_Material_AlphaBlend)
    SetMaterialColor(0, #PB_Material_SpecularColor, RGB(255,255,255))
    
    CreateEntity(0, MeshID(CreateCube(-1, 20)), MaterialID(0))
    RotateEntity(0,20,17.4,31.8)
    
;     For n = 1 To 50
;        MoveEntity(CopyEntity(0, -1), 100 * RandomSign(), 100 * RandomSign(), Random(10) * RandomSign()) 
;     Next
    
    ;-Loop
    While #True
      Repeat : Until WindowEvent() = 0
      RotateEntity(0,xx,yy,zz)
      xx+1.12
      yy+1.458
      zz+1.5
      FlipBuffers()  
      RenderGame3D()
      RenderWorld()
    Wend
  Else
    
  EndIf 
EndProcedure

Procedure RenderGame3D()
  ;RotateCamera(Camera, 0.1, 0.1, 0.1, #PB_Relative)
  If ExamineKeyboard()
    If KeyboardReleased(#PB_Key_Escape)
      End
    EndIf  
  EndIf
  
  If ExamineMouse()
    
  EndIf 
EndProcedure

http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Mon premier cube

Message par falsam »

Bizarre cette texture ....

Code : Tout sélectionner

EnableExplicit

;Scene
Global Camera, Light
Global xx.f=0.5
Global yy.f=0.5
Global zz.f=0.5

;Summary
Declare GameLoad()
Declare RenderGame3D()

GameLoad()

Procedure GameLoad()
  Protected Window, n 
  
  If InitEngine3D() And  InitKeyboard() And InitSprite() And InitMouse() And InitSound()
    Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
    SetWindowColor(Window, 0)
    
    ;-[Screen]
    OpenWindowedScreen(WindowID(Window),0, 0, WindowWidth(Window) , WindowHeight(Window))    
    KeyboardMode(#PB_Keyboard_International)  
    
    ; On indique ou se trouve les textures
    Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    
    ;-Camera
    Camera = CreateCamera(#PB_Any, 0, 20, 100, 100)
    CameraBackColor(Camera, RGB(0, 0, 0))
    MoveCamera(Camera, 0, 0, -100)
    CameraLookAt(Camera, 0, 0, 0)
    
    ;-Light
    Light = CreateLight(#PB_Any, RGB(255, 255, 255), 0, 1000, 0)
    
    SetLightColor(Light, #PB_Light_SpecularColor, RGB(255, 255, 255))
    SetLightColor(Light, #PB_Light_DiffuseColor, RGB(255, 255, 255))
    
    CreateMaterial(0, TextureID(LoadTexture(-1, "caisse.png")))
    
    ;Pas d'alpha blending sur une texture sans transparence
    ;MaterialBlendingMode(0, #PB_Material_AlphaBlend)
    
    ; Par defaut ton entité est crée en 0, 0, 0
    CreateEntity(0, MeshID(CreateCube(#PB_Any, 20)), MaterialID(0))
    
    ;-Loop
    While #True
      ;Evenement fenetre
      Repeat : Until WindowEvent() = 0
      
      ;Traitement 3D
      FlipBuffers()  
      
      RotateEntity(0, xx, yy, zz, #PB_Relative)
      If ExamineKeyboard()
        If KeyboardReleased(#PB_Key_Escape)
          End
        EndIf  
      EndIf
      
      If ExamineMouse()
        
      EndIf 
      
      RenderWorld()
    Wend
  Else
    Debug "Ooops ! probleme d'initialisation"
  EndIf 
EndProcedure
SPH a écrit :2eme question : comment mapper chaque face du cube par une texture differente ?
On ne peut pas car le cube n'est pas composé de sub-meshs représentant chacune des faces.
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Mon premier cube

Message par falsam »

Une solution serait de créer un cube en partant de zero (vertex, face, .....)

Une autre solution est de créer un cube avec six sous entités plans et de texturer chacun de ces sous entités avec la fonction SetEntityMaterial()

:idea: SetEntityMaterial(#Entity, MatiereID [, SousEntity])

Code : Tout sélectionner

EnableExplicit

Declare CreateBox(Mesh.i, Size.f = 1.0)
Declare AddMesh(Mesh, NewX.f=0 , NewY.f=0, NewZ.f=0, ScaleX.f=1, ScaleY.f=1, ScaleZ.f=1, RotateX.f=0, RotateY.f=0, RotateZ.f=0)

;Scene
Global Camera, Light
Global xx.f=0.5
Global yy.f=0.5
Global zz.f=0.5

;Summary
Declare GameLoad()
Declare RenderGame3D()

GameLoad()

Procedure GameLoad()
  Protected Window, n 
  
  If InitEngine3D() And  InitKeyboard() And InitSprite() And InitMouse() And InitSound()
    Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
    SetWindowColor(Window, 0)
    
    ;-[Screen]
    OpenWindowedScreen(WindowID(Window),0, 0, WindowWidth(Window) , WindowHeight(Window))    
    KeyboardMode(#PB_Keyboard_International)  
    
    ; On indique ou se trouve les textures
    Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    
    ;-Camera
    Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
    CameraBackColor(Camera, RGB(0, 0, 0))
    MoveCamera(Camera, 0, 0, -100)
    CameraLookAt(Camera, 0, 0, 0)
    
    ;-Light
    Light = CreateLight(#PB_Any, RGB(255, 255, 255), 0, 1000, 0)
    
    SetLightColor(Light, #PB_Light_SpecularColor, RGB(255, 255, 255))
    SetLightColor(Light, #PB_Light_DiffuseColor, RGB(255, 255, 255))
        
    ;-1 Création de l'entité sans material   
    CreateEntity(0, MeshID(CreateBox(#PB_Any, 20)), #PB_Material_None, 0, 0, 0)
    
    ;-2 Création des materiaux (Les textures) pour chacune des faces
    CreateMaterial(0, TextureID(LoadTexture(-1, "Dirt.jpg")))  
    CreateMaterial(1, TextureID(LoadTexture(-1, "Caisse.png")))
    CreateMaterial(2, TextureID(LoadTexture(-1, "Geebee2.bmp")))
    CreateMaterial(3, TextureID(LoadTexture(-1, "MRAMOR6X6.jpg")))
    CreateMaterial(4, TextureID(LoadTexture(-1, "soil_wall.jpg")))
    CreateMaterial(5, TextureID(LoadTexture(-1, "grass.jpg")))
    
    ;-2 - Application du material sur chaque face du mesh    
    SetEntityMaterial(0, MaterialID(0), 0)  ;UP face
    SetEntityMaterial(0, MaterialID(1), 1)  ;Down face
    SetEntityMaterial(0, MaterialID(2), 2)  ;Front face
    SetEntityMaterial(0, MaterialID(3), 3)  ;Back face
    SetEntityMaterial(0, MaterialID(4), 4)  ;Left face
    SetEntityMaterial(0, MaterialID(5), 5)  ;Right face    
    
    ;-Loop
    While #True
      ;Evenement fenetre
      Repeat : Until WindowEvent() = 0
      
      ;Traitement 3D
      FlipBuffers()  
      
      RotateEntity(0, xx, yy, zz, #PB_Relative)
      If ExamineKeyboard()
        If KeyboardReleased(#PB_Key_Escape)
          End
        EndIf  
      EndIf
      
      If ExamineMouse()
        
      EndIf 
      
      RenderWorld()
    Wend
  Else
    Debug "Ooops ! probleme d'initialisation"
  EndIf 
EndProcedure

; // Ce qui suit peut être placer dans un include (module ou pas)

;Result = CreateBox(#Mesh, Size)
Procedure CreateBox(Mesh.i, Size.f = 1.0)
  Protected Dim SubMesh(5)
  
  If Mesh = #PB_Any
    Mesh = CreateMesh(#PB_Any, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
  Else
    CreateMesh(Mesh, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
  EndIf
    
  AddMesh(CreatePlane(-1, Size, Size, 1, 1, 1, 1),     0.0,  Size/2,     0.0, 1, 1, 1,   0, 180,   0)  ;SubMesh 0 UP face
  AddMesh(CreatePlane(-1, Size, Size, 1, 1, 1, 1),     0.0, -Size/2,     0.0, 1, 1, 1, 180, 180,   0)  ;SubMesh 1 Down face
  AddMesh(CreatePlane(-1, Size, Size, 1, 1, 1, 1),     0.0,       0,  Size/2, 1, 1, 1, -90, 180,   0)  ;SubMesh 2 FRont face
  AddMesh(CreatePlane(-1, Size, Size, 1, 1, 1, 1),     0.0,       0, -Size/2, 1, 1, 1, -90,   0,   0)  ;SubMesh 3 BacK face
  AddMesh(CreatePlane(-1, Size, Size, 1, 1, 1, 1), -Size/2,       0,     0.0, 1, 1, 1, -90,   0, -90)  ;SubMesh 4 LeFt face
  AddMesh(CreatePlane(-1, Size, Size, 1, 1, 1, 1),  Size/2,       0,     0.0, 1, 1, 1, -90,   0,  90)  ;SubMesh 5 RighT face
  
  FinishMesh(#True)
  
  ProcedureReturn Mesh
EndProcedure

Procedure AddMesh(Mesh, NewX.f=0 , NewY.f=0, NewZ.f=0, ScaleX.f=1, ScaleY.f=1, ScaleZ.f=1, RotateX.f=0, RotateY.f=0, RotateZ.f=0)
  Protected Dim MeshData.PB_MeshVertex(0)
  Protected Dim MeshDataInd.PB_MeshFace(0)
  Protected ArrSize, ArrSizeInd, c, i, x.f, y.f, z.f
  
  TransformMesh(Mesh, NewX,NewY,NewZ, ScaleX,ScaleY,ScaleZ, RotateX,RotateY,RotateZ)
  GetMeshData(Mesh,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(Mesh)-1)
  GetMeshData(Mesh,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(Mesh, 0)-1)
  
  ArrSize = ArraySize(MeshData())
  For c=0 To ArrSize    
    x = MeshData(c)\x 
    y = MeshData(c)\y
    z = MeshData(c)\z
    MeshVertexPosition(x,y,z)
    MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)        
  Next   
  
  ArrSizeInd = ArraySize(MeshDataInd()) 
  For i=0 To ArrSizeInd Step 3
    MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
  Next
  
  AddSubMesh(#PB_Mesh_TriangleList)
  ProcedureReturn Mesh
EndProcedure
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Re: Mon premier cube

Message par SPH »

Thanks a lot 8)
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
Guillot
Messages : 532
Inscription : jeu. 25/juin/2015 16:18

Re: Mon premier cube

Message par Guillot »

t'as aussi la façon manuelle
on créé les sommets (MeshVertex)
puis on les assemble par face (MeshFace)

attention : avec MeshFace, l'ordre des sommets à son importance, il definit le "devant" et le "derriere" de la face
par defaut, les faces ne sont visible que si elle sont vu de devant
MeshFace(0,1,2) <> MeshFace(0,2,1)


Code : Tout sélectionner

EnableExplicit

Declare CreateBox(Mesh.i, Size.f = 1.0)
Declare AddMesh(Mesh, NewX.f=0 , NewY.f=0, NewZ.f=0, ScaleX.f=1, ScaleY.f=1, ScaleZ.f=1, RotateX.f=0, RotateY.f=0, RotateZ.f=0)

;Scene
Global Camera, Light
Global xx.f=0.5
Global yy.f=0.5
Global zz.f=0.5

;Summary
Declare GameLoad()
Declare RenderGame3D()

GameLoad()

Procedure GameLoad()
  Protected Window, n 
  
  If InitEngine3D() And  InitKeyboard() And InitSprite() And InitMouse() And InitSound()
    Window = OpenWindow(#PB_Any, 0, 0, 0, 0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
    SetWindowColor(Window, 0)
    
    ;-[Screen]
    OpenWindowedScreen(WindowID(Window),0, 0, WindowWidth(Window) , WindowHeight(Window))    
    KeyboardMode(#PB_Keyboard_International)  
    
    ; On indique ou se trouve les textures
    Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    
    ;-Camera
    Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
    CameraBackColor(Camera, RGB(0, 0, 0))
    MoveCamera(Camera, 0, 0, -100)
    CameraLookAt(Camera, 0, 0, 0)
    
    ;-Light
    Light = CreateLight(#PB_Any, RGB(255, 255, 255), 0, 1000, 0)
    AmbientColor(RGB(64, 64, 64))  
    
    ;-1 Création de l'entité sans material   
    CreateEntity(0, MeshID(CreateBox(#PB_Any, 20)), #PB_Material_None, 0, 0, 0)
    
    ;-2 Création des materiaux (Les textures) pour chacune des faces
    CreateMaterial(0, TextureID(LoadTexture(-1, "Dirt.jpg")))  
    CreateMaterial(1, TextureID(LoadTexture(-1, "Caisse.png")))
    CreateMaterial(2, TextureID(LoadTexture(-1, "Geebee2.bmp")))
    CreateMaterial(3, TextureID(LoadTexture(-1, "MRAMOR6X6.jpg")))
    CreateMaterial(4, TextureID(LoadTexture(-1, "soil_wall.jpg")))
    CreateMaterial(5, TextureID(LoadTexture(-1, "grass.jpg")))
    
    ;-2 - Application du material sur chaque face du mesh    
    SetEntityMaterial(0, MaterialID(0), 0)  ;UP face
    SetEntityMaterial(0, MaterialID(1), 1)  ;Down face
    SetEntityMaterial(0, MaterialID(2), 2)  ;Front face
    SetEntityMaterial(0, MaterialID(3), 3)  ;Back face
    SetEntityMaterial(0, MaterialID(4), 4)  ;Left face
    SetEntityMaterial(0, MaterialID(5), 5)  ;Right face    
    
    ;-Loop
    While #True
      ;Evenement fenetre
      Repeat : Until WindowEvent() = 0
      
      ;Traitement 3D
      FlipBuffers()  
      
      RotateEntity(0, xx, yy, zz, #PB_Relative)
      If ExamineKeyboard()
        If KeyboardReleased(#PB_Key_Escape)
          End
        EndIf  
      EndIf
      
      If ExamineMouse()
        
      EndIf 
      
      RenderWorld()
    Wend
  Else
    Debug "Ooops ! probleme d'initialisation"
  EndIf 
EndProcedure

; // Ce qui suit peut être placer dans un include (module ou pas)

;Result = CreateBox(#Mesh, Size)
Procedure CreateBox(Mesh.i, Size.f = 1.0)  
  Protected s.f=size/2
  If Mesh = #PB_Any
    Mesh = CreateMesh(#PB_Any, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
  Else
    CreateMesh(Mesh, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
  EndIf
  
  AddSubMesh();haut
  MeshVertex(-s,s,-s,0,0,0)
  MeshVertex( s,s,-s,1,0,0)
  MeshVertex(-s,s, s,0,1,0)
  MeshVertex( s,s, s,1,1,0)
  MeshFace(0,3,1):MeshFace(0,2,3)
  AddSubMesh();bas
  MeshVertex(-s,-s,-s,0,0,0)
  MeshVertex( s,-s,-s,1,0,0)
  MeshVertex(-s,-s, s,0,1,0)
  MeshVertex( s,-s, s,1,1,0)
  MeshFace(0,1,3):MeshFace(0,3,2)
  AddSubMesh();gauche
  MeshVertex(-s,-s,-s,0,0,0)
  MeshVertex(-s, s,-s,1,0,0)
  MeshVertex(-s,-s, s,0,1,0)
  MeshVertex(-s, s, s,1,1,0)
  MeshFace(0,3,1):MeshFace(0,2,3)
  AddSubMesh();droite
  MeshVertex(s,-s,-s,0,0,0)
  MeshVertex(s, s,-s,1,0,0)
  MeshVertex(s,-s, s,0,1,0)
  MeshVertex(s, s, s,1,1,0)
  MeshFace(0,1,3):MeshFace(0,3,2)
  AddSubMesh();avant
  MeshVertex(-s,-s,-s,0,0,0)
  MeshVertex( s,-s,-s,1,0,0)
  MeshVertex(-s, s,-s,0,1,0)
  MeshVertex( s, s,-s,1,1,0)
  MeshFace(0,3,1):MeshFace(0,2,3)
  AddSubMesh();arriere
  MeshVertex(-s,-s,s,0,0,0)
  MeshVertex( s,-s,s,1,0,0)
  MeshVertex(-s, s,s,0,1,0)
  MeshVertex( s, s,s,1,1,0)
  MeshFace(0,1,3):MeshFace(0,3,2)
  FinishMesh(#True)
  NormalizeMesh(mesh)
  ProcedureReturn Mesh
EndProcedure
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Re: Mon premier cube

Message par SPH »

Merci beaucoup Guillot

Dis, pkoi il y a une decoupe du cube en haut de l'ecran ?

Image
Dernière modification par SPH le mer. 29/mai/2019 22:13, modifié 1 fois.
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Mon premier cube

Message par falsam »

@SPH : Tu pourrais faire un effort pour mettre une image plus petite !

Chez moi pas de découpe mais ton screenshoot me fais dire que tu as modifier le code de Guillot ....
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Re: Mon premier cube

Message par SPH »

Image pourtant reduite a 800*450

code modifié :

Code : Tout sélectionner

    CreateEntity(0, MeshID(CreateBox(#PB_Any, 50)), #PB_Material_None, 0, 0, 0)
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Re: Mon premier cube

Message par falsam »

ok vu. Souci de camera
Remplace

Code : Tout sélectionner

Camera = CreateCamera(#PB_Any, 0, 20, 100, 100)
par

Code : Tout sélectionner

Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
SPH
Messages : 4726
Inscription : mer. 09/nov./2005 9:53

Re: Mon premier cube

Message par SPH »

Ca marche. :idea:
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: Mon premier cube

Message par Ollivier »

T'as un ResizeCamera() si tu veux scroller le tout. Regarde si les pourcentages peuvent être négatifs, et le tour est joué.
crisot
Messages : 98
Inscription : lun. 30/août/2004 21:03

Re: Mon premier cube

Message par crisot »

Voilà voilà. Tout est commenté. C'est ton code nettoyé.

Code : Tout sélectionner

If Not(InitEngine3D() And InitKeyboard() And InitSprite() And InitMouse() And InitSound())
  End
EndIf

  ;-Affichage
  OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
  OpenWindowedScreen(WindowID(0),0, 0, WindowWidth(0) , WindowHeight(0))
       
  ;-Camera
  CreateCamera(0, 0, 0, 100, 100)
  MoveCamera(0, 0, 0, 100)  ; l'axe Z va de l'écran (0) vers l'utilisateur (positif), ce qui s'éloigne dans l'écran est donc négatif (c'est con mais c'est comme ça, merci OpenGL)
                            ; Si on souhaite que la caméra prenne du recul (qu'elle se rapproche de nous), il faut donc lui mettre une valeur positive
                            ; sinon les axes X et Y seront à l'envers (c'était le cas dans ton code)
  CameraLookAt(0, 0, 0, 0)
    
  ;-Light
    
  CreateLight(0, RGB(255, 0, 0), 100, 0, 100, #PB_Light_Point)    ; Une créé une lumière rouge devant à gauche
  SetLightColor(0, #PB_Light_SpecularColor, RGB(255, 255, 255))   ; On lui donne une specularité blanche
    
  ;-Material
  Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
  CreateMaterial(0, TextureID(LoadTexture(-1, "dirt.jpg")))             ; On créé un Material avec une texture sans canal alpha (jpg)
    
  SetMaterialColor(0,  #PB_Material_AmbientColor, RGB (0, 0, 255))      ; "Ambient" est la couleur du Material quand il n'EST PAS éclairé du tout (y compris si aucune light n'existe). C'est sa couleur dans le noir (il ne pourra jamais être plus sombre que ça).
                                                                        ; Dans notre exemple le coté non éclairé du taurus sera donc bleu
  
  SetMaterialColor(0,  #PB_Material_DiffuseColor, RGB (255, 255, 255))  ; "Diffuse" est la couleur du Material quand il EST éclairé. Cette couleur est multipliée par couleur de la Light et s'ajoute à l'"Ambient".
                                                                        ; Ici je met le Material en blanc mais j'ai mis la lumière en rouge. On aurait pu faire l'inverse (lumière blanche et Material rouge) pour avoir EXACTEMENT le même résultat.
  
  SetMaterialColor(0,  #PB_Material_SpecularColor, RGB (255, 255, 255)) ; "Specular" est la couleur de la brillance du Material (comme lorsque l'on projète une lumière sur du verre ou du métal)
                                                                        ; Ici aussi on peut changer la couleur spéculaire aussi bien coté Material que Light pour avoir le même résultat.
  
  MaterialShininess(0, 16)  ; Ceci est la "brillance" du Material. Plus la valeur est basse, plus l'objet est terne (et moche avec une valeur trop basse). Plus la valeur est haute, plus l'objet est métalique.
    
  ;-Mesh
  
  CreateEntity(0, MeshID(CreateTorus(-1, 16, 4, 32, 128)), MaterialID(0)) ; On créé un Taure avec assez de poly pour être convenable

  ;-Loop
  While #True
    RotateEntity(0,xx,yy,zz)
    xx+1.12
    yy+1.458
    zz+1.5
    RenderWorld()
    FlipBuffers()  

    If ExamineKeyboard()
      If KeyboardReleased(#PB_Key_Escape)
        Break
      EndIf  
    EndIf
  Wend
Juste pour se rendre compte, sans commentaires, le code est minuscules, faut pas se compliquer la vie:

Code : Tout sélectionner

If Not(InitEngine3D() And InitKeyboard() And InitSprite() And InitMouse() And InitSound())
  End
EndIf

  ;-Affichage
  OpenWindow(0, 0, 0, 0, 0, "", #PB_Window_Maximize | #PB_Window_BorderLess)
  OpenWindowedScreen(WindowID(0),0, 0, WindowWidth(0) , WindowHeight(0))
       
  ;-Camera
  CreateCamera(0, 0, 0, 100, 100)
  MoveCamera(0, 0, 0, 100) 
  CameraLookAt(0, 0, 0, 0)
    
  ;-Light
  CreateLight(0, RGB(255, 0, 0), 100, 0, 100, #PB_Light_Point) 
  SetLightColor(0, #PB_Light_SpecularColor, RGB(255, 255, 255))
    
  ;-Material
  Add3DArchive(#PB_Compiler_Home + "Examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
  CreateMaterial(0, TextureID(LoadTexture(-1, "dirt.jpg"))) 
  SetMaterialColor(0,  #PB_Material_AmbientColor, RGB (0, 0, 255))
  SetMaterialColor(0,  #PB_Material_DiffuseColor, RGB (255, 255, 255))
  SetMaterialColor(0,  #PB_Material_SpecularColor, RGB (255, 255, 255))
  MaterialShininess(0, 16) 
    
  ;-Mesh
  CreateEntity(0, MeshID(CreateTorus(-1, 16, 4, 32, 128)), MaterialID(0))

  ;-Loop
  While #True
    RotateEntity(0,xx,yy,zz)
    xx+1.12
    yy+1.458
    zz+1.5
    RenderWorld()
    FlipBuffers()  

    If ExamineKeyboard()
      If KeyboardReleased(#PB_Key_Escape)
        Break
      EndIf  
    EndIf
  Wend
Répondre