- for a better usage of resources just let a short delay(1-5 ms should be enough) at the end of the main event loop.
- I changed some things in the keyboard management. Just have a look and play with arrows and numeric pad keys
- I added a different cursor display when the cursor is inside the screen and outside. This will probably help you in going further to allow the user ie to drag the robot or anything you will imagine.
The mouse position is managed using WindowMouseX() and WindowMouseY() because if you use InitMouse() and ExamineMouse() this will lock the mouse to the screen management and will not allow to manage the window part outside of the screen part.
So just some more ideas for a larger overview.
Anyway you converted my short code well and I am confident you will design nice work ...
Code: Select all
Enumeration
#Window_Main
EndEnumeration
#Background = $602020
;********************* Start added code *******************************************
#FALSE = 0
#true = 1
CameraSpeed = 0
;********************* End added code *******************************************
;
; Main starts here
;
Quit = #FALSE
WindowXSize = 800
WindowYSize = 600
ScreenXSize = 640
ScreenYSize = 480
If OpenWindow(#Window_Main, 0, 0, WindowXSize, WindowYSize, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered, "MyWindow")
If InitEngine3D() And InitSprite() And InitKeyboard() And InitMouse()
OpenWindowedScreen(WindowID(), WindowXSize - ScreenXSize, WindowYSize - ScreenYSize, ScreenXSize, ScreenYSize, #TRUE, 5, 25)
;********************* Start added code *******************************************
Add3DArchive("C:\Recup\PureBasic\Examples\Sources\Data\", #PB_3DArchive_FileSystem)
AmbientColor(RGB(0,200,0)) ; Green 'HUD' like color
CreateMaterial(0, LoadTexture(0, "r2skin.jpg"))
CreateEntity(0, LoadMesh(0, "Robot.mesh"), MaterialID(0))
AnimateEntity(0, "Walk")
CreateCamera(0, 0, 0, 100, 50) ; Front camera
CameraLocate(0,0,0,100)
CreateCamera(1, 0, 50, 100, 50) ; Back camera
CameraLocate(1,0,0,-100)
RotateCamera(1,180,0,0)
CameraRenderMode(1, #PB_Camera_Plot)
;********************* End added code *******************************************
EndIf
AddKeyboardShortcut(0, #PB_Shortcut_Escape, #PB_Shortcut_Escape)
LoadFont(0, "Verdana", 12)
FontID = FontID()
If CreateGadgetList(WindowID())
SetGadgetFont(#PB_Default, FontID)
;
; Here put your gadgets (also you can add a toolbar below or above
;
;********************* Start added code **********************************
Top = 10
GadgetHeight = 24
Frame3DGadget(#PB_Any, 10, Top, 370, 90, "Player...") : Top+20
StringGadget(0, 20, Top, 200, GadgetHeight, "")
ButtonGadget(1, 223, Top, 72, GadgetHeight, "Play")
ButtonGadget(2, 295, Top, 72, GadgetHeight, "Stop") : Top+35
DisableGadget(2,1)
ButtonGadget(8, 100, 86, 80, 24, "Quit")
;********************* End added code *******************************************
EndIf
hCursorArrow = LoadCursor_(0, #IDC_ARROW)
hCursorCross = LoadCursor_(0, #IDC_CROSS)
If CreateStatusBar(0, WindowID())
EndIf
SetCursorPos_(WindowMouseX, WindowMouseY)
Repeat
Select WindowEvent()
Case #PB_EventCloseWindow
Quit = #TRUE
Case #PB_EventMenu
Select EventMenuID()
Case #PB_Shortcut_Escape
Quit = #TRUE
EndSelect
Case #PB_EventGadget
Select EventGadgetID()
;********************* Start added code **********************************
Case 1 ; Play
DisableGadget(2,0) ; Enable the 'Stop' gadget
DisableGadget(1,1) ; Disable the 'Play' Gadget
Case 2 ; Stop
DisableGadget(1,0) ; Enable the 'Play' gadget
DisableGadget(2,1) ; Disable the 'Stop' Gadget
Case 8 ; Quit...
Quit = #TRUE
;********************* End added code *******************************************
EndSelect
EndSelect
;******************* Start added code *********************************************
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left) : KeyX = -CameraSpeed : CameraSpeed + 1 : MoveCamera(0, KeyX / 10, 0, 0) : ElseIf KeyboardReleased(#PB_Key_Left) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Right) : KeyX = CameraSpeed : CameraSpeed + 1 : MoveCamera(0, KeyX / 10, 0, 0) : ElseIf KeyboardReleased(#PB_Key_Right) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Up) : KeyY = -CameraSpeed : CameraSpeed + 1 : MoveCamera(0, 0, 0, KeyY / 10) : ElseIf KeyboardReleased(#PB_Key_Up) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Down) : KeyY = CameraSpeed : CameraSpeed + 1 : MoveCamera(0, 0, 0, KeyY / 10) : ElseIf KeyboardReleased(#PB_Key_Down) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Pad6) : xCam = CameraSpeed : CameraSpeed + 1 : RotateCamera(0, xCam / 10, 0, 0) : ElseIf KeyboardReleased(#PB_Key_Pad6) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Pad4) : xCam = -CameraSpeed : CameraSpeed + 1 : RotateCamera(0, xCam / 10, 0, 0) : ElseIf KeyboardReleased(#PB_Key_Pad4) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Pad2) : yCam = -CameraSpeed : CameraSpeed + 1 : RotateCamera(0, 0, yCam / 10, 0) : ElseIf KeyboardReleased(#PB_Key_Pad2) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Pad8) : yCam = CameraSpeed : CameraSpeed + 1 : RotateCamera(0, 0, yCam / 10, 0) : ElseIf KeyboardReleased(#PB_Key_Pad8) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Pad3) : zCam = -CameraSpeed : CameraSpeed + 1 : RotateCamera(0, 0, 0, zCam / 10) : ElseIf KeyboardReleased(#PB_Key_Pad3) : CameraSpeed = 0 : EndIf
If KeyboardPushed(#PB_Key_Pad9) : zCam = CameraSpeed : CameraSpeed + 1 : RotateCamera(0, 0, 0, zCam / 10) : ElseIf KeyboardReleased(#PB_Key_Pad9) : CameraSpeed = 0 : EndIf
WindowMouseX = WindowMouseX() - 5
WindowMouseY = WindowMouseY() - 23
If WindowMouseX => (WindowXSize - ScreenXSize) And WindowMouseX <= (WindowXSize - 5) And WindowMouseY => (WindowYSize - ScreenYSize) And WindowMouseY <= (WindowYSize - 25)
SetCursor_(hCursorCross)
Else
SetCursor_(hCursorArrow)
EndIf
RotateEntity(0, 1, 0, 0)
RenderWorld()
FlipBuffers()
;****************** End added code **********************************************
;****************** Start Commented out code ***********************
Delay(5) ; let this delay to not consume the whole CPU
; FlipBuffers()
; ClearScreen(0, 0, 0)
;****************** End Commented out code ***********************
Until Quit
EndIf
End