Page 1 of 1
MousePick() 6.10
Posted: Sat Jun 15, 2024 4:33 pm
by tft
Once again, the topic is MousePick(). With the following call, an entity can be created: `CreateEntity(0, ...)` or with `CreateEntity(#PB_Any, ...)`. In both cases, you receive a pointer to the object. However, when entities are created with `#PB_Any`, MousePick is unable to return the handler of the entity. This only works when you use numbering when creating the entity. Because the demo works with numbers, it functions correctly there. The value that MousePick returns is completely meaningless. It is the same for every entity, which indicates that this is a pointer. However, it does not point to any created object. There are several problem descriptions regarding this issue in the forum.
TFT
Re: MousePick() 6.10
Posted: Sat Jun 15, 2024 6:07 pm
by tft
Since I'm not just complaining, I have written some replacement code here to temporarily work around the problem.
Code: Select all
Structure CreateEntityCounter
name.s
Handler.i
Count.i
EndStructure
Global NewList CEC.CreateEntityCounter()
Procedure.i CreateEntity_(nr.i,Mesh.i, Mat.i)
Static count
Shared CEC()
Protected RCode
count + 1
AddElement(CEC())
CEC()\Count = Count
CEC()\Handler = CreateEntity(count,MeshID(Mesh),MaterialID(Mat))
If CEC()\Handler = 0
EndIf
ProcedureReturn CEC()\Handler
EndProcedure
;gibt den Handler zurück
Procedure.i FindEntityByCount(Count.i)
Shared CEC()
Protected RCode.i = -1
ForEach CEC()
If CEC()\Count = Count : Rcode = CEC()\Handler : Break : EndIf
Next
ProcedureReturn RCode
EndProcedure
; Gibt den Counter zurück
Procedure.i FindEntityByHandler(Handler.i)
Shared CEC()
Protected RCode.i = -1
ForEach CEC()
If CEC()\Handler = Handler : Rcode = CEC()\count : Break : EndIf
Next
ProcedureReturn RCode
EndProcedure
Procedure FreeEntity_(count.i)
Shared CEC()
ForEach CEC()
If CEC()\count = count : FreeEntity(count) : DeleteElement(CEC(),1) : Break : EndIf
Next
EndProcedure
Re: MousePick() 6.10
Posted: Sun Jun 16, 2024 7:45 pm
by Comtois
Work fine here
Code: Select all
; ------------------------------------------------------------
;
; PureBasic - MousePick
;
; (c) Fantaisie Software
;
; ------------------------------------------------------------
;
#CameraSpeed = 0.4
Enumeration
#MainWindow
#Editor
EndEnumeration
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
Define.f KeyX, KeyY, MouseX, MouseY
If InitEngine3D()
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()
InitSprite()
InitKeyboard()
InitMouse()
If Screen3DRequester()
; First create materials
;
GetScriptMaterial(0, "Color/Blue")
GetScriptMaterial(1, "Color/Green")
GetScriptMaterial(2, "Color/Red")
GetScriptMaterial(3, "Color/Yellow")
CreateMaterial(4, LoadTexture(0, "Dirt.jpg"))
; Meshes
;
CreateCylinder(2, 1, 4)
; Entities
;
Cylindre=CreateEntity(-1, MeshID(2), MaterialID(2), 0, 2, 0)
Debug cylindre
Debug "***"
; Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, -1, 8, 15, #PB_Absolute)
CameraLookAt(0, -1, 0, 0)
; Light
;
CreateLight(0, $FFFFFF, 1560, 900, 500)
AmbientColor($330000)
;GUI
;
OpenWindow3D(#MainWindow, 10, 10, 340, 75, "MousePick")
StringGadget3D(#Editor, 20, 10, 300, 30, "Clic somewhere", #PB_String3D_ReadOnly)
ShowGUI(128, 1) ; Display the GUI, semi-transparent and display the mouse cursor
WorldDebug(#PB_World_DebugEntity)
Repeat
Screen3DEvents()
Repeat
Event3D = WindowEvent3D()
Until Event3D = 0
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
InputEvent3D(MouseX(), MouseY(), MouseButton(#PB_MouseButton_Left))
If MouseButton(#PB_MouseButton_Left)
EntityPicked = MousePick(0, MouseX(), MouseY())
If EntityPicked>=0
Debug EntityPicked
RotateEntity(EntityPicked, 1,1,1, #PB_Relative)
SetGadgetText3D(#Editor, "Entity = " + Str(EntityPicked))
EndIf
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
CameraLookAt(0, 0, 0, 0)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Re: MousePick() 6.10
Posted: Mon Jun 17, 2024 2:28 pm
by benubi
Comtois' code fails with Debugger=ON, but works with Debugger=OFF. (on Windows 10/x64)
Re: MousePick() 6.10
Posted: Mon Jun 17, 2024 3:00 pm
by Comtois
You are right, there is something wrong with x64 version, work fine with x86.