Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

Object Picking?

Recommended Posts

Hi,

In my game I needed a way to know if the cross hair was over a targetable object.

My cross hair at 320,240 on the screen. I then run through my link list of objects and screen space convert the world position of the closest entity to me. This is done by using the PR_TransformVertexList function. I get camera space out of it also. I use the camera space coords to help with drawing the items in the radar.

Now, you will have the screen space coord of where the object will be on screen at it's center when transformed and rendered. You can use the bbox and/or the radius to help with object size.

This method is working great for me.

Email me at jdsgames@jdsgames.com or jdsgames@netzero.net for more questions. I can send you some source also.

------------------
Jarrod Davis

Share this post


Link to post
Share on other sites
No, I haven't tried anything like that yet.
If you're going with an overhead view then units won't be overlapping and screen coordinates would be a reliable way to pick objects.

Share this post


Link to post
Share on other sites
Hi !!

There is another "simple" way. Use Spheres. In the object picking example you have source to generate a ray from the Screen Coords. Now, you must have a sphere around each object. This is very easy, the center is at the entity location and the radius is set during loading (Just step through all vertices, calc the distance and the farthest distance is your radius). Then, just check each entity sphere for intersection with the ray, and you are done. If you get more then one intersection, just take the object closest to the camera source, that's it.
Source for checking the intersection between a ray and a sphere can be found in my Volumetric Fog Example: www.voodoospotlight.com/devknowledge/index.html

Of course, spheres is not the most precise way to do hit tests, but they are fast and easy to implement. And you won't have to play around with world space vertices, or screen space and stuff like that. The entity location is world space and the ray also, so you are done.

Phillip

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This has got me hacked off.

I just can't get it working, dammit.

What kind of picking/terrain examples do you have in PR3 Chris?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Aw hell.

I've been trying to get picking into the terrain demo for a while, and I can't get the damn thing to work.

I've got a nice overhead camera that works like Star/WarCraft's and a (weak) UI going, but I can't get the damn picking working.

I tried using the picking example, but as it says, its implementation is made to work with all unique objects. Naturally, an RTS game would have numerous duplicates.

I just plugged in the picking and it returned some really wack numbers. I tried altering various things, but to no evail. (Different results, but still bad.)

I noticed the bit about screen-space boxes (or whatever). Can you explain how to implement this?

Could you explain how to modify the picking example to be useful where there are multiple instances of objects?

If anyone could provide a small working example w/ source, I would be ecstatic!

Thanks.

Share this post


Link to post
Share on other sites