ofEasyCam save and restore position/orientation

Hi! I am creating a video installation and using ofCamera in my 3D scene.
I want to pre-record camera positon/orientation and then to restore them by triggering events. The problem is that the restored parameters are not the the same I wanted to restore. Here’s an example… (not exactly my final code, but it shows what i’m doing wrong)

I save the values with this code:

ofEasyCam               cam;
float values[7];

values[0] = cam.getPosition().x;
values[1] = cam.getPosition().y;
values[2] = cam.getPosition().z;

values[3] = cam.getOrientationQuat().x;
values[4] = cam.getOrientationQuat().y;
values[5] = cam.getOrientationQuat().z;
values[6] = cam.getOrientationQuat().w;

An then I’m trying to restore the values like this:


The problem is that I’m getting the different values… When I’m saving the values
Position: 2.88935, -547.984, 255.531
Rotation: 0.248289, 0.225038, -0.542905, 0.770044

But when I’m restoring those i get:
Position: 2.88935, -547.984, 255.531 >> correct!
Rotation: 0.248289, 0, -0.542905, 1 >> incorrect!

Why the rotation values are different in such strange way? I could replace ofEasyCam with ofCamera, but i suspect the reason is my wrong understanding of 3d fundamentals…

have alook at this thread:

Hi, you could just save the ofCamera of ofEasyCam objects in a vector then just use them when you need to.
I have a class for tweening between cameras. let me look for that one.
As @Jordi said in that other thread, to save or load from a file use ofxCameraSaveLoad


Jordi, roymacdonald
Yes, i found setTransformMatrix. The problem is that is’s removed from latest OF:

I also thought about saving/restoring camera scale - but it didn’t help. In my example it’s always 1/1/1. I don’t understand how such important thing in 3D can be so unclear… But if setTransformMatrix was removed as not reliable - I hope there’s even more reliable method to do it :slight_smile:

@gonzzza setting the individual components instead of the full matrix is the way to do it. can you post how you are reading back those values in the camera? your original code seems correct and setting the position and the quaternion back just sets them so not sure how those would change after.

Also ofEasyCam sets itself from the interaction with the mouse so that might be the cause perhaps try an ofCamera instead to see if that’s the problem

Also ofEasyCam sets itself from the interaction with the mouse

Yes, exactly. I was moving the camera with the mouse to find an “effective” angle, which I want to restore later. But while moving the camera with a mouse - all the angle/position values were changing aswell, so I assumed if i will use those exact same values (position, rotation) - i will get the same view, but i don’t.

I will do some more testing.

Hi @gonzzza, the ofEasyCam sets some stuff automatically on the first update, like the auto distance as well as all the event listening. set the auto distance to false before loading the values. I had this same problem some months ago and I’m almost sure that this was the fix.

Yes! This was causing the wrong camera position.

cam.setAutoDistance(false) did fix it.

Thankyou, Roy!


Hi all, I was googling for an ofx-addon to save multiple camera positions from a camera traveling to later being re-loaded and then I came across with this conversation. Do any of you know an addon for it? AFAIK ofxCameraSaveLoad can save and restore just one camera instance. If there is none, it could be worth to implement one?

Hi, you can just use ofxCameraSaveLoad and save the camera at each frame, in a different file and then reload those files. You will be saving a lot of data that might be unnecessary to save but it would be easy and fast to code.
I madethis class a while ago that allows for a camera to travel over a path. It might be useful too.

Wow! the ofxCameraSaveLoad operates perfectly. Although if I’m having to save the camera each frame, after some minutes it will certainly produce a large stack of files and over-saved data that I won’t need later. However I think I can save the camera with a lower frame-rate to later apply a traveling between saved cameras with your TravelingCam. Probably it’s what you just had in mind. Thanks @roymacdonald.


sort of. That traveling camera I mentioned is following an ofPolyline so you actually just pass the polyline and the speed at which you want it to move. The camera is always facing front relative to the motion. so at the end I did not save anything with ofxCameraSaveLoad, instead I saved the ofPolyline.
Take a look at what’s being done inside of ofxCameraSaveLoad, it is really simple, you might want to change that and just save the needed parameters instead of saving all of it.

Yep, I had a look to your work “New york is flat…almost” (very nice BTW) I understand you moved the camera from point to point all along the polyline.

Take a look at what’s being done inside of ofxCameraSaveLoad, it is really simple, you might want to change that and just save the needed parameters instead of saving all of it.

I already had a look to ofxCameraSaveLoad. I’m not so much worried about the saved extra data but about to have thousands of files for each position after several recorded minutes at 20-30 fps. I’m moving the camera manually with leap motion and I want to be able to recover the path later on. That’s why I was thinking on saving the camera position let’s say every 1 second, which produces 20-30 times less files and probably a smoother camera movement after performing the traveling.

Since your TravelingCam class takes just points of a ofPolyline instead of just a ofCamera/ofEasyCam/ofNode, I guess I can just recall saved camera positions with ofxCameraSaveLoad and then interpolate two adjacent camera positions and their lookat points with the proper speed. That won’t hurt much : )


The travelingCam class inherits from ofCamera, so actually you can use ofxCameraSaveLoad with it, without making changes.

I wouldn’t mind having a lot of files, all these are small in size, just put them in a separate folder and you can name these with their frame number. It could end up being a lot more efficient than loading all from a big file. I’ve done it a lot of times. Just as a reminder, for example, a very common thing in movie post production pipelines is to use image file sequences and it works really well.

The travelingCam class inherits from ofCamera , so actually you can use ofxCameraSaveLoad with it, without making changes.

Good point!

I wouldn’t mind having a lot of files…

I’m always scared of having thousands of files in the same folder, even if they are tiny.
But as you mention, I guess it’s the way to go.
In that case the traveling can be simply skipped since the camera settings would be recorded every frame.

Thanks again @roymacdonald.

1 Like