Using a Frustum or writing my own..?

Problems building or running the engine, queries about how to use features etc.
Srekel
Halfling
Posts: 89
Joined: Tue Jun 08, 2004 8:33 pm

Using a Frustum or writing my own..?

Post by Srekel »

In our game, we have a bunch of turrets. They are supposed to be looking in a direction, and they have a gun which can turn a number of degrees in each direction from that direction. Let me show with some ASCII art. ;)

Code: Select all

          B

       --------/
   ---/
TTT/
TG          A
TTT\
TTT ---\
        -------\


         B

The T's are the turret (from the side), and G is the gun inside it. the lines dictate the field of view of the gun, it can see anything inside A but not what's in B.

What I want to do is to determine which entities the gun can see and target. Now, I can probably attach an Ogre Frustum to each turret, and just call Frustum::isVisible(someEntity) for each entity to find out which one would make a good target.

I could probably also write a method of my own for determining which entities are visible or not from the gun's point of view. It will be written in Python since we're using PyOgre (which by the way kicks ass :)), so it will probably not be as fast as the Frustum way, but I'm guessing it will be less intensive on the memory...?

So what I'm asking is: which method would you recommend? Obviously, it will probably be easier to just use the Frustum, but is there any performance to be gained? Worst case scenario is something like 15-20 turrets, and 75-150 enemy entities.
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

Always reuse before you rewrite, especially if the reusable version may be a little faster :)
User avatar
pjcast
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2543
Joined: Fri Oct 24, 2003 2:53 am
Location: San Diego, Ca
x 2

Post by pjcast »

friend_of_ACCU wrote:reuse if u're an optimist and lazy ass
English does not appear to be your first language (from all your posts so far). However, you need to tone down your reponses on this board, as we pride ourselves on being a friendly, professional forum.
Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/
Srekel
Halfling
Posts: 89
Joined: Tue Jun 08, 2004 8:33 pm

Post by Srekel »

Thanks sinbad, good advice (as always). :)
Why I wondered was because I was worried that the Frustum might only be intended to be used for the camera, so only one would be active at the time, and it might therefore necessarily not be very efficient, or something.

That, and perhaps someone knows of a very simple and fast method for checking if an object is inside a frustum, or a cone for that matter (probably even better). I probably have the math in a book on my shelf, so it's more of a small code example I'm interested in.

I'll use a Frustum though unless someone has a great idea. :)

And pjcast, I thought friend_of_ACCU's reply was funny (I hope that was the point of it too. ;) ).
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179

Post by jacmoe »

It seems like friend_of_ACCU has a defunct ARU unit. :?
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
BlasterN
Gnome
Posts: 378
Joined: Thu Mar 24, 2005 1:07 am
Location: Spain

Post by BlasterN »

I think write a new Frustum is too much for the people who use ogre.
Thats for sinbad that knows all ogre engine like his hand.

--
I remember to see something in game programing gems about the frustum if I find it i will post it.
Works:
MapToMesh | Bengine B9 @ www.sourceforge.net/projects/maptoogremesh/
3DWorldStudio exporter@ www.blastern.info
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66

Post by sinbad »

That, and perhaps someone knows of a very simple and fast method for checking if an object is inside a frustum, or a cone for that matter (probably even better). I probably have the math in a book on my shelf, so it's more of a small code example I'm interested in.
Well, if it's a cone you're interested in, you can do something much simpler (and faster) than using Frustum planes. All you need to do is take the direction vector of the turret, and dot product it with the normalised vector from the turret to the point. The result is the cosine of the angle between the 2 vectors. If you define a visibility threshold in terms of this (1 is in the centre of the cone, 0 is 90 degrees away, so pick a value in between), you can determine if the object is within the cone. Note that the Vector3::normalise method returns the previous length of the vector too, so you can use that to eliminate things at distance.
Srekel
Halfling
Posts: 89
Joined: Tue Jun 08, 2004 8:33 pm

Post by Srekel »

Just wanted to say thanks, the dot product method worked perfectly!