About Store Forum Documentation Contact



Post Reply 
find distance to nearest ocean, lake or river
Author Message
yvanvds Offline
Member

Post: #1
find distance to nearest ocean, lake or river
Hello again.

Does any of you know of a way to find the nearest river or lake and see how far away it is?

Right now i have some sounds placed at certain points on the river or ocean, but this is far from ideal because a river is typically long and narrow while sounds have a circular rolloff.

Having a few water sounds loaded at anytime, and increasing them in volume when you go near to a river would be much easier.

Water like lakes and rivers are loaded in the World object's private member Memc<WaterArea > _water; but i see no way to retrieve them from it.

Finding the nearest 'ocean' might be tricky. I'd have to find the nearest point on the heightmap that is below sea level. Scan the whole area manually at each update will work, but seems like overkill to me.

Any ideas?
12-17-2012 04:47 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #2
RE: find distance to nearest ocean, lake or river
Not sure about rivers, maybe Esenthel can give you some way to access the river spline data from the Memc<WaterArea>.

As for oceans, I think scanning for the nearest point below sea level will work. However I would run it on a background thread, at maybe 10 times per second (keep it low priority) and only check up to a certain radius around the player, like 100m for example.
12-18-2012 01:36 AM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #3
RE: find distance to nearest ocean, lake or river
ok, thanks fatcoder.

Hopefully Esenthel can give me access to the river data somehow.

And yes, scanning for oceans seems the most obvious solution. Or perhaps i can an exported image of the heightmap somehow (by comparing my position with a position on the image and checking for a certain color). I'll look further in to it.

Edit: Now that i think of it, if i could create an image of the whole world with white for land masses and blue for ocean and rivers, blur that to a degree and map the blue value of a position to the volume of the water sounds, now that would be a neat trick :-)
(This post was last modified: 12-19-2012 09:43 PM by yvanvds.)
12-19-2012 09:39 PM
Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #4
RE: find distance to nearest ocean, lake or river
Yes, that would work even better. You can build the image by iterating through the world areas and reading the height map data. In fact, you could just copy the height map image into a larger image, offsetting by the area's position.

With enough blur, you can then get the water sound volume with a single pixel lookup in the image.
12-20-2012 01:00 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
RE: find distance to nearest ocean, lake or river
Mayb you could try using:
Game.World.path().nearestSurface(.. , PMF_SWIM);
(I haven't tested it)
12-29-2012 12:48 PM
Find all posts by this user Quote this message in a reply
yvanvds Offline
Member

Post: #6
RE: find distance to nearest ocean, lake or river
Works, thanks.

Although i realize i still need to know if it's an ocean or a river that's nearby. An ocean sounding when a small river is nearby feels a bit wrong :-)

Checking for if the terrain position is below zero would help, only my world is a bit too flat, so i have a lot of rivers that are partly below sea level, with a river set just above the ocean water. Too late to change the gameworld now, but I'll figure something.
(This post was last modified: 01-01-2013 10:00 PM by yvanvds.)
01-01-2013 09:59 PM
Find all posts by this user Quote this message in a reply
Post Reply