## Ray Casting

So you'll have to write your own.

BUT I am certain you don't need to cast rays to do this. I'd imagine you have some way of determining the height at any given point on the ocean. Combine this with the location of the ocean plane will get you a three-space coordinate of any point on the ocean waves. Seems to me this is all you need to have the camera bob with the ocean. Jus tplace the camera at that point. Then maybe offset the camera by some factor times the normal at that point to get it above the waves.

If you really want to cast a ray to check where the camera is relative to the ocean:

1. translate the point of the camera to the ocean's local coordinates. This will be the orgin of the ray.

2. The direction for the ray will be the negation of the up normal of the ocean plane: The normal pointing down towards the ocean. Normalize this for convenience. Now you got a ray of the form: R = orgin + dir * time.

3. I presume your ocean is made of triangles. So for each triangle in the ocean check if it collides with the ray, and find the minimum time of intersection. This minimum time corresponds to the distance of the camera to the ocean.

4. Modulate your camera's height above the ocean by this distance.

Unfortunately, checking a ray-triangle intersection with anything reasonable complex is ridiculously slow.

A B

C D

You can use linear interpolation between points A and B based upon the camera's X coordinate to find a new point E, and do the same between points C and D to find point F. You can then find the location of the point on the surface below the camera by doing another linear interpolation between the new points E and F based upon the camera's Z coordinate. If you add the offset you want to that point's Y coordinate, you're done.

There was another discussion a while ago which talks about linear, bilinear and cubic interpolation for use in landscape generation, which more or less relates to the method I'm trying to describe. You can read it here.