Creating camera path

In general, how do you specify the path of your camera when making a scene?

I am creating a simple solar system with 3d shapes for a music video. I can create the scene and populate it with spheres and apply textures to those spheres. Using GUI controls or ofxEasyCam I can spin and zoom around the scene.

I now would like to specify a path for my camera around the different planets of the solar system. It seems like I can do things like “start at (0,0,1000) and zoom into (0,0,100) at a rate of 10 units per second.” However, this isn’t really the level of control I need for creating a music video.

So I’m not sure how to take that step from camera movement for simply seeing your scene to camera motion for a final render/ movie.

Do people generally make a seperate utility/ debug program for specifying their camera path and tweaking it? I saw which is a collection of peoples’ development/ debug interfaces for their programs. Do I need to create something like this?

I also checked out this lecture from Ken joy on camera motion. He explains that most curves aren’t suitable for camera motion because they aren’t smooth enough, and he uses catmull-rom curves to solve that problem:

Thanks in advance!

you can make the camera follow an ofPolyline.
Check this out.

there is a class called travelingCam that does exactly what you want/need.
Also, theres a class called pathEditor that lets you create the paths that the camera follows.
Check the whole project to see how to implement it.

Thanks for the quick reply!

Been playing around with flat city, this is exactly what I was looking for. Thanks for open sourcing so much of your code! Flat city is a really cool project

Glad it worked for you.
feel free to reuse any of the code there!.
let me know once you’ve published this project you are working on.

Yea, I’ll post it here when it’s done. I’m going to start a repo for it soon.

Do you (or anyone else reading this) have any insight into tweening camera orientation between way points?

The thing I’m adding to flat city right now is the ability to save camera orientation at each waypoint. So in addition to the points of the path the camera follows, at every point I want to save the orientation of the camera.

I think most of the time the camera orientation will be as it is now, which is pointing forward toward the next waypoint on the path. However, sometimes I might want to make the camera pan over so it’s pointing perpendicular to the path, or make it tilt up.

Which brings me to the one difficultly in implementing this: tweening the camera orientation between the waypoints. Did you play with this when you were developing flat city?

It might not be so difficult, I’m not sure yet, but I imagine that if I don’t get the tweening just right, the camera will be jerky during pans (I’ve notice the camera is especially sensitive to non-gradual changes).


Hi, sure.
did you notice that when you clic the mouse the camera will change the orientation to look towards the clicked point?
the same idea might work for what you are looking for.
Another way would be to use the ofQuaternion::slerp(...)!show_slerp
this method takes two quaternions and it will interpolate according to de float number you pass to it. these 2 quaternions could be the stored orientations.
The camera has the setOrientation() method which recieves a quaternion,
it should be something like the following. you should place this in the update

ofQuaternion q;
//float positionBetweenWaypoints; //this goes between 0 and 1
//startWaypointOrientation, endWaypointOrientation are the stored quaternions
q.slerp(positionBetweenWaypoints, startWaypointOrientation, endWaypointOrientation);

Hope it helps

Just an update, slerp is indeed what ended up using to interpolate my camera position between way points.

At this point, in the edit mode I can set points for the camera and set camera orientations at each point.

As I said in the first post, my scene is a solar system. When I run it currently, I have plants orbiting around a sun. However, when I pause the camera’s path, the sun and planets continue to move.

Next I want to make it deterministic, so that every run will come out the same.

I want it to not only freeze the camera and the planets, but also if I move backwards in the camera path, the planets all move backwards. So each camera position will correspond to a deterministic “frame” of the movie it is shooting.

I think to do this I need to replace ofGetElapsedTimef() throughout the code with my own function, something like getTimeBasedOnFrameNum(). Each time the camera moves forward one it’s path 1 “frame” getTimeBasedOnFrameNum() increments the elapsed time by 1 frame’s worth of time. Similarly, moving the camera backwards

I put my code up here:

It’s mostly Roy MacDonald’s flat city with some changes I’ve made. Planning on cleaning up my parts of the code soon.

@slackermann cool. It is best if you avoid using a frame based mechanism, as it implies that every frame has the exact same duration which is actually not true. Instead you should rely completely on the elapsed time. This will give you much smoother movements.
If you use any random you should call ofSeedRandom(anyNumber); to “reset” the random number generation.

When I’ve had to animate camera positions in the past in OF I’ve used this addon in combination with ofxTimeline.

It took some patience to set up, but when I did it was very helpful to have the GUI. It gives you a really slick timeline “debug mode”. Just an alternative for the future.

In case anyone else reading this wants to use ofxTimeline, here’s a nice thread that explains how to modify it to use it with the newest version of openframeworks:

I’m going to play with it tomorrow.

I integrated ofxTimeline. Now all the movement of the planets (and the camera) are based on the time in the timeline. So now the scene is deterministic. Every run will be the same, so the camera can be placed based on the elements of the scene.

If anyone else is trying to do something like this, you can checkout this commit:

Here’s what I end up with:

1 Like