About Store Forum Documentation Contact



Post Reply 
How to get the AABB for the terrain
Author Message
monotonic Offline
Member

Post: #1
How to get the AABB for the terrain
Hi All,

I've been away for a while but I'm finally getting back into it and will have a license purchased as soon as PayPal allows me to make a payment!

Anyway, I'm working on a game which requires me to limit the camera movement to the bounds of the terrain. The camera will be an overhead floating camera like an RTS game. So what I need is to get the AABB from the terrain as a whole, and I cannot seem to find anyway of even getting a handle on the terrain object.

Any help will be appreciated.
03-29-2015 10:58 AM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: How to get the AABB for the terrain
Hi,

You could do 4 raycasts down (use hmHeight in Area class) and check if you are above terrain. If one of the rays is not hitting terrain, you disable movement in that direction.
03-29-2015 11:24 AM
Find all posts by this user Quote this message in a reply
monotonic Offline
Member

Post: #3
RE: How to get the AABB for the terrain
Hi Tottel,

That would be one way to do it, but I was trying to make this as efficient as I possibly can. However if getting the AABB of the terrain as a whole is not feasible then this would be the way to go.

Thank you for the input, it is appreciated.
03-29-2015 11:26 AM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #4
RE: How to get the AABB for the terrain
Are you saying that you don't know the x/z extents of the terrain at run time? So long as these are known then some simple calculations based on the camera height and FOV should enable you to calculate the extent of camera travel in any direction assuming the camera maintains a constant height above the terrain.

If it's land above sea level or something like that then that's a different issue and the sampled terrain height could be used but you specifically mentioned the bounding box which makes me think this isn't the case here!
03-29-2015 02:02 PM
Find all posts by this user Quote this message in a reply
monotonic Offline
Member

Post: #5
RE: How to get the AABB for the terrain
Hi Pixel,

Precisely, when designing the world I know how big the terrain is, however to re-use a common bit of code to restrict the camera for a whole range of different world sizes is a different story.

What I need is a way of calculating the terrain size. Restricting the camera is the easy part, figuring out the AABB of the terrain is the bit I'm after.

I'm not just going to be using this for restricting the camera, it will also be used for a potential field generation algorithm I have.
03-29-2015 02:15 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #6
RE: How to get the AABB for the terrain
I'd be tempted to simply pass the level extents in with the level as they are known at design time.

There may be a way of returning the terrain AABB although I can't say I've come across that before. You might have to iterate through the defined areas having first obtained the area size and calculate the extents from that.
03-29-2015 02:49 PM
Find all posts by this user Quote this message in a reply
monotonic Offline
Member

Post: #7
RE: How to get the AABB for the terrain
Yeah I tried to iterate over the activeAreas collection and build up the AABB from the extents, however all of the x,z co-ords seems to have odd values e.g. -1, and 0.000032423 for example.

I've took the ugly/easy route and added a WorldDefinition object, which I populate with the BlockCountX/Z values and use them instead.

Thanks for your input Pixel and Tottel, it is appreciated.
03-29-2015 02:58 PM
Find all posts by this user Quote this message in a reply
Pixel Perfect Offline
Member

Post: #8
RE: How to get the AABB for the terrain
(03-29-2015 02:58 PM)monotonic Wrote:  ...
Thanks for your input Pixel and Tottel, it is appreciated.
You're welcome, nice to see you back again smile
03-29-2015 03:03 PM
Find all posts by this user Quote this message in a reply
Post Reply