ofxGrabCam is an ofEasyCam replacement

Hey all

If you’re working in 3D then I suggest checking out ofxGrabCam
It’s the daddy of ofEasyCam, and bro to ofxGameCamera

https://github.com/elliotwoods/ofxGrabCam/

enjoy!

elliot

this is basically the best thing ever.

i think you should hack the OF core to generate option/shift/cmd/control messages for OSX and windows… the ‘h’ is great, but arbitrary enough to be scary. i know at least three apps where ‘h’ has meant ‘show/hide’ for something :slight_smile:

and/or add in scroll support for zooming.

but really this needs to be integrated into ofEasyCam in the core… it’s so good.

ha. stoked you like it!
i’m putting your ‘review’ in the readme

i think scroll wheel is a definite next for openFrameworks.

Hi.

I started using ofxGrabCam and like it a lot. Thanks.

Now I am trying to define some preset positions, orientation …

I tried get and setGlobalOrientation, get and setGlobalPosition but it does not jump to the position i thought it would.

Thanks for you help.

Stephan.

chances are that you’re moving the ofNode which the camera is positioned with respect to
(i’m not in oF at the moment so not too sure)

i.e. if the ofCamera’s ofNode is at 0,0,0, then the camera position is offset from that position, and looking at 0,0,0

i’ll have a look when i’m back
or if you find the fix first then post it / request some pull, and i’ll add it

i just discovered a bug that basically makes this unusable for me :frowning:

if you do anything to the modelview matrix it destroys the interaction. e.g., add an ofScale after camera.begin():

  
  
camera.begin();  
ofScale(2, 2, 2);  
...  
  

or:

  
  
camera.begin();  
ofRotateX(180);  
...  
  

etc.

i think i figured out how to save a certain view and jump back to it.

ofVec3f newP;
ofQuaternion newQ;

if(key == ‘g’){
newP = camera.getPosition();
newQ = camera.getOrientationQuat();
}
if(key == ‘s’){
camera.setPosition(newP);
camera.setGlobalOrientation(newQ);
}

fixes for the above are on github now
also the example app can save and load pose of camera (using global transformation matrix)

back when we were originally looking at 3D, my thought was to have a ‘ofCameraState’ class which would be settable/gettable/tweenable, but it seemed like a bad idea after i saw ofNode

perhaps ofNode::operator= could also be overloaded to allow the pose of any object inheriting ofNode to be set to that of another ofNode.

e.g.

  
  
ofxGrabCam cam;  
ofNode pose1;  
  
pose1 = cam;  
  
cam.roll(40);  
  
cam = pose1;  
  

or

  
  
ofNode::getPose(ofNode& other) const;  
ofNode::setPose(const ofNode& other);  
  

nice. thank you very much.

what do you think is the best way to actually save ofMatrix4x4 to disk and read it back in on setup() ?

thx

ofxParameter :wink:

the most ‘trivial’ way is probably ofFile

  
  
ofMatrix4x4 mat;  
ofFile outFile("savePose.mat", ios::write, true);  
outFile.write(mat.getPtr(), sizeof(float) * 16);  
outFile.close();  
  

  
  
ofMatrix4x4 mat;  
ofFile inFile("savePose.mat", ios::read, true);  
inFile.read(mat.getPtr(), sizeof(float) * 16);  
inFile.close;  
  

that’d probably work, but needs testing

if you’ve got Talky (ofxTalky) it’s even easier.
something like

  
  
ofMatrix4x4 mat  
TalkyBuffer buffer;  
buffer << mat;  
buffer.saveFile("filename");  
  
buffer.loadFile("filename");  
buffer >> mat;  
  

1 Like

thanks again.

i used ofFile:

  
ofMatrix4x4 savedPose;  
  
//to load saved data i used:  
	ofFile inFile;  
	inFile.open("savePose.mat", ofFile::ReadOnly, true);    
	inFile.read((char*) savedPose.getPtr(), sizeof(float) * 16);    
	inFile.close();   
camera.setTransformMatrix(savedPose);  

//to save the new position i used:

  
savedPose = camera.getGlobalTransformMatrix();  
  
		ofFile outFile;  
		outFile.open("savePose.mat", ofFile::WriteOnly, true);    
		outFile.write((char*) savedPose.getPtr(), sizeof(float) * 16);    
		outFile.close();    

you can also do:

  
  
ofMatrix4x4 mat    
ofFile outFile;    
outFile.open("savePose.mat", ofFile::WriteOnly, true);    
outFile << mat;    
outFile.close();  
    
ofFile inFile;    
inFile.open("savePose.mat", ofFile::ReadOnly, true);      
inFile >> mat;    
inFile.close();  
  

aha. we got streams. fantastic, didn’t know that

ofxGrabCam is great, only problem is that it disables alpha blending for me. I set alpha blending in my draw function with ofEnableAlphaBlending() which works fine with ofEasyCam but not ofxGrabCam. Is there another way to do this?

Thanks in advance.

i turn on depth buffer by default
this isn’t done by ofEasyCam

perhaps check it’s not a depth buffer issue first
(e.g. alpha channels in textures and depth buffers don’t get along, and no default alpha test in oF to get around that)

ah ok got it, just had to disable the depth buffer when I was drawing my object. Thanks!