There is an excellent explanation from somebody more expert than me, in this thread, about scaling the PickScreen vectors. See post by Bobba.
http://forum.thegamecreators.com/?m=forum_view&t=129031&b=10
I tried to apply it in your program (although, to tell the truth, I will need to re-read that post a few times to completely understand it) and it actually works:
#include "DarkGDK.h"
float mouseX,
mouseY;
float cameraX= 0,
cameraY= 0,
cameraZ= -50,
vectorX,
vectorY,
vectorZ;
float objectZ = -15;
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbMakeObjectBox(1,1,1,1);
dbMakeCamera(1);
dbPositionCamera(1,cameraX,cameraY,cameraZ);
while ( LoopGDK ( ) )
{
mouseX = dbMouseX();
mouseY = dbMouseY();
dbPickScreen(mouseX,mouseY, objectZ-cameraZ);
vectorX = dbGetPickVectorX();
vectorY = dbGetPickVectorY();
vectorZ = dbGetPickVectorZ();
vectorX /= vectorZ;
vectorY /= vectorZ;
vectorX *= objectZ-cameraZ;
vectorY *= objectZ-cameraZ;
vectorX += dbCameraPositionX(1);
vectorY += dbCameraPositionY(1);
dbPositionObject(1, vectorX, vectorY, objectZ);
dbSync ( );
}
return;
}
I even introduced this objectZ variable in case you want to change the Z position of that box. I haven't tested this with different camera positions and angles, though.
You might also want to look at this thread, in which the last code post gives a way to change the object's real world coordinates, until the object's screen coordinates match the mouse cursor. It may not look very professional and it's slower than the PickScreen because of the loop, but it works.
http://forum.thegamecreators.com/?m=forum_view&t=150702&b=22
One remark: if you create an additional camera, then in the dbCameraPosition commands you need to give the ID number otherwise it refers to camera zero.