Lightweight ofCamera class that replicates camera controls of first person video games. It uses mouse to look around, hides cursor on activation and has reassignable keys which by default set to WASD for moving the camera, E and C to move camera up and down, Q and R to roll left and right and F to reset camera's up vector.
Tested on Linux and Windows, should work on Mac as well.
For openFrameworks:
For CMake-based openFrameworks:
Add this repo as a git submodule to your ofApp folder and use ofxaddon command in CMakeLists.txt.
Include header file in ofApp.h, add an instance of ofxFirstPersonCamera:
#pragma once
#include "ofMain.h"
#include "ofxFirstPersonCamera.h"
class ofApp : public ofBaseApp
{
public:
void mousePressed(ofMouseEventArgs &mouse);
void draw();
ofxFirstPersonCamera cam;
};Enable first person camera control in setup call and set computed matrix to any ofCamera:
#include "ofApp.h"
void ofApp::mousePressed(ofMouseEventArgs &mouse)
{
cam.toggleControl();
}
void ofApp::draw()
{
cam.begin();
ofDrawGrid(10.0f, 10, true);
cam.end();
}