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 / Selecting an object in the 3D space?

Author
Message
Drowneath
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location: In your eyes
Posted: 17th Jul 2009 18:27 Edited at: 17th Jul 2009 19:18
Hello there,

I'm looking for a way to detect whether a user's cursor is hovering on an object (say a cube) in the 3D space

illust: (o = cursor)
__________________________________________________________________
| Cursor outside the cube ===== | Cursor inside the cube ========|
--------------------------------|--------------------------------|
=========_________==============|=========_________==============|
==o=====|=========|=<-=the=cube=|========|=========|=============|
========|=========|=============|========|===o=====|=============|
========|=========|=============|========|=========|=============|
========|_________|====false====|========|_________|====true=====|
================================|================================|
--------------------------------|--------------------------------|

and later maybe once the problem above is solved, I need to store the selected object ID when the user left-clicked it (dbMouseClick() = 1)


I don't have any idea about this.
Could anyone help me out?

Some example lines of code would be great



Thanks.
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 17th Jul 2009 20:21
dbPickObject() ?

Drowneath
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location: In your eyes
Posted: 17th Jul 2009 21:16
Sorry,
The illustration looks messed up.

Here I attached the illust. image.

What I'm talking about is,
something like when you're selecting a unit in an RTS game, or maybe a monster in an RPG game.

How to determine whether the mouse cursor is hovering the unit or not? And if we do a mouse left-click, how do we get the selected object's ID?

Attachments

Login to view attachments
Iuzidal
15
Years of Service
User Offline
Joined: 25th Jun 2009
Location:
Posted: 17th Jul 2009 22:09
jezza gave you the answer. No clicking necessary, as soon as the mouse is over the object it will return the ID.

dbPickObject
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.

Syntax
int dbPickObject ( int iX, int iY, int iObjectStart, int iObjectEnd )
Drowneath
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location: In your eyes
Posted: 18th Jul 2009 04:54
Yeah, thanks

Login to post a reply

Server time is: 2024-10-01 08:26:37
Your offset time is: 2024-10-01 08:26:37