Selection Rectangle

Any ideas how I would check for certain entities within this rectangle?

I had multiple ideas like doing a ToScreen of each entity of that specific class, or somehow a WithinAABox, but I need them to be precisely inside the rectangle and not very expensive. (Because their could be hundreds of these entities.)

http://puu.sh/4UWqg/1de5ecaa79.png

ToScreen all entity positions and check if they are inside your rectangle.

I wish it were that simple, but unfortunately I don’t think that would be the best option since like I said; there could be hundreds of these entities.
I’d also prefer checking if even a piece of their bounding box is within the rectangle. So it’s going to be very costly.

It’ll be costly either way. I don’t think you’ll be able to fit hundreds of big enough objects for the OBB to matter.

You’re right, it’ll be costly no matter what. I guess I’ll just optimize it down the road. Until then:

http://puu.sh/4UZgN/a94e919450.png

Lol. OBB **definitely **doesn’t matter for cans.

The cans are just for testing. :v:

I’d get the gui.ScreenToVector of both onscreen square corners and use ents.FindInBox with a box slightly larger than the one you create with the two world vectors (in case the terrain is uneven and the entity’s positional vector is at the foot).

[editline]20th October 2013[/editline]

But if I remember correctly, ScreenToVector has trouble with custom cameras like you’re using. Someone in the last two months posted a lovely piece of code to replace it with.

Glad I bookmarked this: http://forum.facepunch.com/showthread.php?t=891702&p=32941555&viewfull=1#post32941555

To check if an entity is within the rectangle, I’m using the OBBCenter of the entity. That way it feels more comfortable and as if it’s selecting it because half of it is within the box.

I don’t think I mind having to loop through all entities of a certain class at the moment, since it doesn’t seem to cause that much of a problem.