Cam / easyCam... Rotation

hello everyone!

Just a simple question: how i can turn a camera or a easycam? i need to turn it like 90°

thank you :slight_smile:

ofEasyCam extends ofCamera which extends ofNode. There are methods to rotate the camera around its local axis in ofNode

  
// helpful rotation methods  
void tilt(float degrees);		// tilt up+down (around local x axis)  
void pan(float degrees);	// rotate left+right (around local y axis)  
void roll(float degrees);	// roll left+right (around local z axis)  

There are also rotate methods that allow you to define the axis and degrees of rotation

  
void rotate(float degrees, const ofVec3f& v);	// rotate around arbitrary axis by angle  
void rotate(float degrees, float vx, float vy, float vz);  

so if you wanted to rotate a camera 90 degrees around its local y axis, you could try:

  
camera.rotate(90, camera.getUpDir() );  

Another very useful method is lookAt. This allows you to move the camera around and the look at a target that you specify. It is very handy for following moving targets.

  
// orient node to look at position (-ve z axis pointing to node)  
void lookAt(const ofVec3f& lookAtPosition, ofVec3f upVector = ofVec3f(0, 1, 0));  
void lookAt(const ofNode& lookAtNode, const ofVec3f& upVector = ofVec3f(0, 1, 0));  

Hope this helps.

thank you, it’s working!

but there is something strange: it’s blinking all the time…x

i do this (i put only 10 degree to see where is my drawing):

  
  
mainCam.setPosition(ofGetWidth()/2, ofGetHeight()/2, 1000);  
      
    cam1.setPosition(ofGetWidth()/2,ofGetHeight()/2, 1000);  
    cam1.rotate(10, cam1.getUpDir() );  
      
    cam2.setPosition(ofGetWidth()/2, ofGetHeight()/2, 1000);  
    cam2.rotate(-10, cam2.getUpDir() );  
  

normally it’s okay, but it’s blinking, i show you the .cpp:

  
#include "testApp.h"  
  
  
  
ofEasyCam cam, cam2, cam3;  
  
//--------------------------------------------------------------  
void testApp::setup(){  
          
    ofBackground(0);  
	ofSetFrameRate(40);  
    //fbo  
	fbo1.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);  
    fbo2.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);  
    Mainfbo.allocate(ofGetWidth(), ofGetHeight(), GL_RGB);  
      
    //the mesh defines a shape, in this case a rectangle  
    //we need to use two triangles make the rectangle  
    //the vertex coordinates are the coordinates that make the  
    //size of the shape we want, in this case ofGetWidth()/2.0 and ofGetHeight()/2.0  
    //the texture coordinates are the size of the texture we will draw on to the mesh  
    //so in this case it is the same size as Mainfbo  
      
    //first triangle in the mesh //OK  
    mesh1.addTexCoord(ofVec2f(0,0));//T1  
    mesh1.addVertex(ofVec3f(0,0,0));//v1  
      
    mesh1.addTexCoord(ofVec2f(fbo1.getWidth()/2, 0));//T2  
    mesh1.addVertex(ofVec3f(ofGetWidth()/2.0, 0, 0));//v2  
      
    mesh1.addTexCoord(ofVec2f(0, fbo1.getHeight()));//T3  
    mesh1.addVertex(ofVec3f(0, ofGetHeight(), 0));//v3  
      
      
      
    //Second triangle in the mesh //OK  
    mesh2.addTexCoord(ofVec2f(fbo2.getWidth(),0));//T1  
    mesh2.addVertex(ofVec3f(ofGetWidth(),0,0));//v1  
      
    mesh2.addTexCoord(ofVec2f(fbo2.getWidth()/2, 0));//T2  
    mesh2.addVertex(ofVec3f(ofGetWidth()/2.0, 0, 0));//v2  
      
    mesh2.addTexCoord(ofVec2f(fbo2.getWidth(), fbo2.getHeight()));//T3  
    mesh2.addVertex(ofVec3f(ofGetWidth(), ofGetHeight(), 0));//v3*/  
      
      
      
    //Main triangle in the mesh // OK  
    MainMesh.addTexCoord(ofVec2f(0,Mainfbo.getHeight()));//T1  
    MainMesh.addVertex(ofVec3f(0,ofGetHeight(),0));//v1  
      
    MainMesh.addTexCoord(ofVec2f(Mainfbo.getWidth(), Mainfbo.getHeight()));//T2  
    MainMesh.addVertex(ofVec3f(ofGetWidth(), ofGetHeight(), 0));//v2  
      
    MainMesh.addTexCoord(ofVec2f(Mainfbo.getWidth()/2, 0));//T3  
    MainMesh.addVertex(ofVec3f(ofGetWidth()/2, 0, 0));//v3  
      
      
  
      
  }  
  
//--------------------------------------------------------------  
void testApp::update(){  
          
	//Dessin des fbo  
      
    fbo1.begin();  
    drawFbo1();  
    fbo1.end();  
      
    fbo2.begin();  
    drawFbo2();  
    fbo2.end();  
      
    Mainfbo.begin();  
    drawMainFbo();  
    Mainfbo.end();  
      
   
}  
//-------------------------- FBO 1 -----------------------------  
void testApp::drawFbo1(){  
      
    cam1.begin();  
    //écran clair  
	ofClear(0,0,0, 0);  
      
    ofPushMatrix();  
    customDraw3d();  
    ofPopMatrix();  
    cam1.end();  
    cam1.disableMouseInput();  
      
}  
//-------------------------- FBO 2 -----------------------------  
  
void testApp::drawFbo2(){  
      
    cam2.begin();  
    //écran clair  
    ofClear(0,0,0, 0);  
  
    ofPushMatrix();  
    customDraw3d();  
	ofPopMatrix();  
    cam2.end();  
    cam2.disableMouseInput();  
     
  
}  
//------------------------- MAIN FBO ---------------------------  
  
void testApp::drawMainFbo(){  
      
    mainCam.begin();  
    //écran clair  
    ofClear(0,0,0, 0);  
      
    ofPushMatrix();  
    customDraw3d();  
	ofPopMatrix();  
    mainCam.end();  
    mainCam.disableMouseInput();  
      
}  
  
//--------------------- ENVIRRONEMENT 3D -----------------------  
void testApp::customDraw3d(){  
      
     
    mainCam.setPosition(ofGetWidth()/2, ofGetHeight()/2, 1000);  
      
    cam1.setPosition(ofGetWidth()/2,ofGetHeight()/2, 1000);  
    cam1.rotate(10, cam1.getUpDir() );  
      
    cam2.setPosition(ofGetWidth()/2, ofGetHeight()/2, 1000);  
    cam2.rotate(-10, cam2.getUpDir() );  
      
      
      
      
    ofPushMatrix();  
      
    if (MX == true)  
        ofRotate(ofGetMouseY());  
    else {  
          
        ofSetColor(255,100,0);  
        //do the same thing from the first example...  
        ofMesh mesh;  
        mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);  
        for(int i = 1; i < points.size(); i++){  
              
            //find this point and the next point  
            ofVec3f thisPoint = points[i-1];  
            ofVec3f nextPoint = points[i];  
              
            //get the direction from one to the next.  
            //the ribbon should fan out from this direction  
            ofVec3f direction = (nextPoint - thisPoint);  
              
            //get the distance from one point to the next  
            float distance = direction.length();  
              
            //get the normalized direction. normalized vectors always have a length of one  
            //and are really useful for representing directions as opposed to something with length  
            ofVec3f unitDirection = direction.normalized();  
              
            //find both directions to the left and to the right  
            ofVec3f toTheLeft = unitDirection.getRotated(-90, ofVec3f(0,0,1));  
            ofVec3f toTheRight = unitDirection.getRotated(90, ofVec3f(0,0,1));  
              
            //use the map function to determine the distance.  
            //the longer the distance, the narrower the line.  
            //this makes it look a bit like brush strokes  
            float thickness = ofMap(distance, 0, 30, 10, 1, true);  
              
            //calculate the points to the left and to the right  
            //by extending the current point in the direction of left/right by the length  
            ofVec3f leftPoint = thisPoint+toTheLeft*thickness;  
            ofVec3f rightPoint = thisPoint+toTheRight*thickness;  
              
            //add these points to the triangle strip  
            mesh.addVertex(ofVec3f(leftPoint.x, leftPoint.y, leftPoint.z));  
            mesh.addVertex(ofVec3f(rightPoint.x, rightPoint.y, rightPoint.z));  
        }  
          
        //end the shape  
        mesh.draw();  
  
    }  
  
      
    ofPopMatrix();   
  
}  
  
  
//--------------------------------------------------------------  
void testApp::draw(){  
      
    // OK  
    ofClear(30);  
      
    fbo1.getTextureReference().bind();  
    mesh1.draw();  
    fbo1.getTextureReference().unbind();  
      
    fbo2.getTextureReference().bind();  
    mesh2.draw();  
    fbo2.getTextureReference().unbind();  
      
    Mainfbo.getTextureReference().bind();  
    MainMesh.draw();  
    Mainfbo.getTextureReference().unbind();  
    //  
      
    ofSetColor(255, 100, 0);  
    ofCircle(ofGetMouseX(), ofGetMouseY(), 10);  
  
      
}  
  
//--------------------------------------------------------------  
void testApp::keyPressed(int key){  
  
    if (key == ' ')  
        int MX = true;      
}  
  
//--------------------------------------------------------------  
void testApp::keyReleased(int key){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseMoved(int x, int y ){      
  
      
}  
  
//--------------------------------------------------------------  
void testApp::mouseDragged(int x, int y, int button){  
  
    ofVec3f mousePoint(x,y,0);  
    points.push_back(mousePoint);  
      
      
}  
  
//--------------------------------------------------------------  
void testApp::mousePressed(int x, int y, int button){  
  
}  
  
//--------------------------------------------------------------  
void testApp::mouseReleased(int x, int y, int button){  
  
}  
  
//--------------------------------------------------------------  
void testApp::windowResized(int w, int h){  
  
}  
  
//--------------------------------------------------------------  
void testApp::gotMessage(ofMessage msg){  
  
}  
  
//--------------------------------------------------------------  
void testApp::dragEvent(ofDragInfo dragInfo){   
  
}  

The rotate functions are cumulative, so every time you call rotate(), it will rotate an additional 10 degrees, which is a pretty big rotation every frame. Try just setting the cameras once in the setup function or calling setRotation with a quaternion.

i want to rotate around an object, my object is a mesh conisting out of a lot of vec3f points. its a sphere, im wondering how do i set my cam up to lock onto my sphere and get different angles on it, i want to change the only of view basicly.

use an ofEasyCam object and call its setTarget(...) to set the point around which it will rotate. Set this to the center of your mesh.
hope this helps.
best