Page 1 sur 1

[RESOLU] Simple cube qui tourne

Publié : mar. 26/sept./2006 10:46
par Progi1984
Voilà, je cherche un code avec un simple cube qui tourne... Le Helloworld de la 3D. Peut importe que cela utilise un mesh de type fichier ou de type data.

Merci d'avance

Publié : mar. 26/sept./2006 10:56
par Anonyme
http://purebasic.forum-gratuit.com/viewtopic.php?t=4343

C'est en software, mais ca devrais faire l'affaire. :wink:

Publié : mar. 26/sept./2006 11:09
par Progi1984
Je cherche quelque chose en mesh, dsl... car je veux tester de la 2D sur 3D !

Publié : mar. 26/sept./2006 11:13
par Anonyme
Je ne te comprend pas , tu veut donc utilisé cela pour de la 2D, Cherche donc comment lire un fichier contenant une liste de vertices, utilise OpenGL ou DX pour les textures, tu devrais dl l'embryon de mon moteur 3D , y a le header d'un *.ase (format ascii de max). sinon djes a un header de *.lwo (lightwave), par contre j'ai pas de liens pour le lwo.

@++

Edit : Y a les exemples 3d de comtois avec ogre aussi

Publié : mar. 26/sept./2006 11:32
par comtois
tu as un exemple de cube dans ton répertoire Examples !
le fichier meshmanual.pb

sinon un autre cube

Et comme le dit cplBator, il y a aussi pas mal d'exemples de cubes dans mes codes. Je ne fais que des cubes :)

Publié : mar. 26/sept./2006 11:37
par Progi1984
J'ai trouvé ca :

Code : Tout sélectionner

;Comtois 01/05/06
;PB4.0 Beta 11


Resultat = MessageRequester("Cube 3D","Full Screen ?",#PB_MessageRequester_YesNo)
If Resultat = 6     
  FullScreen=1
Else           
  FullScreen=0
EndIf

;- Initialisation
If InitEngine3D() = 0
   MessageRequester( "Erreur" , "Impossible d'initialiser la 3D , vérifiez la présence de engine3D.dll" , 0 )
   End
ElseIf InitSprite() = 0 Or InitKeyboard() = 0
   MessageRequester( "Erreur" , "Impossible d'initialiser DirectX 7 Ou plus" , 0 )
   End
EndIf

If Fullscreen
  OpenScreen(800,600,32,"Cube 3D")
Else
  OpenWindow(0,0, 0, 800 , 600 ,"Cube 3D",#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0),0,0, 800 , 600,0,0,0)
EndIf

Macro MyRGB(Rouge,Vert,Bleu)
  Rouge << 16 + Vert << 8 + Bleu
EndMacro

Structure Vertex
   px.f
   py.f
   pz.f
   nx.f
   ny.f
   nz.f
   co.l
   u.f
   v.f
EndStructure

Structure FTriangle
   f1.w
   f2.w
   f3.w
EndStructure

Structure s_Mesh
   No.l
   *VBuffer.Vertex
   *Ibuffer.FTriangle
EndStructure


Global Angle.f,Pas.f, CameraMode.l
Global *VBuffer,*IBuffer

Define.s_Mesh CubeMesh


Procedure CreateColorMeshCube(*Mesh.s_Mesh, Color.l)
   *Mesh\VBuffer=AllocateMemory(SizeOf(Vertex)*24)
   *Mesh\IBuffer=AllocateMemory(SizeOf(FTriangle)*12)
   CopyMemory(?Vertices , *Mesh\VBuffer, SizeOf(Vertex)*24)
   CopyMemory(?Triangles, *Mesh\IBuffer, SizeOf(Vertex)*24)
     
   If CreateMesh(*Mesh\No,100)
      Flag = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate | #PB_Mesh_Color
      SetMeshData(*Mesh\No, Flag         , *Mesh\VBuffer, 24)
      SetMeshData(*Mesh\No, #PB_Mesh_Face, *Mesh\IBuffer, 12)
;      ProcedureReturn 1
   Else
      ProcedureReturn 0   
   EndIf
  *Mem.Vertex = *Mesh\VBuffer
  For i = 0 To 23
    *Mem\co=Color
    *Mem + SizeOf(Vertex)
  Next i
  Flag = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate | #PB_Mesh_Color
  SetMeshData(*Mesh\No, Flag  , *Mesh\VBuffer, 24)
  ProcedureReturn 1
EndProcedure 

;-Mesh
CubeMesh\No = 0
CreateColorMeshCube(@CubeMesh, MyRGB(0,128,128))


;-Texture
CreateTexture(0,128, 128)
StartDrawing(TextureOutput(0))
  Box(0, 0, 128, 128, 0)
  Box(1, 1, 126, 126, $FFFFFF)
StopDrawing()

;-Material
CreateMaterial(0,TextureID(0))
MaterialAmbientColor(0,-1)

;-Entity
CreateEntity(0,MeshID(0),MaterialID(0))
ScaleEntity(0,90,90,90)

;-Camera
CreateCamera(0, 0, 0 , 100 , 100)
MoveCamera(0,0,0,-400)
CameraLookAt(0,EntityX(0),EntityY(0),EntityZ(0))


;-Light
AmbientColor(RGB(255,255,255))

pas = 0.8
Repeat
   ;ClearScreen(0)
   If fullscreen = 0
      While WindowEvent() : Wend
   EndIf
   Angle + Pas
   RotateEntity(0,angle,angle/2,-Angle)

   If ExamineKeyboard()
     If KeyboardReleased(#PB_Key_F1)
       CameraMode=1-CameraMode
       CameraRenderMode(0,CameraMode)
     EndIf
   EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

DataSection
;{
Vertices:
;Dessus 0 à 3
Data.f -0.5,0.5,-0.5
Data.f 0,1,0
Data.l 0
Data.f 0,0

Data.f 0.5,0.5,-0.5
Data.f 0,1,0
Data.l 0
Data.f 0,1

Data.f 0.5,0.5,0.5
Data.f 0,1,0
Data.l 0
Data.f 1,1

Data.f -0.5,0.5,0.5
Data.f 0,1,0
Data.l 0
Data.f 1,0

;Dessous 4 à 7
Data.f -0.5,-0.5,0.5
Data.f 0,-1,0
Data.l 0
Data.f 0,0

Data.f 0.5,-0.5,0.5
Data.f 0,-1,0
Data.l 0
Data.f 0,1

Data.f 0.5,-0.5,-0.5
Data.f 0,-1,0
Data.l 0
Data.f 1,1

Data.f -0.5,-0.5,-0.5
Data.f 0,-1,0
Data.l 0
Data.f 1,0

;Devant 8 à 11
Data.f -0.5,0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 0,0

Data.f 0.5,0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 0,1

Data.f 0.5,-0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 1,1

Data.f -0.5,-0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 1,0

;Derrière 12 à 15
Data.f 0.5,0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 0,0

Data.f -0.5,0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 0,1

Data.f -0.5,-0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 1,1

Data.f 0.5,-0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 1,0

;Cote gauche 16 à 19
Data.f -0.5,0.5,-0.5
Data.f -1,0,0
Data.l 0
Data.f 0,0

Data.f -0.5,0.5,0.5
Data.f -1,0,0
Data.l 0
Data.f 0,1

Data.f -0.5,-0.5,0.5
Data.f -1,0,0
Data.l 0
Data.f 1,1

Data.f -0.5,-0.5,-0.5
Data.f -1,0,0
Data.l 0
Data.f 1,0

;Cote droit 20 à 23
Data.f 0.5,0.5,0.5
Data.f 1,0,0
Data.l 0
Data.f 0,0

Data.f 0.5,0.5,-0.5
Data.f 1,0,0
Data.l 0
Data.f 0,1

Data.f 0.5,-0.5,-0.5
Data.f 1,0,0
Data.l 0
Data.f 1,1

Data.f 0.5,-0.5,0.5
Data.f 1,0,0
Data.l 0
Data.f 1,0

Triangles:
;0 à 3
Data.w 2,1,0
Data.w 0,3,2
;4 à 7
Data.w 6,5,4
Data.w 4,7,6
;8 à 11
Data.w 10,9,8
Data.w 8,11,10
;12 à 15
Data.w 14,13,12
Data.w 12,15,14
;16 à 19
Data.w 18,17,16
Data.w 16,19,18
;20 à 23
Data.w 22,21,20
Data.w 20,23,22
;}
EndDataSection
Merci Comtois !