Code : Tout sélectionner
;_______________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
; Cse - Ollivier
;_______________________________________________________________________________________
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
EnableExplicit
;{ Head }
;{ World }
Structure WORLD
*EntiPtr
EntiQtt.L
EndStructure
ProcedureDLL.L InitWorld32(MaxEntity.L)
;_______________________________________________________________________________________
; Cette procédure doit être appelée avant toute exploitation 3D
; Elle amorce DirectX, prépare un écran graphique et une vision 3D plein écran
;
; MaxEntity.L : Quantité maximum d'entités à traiter
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Protected *Result.WORLD
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "Ogre3D", $80000000)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0)
CreateCamera(0, 0, 0, 100, 100)
CameraRange(0, 0.1, 10000)
*Result = AllocateMemory(SizeOf(WORLD) )
*Result\EntiPtr = AllocateMemory(MaxEntity * 4)
ProcedureReturn *Result
EndProcedure
ProcedureDLL WalkWorld()
;_______________________________________________________________________________________
; Explore le monde sans règles précises (liberté de positions et d'angles de caméra)
; Utile pour explorer un décor
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Protected ExitCode.L
Protected Event0.L
Protected Event1.L
Protected EntityAngleX.F
Protected EntityAngleY.F
Protected EntityAngleZ.F
CameraLocate(0, 100, 1.80, 100)
CreateLight(0,$FFFFFF)
LightLocate(0,100,5,100)
Repeat
Delay(24)
StartDrawing(ScreenOutput() )
DrawText(0, 0, "MODE CAMERA : LIBRE", $FFFFFF, $000000)
DrawText(0, 16, "X= " + Str(CameraX(0) ) )
DrawText(0, 32, "Y= " + Str(CameraY(0) ) )
DrawText(0, 48, "Z= " + Str(CameraZ(0) ) )
StopDrawing()
FlipBuffers()
ClearScreen(0)
ExamineKeyboard()
ExamineMouse()
If KeyboardPushed(#PB_Key_Right): MoveCamera(0, 1, 0, 0):EndIf
If KeyboardPushed(#PB_Key_Left): MoveCamera(0, -1, 0, 0):EndIf
If KeyboardPushed(#PB_Key_PageUp): MoveCamera(0, 0, 1, 0):EndIf
If KeyboardPushed(#PB_Key_PageDown): MoveCamera(0, 0, -1, 0):EndIf
If KeyboardPushed(#PB_Key_Up): MoveCamera(0, 0, 0, -1):EndIf
If KeyboardPushed(#PB_Key_Down): MoveCamera(0, 0, 0, 1):EndIf
Event0 = WindowEvent()
If Event0 = 16: ExitCode | 1: EndIf
If Event0 = #PB_Event_Menu: ExitCode | 2: EndIf
If Event0 = #WM_RBUTTONDOWN: DisplayPopupMenu(0, WindowID(0) ): EndIf
If KeyboardPushed(#PB_Key_Escape): ExitCode | 1: EndIf
RotateCamera(0, -MouseDeltaX(), -MouseDeltaY(), 0)
CameraLocate(0, CameraX(0), 1.80, CameraZ(0) )
RenderWorld()
Until ExitCode
EndProcedure
ProcedureDLL ExploreWorld()
;_______________________________________________________________________________________
; Explore le monde sans règles précises (liberté de positions et d'angles de caméra)
; Utile pour explorer un décor
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Protected ExitCode.L
Protected Event0.L
Protected Event1.L
Protected EntityAngleX.F
Protected EntityAngleY.F
Protected EntityAngleZ.F
MoveCamera(0, 0, 0, 50)
CreateLight(0,$FFFFFF)
LightLocate(0,100,5,100)
Repeat
Delay(24)
StartDrawing(ScreenOutput() )
DrawText(0, 0, "MODE CAMERA : LIBRE", $FFFFFF, $000000)
DrawText(0, 16, "X= " + Str(CameraX(0) ) )
DrawText(0, 32, "Y= " + Str(CameraY(0) ) )
DrawText(0, 48, "Z= " + Str(CameraZ(0) ) )
StopDrawing()
FlipBuffers()
ClearScreen(0)
ExamineKeyboard()
ExamineMouse()
If KeyboardPushed(#PB_Key_Right): MoveCamera(0, 1, 0, 0):EndIf
If KeyboardPushed(#PB_Key_Left): MoveCamera(0, -1, 0, 0):EndIf
If KeyboardPushed(#PB_Key_PageUp): MoveCamera(0, 0, 1, 0):EndIf
If KeyboardPushed(#PB_Key_PageDown): MoveCamera(0, 0, -1, 0):EndIf
If KeyboardPushed(#PB_Key_Up): MoveCamera(0, 0, 0, -1):EndIf
If KeyboardPushed(#PB_Key_Down): MoveCamera(0, 0, 0, 1):EndIf
Event0 = WindowEvent()
If Event0 = 16: ExitCode | 1: EndIf
If Event0 = #PB_Event_Menu: ExitCode | 2: EndIf
If Event0 = #WM_RBUTTONDOWN: DisplayPopupMenu(0, WindowID(0) ): EndIf
If KeyboardPushed(#PB_Key_Escape): ExitCode | 1: EndIf
RotateCamera(0, -MouseDeltaX(), -MouseDeltaY(), 0)
RenderWorld()
Until ExitCode
EndProcedure
ProcedureDLL MapWorld(AltitudeIni.F)
;_______________________________________________________________________________________
; Explore le monde à 40m d'altitude
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Protected ExitCode.L
Protected Event0.L
Protected Event1.L
Protected EntityAngleX.F
Protected EntityAngleY.F
Protected EntityAngleZ.F
CreateLight(0,$FFFFFF)
LightLocate(0,100,5,100)
CreateLight(1,$FFFFFF)
LightLocate(1,100,35,100)
CameraLocate(0, 0.0, 40.0, 0.0)
RotateCamera(0, 0.0, -90.0, 0.0)
Repeat
Delay(48)
StartDrawing(ScreenOutput() )
DrawText(0, 0, "MODE CAMERA : LECTURE DE CARTE", $FFFFFF, $000000)
DrawText(0, 16, "X= " + Str(CameraX(0) ) )
DrawText(0, 32, "Altitude = " + Str(CameraY(0) ) + "m")
DrawText(0, 48, "Z= " + Str(CameraZ(0) ) )
StopDrawing()
FlipBuffers()
ClearScreen(0)
ExamineKeyboard()
; ExamineMouse()
If KeyboardPushed(#PB_Key_Right): MoveCamera(0, 1, 0, 0):EndIf
If KeyboardPushed(#PB_Key_Left): MoveCamera(0, -1, 0, 0):EndIf
If KeyboardPushed(#PB_Key_PageUp): MoveCamera(0, 0, 0, -10):EndIf
If KeyboardPushed(#PB_Key_PageDown): MoveCamera(0, 0, 0, 10):EndIf
If KeyboardPushed(#PB_Key_Up): MoveCamera(0, 0, 1, 0):EndIf
If KeyboardPushed(#PB_Key_Down): MoveCamera(0, 0, -1, 0):EndIf
Event0 = WindowEvent()
If Event0 = 16: ExitCode | 1: EndIf
If Event0 = #PB_Event_Menu: Event1 = EventMenu(): EndIf
If Event0 = #WM_RBUTTONDOWN: EndIf
If KeyboardPushed(#PB_Key_Escape): ExitCode | 1: EndIf
RenderWorld()
Until ExitCode
EndProcedure
ProcedureDLL FlyWorld(AltitudeIni.F)
;_______________________________________________________________________________________
; Perçoit le paysage en isométrique avec d'altitude stable et des angles constants
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Protected ExitCode.L
Protected Event0.L
Protected Event1.L
Protected CamX.F
Protected CamY.F
Protected CamZ.F
Protected EntityAngleX.F
Protected EntityAngleY.F
Protected EntityAngleZ.F
CreateLight(0,$FFFFFF)
LightLocate(0,100,5,100)
CreateLight(1,$FFFFFF)
LightLocate(1,100,35,100)
CameraLocate(0, 100.0, 40.0, 100.0)
RotateCamera(0, 45.0, -45.0, 0.0)
Repeat
Delay(48)
StartDrawing(ScreenOutput() )
DrawText(0, 0, "MODE HELICO EN ISO", $FFFFFF, $000000)
DrawText(0, 16, "X= " + Str(CameraX(0) ) )
DrawText(0, 32, "Altitude = " + Str(CameraY(0) ) + "m")
DrawText(0, 48, "Z= " + Str(CameraZ(0) ) )
StopDrawing()
FlipBuffers()
ClearScreen(0)
ExamineKeyboard()
; ExamineMouse()
If KeyboardPushed(#PB_Key_PageUp): MoveCamera(0, 0, 0, -1):EndIf
If KeyboardPushed(#PB_Key_PageDown): MoveCamera(0, 0, 0, 1):EndIf
CamY = CameraY(0)
If KeyboardPushed(#PB_Key_Right): MoveCamera(0, 1, 0, 0):EndIf
If KeyboardPushed(#PB_Key_Left): MoveCamera(0, -1, 0, 0):EndIf
If KeyboardPushed(#PB_Key_Up): MoveCamera(0, 0, 1, 0):EndIf
If KeyboardPushed(#PB_Key_Down): MoveCamera(0, 0, -1, 0):EndIf
CameraLocate(0, CameraX(0), CamY, CameraZ(0) )
Event0 = WindowEvent()
If Event0 = 16: ExitCode | 1: EndIf
If Event0 = #PB_Event_Menu: Event1 = EventMenu(): EndIf
If Event0 = #WM_RBUTTONDOWN: EndIf
If KeyboardPushed(#PB_Key_Escape): ExitCode | 1: EndIf
RenderWorld()
Until ExitCode
EndProcedure
ProcedureDLL WorldMenu()
;ExploreWorld()
;MapWorld(200.0)
;FlyWorld(40.0)
WalkWorld()
EndProcedure
;}
;{ Texture }
Structure ENTI
N.L
Texture.L
Material.L
Mesh.L
MeshData.L
EndStructure
ProcedureDLL TextureMonochrom(*Enti.ENTI, Color.L)
*Enti\Texture = CreateTexture(-1, 256, 256)
StartDrawing(TextureOutput(*Enti\Texture) )
Box(0, 0, 256, 256, Color)
StopDrawing()
EndProcedure
ProcedureDLL TextureGrass(*Enti.ENTI)
Protected x.L
Protected y.L
Protected R.L
Protected V.L
Protected B.L
*Enti\Texture = CreateTexture(-1, 256, 256)
StartDrawing(TextureOutput(*Enti\Texture) )
For y = 0 To 255
For x = 0 To 255
V = Random(255)
R = Random(V)
B = 0
Box(x, y, 1, 1, RGB(R, V, B) )
Next
Next
StopDrawing()
EndProcedure
;}
;{ Mesh }
ProcedureDLL CreateMeshBuffer()
;_______________________________________________________________________________________
; CreateMeshBuffer() crée un buffer vierge qui va contenir la structure fil de fer.
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Protected *Enti.ENTI
*Enti = AllocateMemory(SizeOf(ENTI) )
*Enti\MeshData = AllocateMemory(16)
PokeL(*Enti\MeshData, AllocateMemory(1 << 17) ) ; Mémoire pour les sommets
PokeL(*Enti\MeshData + 4, AllocateMemory(1 << 17) ) ; Mémoire pour les faces
PokeL(*Enti\MeshData + 8, 0) ; Quantité de sommets
PokeL(*Enti\MeshData + 12, 0) ; Quantité de face
ProcedureReturn *Enti
EndProcedure
ProcedureDLL FreeMeshBuffer(*MeshBuffer)
;_______________________________________________________________________________________
; Libère le buffer de structure fil de fer
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
FreeMemory(PeekL(*MeshBuffer) )
FreeMemory(PeekL(*MeshBuffer + 4) )
FreeMemory(*MeshBuffer)
EndProcedure
ProcedureDLL MeshAddTria(*MB, x1.F, y1.F, z1.F, x2.F, y2.F, z2.F, x3.F, y3.F, z3.F)
Protected Ax.F
Protected Ay.F
Protected Az.F
Protected Bx.F
Protected By.F
Protected Bz.F
Protected Nx.F
Protected Ny.F
Protected Nz.F
Protected *VertexList
Protected *FaceList
Protected VertexQ.L
Protected FaceQ.L
Protected *Vertex
Protected *Face
*VertexList = PeekL(*MB)
*FaceList = PeekL(*MB + 4)
VertexQ = PeekL(*MB + 8)
FaceQ = PeekL(*MB + 12)
*Vertex = *VertexList + VertexQ * 32
*Face = *FaceList + FaceQ * 6
Ax = x2 - x1: Ay = y2 - y1: Az = z2 - z1
Bx = x3 - x1: By = y3 - y1: Bz = z3 - z1
Nx = (Ay * Bz) - (By * Az)
Ny = (Ax * Bz) - (Bx * Az)
Nz = (Ax * By) - (Bx * Ay)
PokeF(*Vertex, x1)
PokeF(*Vertex + 4, y1)
PokeF(*Vertex + 8, z1)
PokeF(*Vertex + 12, nx)
PokeF(*Vertex + 16, ny)
PokeF(*Vertex + 20, nz)
PokeF(*Vertex + 24, 0.0)
PokeF(*Vertex + 28, 0.0)
*Vertex + 32: VertexQ + 1
PokeF(*Vertex, x2)
PokeF(*Vertex + 4, y2)
PokeF(*Vertex + 8, z2)
PokeF(*Vertex + 12, nx)
PokeF(*Vertex + 16, ny)
PokeF(*Vertex + 20, nz)
PokeF(*Vertex + 24, 1.0)
PokeF(*Vertex + 28, 0.0)
*Vertex + 32: VertexQ + 1
PokeF(*Vertex, x3)
PokeF(*Vertex + 4, y3)
PokeF(*Vertex + 8, z3)
PokeF(*Vertex + 12, nx)
PokeF(*Vertex + 16, ny)
PokeF(*Vertex + 20, nz)
PokeF(*Vertex + 24, 0.0)
PokeF(*Vertex + 28, 1.0)
*Vertex + 32: VertexQ + 1
PokeW(*Face, VertexQ - 4)
PokeW(*Face + 2, VertexQ - 3)
PokeW(*Face + 4, VertexQ - 2)
*Face + 6: FaceQ + 1
PokeW(*Face, VertexQ - 2)
PokeW(*Face + 2, VertexQ - 3)
PokeW(*Face + 4, VertexQ - 1)
*Face + 6: FaceQ + 1
PokeL(*MB + 8, VertexQ)
PokeL(*MB + 12, FaceQ)
EndProcedure
ProcedureDLL MeshAddQuad(*MB, x1.F, y1.F, z1.F, x2.F, y2.F, z2.F, x3.F, y3.F, z3.F, x4.F, y4.F, z4.F)
Protected Ax.F
Protected Ay.F
Protected Az.F
Protected Bx.F
Protected By.F
Protected Bz.F
Protected Nx.F
Protected Ny.F
Protected Nz.F
Protected *VertexList
Protected *FaceList
Protected VertexQ.L
Protected FaceQ.L
Protected *Vertex
Protected *Face
*VertexList = PeekL(*MB)
*FaceList = PeekL(*MB + 4)
VertexQ = PeekL(*MB + 8)
FaceQ = PeekL(*MB + 12)
*Vertex = *VertexList + VertexQ * 32
*Face = *FaceList + FaceQ * 6
Ax = x2 - x1: Ay = y2 - y1: Az = z2 - z1
Bx = x3 - x1: By = y3 - y1: Bz = z3 - z1
Nx = (Ay * Bz) - (By * Az)
Ny = (Ax * Bz) - (Bx * Az)
Nz = (Ax * By) - (Bx * Ay)
PokeF(*Vertex, x1)
PokeF(*Vertex + 4, y1)
PokeF(*Vertex + 8, z1)
PokeF(*Vertex + 12, nx)
PokeF(*Vertex + 16, ny)
PokeF(*Vertex + 20, nz)
PokeF(*Vertex + 24, 0.0)
PokeF(*Vertex + 28, 0.0)
*Vertex + 32: VertexQ + 1
PokeF(*Vertex, x2)
PokeF(*Vertex + 4, y2)
PokeF(*Vertex + 8, z2)
PokeF(*Vertex + 12, nx)
PokeF(*Vertex + 16, ny)
PokeF(*Vertex + 20, nz)
PokeF(*Vertex + 24, 1.0)
PokeF(*Vertex + 28, 0.0)
*Vertex + 32: VertexQ + 1
PokeF(*Vertex, x3)
PokeF(*Vertex + 4, y3)
PokeF(*Vertex + 8, z3)
PokeF(*Vertex + 12, nx)
PokeF(*Vertex + 16, ny)
PokeF(*Vertex + 20, nz)
PokeF(*Vertex + 24, 0.0)
PokeF(*Vertex + 28, 1.0)
*Vertex + 32: VertexQ + 1
PokeF(*Vertex, x4)
PokeF(*Vertex + 4, y4)
PokeF(*Vertex + 8, z4)
PokeF(*Vertex + 12, nx)
PokeF(*Vertex + 16, ny)
PokeF(*Vertex + 20, nz)
PokeF(*Vertex + 24, 1.0)
PokeF(*Vertex + 28, 1.0)
*Vertex + 32: VertexQ + 1
PokeW(*Face, VertexQ - 4)
PokeW(*Face + 2, VertexQ - 3)
PokeW(*Face + 4, VertexQ - 2)
*Face + 6: FaceQ + 1
PokeW(*Face, VertexQ - 2)
PokeW(*Face + 2, VertexQ - 3)
PokeW(*Face + 4, VertexQ - 1)
*Face + 6: FaceQ + 1
PokeL(*MB + 8, VertexQ)
PokeL(*MB + 12, FaceQ)
EndProcedure
ProcedureDLL MeshAddSquare(*MB, x.F, y.F, z.F, Side.F)
Protected x1.F
Protected y1.F
Protected z1.F
Protected x2.F
Protected y2.F
Protected z2.F
Protected x3.F
Protected y3.F
Protected z3.F
Protected x4.F
Protected y4.F
Protected z4.F
x * Side
z * Side
x1 = x
y1 = y
z1 = z
x2 = x
y2 = y
z2 = z + Side
x3 = x + Side
y3 = y
z3 = z
x4 = x + Side
y4 = y
z4 = z + Side
MeshAddQuad(*MB, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
EndProcedure
ProcedureDLL MeshAddBox(*MB, x1.F, y1.F, z1.F, x2.F, y2.F, z2.F)
MeshAddQuad(*MB, x1, y1, z2, x2, y1, z2, x1, y2, z2, x2, y2, z2)
MeshAddQuad(*MB, x1, y1, z1, x1, y1, z2, x1, y2, z1, x1, y2, z2)
MeshAddQuad(*MB, x2, y1, z1, x1, y1, z1, x2, y2, z1, x1, y2, z1)
MeshAddQuad(*MB, x2, y1, z2, x2, y1, z1, x2, y2, z2, x2, y2, z1)
MeshAddQuad(*MB, x1, y1, z1, x2, y1, z1, x1, y1, z2, x2, y1, z2)
MeshAddQuad(*MB, x1, y2, z2, x2, y2, z2, x1, y2, z1, x2, y2, z1)
EndProcedure
ProcedureDLL CatchMesh(*Enti.ENTI)
;_______________________________________________________________________________________
; Transfert les données du buffer *MeshBuff dans la nouvelle structure Mesh
;¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*Enti\Mesh = CreateMesh(-1, PeekL(*Enti\MeshData + 8) )
SetMeshData(*Enti\Mesh, 13, PeekL(*Enti\MeshData), PeekL(*Enti\MeshData + 8) )
SetMeshData(*Enti\Mesh, 16, PeekL(*Enti\MeshData + 4), PeekL(*Enti\MeshData + 12) )
EndProcedure
;}
;{ Entity }
ProcedureDLL CatchEntity(*World.WORLD, *Enti.ENTI, n.L)
Protected *EntityIndex
CatchMesh(*Enti)
*Enti\Material = CreateMaterial(-1, TextureID(*Enti\Texture) )
CreateEntity(n, MeshID(*Enti\Mesh), MaterialID(*Enti\Material) )
*Enti\N = n
*EntityIndex = *World\EntiPtr + (*World\EntiQtt * 4)
PokeL(*EntityIndex, *Enti)
*World\EntiQtt + 1
EndProcedure
ProcedureDLL EntiBalise(*World.WORLD, n.L)
Protected *Enti.ENTI
*Enti = CreateMeshBuffer()
MeshAddBox(*Enti\MeshData, 0.0, 0.0, 0.0, 10.0, 10.0, 10.0)
MeshAddBox(*Enti\MeshData, 2.0, -10.0, 2.0, 8.0, 20.0, 8.0)
TextureMonochrom(*Enti, #Blue)
CatchEntity(*World, *Enti, n)
EndProcedure
ProcedureDLL EntiBuilding(*World.WORLD, n.L, x.F, y.F, z.F, Side.F, LevelHeight.F, LastLevel.L)
Protected *Enti.ENTI
Protected Height.F
Protected i.L
Height = LevelHeight * (LastLevel + 1.0)
*Enti = CreateMeshBuffer()
For i = 0 To LastLevel
MeshAddBox(*Enti\MeshData, x, y + (LevelHeight * i), z, x + Side, y + 0.15 + (LevelHeight * i), z + Side)
Next
MeshAddBox(*Enti\MeshData, x, y, z, x + 0.20, y + Height, z + 0.20)
MeshAddBox(*Enti\MeshData, x + Side, y, z, x + 0.20 + Side, y + Height, z + 0.20)
MeshAddBox(*Enti\MeshData, x, y, z + Side, x + 0.20, y + Height, z + 0.20 + Side)
MeshAddBox(*Enti\MeshData, x + Side, y, z + Side, x + 0.20 + Side, y + Height, z + 0.20 + Side)
TextureMonochrom(*Enti, #White)
CatchEntity(*World, *Enti, n)
EndProcedure
ProcedureDLL EntiMapRandom(n.L, w.L, d.L, Altitude.L)
Protected *MeshBuff
Protected x.F
Protected y.F
Protected z.F
Protected ix.L
Protected iz.L
Protected i1y.F
Protected i2y.F
Protected i3y.F
Protected i4y.F
Protected Dist.F
Protected dx.F
Protected dz.F
; *MeshBuff = CreateMeshBuffer()
Global Dim Alt.F(w, d)
For ix = 0 To w
For iz = 0 To d
dx = (ix - w / 2)
dz = (iz - d / 2)
Dist = (dx * dx) + (dz * dz)
Alt(ix, iz) = Sin(Dist / 64.0) * Altitude + Random(10)
Next
Next
For ix = 0 To w - 1
For iz = 0 To d - 1
x = ix * 10.0
z = iz * 10.0
i1y = Alt(ix, iz + 1)
i2y = Alt(ix + 1, iz + 1)
i3y = Alt(ix, iz)
i4y = Alt(ix + 1, iz)
MeshAddQuad(*MeshBuff, x, i1y, z, x + 10.0, i2y, z, x, i3y, z - 10.0, x + 10.0, i4y, z - 10.0)
Next
Next
; CatchMesh(0, *MeshBuff)
TextureGrass(0)
CreateEntity(n, MeshID(0), MaterialID(0) )
EndProcedure
ProcedureDLL EntiMapSquarePlain(*World.WORLD, n.L, MapWidth.F, MapDepth.F, Altitude.F, TileSide.F)
Protected *Enti.ENTI
Protected ixMax.L
Protected izMax.L
Protected ix.L
Protected iz.L
*Enti = CreateMeshBuffer()
TextureGrass(*Enti)
ixMax = Int(MapWidth / TileSide) - 1
izMax = Int(MapDepth / TileSide) - 1
For ix = 0 To ixMax
For iz = 0 To izMax
MeshAddSquare(*Enti\MeshData, ix, Altitude, iz, TileSide)
Next
Next
CatchEntity(*World, *Enti, n)
EndProcedure
;}
;}
; *** C'est ici que tout commence ! ***
Define *World.WORLD
Define i.L
*World = InitWorld32(16)
EntiMapSquarePlain(*World, 2, 320.0, 320.0, 0.0, 10.0) ;: EntityLocate(2, 20.0, 0.0, 0.0)
For i = 0 To 50
EntiBuilding(*World, i + 3, Random(31) * 10.0, 0.0, Random(31) * 10.0, 10.0, 2.5, 1 + Random(9) )
Next
WalkWorld()