Here is the code I use to get to the start / stop rotation function. This code works but can we do better?
■ ShortKey : R : Run rotation - Space Bar : Stop Rotation.
Code: Select all
Enumeration
#Mainform
EndEnumeration
Define.l Event
Global WindowStyle.i=#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_ScreenCentered
Global Texture.i, Material.i, Mesh.i, Entity.i
InitEngine3D()
InitKeyboard()
InitSprite()
InitMouse()
OpenWindow(#Mainform,0,0,1024,768, "Start/Stop Rotate material", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Mainform),0,0,1024,768,0, 0, 0)
KeyboardMode(#PB_Keyboard_International)
;
;Lumiere et ombre
AmbientColor(RGB(127, 127, 127))
CreateLight(#PB_Any,RGB(151, 251, 151), -1.8, 10, 5)
WorldShadows(#PB_Shadow_Additive)
;
; Une camera
Camera = CreateCamera(#PB_Any,0,0,100,100)
CameraBackColor(Camera, RGB(145, 182, 201))
MoveCamera(Camera, 2, 5, 15, #PB_Absolute)
CameraLookAt(Camera, 0,0,0)
;
;Un cube (Texture + Material + Mesh + Entité)
Texture = CreateTexture(#PB_Any,256,256)
StartDrawing(TextureOutput(Texture))
Box(0,0,256,256, RGB(255, 215, 0))
Box(64, 64, 128, 128 ,RGB(0, 0, 0))
StopDrawing()
Material = CreateMaterial(#PB_Any, TextureID(Texture))
Mesh = CreateCube(#PB_Any, 3)
Entity = CreateEntity(#PB_Any, MeshID(Mesh), MaterialID(Material))
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event = 0
If ExamineKeyboard()
If KeyboardPushed (#PB_Key_Escape)
Break
EndIf
;Stop la rotation
If KeyboardReleased (#PB_Key_Space)
RemoveMaterialLayer(Material)
AddMaterialLayer(Material, TextureID(Texture), 0)
;RotateMaterial(Material, 0, #PB_Material_Animated)
EndIf
;Redémarre la rotation
If KeyboardReleased (#PB_Key_R)
RemoveMaterialLayer(Material)
AddMaterialLayer(Material, TextureID(Texture), 0)
RotateMaterial(Material, 0.1, #PB_Material_Animated)
EndIf
EndIf
; Affiche le rendu de la scène
ClearScreen(RGB(0, 0, 0))
RenderWorld(80)
FlipBuffers()
ForEver