Page 1 of 2

How can I create a dungoen with ogre and PB?

Posted: Sat Jun 28, 2008 4:02 pm
by IceSoft
Hello,

How can I create a dungoen with ogre and PB?
Maybe someone have a sample source code?

Thanks
IceSoft

Posted: Sat Jun 28, 2008 4:15 pm
by Foz
I would wait for a bit. The Ogre engine in PB is being brought upto date for version 4.30 and I don't really want to learn how to use Ogre twice. ;)

Posted: Sat Jun 28, 2008 4:30 pm
by IceSoft
Foz wrote:I would wait for a bit. The Ogre engine in PB is being brought upto date for version 4.30 and I don't really want to learn how to use Ogre twice. ;)
Will it be so different?
Can I use my 2D datas (generated with Dungeon generator) to create a 3D labyrinth with Ogre and PB?

Posted: Sat Jun 28, 2008 4:45 pm
by Foz
I beleive that a lot has been added and changed since the current Ogre version in PB.

If you start working on a version now, you may end up throwing away a lot of code as a simpler method may become available.

Posted: Sat Jun 28, 2008 5:19 pm
by Comtois
IceSoft wrote:Can I use my 2D datas (generated with Dungeon generator) to create a 3D labyrinth with Ogre and PB?
yes you can. you can replace each title 2D by a plan 3D or a box

Posted: Sat Jun 28, 2008 8:00 pm
by Comtois
it is not beautiful, it is to show how to do. I am certain that you will do much better

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0,0,0,800,600,"Dungeon")
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)

#CameraSpeed = 10
Define.f KeyX, KeyY, MouseX, MouseY 

AmbientColor(RGB(128,128,128))

; Create a plan, manually
;
CreateMesh(1,100)
SetMeshData(1, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?PlanVertices, 4)
SetMeshData(1, #PB_Mesh_Face, ?PlanFaces, 4)

CreateTexture(1,64,64)
StartDrawing(TextureOutput(1))
  Box(0,0,64,64,#Blue)
  Box(1,1,62,62,#Yellow)
StopDrawing()

CreateMaterial(1, TextureID(1))
Restore Level
For z=1 To 6
  For x=1 To 6
    Read Title
    If Title = 1 
      Entity=CreateEntity (#PB_Any, MeshID(1), MaterialID(1))
      RotateEntity(entity,0,90,0)
      ScaleEntity(entity, 64, 1, 64)
      EntityLocate(entity,x*64,0,z*64)
    ElseIf Title = 2
      Entity=CreateEntity (#PB_Any, MeshID(1), MaterialID(1))
      RotateEntity(entity,0,0,90)
      ScaleEntity(entity, 64, 1, 64) 
      EntityLocate(entity,x*64,0,z*64)     
    EndIf
  Next x
Next z      

CreateLight(0, RGB(255,255,255),  100.0, 100, 0)

CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,50,100)
CameraLookAt(0,EntityX(entity),EntityY(entity),EntityZ(entity))
  
Repeat
  
  ClearScreen(0)
        
  If ExamineKeyboard()
    
    If KeyboardPushed(#PB_Key_Left)
      KeyX = -#CameraSpeed 
    ElseIf KeyboardPushed(#PB_Key_Right)
      KeyX = #CameraSpeed 
    Else
      KeyX = 0
    EndIf
              
    If KeyboardPushed(#PB_Key_Up)
      KeyY = -#CameraSpeed 
    ElseIf KeyboardPushed(#PB_Key_Down)
      KeyY = #CameraSpeed 
    Else
      KeyY = 0
    EndIf


  EndIf
  
  If ExamineMouse()
    MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
    MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
  EndIf
       
  RotateCamera(0, MouseX, MouseY, RollZ)
  MoveCamera  (0, KeyX, 0, KeyY)
  
  LightLocate(0, CameraX(0)+100, CameraY(0), CameraZ(0))
  
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

    

  
End

DataSection

  PlanVertices:
    
    ; Note normals are important component to allow correct light support (and therefore shadow)
    ;
    Data.f -0.5, 0, -0.5    ; Vertex 0
    Data.f 1, 1, 1    ; Normals (perpendicular to the plan)
    Data.f 0   , 1    ; UVCoordinate
    
    Data.f 0.5, 0, -0.5    ; Vertex 1
    Data.f 1,1,1      ; Normals
    Data.f 1, 1       ; UVCoordinate
    
    Data.f 0.5, 0, 0.5    ; Vertex 2
    Data.f 1,1,1      ; Normals
    Data.f 1, 0       ; UVCoordinate
    
    Data.f -0.5, 0, 0.5    ; Vertex 3
    Data.f 1,1,1      ; Normals
    Data.f 0,    0    ; UVCoordinate

  PlanFaces:
    Data.w 2, 1, 0 ; bottom face (clockwise as it's reversed...)
    Data.w 0, 3, 2 
    Data.w 0, 1, 2 
    Data.w 2, 3, 0     
  Level:
  Data.l 1,1,1,1,1,1  
  Data.l 2,0,2,0,0,2 
  Data.l 2,0,0,0,0,2 
  Data.l 2,0,1,1,0,2 
  Data.l 2,0,0,0,0,2 
  Data.l 1,1,1,1,1,1 
EndDataSection

Posted: Sat Jun 28, 2008 8:21 pm
by Comtois
a second example using cube

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0,0,0,800,600,"Dungeon")
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)

#CameraSpeed = 10
Define.f KeyX, KeyY, MouseX, MouseY 
Macro MaCouleur(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 CreateMeshCube(*Mesh.s_Mesh)
   *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
EndProcedure   

Procedure UpColorCube(*Mesh.s_Mesh,Color)
  *Mem.Vertex = *Mesh\VBuffer
  For i = 0 To 3
    *Mem\co=Color
    *Mem + SizeOf(Vertex)
  Next i
EndProcedure 

Procedure DownColorCube(*Mesh.s_Mesh,Color)
  *Mem.Vertex = *Mesh\VBuffer + 4 * SizeOf(Vertex)
  For i = 0 To 3
    *Mem\co=Color
    *Mem + SizeOf(Vertex)
  Next i
EndProcedure

Procedure FrontColorCube(*Mesh.s_Mesh,Color)
  *Mem.Vertex = *Mesh\VBuffer + 8 * SizeOf(Vertex)
  For i = 0 To 3
    *Mem\co=Color
    *Mem + SizeOf(Vertex)
  Next i
EndProcedure
 
Procedure BackColorCube(*Mesh.s_Mesh,Color)
  *Mem.Vertex = *Mesh\VBuffer + 12 * SizeOf(Vertex)
  For i = 0 To 3
    *Mem\co=Color
    *Mem + SizeOf(Vertex)
  Next i
EndProcedure

Procedure LeftColorCube(*Mesh.s_Mesh,Color) 
  *Mem.Vertex = *Mesh\VBuffer + 16 * SizeOf(Vertex)
  For i = 0 To 3
    *Mem\co=Color
    *Mem + SizeOf(Vertex)
  Next i
EndProcedure
 
Procedure RightColorCube(*Mesh.s_Mesh,Color)
  *Mem.Vertex = *Mesh\VBuffer + 20 * SizeOf(Vertex)
  For i = 0 To 3
    *Mem\co=Color
    *Mem + SizeOf(Vertex)
  Next i
EndProcedure

Procedure UpDateCube(*Mesh.s_Mesh)
   Flag = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate | #PB_Mesh_Color
   SetMeshData(*Mesh\No, Flag  , *Mesh\VBuffer, 24)
EndProcedure
  
;Mesh
AmbientColor(RGB(128,128,128))


; Create a plan, manually
;
;CreateMesh(1,100)
;SetMeshData(1, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color, ?CubeData2, 8)
;SetMeshData(1, #PB_Mesh_Face, ?CubeDataIndex, 12)
CubeMesh\No = 0
CreateMeshCube(@CubeMesh)
UpColorCube(@CubeMesh, MaCouleur(255,0,0))
DownColorCube(@CubeMesh, MaCouleur(255,255,0))
FrontColorCube(@CubeMesh, MaCouleur(0,255,0))
BackColorCube(@CubeMesh, MaCouleur(0,0,255))
LeftColorCube(@CubeMesh, MaCouleur(255,128,0))
RightColorCube(@CubeMesh, MaCouleur(255,255,255))
UpDateCube(@CubeMesh)

; CreateTexture(1,64,64)
; StartDrawing(TextureOutput(1))
;   Box(0,0,64,64,#Blue)
;   Box(1,1,62,62,#Yellow)
; StopDrawing()
;-Texture
CreateTexture(1,128, 128)
StartDrawing(TextureOutput(1))
  Box(0, 0, 128, 128, 0)
  Box(1, 1, 126, 126, $FFFFFF)
StopDrawing()

CreateMaterial(1, TextureID(1))
MaterialAmbientColor(1,-1)
Restore Level
For z=1 To 6
  For x=1 To 6
    Read Title
    If Title = 1 
      Entity=CreateEntity (#PB_Any, MeshID(CubeMesh\No), MaterialID(1))
      ScaleEntity(entity, 64, 64, 64)
      EntityLocate(entity,x*64,0,z*64)
    ElseIf Title = 2
      Entity=CreateEntity (#PB_Any, MeshID(CubeMesh\No), MaterialID(1))
      ScaleEntity(entity, 64, 64, 64) 
      EntityLocate(entity,x*64,0,z*64)     
    EndIf
  Next x
Next z      

;CreateLight(0, RGB(255,255,255),  100.0, 100, 0)

CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,50,100)
CameraLookAt(0,EntityX(entity),EntityY(entity),EntityZ(entity))

Repeat
  
  ClearScreen(0)
        
  If ExamineKeyboard()
    
    If KeyboardPushed(#PB_Key_Left)
      KeyX = -#CameraSpeed 
    ElseIf KeyboardPushed(#PB_Key_Right)
      KeyX = #CameraSpeed 
    Else
      KeyX = 0
    EndIf
              
    If KeyboardPushed(#PB_Key_Up)
      KeyY = -#CameraSpeed 
    ElseIf KeyboardPushed(#PB_Key_Down)
      KeyY = #CameraSpeed 
    Else
      KeyY = 0
    EndIf


  EndIf
  
  If ExamineMouse()
    MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
    MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
  EndIf
       
  RotateCamera(0, MouseX, MouseY, RollZ)
  MoveCamera  (0, KeyX, 0, KeyY)
  

  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

    

  
End
#SQRT13 = 0.57735026
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
       
  Level:
  Data.l 1,1,1,1,1,1  
  Data.l 2,0,2,0,0,2 
  Data.l 2,0,0,0,0,2 
  Data.l 2,0,1,1,0,2 
  Data.l 2,0,0,0,0,2 
  Data.l 1,1,1,1,1,1 
EndDataSection

Posted: Sat Jun 28, 2008 11:16 pm
by Rook Zimbabwe
Excellent examples Comtois! 8)

Does anyone know how we are going to handle collisions in Ogre? I know that OrgreWiki likes OPCODE

http://www.codercorner.com/Opcode.htm

And does mention a few other models... We could also handle it natively like Blitz3D used to do...

Posted: Sat Jun 28, 2008 11:45 pm
by Kaeru Gaman
really good, Comtois.
personally I like the first example better.

but for both, the way they show how to use SetMeshData with Vertices etc.
I wish we had examples for this in the PB-Help or a Tutorial.

for a dungeon, an Engine like this from Descent could be nice.
the map build out of boxes wich are connected at their sides and can be distorted in any way, camera within the boxes.

Posted: Sun Jun 29, 2008 12:26 am
by Comtois
this one is more complete.

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0,0,0,800,600,"Dungeon")
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0)

#CameraSpeed = 10
Define.f KeyX, KeyY, MouseX, MouseY

AmbientColor(RGB(128,128,128))

; Create a plan, manually
;
CreateMesh(1,100)
SetMeshData(1, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M1, 8)
SetMeshData(1, #PB_Mesh_Face, ?PlanFaces2, 8)
CreateMesh(2,100)
SetMeshData(2, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M2, 4)
SetMeshData(2, #PB_Mesh_Face, ?PlanFaces, 4)
CreateMesh(3,100)
SetMeshData(3, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M3, 8)
SetMeshData(3, #PB_Mesh_Face, ?PlanFaces2, 8)
CreateMesh(4,100)
SetMeshData(4, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M4, 8)
SetMeshData(4, #PB_Mesh_Face, ?PlanFaces2, 8)
CreateMesh(5,100)
SetMeshData(5, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M5, 4)
SetMeshData(5, #PB_Mesh_Face, ?PlanFaces, 4)
CreateMesh(6,100)
SetMeshData(6, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M6, 8)
SetMeshData(6, #PB_Mesh_Face, ?PlanFaces2, 8)
CreateMesh(7,100)
SetMeshData(7, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M7, 8)
SetMeshData(7, #PB_Mesh_Face, ?PlanFaces2, 8)
CreateMesh(8,100)
SetMeshData(8, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M8, 8)
SetMeshData(8, #PB_Mesh_Face, ?PlanFaces2, 8)
CreateMesh(9,100)
SetMeshData(9, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M9, 8)
SetMeshData(9, #PB_Mesh_Face, ?PlanFaces2, 8)
CreateMesh(10,100)
SetMeshData(10, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M10, 8)
SetMeshData(10, #PB_Mesh_Face, ?PlanFaces2, 8)
CreateMesh(11,100)
SetMeshData(11, #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate, ?M11, 8)
SetMeshData(11, #PB_Mesh_Face, ?PlanFaces2, 8)

CreateTexture(1,64,64)
StartDrawing(TextureOutput(1))
  Box(0,0,64,64,#Blue)
  Box(1,1,62,62,#Yellow)
StopDrawing()

CreateMaterial(1, TextureID(1))
Restore Level
For z=1 To 8
  For x=1 To 7
    Read Title
    If title
      Entity=CreateEntity (#PB_Any, MeshID(Title), MaterialID(1))
      ScaleEntity(entity, 64, 64, 64)
      EntityLocate(entity,x*64,0,z*64)
    EndIf
  Next x
Next z     

CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0,0,150,100)
CameraLookAt(0,EntityX(entity),EntityY(entity),EntityZ(entity))
 
Repeat
 
  ClearScreen(0)
       
  If ExamineKeyboard()
   
    If KeyboardPushed(#PB_Key_Left)
      KeyX = -#CameraSpeed
    ElseIf KeyboardPushed(#PB_Key_Right)
      KeyX = #CameraSpeed
    Else
      KeyX = 0
    EndIf
             
    If KeyboardPushed(#PB_Key_Up)
      KeyY = -#CameraSpeed
    ElseIf KeyboardPushed(#PB_Key_Down)
      KeyY = #CameraSpeed
    Else
      KeyY = 0
    EndIf


  EndIf
 
  If ExamineMouse()
    MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
    MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
  EndIf
       
  RotateCamera(0, MouseX, MouseY, RollZ)
  MoveCamera  (0, KeyX, 0, KeyY)
 
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

End

DataSection

  M1:
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  1.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  1.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
    
    Data.f  0.5, 0, 1.0 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 1.0 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
  M2:
    Data.f  0.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  1.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  1.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
  M3:
    Data.f  0.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  1.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  1.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
    
    Data.f  0.5, 0, 1.0 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 1.0 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3    
  M4:
    Data.f  0.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
   
    Data.f  0.5, 0, 1.0 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 1.0 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
  M5:
    Data.f  0.5, 0, 1.0 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 1.0 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.0 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.0 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
  M6:
    Data.f  0.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
    
    Data.f  0.5, 0, 1.0 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 1.0 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.0 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.0 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
  M7:
    Data.f  0.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
    
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.0 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.0 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3      
  M8:
    Data.f  0.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  1.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  1.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
    
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.0 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.0 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
  M9:
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  1.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  1.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
    
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.0 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.0 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3    
  M10:
    Data.f  0.5, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  1.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  1.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
    
    Data.f  0.5, 0, 1.0 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 1.0 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.0 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.0 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3    
  M11:
    Data.f  0.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  1.0, 1, 0.5 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  1.0, 0, 0.5 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3
    
    Data.f  0.5, 0, 1.0 : Data.f 1, 1, 1 : Data.f 0, 1 ; Vertex 0
    Data.f  0.5, 1, 1.0 : Data.f 1, 1, 1 : Data.f 1, 1 ; Vertex 1
    Data.f  0.5, 1, 0.0 : Data.f 1, 1, 1 : Data.f 1, 0 ; Vertex 2
    Data.f  0.5, 0, 0.0 : Data.f 1, 1, 1 : Data.f 0, 0 ; Vertex 3

  PlanFaces:
    Data.w 2, 1, 0 ; bottom face (clockwise as it's reversed...)
    Data.w 0, 3, 2
    Data.w 0, 1, 2
    Data.w 2, 3, 0     
  PlanFaces2:
    Data.w 2, 1, 0 ; bottom face (clockwise as it's reversed...)
    Data.w 0, 3, 2
    Data.w 0, 1, 2
    Data.w 2, 3, 0         
    Data.w 6, 5, 4 ; bottom face (clockwise as it's reversed...)
    Data.w 4, 7, 6
    Data.w 4, 5, 6
    Data.w 6, 7, 4  
  Level:

  Data.l  1, 2, 2, 3, 2, 2, 4 
  Data.l  5, 0, 0, 5, 0, 0, 5
  Data.l  5, 0, 1, 0, 4, 0, 5
  Data.l  5, 0, 5, 5, 5, 0, 5
  Data.l 10, 4, 9,11, 7, 3, 6
  Data.l  5, 0, 0, 5, 0, 6, 5
  Data.l  5, 5, 0, 5, 0, 0, 5
  Data.l  9, 8, 2, 8, 2, 8, 7
   
EndDataSection

Posted: Sun Jun 29, 2008 11:20 am
by Num3
Something like this?

Image

Ehehe
I made this dungeon algorithm to create caves...
http://www.evilscience.co.uk/?p=53

Then made a cube mesh and a flat plane for the wall and ceilling ;)

Posted: Sun Jun 29, 2008 3:23 pm
by Rook Zimbabwe
You have some code for this incredible example?

At east the part where you bashed his formula into PB? :D

Posted: Sun Jun 29, 2008 8:25 pm
by Num3
Sure thing..

This is just a small strip down of something else i'm making that i will release in the near future :wink:

I can't give you the meshes, because they will not work, but they are just a cube sized (10x10x10 unit's) and 2 planes (one with the uv pointing up and the other flipped so the uv points down, sized 10x10 units)...

The textures i used are only 256x256 which are very bad and look horrible...

Screen3DRequester.pb is is your Examples directory of Purebasic

Code: Select all

;

; /// The maze ///
#CameraSpeed = 15

Global x.l, y.l
x = 64
y = 64

Global Dim map(x, y)

Global probability.l, h.l, itinerations.l, Neighbours.l

Procedure examineNeighbours(xx, yy)
  c = 0
  If xx-1>0
    If map(xx-1, yy) = 0
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x
    If map(xx + 1, yy) = 0
      c + 1
    EndIf
  EndIf
  
  If yy-1>0
    If map(xx, yy-1) = 0
      c + 1
    EndIf
  EndIf
  
  If yy + 1<y
    If map(xx, yy + 1) = 0
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x And yy + 1<y
    If map(xx + 1, yy + 1) = 0
      c + 1
    EndIf
  EndIf
  
  If xx-1>0 And yy-1>0
    If map(xx-1, yy-1) = 0
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x And yy-1>0
    If map(xx + 1, yy-1) = 0
      c + 1
    EndIf
  EndIf
  
  If xx-1>0 And yy + 1<y
    If map(xx-1, yy + 1) = 0
      c + 1
    EndIf
  EndIf
  
  ProcedureReturn c
  
EndProcedure

Procedure RIP(xx, yy) ; Remove Isolated Points
  c = 0
  
  ; *** Wall ***
  If xx-1>0
    If map(xx-1, yy) = 0
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x
    If map(xx + 1, yy) = 0
      c + 1
    EndIf
  EndIf
  
  If yy-1>0
    If map(xx, yy-1) = 0
      c + 1
    EndIf
  EndIf
  
  If yy + 1<y
    If map(xx, yy + 1) = 0
      c + 1
    EndIf
  EndIf
  
  If c = 0
    map(xx, yy) = 1
  EndIf
  
  ; *** Floor ***
  c = 0
  If xx-1>0
    If map(xx-1, yy) = 1
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x
    If map(xx + 1, yy) = 1
      c + 1
    EndIf
  EndIf
  
  If yy-1>0
    If map(xx, yy-1) = 1
      c + 1
    EndIf
  EndIf
  
  If yy + 1<y
    If map(xx, yy + 1) = 1
      c + 1
    EndIf
  EndIf
  
  If c = 0
    map(xx, yy) = 0
  EndIf
  
EndProcedure

h = 0
itinerations = x*y*5
probability = 34
Neighbours = 4

For a = 0 To x
  For b = 0 To y
    If Random(100)<probability
      map(a, b) = 1
    EndIf
  Next
Next

For a = 0 To itinerations
  
  xx = Random(x)
  yy = Random(y)
  
  If h = 1
    If examineNeighbours(xx, yy)>Neighbours
      map(xx, yy) = 1
    Else
      map(xx, yy) = 0
    EndIf
  Else
    ; *** Step 3-2 ***
    If examineNeighbours(xx, yy)>Neighbours
      map(xx, yy) = 0
    Else
      map(xx, yy) = 1
    EndIf
  EndIf
  
Next

For a = 0 To x
  For b = 0 To y
    rip(a, b)
  Next
Next


: /// 3d engine stuff ///

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  Add3DArchive(GetCurrentDirectory(), #PB_3DArchive_FileSystem)
  Add3DArchive("textures\", #PB_3DArchive_FileSystem)
  Add3DArchive("data\", #PB_3DArchive_FileSystem)

  
  If Screen3DRequester()
    
    ; The fog that gives us the 'dark closed' ambient
    Fog($0, 1, 50, 500)
    
    AmbientColor($FFFFFF)
       
    Parse3DScripts()
    
    CreateEntity(0, LoadMesh(0, "cube.mesh"), #PB_Material_None)
    CreateEntity(1, LoadMesh(1, "floor.mesh"), #PB_Material_None)
    CreateEntity(2, LoadMesh(2, "cealing.mesh"), #PB_Material_None)
    
    ; A light source (not really used in this example)
    CreateLight(0, $ffffff, 0, 1000, 0)
    
    CreateCamera(0, 0, 0, 100, 100)

    ;Reduce the camera range or there will be to many triangles on screen
    CameraRange(0, 0.1, 800)
    CameraLocate(0, 0, 10, 0)

    ;*** Read map() and place every single cell on the world
    For a = 0 To x
      For b = 0 To y
        ;*** Place floor tiles
        current.l = CopyEntity(1, #PB_Any)
        EntityLocate(CURREnt, 100*a, 0, 100*b)
        ScaleEntity(current, 10, 0, 10)
        ;*** Place ceiling tiles
         current.l = CopyEntity(2, #PB_Any)
         EntityLocate(CURREnt, 100*a, 50, 100*b)
         ScaleEntity(current, 10, 0, 10)
         ;*** Place walls
        If map(a, b) = 1
          current.l = CopyEntity(0, #PB_Any)
          EntityLocate(CURREnt, 100*a, 0, 100*b)
          ScaleEntity(current, 10, 5, 10)
        EndIf
      Next
    Next
    
    Repeat
      
      If IsScreenActive()
        
        Screen3DEvents()
        
        If ExamineKeyboard()
          
          If KeyboardReleased(#PB_Key_P)
            CreateSprite(0, 800, 600)
            GrabSprite(0, 0, 0, 800, 600)
            SaveSprite(0, "test.bmp")
            FreeSprite(0)
          EndIf
          
          If KeyboardPushed(#PB_Key_Left)
            KeyX = -#CameraSpeed
          ElseIf KeyboardPushed(#PB_Key_Right)
            KeyX = #CameraSpeed
          Else
            KeyX = 0
          EndIf
          
          If KeyboardPushed(#PB_Key_Up)
            KeyY = -#CameraSpeed
          ElseIf KeyboardPushed(#PB_Key_Down)
            KeyY = #CameraSpeed
          Else
            KeyY = 0
          EndIf
          
        EndIf
        
        If ExamineMouse()
          MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
          MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2         
        EndIf

        
        RotateCamera(0, MouseX, 0, RollZ)
        MoveCamera(0, KeyX, 0, KeyY) ;+height
        
        RenderWorld()
        
        SetWindowTitle(0, StrF(Engine3DFrameRate(#PB_Engine3D_Current), 2) + "[" + Str(CountRenderedTriangles()) + "]" + "[Cam: " + Str(CameraX(0)) + ":" + Str(CameraY(0)) + ":" + Str(CameraZ(0)) + "]")
        
      Else
        Delay(50)
      EndIf
      
      Delay(1)
      FlipBuffers(2)
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Posted: Sun Jun 29, 2008 8:27 pm
by Num3
Here is a stand-alone maze generation routine, based on the 'Evil Science algorithm'...

Code: Select all



Global x.l, y.l
x = 127
y = 127
CreateImage(0, x, y)

Global Dim map(x, y)

Global probability.l, h.l, itinerations.l, Neighbours.l

Procedure examineNeighbours(xx, yy)
  c = 0
  If xx-1>0
    If map(xx-1, yy) = 0
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x
    If map(xx + 1, yy) = 0
      c + 1
    EndIf
  EndIf
  
  If yy-1>0
    If map(xx, yy-1) = 0
      c + 1
    EndIf
  EndIf
  
  If yy + 1<y
    If map(xx, yy + 1) = 0
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x And yy + 1<y
    If map(xx + 1, yy + 1) = 0
      c + 1
    EndIf
  EndIf
  
  If xx-1>0 And yy-1>0
    If map(xx-1, yy-1) = 0
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x And yy-1>0
    If map(xx + 1, yy-1) = 0
      c + 1
    EndIf
  EndIf
  
  If xx-1>0 And yy + 1<y
    If map(xx-1, yy + 1) = 0
      c + 1
    EndIf
  EndIf
  
  ProcedureReturn c
  
EndProcedure

Procedure RIP(xx, yy) ; Remove Isolated Pixels
  c = 0
  
  ; *** Wall ***
  If xx-1>0
    If map(xx-1, yy) = 0
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x
    If map(xx + 1, yy) = 0
      c + 1
    EndIf
  EndIf
  
  If yy-1>0
    If map(xx, yy-1) = 0
      c + 1
    EndIf
  EndIf
  
  If yy + 1<y
    If map(xx, yy + 1) = 0
      c + 1
    EndIf
  EndIf
  
  If c = 0
    map(xx, yy) = 1
  EndIf
  
  
  ; *** Floor ***
  c = 0
  If xx-1>0
    If map(xx-1, yy) = 1
      c + 1
    EndIf
  EndIf
  
  If xx + 1<x
    If map(xx + 1, yy) = 1
      c + 1
    EndIf
  EndIf
  
  If yy-1>0
    If map(xx, yy-1) = 1
      c + 1
    EndIf
  EndIf
  
  If yy + 1<y
    If map(xx, yy + 1) = 1
      c + 1
    EndIf
  EndIf
  
  If c = 0
    map(xx, yy) = 0
  EndIf
  
EndProcedure

h = 0
itinerations = x*y*5
probability = 34
Neighbours = 4

For a = 0 To x
  For b = 0 To y
    If Random(100)<probability
      map(a, b) = 1
    EndIf
  Next
Next

For a = 0 To itinerations
  
  xx = Random(x)
  yy = Random(y)
  
  If h = 1
    If examineNeighbours(xx, yy)>Neighbours
      map(xx, yy) = 1
    Else
      map(xx, yy) = 0
    EndIf
  Else
    ; *** Step 3-2 ***
    If examineNeighbours(xx, yy)>Neighbours
      map(xx, yy) = 0
    Else
      map(xx, yy) = 1
    EndIf
  EndIf
  
Next

For a = 0 To x
  For b = 0 To y
    rip(a, b)
  Next
Next

StartDrawing(ImageOutput(0))
  For a = 0 To x
    For b = 0 To y
      If map(a, b) = 1
        Plot(a, b, $FFFFFF)
      ElseIf map(a, b) = 2
        Plot(a, b, $0005FF)
      EndIf
    Next
  Next
StopDrawing()

;ResizeImage(0, 480, 480, #PB_Image_Raw)
SaveImage(0, GetTemporaryDirectory() + "dungeon.bmp")

RunProgram(GetTemporaryDirectory() + "dungeon.bmp")

Posted: Sun Jun 29, 2008 8:53 pm
by Num3
I have much interest in IceSoft algorithm because i would like to use it to build much more interesting dungeons using prefab's, instead of boring cubes...

Prefabs are just pre-built pieces that snap together like a 3d lego, like in this real world picture:

Image

Making games in 3d is much easier than it is in 2d (trust me on this one) ;)