[Solved]Camera following a path without falling off the edge

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Willem
Posts: 8
Joined: Wed Apr 07, 2010 1:33 am
Location: New Zealand

[Solved]Camera following a path without falling off the edge

Post by Willem »

I made a mesh which represents a road network from GPS points and would like to have a FPS type camera traverse the road network without falling off the road (leaving the road, going over the edge), and can turn left/right into streets etc. The road is suspended in space, i.e. there is no adjacent terrain, just the road.

What would be the best approach? How can I test that I am still on the road? Can one search for a vertice close to the camera position? I looked at the TriangleSelector but can't see how I can use that to stop falling off the road as there would be no triangles to select.

I want to be able to steer the vehicle (i.e. not have a predetermined fix path).

I looked at Tutorial 7 sample code using collision detection, which is close to what I want, but I don't have vertical side(s) to collide against, unless I add sidewalk(s) to both sides of the road and have the road depressed and can then test for collision with the sidewalk. Is this the only way to solve the problem?

Any ideas/pointers/advice would be appreciated.

Thanks
Willem
Last edited by Willem on Sun Sep 19, 2010 12:46 am, edited 1 time in total.
blAaarg
Posts: 94
Joined: Tue Mar 02, 2010 9:11 pm
Location: SoCal

Post by blAaarg »

If you have the two adjacent vertices that represent the segment of the road you are on at any given time, you could use vector3df::interpolate() to slide down the length of that road segment. This would give more of a train track effect than a road you could swerve around on.

If you wanted to be able to steer(swerve) around on any given road segment, you could have an empty scene node do the above, attach your camera to the empty node as a child, use set(relative)Position() on the camera to make it vary its position from the track/road, and make sure to clamp the camera's position to the width of the road. This would act a bit more like a water skiier roped to a boat.

Another thought, if you want more freedom to bump around on the road w/out having to slide down its length:
Again, if you know the position of the two vertices representing the road segment you are on, you could use them to make a line3df and use lined3df::getClosestPoint (camera) and camera->getDistanceFromSQ(closestPoint) to test if your camera is trying to get too far off the road and take some action to prevent it from doing so.

Of course, there are other considerations. You might have to make your own animator based on the FPSCamera but which would be able to do its own distance-from-the-road testing, instead of collision testing.

Hopefully, those ideas are useful. :)
"Computers don't make mistakes! What they do they do on purpose!!"

-Dale Gribble
Willem
Posts: 8
Joined: Wed Apr 07, 2010 1:33 am
Location: New Zealand

Post by Willem »

Thank you very much, very useful

Willem
Willem
Posts: 8
Joined: Wed Apr 07, 2010 1:33 am
Location: New Zealand

Solution

Post by Willem »

For the time being the best solution which gives me the desired behaviour was to create a custom CameraSceneNodeFPS and in the CSceneNodeAnimatorCameraFPS::animateNode function a check is made to detect collision with a ray (origin camera position) and the road. If there is no collision (i.e. the next camera position is not vertically above any mesh triangles) the camera position is not changed.
Post Reply