Automatic "Lock on target"

88dc730f0f71e55be39de0ad103bd9ff
1
Alienizer 109 Dec 12, 2013 at 02:51

Hi,

I’m working on a shooting game (airplanes) and I want to “lock on target” and draw a red rectangle around the targeted airplane. Each airplane have an AABBox which is of no use to get a bounding rectangle around the object when the object is rotated in any direction other than it’s original which formed the bbox.

I can’t seem to find anything and anyways to generate a bounding rectangle around a 3D object. Seems so simple I thought I could do it but it’s been days now and I can’t get it right.

I’ve tried by creating a new bbox of the rotated object and use the near plane of the bbox, but it’s too big if the object is rotated and not always centered.

Anyone have a solution, links, ideas etc. ?

Thanks -Al

10 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
1
Reedbeta 167 Dec 12, 2013 at 06:53

It’s a 2D rectangle around the model on screen that you want? The simplest thing might be to loop over all the vertices and project them to screen space (using the same matrices that you use for rendering), then find the 2D bounding rect of the screen-space verts.

That’s probably too expensive though, so you could consider manually placing a few anchor points, like at the nose, tail, and ends of the wings, and just projecting those. That would be much faster than using every vertex in the model.

You’ll have to watch out for what happens when the plane gets too close to the camera, as the rectangle will get big (and even infinite, if one of the projected points goes behind the camera). It might be wise to impose a maximum size for the rect, or something like that.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Dec 12, 2013 at 07:59

I see what you mean, makes sense.

Is there a more complex/faster method of doing this as well? How do they do it in commercial games?

Thanks Reedbeta

B20d81438814b6ba7da7ff8eb502d039
1
Vilem_Otte 117 Dec 12, 2013 at 09:11

Basically Reed describes the method we’ve used for marking some parts of scene with slight difference, don’t use anchor points or all vertices, project bounding volume (we use AABBs … in case of planes you would probably like to use bounding sphere around them) that is around your model ~ projecting those 8 points is a nothing (if it hurts your performance, you can always do that in CUDA, if you for some reason need all the CPU power).

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Dec 12, 2013 at 13:55

depends on how exact you want it, but you could get the bounding 2d from the bounding 3d, if your windowing functions, if the window costs more than the function itself whats the point in it.

88dc730f0f71e55be39de0ad103bd9ff
1
Alienizer 109 Dec 12, 2013 at 16:37

The problem with AABB and Bounding Sphere is that they don’t guarantee the object is centered in the rectangle.

I need something like a “zoom extents” function to find the 2D shape and get the extents from it to get a perfect fit rectangle.

What about re-creating the AABB of the object based on its current rotation and then projecting the object on the AABB near plane and then shrinking the near plane to fit, that would automatically make the 2D rectangle?

Or is there a better way? I don’t mind going through all the vertices for the object to get it done.

A8433b04cb41dd57113740b779f61acb
1
Reedbeta 167 Dec 12, 2013 at 18:12

If you don’t mind going through all the vertices, just project them to screen space and calculate the AABB in 2D. That’ll be the most accurate way. There’s no reason to mess around with re-creating a 3D AABB and trying to map it to the near plane, which will be just as expensive but less accurate.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Dec 12, 2013 at 18:20

You’re right. Thanks!

Fd80f81596aa1cf809ceb1c2077e190b
0
rouncer 103 Dec 12, 2013 at 21:44

an aabb has 8 points, the model has more, how is it not trading accuracy for speed.

17ba6d8b7ba3b6d82970a7bbba71a6de
0
vrnunes 102 Dec 12, 2013 at 23:44

Also, you can use a low-poly version (eg: last lod level) of your planes with the same technique proposed by Reedbeta.

88dc730f0f71e55be39de0ad103bd9ff
0
Alienizer 109 Dec 13, 2013 at 00:23

True, but it’s fast enough to go through the vertices since there aren’t that many.