if you can't find a 3D Image Button gadget, then i suggest to use the 3D objects as buttons (spheres, cubes, ...). we only picked the body of the object, then we will know its name, then we add code .
or what is suitable for the system.
can have many moments while pressing the Button.
suitable for static scenes, but for a movable scenes we must reposition these Buttons, haven't tried it.
Code: Select all
;
; ------------------------------------------------------------
;
; PureBasic - CompoundBody
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
Declare DrawCurve()
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
#CameraSpeed = 1
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts" , #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI" , #PB_3DArchive_FileSystem)
Parse3DScripts()
;WorldDebug(#PB_World_DebugBody)
;-------------------------------
; create material
CreateMaterial(1, LoadTexture(1, "White.jpg"))
SetMaterialColor(1, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
;
CreateMaterial(2, LoadTexture(2, "dirt.jpg"))
SetMaterialColor(2, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
CreateMaterial(3, LoadTexture(3, "ground_diffuse.png"))
SetMaterialColor(3, #PB_Material_AmbientColor, #PB_Material_AmbientColors)
CreateMaterial(4, LoadTexture(4, "snow_1024.jpg"))
CreateMaterial(5, LoadTexture(5, "Geebee2.bmp"))
;-------------------------------
CreateCube(1, 1.0)
CreateSphere(3, 2)
DrawCurve()
;Buttons Ground
;
Ground = CreateEntity(#PB_Any, MeshID(1), MaterialID(4), -11,11 , 0)
ScaleEntity(Ground, 12, 0.4, 6)
RotateEntity(Ground, 90,0,0)
CreateEntityBody(Ground, #PB_Entity_StaticBody)
;buttons:
CreateCube(2, 3)
CreateEntity(2, MeshID(2), MaterialID(5), -8, 11, 0)
CreateEntityBody(2, #PB_Entity_BoxBody, 0, 0.5, 0.5)
CreateEntity(3, MeshID(3), MaterialID(3), -14, 11, 0)
CreateEntityBody(3, #PB_Entity_SphereBody, 0, 0.5, 0.5)
; camera
;
CreateCamera(0, 0, 0, 100, 100, #True)
MoveCamera(0,0,2,30, #PB_Absolute)
CameraBackColor(0, RGB(200,200,100))
; GUI
OpenWindow3D(0, 0, 0, 50 , 10 , "")
HideWindow3D(0,1)
ShowGUI(128, 1) ; Display the GUI, semi-transparent and display the mouse cursor
Repeat
Screen3DEvents()
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
InputEvent3D(MouseX(), MouseY(),0)
ent = BodyPick(CameraID(0), MouseButton(#PB_MouseButton_Left), MouseX(), MouseY(), 1)
If ent = 3
Sleep_(200)
x.f+1:y.f=0: ScrollMaterial(3,x,y,#PB_Material_Animated)
x=0
rotate ! 1
ElseIf ent = 2: Debug "ok"
EndIf
EndIf
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
MoveCamera (0, KeyX, 0, KeyY)
;RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
If rotate = 0
ScrollMaterial(3,0,0,#PB_Material_Animated)
EndIf
RotateEntity(0, 0,rotate, 0, #PB_Relative)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
Procedure DrawCurve()
Protected.f a, b, x, y, z, t
Protected n.l
a.f = 0.2 :b.f=0.8 : n=20: t.f
CreateMesh(0, #PB_Mesh_LineStrip, #PB_Mesh_Static) ; #PB_Mesh_LineStrip to joint the points with lines
While t <= 2*#PI
x = Cos(t) - Cos(6* t)/2 + Sin(14* t)/3
y = Cos(14* t)/3 + Sin(t)- Sin(6* t)/2
z = 0
MeshVertexPosition(x, y, z)
MeshVertexColor(RGB(0,0,255))
t + 0.01
Wend
;************************************************************
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(1))
CreateEntity(0, MeshID(0), #PB_Material_None ,0,0,0)
ScaleEntity(0,4,4,4)
EndProcedure