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.

DarkBASIC Discussion / Selecting a 3D object with a mouseclick

Author
Message
Zinc Avenger
23
Years of Service
User Offline
Joined: 29th Jan 2003
Location:
Posted: 15th Apr 2003 02:22
Okay, I have a universe set up, and a spinny-rotating camera and so forth, and I am currently trying to work out how to select an object by clicking on any part of the object.

I can get its origin screen-X and screen-Y but that only gives me a single 2D point co-ordinate, which is not much help.

I could do it with a dragging selection box (Check to see whether screen-X and screen-Y of each object's origin is within box etc.) but that is not a suitable mechanism for my program.

The real problem is that depending on distance from camera the size and (apparent) shape of the objects will change, so I can't simply check for clicks within a certain distance of the origin point.

Is there a simple way of doing this, or am I going to have to go with my last-resort option of stretching a plain off in that direction and seeing what it collides with?
Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 15th Apr 2003 03:19
There are too many variables to consider to do things other than collision detection. If all the faces were the same shape, or even more optimally if you were selecting a cell of a matrix, it would be much simpler.

I would actually use some sort of massless projectile method to test collisions for your clicking. This way, the first thing the projectile would hit would be the first visible thing that you clicked on. You could take a tally of everything an invisible plane would hit and then compare the distances (squared) of those to the player, but this wouldn't be accurate where objects would overlap.
big fella
23
Years of Service
User Offline
Joined: 11th Apr 2003
Location:
Posted: 15th Apr 2003 04:53
it sounds like your making a homeworld type game?, if so good luck.

Hell IVIonkey
23
Years of Service
User Offline
Joined: 1st Apr 2003
Location: Outer Limits
Posted: 15th Apr 2003 05:24
Hmm, if you grab the values of the vertices of each face, then your original hope would be possible. I saw somebody do this once for a collision demo, but it's probably not worth your time.
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 15th Apr 2003 20:28
You could change the distance that you have to click away from it according to the distance from the camera and the size. That wouldn't be exact and would only work if the object is about the same size in all dimensions (cube/sphere), but its better than keeping the area the same all the time.

Why the hell'd you ask me for crying out loud!?!

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
Zinc Avenger
23
Years of Service
User Offline
Joined: 29th Jan 2003
Location:
Posted: 17th Apr 2003 01:14
Thanks to everyone who has posted a response.

Looks like I'm going to have to go with the collision idea, I shall stretch off a cube or something and see what it collides with. I'll post the code here when I've worked it all out.

Login to post a reply

Server time is: 2026-06-11 21:23:17
Your offset time is: 2026-06-11 21:23:17