Hi
I wondered in another post how B3D does it's LinePick but I'd like to formalize that question here, now.
It seems to 'walk along' the pick line until it hits a pickable entity. I say this because the time taken to do the pick is shorter the nearer to the pick line origin an entity is encountered. Then there's the ability to give the pick line a radius. I'm struggling to visualize how LinePick's functionality is realized efficiently, TBH.
The reason I'm pondering this is because I want to do a LinePick function for my 2D vector entity lib.
Hopefully, because I'm only dealing with entities defined entirely of 2D vectors, things shouldn't be as complex as B3D's LinePick (*nervous giggle*). Basically, it's going to boil down to using a line intersection test between the pick line and all the vectors comprising an entity, I guess?!
However, it's not quite as simple as that for a couple of reason that spring immediately to mind:
- If an intersection is found between the pick line and an entity's vector, I still need to continue checking the rest of the entity's vectors in case an intersection is found that's closer to the pick line's origin (I need PickedX,PickedY functionality, too).
- I'll need to check every pickable entity to find the entity whose vector intersected with the pick line, nearest to the pick line's origin.
I think this basic approach will work but it occurs to me that there's going to potentially be a lot of distance checks (although, I may be able to avoid use of Sqr and just work using the squared distances involved), and secondly, this cant be the way B3D does things as my way takes the same amount of time to execute, regardless of the pick line length and how close to it's origin an entity is picked. Also, how to implement a pick line radius - or, line width, in my case - goodness knows!
Am I missing a better way to achieve this? Any help and/or insights into how B3D does LinePick, much appreciated.
Thanks.
(In the meantime, I think I'm going to try and implement the method I mentioned, and see how things work out...)
I wondered in another post how B3D does it's LinePick but I'd like to formalize that question here, now.
It seems to 'walk along' the pick line until it hits a pickable entity. I say this because the time taken to do the pick is shorter the nearer to the pick line origin an entity is encountered. Then there's the ability to give the pick line a radius. I'm struggling to visualize how LinePick's functionality is realized efficiently, TBH.
The reason I'm pondering this is because I want to do a LinePick function for my 2D vector entity lib.
Hopefully, because I'm only dealing with entities defined entirely of 2D vectors, things shouldn't be as complex as B3D's LinePick (*nervous giggle*). Basically, it's going to boil down to using a line intersection test between the pick line and all the vectors comprising an entity, I guess?!
However, it's not quite as simple as that for a couple of reason that spring immediately to mind:
- If an intersection is found between the pick line and an entity's vector, I still need to continue checking the rest of the entity's vectors in case an intersection is found that's closer to the pick line's origin (I need PickedX,PickedY functionality, too).
- I'll need to check every pickable entity to find the entity whose vector intersected with the pick line, nearest to the pick line's origin.
I think this basic approach will work but it occurs to me that there's going to potentially be a lot of distance checks (although, I may be able to avoid use of Sqr and just work using the squared distances involved), and secondly, this cant be the way B3D does things as my way takes the same amount of time to execute, regardless of the pick line length and how close to it's origin an entity is picked. Also, how to implement a pick line radius - or, line width, in my case - goodness knows!
Am I missing a better way to achieve this? Any help and/or insights into how B3D does LinePick, much appreciated.
Thanks.
(In the meantime, I think I'm going to try and implement the method I mentioned, and see how things work out...)