PureGDK - 3D Programming for PureBasic
EZRotate Obj and Cam commands
Thanks, Mistrel - they seem to work fine now.
dbPositionMouse
Mistrel,
I've been trying to use dbMouseMoveX along with dbPositionMouse to create a mouse driven camera rotation.
Here's the basic premise:
1. Look to see if mouse has moved in the X direction
2. Turn the camera Left (or Right) according to the amount mouse X moved.
3. Display camera angle Y as text
4. Sync
5. Position mouse back to original position to ensure mouse does not go off the side of the app window.
In the DarkBasic version, the code works fine. As I move the mouse left or right, the camera turns left or right, relative to the amount I move the mouse.
Here's the DB version:
When translated over to PureBasic with PureGDK, it appears something keeps resetting the turns back. If I don't re-position the mouse (by removing the dbPositionMouse command) then the routine works OK, but the mouse can move outside of the PB program window.
Here's the PB/PureGDK code:
Any ideas why this occurs? Could this be some sort of weird bug? Or does it have to do with the windowed DB screen in PureBasic?
I've been trying to use dbMouseMoveX along with dbPositionMouse to create a mouse driven camera rotation.
Here's the basic premise:
1. Look to see if mouse has moved in the X direction
2. Turn the camera Left (or Right) according to the amount mouse X moved.
3. Display camera angle Y as text
4. Sync
5. Position mouse back to original position to ensure mouse does not go off the side of the app window.
In the DarkBasic version, the code works fine. As I move the mouse left or right, the camera turns left or right, relative to the amount I move the mouse.
Here's the DB version:
Code: Select all
make camera 1
position camera 1,0,0,-20
make object cube 2,2
color object 2,rgb(255,255,0)
position object 2,8,0,0
make object sphere 1,10
color object 1,rgb(0,255,0)
px=object position x(1)
py=object position y(1)
pz=object position z(1)
point camera 1,px,py,pz
position mouse 50,50
while mouseclick()=0
mx = mousemovex()
Turn Camera Left 1,mx
text 10,10,str$(camera angle y(1),3)
sync
position mouse 50,50
endwhile
rem delete mesh MeshNumber
delete objects 1,2
end
When translated over to PureBasic with PureGDK, it appears something keeps resetting the turns back. If I don't re-position the mouse (by removing the dbPositionMouse command) then the routine works OK, but the mouse can move outside of the PB program window.
Here's the PB/PureGDK code:
Code: Select all
OpenWindow(0,0,0,640,480,"DarkBasic Professional - PureGDK",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
hDBWnd=OpenDBWnd(WindowID(0),0,0,640,480)
dbSyncRate(60)
dbBackdropOn()
dbColorBackdrop(dbRGB(0,0,0))
dbMakeCamera(1)
dbPositionCamera(0,0,-20)
dbMakeObjectCube(2,2)
dbColorObject(2,dbRGB(255,255,0))
dbPositionObject(2,8,0,0)
dbMakeObjectSphere(1,10)
dbColorObject(1,dbRGB(0,2550,0))
dbPointCamera(dbObjectPositionX(1),dbObjectPositionY(1),dbObjectPositionZ(1),1)
dbPositionMouse(50,50)
Repeat
mx=dbMouseMoveX()
dbTurnCameraLeft(mx,1)
dbText(10,10,StrF(dbCameraAngleY(1)))
dbSync()
dbPositionMouse(50,50)
Until WindowEvent()=#PB_Event_CloseWindow Or dbKeyState(#VK_ESCAPE)
End
The reason it's stuttering is because you're getting the position of the mouse delta and then moving the mouse back to a given origin which would be the negative value of your previous delta. Hence the your camera isn't going to ever rotate.
I don't know how DBP handles mouse movements but I've replaced most of the input library with native Win32 API calls to additional functionality; mouse positions outside of the render window, more mouse buttons, virtual keys, etc.
After you move the mouse to wherever you want to lock it don't forget to reset the mouse delta:
Maybe DBP doesn't update the mouse delta when using MOUSEMOVEX/Y(). I would consider this a native bug in DBP which PureGDK has already fixed for you. 
I don't know how DBP handles mouse movements but I've replaced most of the input library with native Win32 API calls to additional functionality; mouse positions outside of the render window, more mouse buttons, virtual keys, etc.
After you move the mouse to wherever you want to lock it don't forget to reset the mouse delta:
Code: Select all
DeltaX=dbMouseMoveX()
dbPositionMouse(0,0)
DeltaX=dbMouseMoveX()

Last edited by Mistrel on Fri May 01, 2009 1:55 am, edited 1 time in total.
Mouse Deltas and dbMouseTurnLeft
I understand that the mouse deltas are being reset...in the code I'm watching for a mouse delta, turning the camera by that delta, then resetting the mouse back to its original position. The mouse definitely will stutter.
However, if I am understanding the Turn Camera left command, then when I tell the camera to turn left a certain amount, it is relative to the current camera angles. This is evident in the Dark Basic code example, where the camera continues to turn left or right, regardless of the mouse position. It does not appear to work the same for the PureBasic version. Instead, it appears the PB version of Turn Camera Left command resets the angles, or uses the mouse position to rotate the camera an absolute amount according to mouse position.
Am I interpreting this correctly?
Basically, I believe the dbMouseMoveX() function is working fine, but the dbTurnCameraLeft function is not because it is somehow tied to the mouse position command.
If the stuttering occurred in both the DB code and the PB code, then I would be fine with it. But the DB version works, whereas the PB version does not.
However, if I am understanding the Turn Camera left command, then when I tell the camera to turn left a certain amount, it is relative to the current camera angles. This is evident in the Dark Basic code example, where the camera continues to turn left or right, regardless of the mouse position. It does not appear to work the same for the PureBasic version. Instead, it appears the PB version of Turn Camera Left command resets the angles, or uses the mouse position to rotate the camera an absolute amount according to mouse position.
Am I interpreting this correctly?
Basically, I believe the dbMouseMoveX() function is working fine, but the dbTurnCameraLeft function is not because it is somehow tied to the mouse position command.
If the stuttering occurred in both the DB code and the PB code, then I would be fine with it. But the DB version works, whereas the PB version does not.
Your code is flawed. You can't grab the mouse delta, move the mouse back to its origin, and not expect the delta value to be reversed. The DBP implementation doesn't make sense. Considering there is no API for mouse delta it's most likely that DBP does not know to factor in MOUSEMOVEX/Y() values into the delta. If this is the case then the original DBP functionality is flawed.
Last edited by Mistrel on Fri May 01, 2009 1:55 am, edited 1 time in total.
Mouse Deltas revisited
I am grabbing the mouse deltas into a variable.
Once I do that the delta value itself is stored away in a variable so it shouldn't matter what happens to the mouse position at that point - I have the delta value stored away in the variable.
I then turn the camera by the stored delta value. The dbTurnCameraLeft command should turn the camera the amount of the stored delta value.
Are you saying that regardless of me storing the delta X value of the mouse into a variable, that there is some sort of reversing of the variable (in this case mx) to negate the turn?
If I figure the deltas myself, then the Turn Camera Left command works fine, as can be shown in this code:
Also note that I did change where the Position Mouse command is done, but if I try the code using dbMouseMoveX, it still won't work properly.
So I guess I can use the code above, but it doesn't fix the dbMouseMove commands.
Once I do that the delta value itself is stored away in a variable so it shouldn't matter what happens to the mouse position at that point - I have the delta value stored away in the variable.
I then turn the camera by the stored delta value. The dbTurnCameraLeft command should turn the camera the amount of the stored delta value.
Are you saying that regardless of me storing the delta X value of the mouse into a variable, that there is some sort of reversing of the variable (in this case mx) to negate the turn?
If I figure the deltas myself, then the Turn Camera Left command works fine, as can be shown in this code:
Code: Select all
OpenWindow(0,0,0,640,480,"DarkBasic Professional - PureGDK",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
hDBWnd=OpenDBWnd(WindowID(0),0,0,640,480)
dbSyncRate(60)
dbBackdropOn()
dbColorBackdrop(dbRGB(0,0,0))
dbMakeCamera(1)
dbPositionCamera(0,10,-20)
dbMakeObjectCube(2,2)
dbColorObject(2,dbRGB(255,255,0))
dbPositionObject(2,8,0,0)
dbMakeObjectSphere(1,10)
dbColorObject(1,dbRGB(0,2550,0))
dbPointCamera(dbObjectPositionX(1),dbObjectPositionY(1),dbObjectPositionZ(1),1)
dbPositionMouse(100,100)
Repeat
inx.f=dbMouseX()
If inx <> 100
mx.f=(inx-100)/10.0
cbefore.f=dbCameraAngleY(1)
dbTurnCameraLeft(mx,1)
cafter.f=dbCameraAngleY(1)
Debug StrF(mx)+","+StrF(cbefore)+"..."+StrF(cafter)
dbText(10,10,StrF(dbCameraAngleY(1)))
dbPositionMouse(100,100)
EndIf
dbSync()
Until WindowEvent()=#PB_Event_CloseWindow Or dbKeyState(#VK_ESCAPE)
End
So I guess I can use the code above, but it doesn't fix the dbMouseMove commands.
Mouse Delta routines
Sorry about the long thread about the mouse commands. My goal is to have the mouse control left/right and up down movement of the camera in a way that does not stop the camera when it gets to to edges of my window or screen. This means I need to reposition the mouse to an arbitrary point each time I watch for changes so no matter how much I move the mouse in any direction, I won't be "stopped" by the screen and/or window limitations.
I see what you're doing differently. You're assuming that the delta is always the difference from the location of the mouse cursor after the first call. I don't understand your interpretation considering PureGDK uses the same functionality in DBP; the mouse delta is always the difference in position from the last call to MOUSEMOVEX()/dbMouseMoveX():
To reiterate what you're doing and why the mouse is stuttering see this example:
Here is the bug in DBP which is causing the discrepency you're experiencing:
The correct result as it appears using PureGDK:
Your implementation corrected:
Code: Select all
sync on
do
cls
print mousemovex()
sync
loop
Code: Select all
Procedure DeltaX()
Static LastX, FirstRun
DeltaX=DesktopMouseX()-LastX
LastX=DesktopMouseX()
If Not FirstRun
FirstRun+1
ProcedureReturn 0
EndIf
ProcedureReturn DeltaX
EndProcedure
;/ Set mouse to origin
SetCursorPos_(0,0)
Debug DeltaX() ;/ The first delta is always 0
;/ Simulated mouse movement
SetCursorPos_(20,0)
Debug DeltaX() ;/ Delta is 20
;/ Reset mouse to origin
SetCursorPos_(0,0)
Debug DeltaX() ;/ Delta is -20
Code: Select all
position mouse 0,0
print mousemovex() `the first call is always 0
position mouse 20,0
print mousemovex() `notice how DBP does not update the mouse delta
do
loop
Code: Select all
OpenWindow(0,0,0,640,480,"DarkBasic Professional - PureGDK",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
hDBWnd=OpenDBWnd(WindowID(0),0,0,640,480)
dbPositionMouse(0,0)
Debug dbMouseMoveX() ;/ The first call is always 0
dbPositionMouse(20,0)
Debug dbMouseMoveX() ;/ PureGDK updates the mouse delta correctly
Code: Select all
OpenWindow(0,0,0,640,480,"DarkBasic Professional - PureGDK",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
hDBWnd=OpenDBWnd(WindowID(0),0,0,640,480)
dbSyncRate(60)
dbBackdropOn()
dbColorBackdrop(dbRGB(0,0,0))
dbMakeCamera(1)
dbPositionCamera(0,0,-20)
dbMakeObjectCube(2,2)
dbColorObject(2,dbRGB(255,255,0))
dbPositionObject(2,8,0,0)
dbMakeObjectSphere(1,10)
dbColorObject(1,dbRGB(0,2550,0))
dbPointCamera(dbObjectPositionX(1),dbObjectPositionY(1),dbObjectPositionZ(1),1)
dbPositionMouse(50,50)
Repeat
dbTurnCameraLeft(dbWrapValue(dbCameraPositionX(1)+dbMouseMoveX()),1)
dbText(10,10,StrF(dbCameraAngleY(1)))
dbPositionMouse(50,50)
dbMouseMoveX() ;/ Reset mouse delta
dbSync()
Until WindowEvent()=#PB_Event_CloseWindow Or dbKeyState(#VK_ESCAPE)
End
Last edited by Mistrel on Fri May 01, 2009 2:59 am, edited 1 time in total.
mouse deltas
Mistrel,
I now understand. So unless you do another call do dbMouseMoveX() to reset the delta back to the absolute position, then it won't work correctly.
Thanks, Mistrel! I was thinking the deltas were always coming from the last place I positioned the mouse using the PositionMouse command. The PositionMouse command does not do anything to the deltas at all.
I really appreciate taking the time to show me that. So in reality, the DB code is not working as it's supposed to, but your code is (as you tried to tell a few posts ago). I just didn't understand it all until I had code to see how it was done properly.
Thanks again.
I now understand. So unless you do another call do dbMouseMoveX() to reset the delta back to the absolute position, then it won't work correctly.
Thanks, Mistrel! I was thinking the deltas were always coming from the last place I positioned the mouse using the PositionMouse command. The PositionMouse command does not do anything to the deltas at all.
I really appreciate taking the time to show me that. So in reality, the DB code is not working as it's supposed to, but your code is (as you tried to tell a few posts ago). I just didn't understand it all until I had code to see how it was done properly.
Thanks again.
Hi Mistrel,
I have a huge problem. I cant tell what happened but now none of PGDK sources are compiling.
Here is the error report I get from your aspect-ratio example:
And here is FullSourceDump.dba from the aspect-ratio folder:
I did update DBPro and the PureGDK dll folder to 7.3 but I tried to revert back to 7.2 and the same happens. I also created 2 user libraries compiled with tailbite, but I deleted them from PureLibraries folder but the PGDK still wont work. All my other PureBasic source work fine and everything non PGDK related works as expected so the problem is somewhere on GDK side.
I hope you can help.
Thanks,
Olby
I have a huge problem. I cant tell what happened but now none of PGDK sources are compiling.

Here is the error report I get from your aspect-ratio example:
Code: Select all
PARSER ERROR
------------
Subscript must be Integer or DWORD when referencing an array at line 2.
PROGRAM TRACE
-------------
LoadGDKMain(GDKVal(CL$()))=0
GDKMessage "PureGDK Error",GDKEr
ERROR TRACE
-----------
PARSER ERROR
------------
Could not determine parameter type of 'LoadGDKMain(GDKVal(CL$()))' at line 2.
PROGRAM TRACE
-------------
LoadGDKMain(GDKVal(CL$()))=0
GDKMessage "PureGDK Error",GDKEr
ERROR TRACE
-----------
Failed to 'DoExpressionList::DoExpressionListString'
Failed to 'DoJump::Do ExpressionList'
Failed to 'DoStatement(TokenID)'
Failed to 'DoBlock(0)'
Failed to 'MakeStatements'
Failed to Parse Program (MakeDBM->MakeProgram)'
Code: Select all
sync on: sync: sync
If LoadGDKMain(GDKVal(CL$()))=0
GDKMessage "PureGDK Error",GDKError_ResolveID(GDKError_GetLastID())+"."
End
EndIf
#Constant DBP_INPUT=135
#Constant DBP_END=3
mem=make memory(20)
For i=1 To 2
If loopcount=40
Select GDKGetCompatibility(0)
Case DBP_INPUT
void=GDKGetCompatibility(mem)
input GDKGetStr(*mem),result$
GDKCompatibilityReturnS result$
GDKClearCompatibility
EndCase
Case DBP_END
End
EndCase
EndSelect
loopcount=0
EndIf
dec i,1
inc loopcount,1
Next i
IncludeGDKCallback
Show Window
IncludeGDKLoader
autocam off
load object "",1
I hope you can help.

Thanks,
Olby
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
PureGDK doesn't reference any arrays in DBP so the parser is obviously confused. Uninstall PureGDK and DBP, delete the DBP install directory to remove any leftover files, then reinstall 7.2 and PureGDK in that order.
It's most likely an error in your configuration. It could be in DBP or somewhere in PureGDK. I can't tell without the exact steps you took to cause the error.
It's most likely an error in your configuration. It could be in DBP or somewhere in PureGDK. I can't tell without the exact steps you took to cause the error.
Oh, I was afraid you will suggest this. I have billions of plugins and other stuff installed with DBPro so it will take ages to get it all back. I will at first try to remove & reinstall the GDK and see what happens.Mistrel wrote:PureGDK doesn't reference any arrays in DBP so the parser is obviously confused. Uninstall PureGDK and DBP, delete the DBP install directory to remove any leftover files, then reinstall 7.2 and PureGDK in that order.
It's most likely an error in your configuration. It could be in DBP or somewhere in PureGDK. I can't tell without the exact steps you took to cause the error.
[Edit]
Everything is fine now. I just reinstalled GDK and now it works again. Dunno what caused this but must have been something with the libraries I was compiling and testing.
Btw the 7.3 update currently works fine with the GDK.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)