Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Problem getting 3d coordinates from 2d.

Author
Message
Alex843
15
Years of Service
User Offline
Joined: 12th Jun 2009
Location:
Posted: 13th Jun 2009 01:36 Edited at: 13th Jun 2009 04:16
Hello everyone,
I’m trying to make an rts game. I’ve looked all over the place and haven’t been able to get a resolution to this. Basically I need to be able to throw down way points by using the mouse; to do that I need to get the real 3d coordinates in relation to where the mouse is at on the screen. The problem is I seem to be using dbpickscreen in the wrong way or just simply misunderstanding what it can be used for.

I went ahead just made a simple new project just to show what’s wrong. All the program does is make a box follow the mouse at a specific distance away from the camera. If you run it you will notice that the box is rarely ever in sync with the mouse, and as you move towards the extremes of the window it starts to get really off. Now I don’t need this to be perfect but it would be nice if it was close.


[/code]
#include "DarkGDK.h"

int mouseX,
mouseY;

float cameraX= 0,
cameraY= 0,
cameraZ= -50,
vectorX,
vectorY,
vectorZ;


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,cameraZ);
vectorX = dbGetPickVectorX()+ dbCameraPositionX();
vectorY = dbGetPickVectorY()+ dbCameraPositionY();
vectorZ = dbGetPickVectorZ()+ dbCameraPositionZ();

dbPositionObject(1, - vectorX, - vectorY, 0);

dbSync ( );
}

return;
}
[code]

Any help with this would be greatly appreciated.
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 13th Jun 2009 06:51
Is this thread messed up for anyone else?? I cant see any posts or anything (attached screenshot xD)

Attachments

Login to view attachments
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 13th Jun 2009 06:54
Sorry for double post but now My post is the only one here??

Attaching another screenshot for the devs.

Attachments

Login to view attachments
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 13th Jun 2009 10:35
Quote: "I cant see any posts or anything (attached screenshot xD)"


This happens when the poster is still on moderation. You see he joined the board yesterday. It takes time for the post to get approved and displayed. It is visible now.
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 13th Jun 2009 11:06
Oops I see, Sorry alex for taking up your first 2 posts >.<

As for helping you i'm afraid I have no input..

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 13th Jun 2009 12:18 Edited at: 13th Jun 2009 12:28
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:




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.
Alex843
15
Years of Service
User Offline
Joined: 12th Jun 2009
Location:
Posted: 13th Jun 2009 19:22
Quote: "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:

+ Code Snippet

#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."


Thanks alot! I was hitting my head against a wall trying to figure this out. I appears to work good, I'm going apply this to my real program and see if moving the camera around has any affect on it.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 28th Jun 2009 14:13
In the meantime I stumbled on a much easier solution, which works if you have a terrain. Although there was none in your program above, I suppose you will have a terrain for an RTS. I thought I'd call your attention to this, in case you still need it:



It is from an RTS tutorial here: http://zimnox.com/dbcc/?page=tutorials
Bubzy
15
Years of Service
User Offline
Joined: 29th Jun 2009
Location: somewhere
Posted: 2nd Jul 2009 03:01
i've just been working on a similar problem, i have a cube to replace my mouse pointer.



works ok for me, ill probably check out some of the code mentioned above too though

void void void void void void void

Login to post a reply

Server time is: 2024-10-01 05:47:35
Your offset time is: 2024-10-01 05:47:35