Code: Select all
EnableExplicit
Procedure error(error_num.i)
Debug "error"
Debug error_num
End
EndProcedure
Enumeration
#window
;3D
#texture
#material
#camera
EndEnumeration
#window_w = 640
#window_h = 480
#window_title = "CLIPViewer"
;3D Options
#FPS = 60
#mouse_speed = 0.2
#camera_speed = 0.5
#texture_w = 32
#texture_h = 32
#texture_color = 16750130
#fog_color = 10526880
#for_intensity = 1
#fog_start = 128
#fog_end = 1024
#axis_color = 65535
Procedure.i mouse()
Protected MouseX.f = - MouseDeltaX() / 6; * #mouse_speed
Protected MouseY.f = - MouseDeltaY() / 6; * #mouse_speed
RotateCamera(#camera, MouseY, MouseX, 0, #PB_Relative)
EndProcedure
Procedure.i keyboard()
Protected cam_forward_backward.f
Protected cam_leftward_rightward.f
If KeyboardPushed(#PB_Key_W)
cam_forward_backward = - #camera_speed
ElseIf KeyboardPushed(#PB_Key_S)
cam_forward_backward = #camera_speed
Else
cam_forward_backward = 0
EndIf
If KeyboardPushed(#PB_Key_A)
cam_leftward_rightward = - #camera_speed
ElseIf KeyboardPushed(#PB_Key_D)
cam_leftward_rightward = #camera_speed
Else
cam_leftward_rightward = 0
EndIf
If KeyboardPushed(#PB_Key_LeftShift)
cam_forward_backward * 10
cam_leftward_rightward * 10
EndIf
MoveCamera(#camera, cam_leftward_rightward, 0, cam_forward_backward)
EndProcedure
Procedure.i create_axis()
CreateLine3D(#PB_Any, 0, 0, 0, #axis_color, 5, 0, 0, #axis_color)
CreateLine3D(#PB_Any, 0, 0, 0, #axis_color, 0, 5, 0, #axis_color)
CreateLine3D(#PB_Any, 0, 0, 0, #axis_color, 0, 0, 5, #axis_color)
Protected cube.i = CreateCube(#PB_Any, 5)
CreateEntity(#PB_Any, MeshID(cube), MaterialID(#material))
EndProcedure
If InitEngine3D() = 0
error(0)
Else
If InitSprite() = 0
error(1)
Else
If InitKeyboard() = 0
error(2)
Else
If InitMouse() = 0
error(3)
Else
If OpenWindow(#window, #PB_Ignore, #PB_Ignore, #window_w, #window_h, #window_title, #PB_Window_SystemMenu | #PB_Window_ScreenCentered) = 0
error(4)
Else
If OpenWindowedScreen(WindowID(#window), 0, 0, #window_w, #window_h, 0, 0, 0, #PB_Screen_NoSynchronization) = 0
error(5)
Else
SetFrameRate(#FPS)
If CreateTexture(#texture, 32, 32) = 0
error(6)
Else
If StartDrawing(TextureOutput(#texture)) = 0
error(7)
Else
Box(0, 0, #texture_w, #texture_h, #texture_color)
StopDrawing()
If CreateMaterial(#material, TextureID(#texture)) = 0
error(8)
Else
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 5, -20)
RotateCamera(#camera, 0, 180, 0)
;Fog(#fog_color, #for_intensity, #fog_start, #fog_end)
;MaterialShadingMode(#material, #PB_Material_Phong | #PB_Material_Wireframe)
create_axis()
Define current_mesh.i = CreateMesh(#PB_Any, #PB_Mesh_TriangleFan, #PB_Mesh_Static)
MeshVertexPosition(0, 0, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(-5, 5, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(-3, 7, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(0, 10, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(3, 7, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
MeshVertexPosition(5, 5, 0)
MeshVertexColor(RGB(Random(255),Random(255),Random(255)))
FinishMesh(1)
CreateEntity(#PB_Any, MeshID(current_mesh), MaterialID(#material))
CreateLight(#PB_Any, RGB(255, 0, 0), 10, 10, 0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Default
ExamineKeyboard()
keyboard()
ExamineMouse()
mouse()
RenderWorld()
FlipBuffers()
If KeyboardPushed(#PB_Key_Escape) <> 0
Break
EndIf
EndSelect
ForEver
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
- Why MeshVertexColor() does not work?
- Why CreateLight() does not work (no shadows)?