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 / 2D Mouse Position and 3D Object Selection

Author
Message
ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 14th May 2009 10:23
I'm a little new to this aspect of programming.

I want the user to be able to hover and click his mouse over any object in 3D space, no matter how far away it is and be able to see its stats print out on the screen.

I can do the printing out part but I'm not sure how I would translate the 2D mouse position to the 3D object selection.

BTW, I'm currently only using DGDK Objects (spheres, cubes, etc).

Can anyone help me out?
ABXG
15
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Canada
Posted: 14th May 2009 10:50
Try the following:

int dbObjectScreenX ( int iObject )


int dbObjectScreenY ( int iObject )


------------------------------------
Currently 1500+ lines of code into an "over-the-shoulder" action RPG with combat based on rag-doll physics.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 14th May 2009 19:51
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 14th May 2009 21:57
dbPickObject() is definitely the better method IMO.

i like orange
ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 14th May 2009 23:13
Can someone post the text that explains dbPickObject()? For some reason searching the help file doesn't bring up the function and I can't find the text else where.
ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 14th May 2009 23:36
Update:

I found the function and tried to use it as such:


And I also tried using dbObjectScreenX() like this:


But neither have worked. Can anyone help?
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 14th May 2009 23:41
Don't know why the help search does not find it for you, but anyway, here is the text:

int dbPickObject (int iX, int iY, int iObjectStart, int iObjectEnd)

"This command will return the Object Number of the closest object at the specified screen coordinates. The objects that are tested against the 2D coordinate are only those within the Object Start and Object End range in order to speed up specific tests. If no object exists at the coordinate, a value of zero is returned. If an object number is returned, additional data will be generated and stored internally. This extra data can be retrieved using the dbGetPickVector and dbGetPickDistance commands."

Remark: I recently tried these "GetPickVectorX" (and Y and Z) commands that the help mentions, and they didn't work for me. But you don't need them if you only want the object number, that will be returned by dbPickObject.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 14th May 2009 23:47
Sorry, we cross-posted.

There is nothing obviously wrong with the code you posted, how does it not work? Nothing happens or something happens but not what you expect? Can you maybe post the entire code you're testing with?
go2none
15
Years of Service
User Offline
Joined: 8th Oct 2008
Location: London
Posted: 15th May 2009 00:01
The code you posted should work, there is nothing wrong with it.



Apart from the fact that it hides and shows the object every frame.
ReiKumar
16
Years of Service
User Offline
Joined: 23rd Sep 2008
Location:
Posted: 15th May 2009 01:22
Thanks guys that worked.



I was being silly.

I put the code outside the update loop

Thanks for your help.

Login to post a reply

Server time is: 2024-10-01 01:14:37
Your offset time is: 2024-10-01 01:14:37