Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 41 additions and 14 deletions.
  1. +35 −13 src/ofxGameCamera.cpp
  2. +6 −1 src/ofxGameCamera.h
48 src/ofxGameCamera.cpp
View
@@ -53,37 +53,42 @@ ofxGameCamera::ofxGameCamera() {
cameraPositionFile = "_gameCameraPosition.xml";
}
-void ofxGameCamera::begin(ofRectangle rect) {
- ofVec3f startPos = getPosition();
- ofVec2f startRot = ofVec3f(rotationX, rotationY, rotationZ);
+void ofxGameCamera::setup(){
+ ofAddListener(ofEvents().update, this, &ofxGameCamera::update);
+}
+void ofxGameCamera::update(ofEventArgs& args){
+
+ ofVec3f startPos = getPosition();
+ ofVec2f startRot = ofVec3f(rotationX, rotationY, rotationZ);
+
//forward
if(applyTranslation){
if(ofGetKeyPressed('w') || (useArrowKeys && ofGetKeyPressed(OF_KEY_UP)) ){
targetNode.dolly(-speed);
//dolly(-speed);
}
-
+
if(ofGetKeyPressed('s') || (useArrowKeys && ofGetKeyPressed(OF_KEY_DOWN)) ){
targetNode.dolly(speed);
//dolly(speed);
}
-
+
if(ofGetKeyPressed('a') || (useArrowKeys && ofGetKeyPressed(OF_KEY_LEFT)) ){
targetNode.truck(-speed);
//truck(-speed);
}
-
+
if(ofGetKeyPressed('d') || (useArrowKeys && ofGetKeyPressed(OF_KEY_RIGHT)) ){
targetNode.truck(speed);
//truck(speed);
}
-
+
if(ofGetKeyPressed('c') || (useArrowKeys && ofGetKeyPressed(OF_KEY_PAGE_DOWN)) ){
targetNode.boom(-speed);
//boom(-speed);
}
-
+
if(ofGetKeyPressed('e') || (useArrowKeys && ofGetKeyPressed(OF_KEY_PAGE_UP)) ){
targetNode.boom(speed);
}
@@ -95,18 +100,20 @@ void ofxGameCamera::begin(ofRectangle rect) {
if(applyRotation){
if(ofGetKeyPressed('r')){
targetZRot += rollSpeed;
-// updateRotation();
+ applyRotation = true;
+ // updateRotation();
}
if(ofGetKeyPressed('q')){
targetZRot -= rollSpeed;
-// updateRotation();
+ // updateRotation();
+ applyRotation = true;
}
}
-
+
ofVec2f mouse( ofGetMouseX(), ofGetMouseY() );
if(usemouse && applyRotation && ofGetMousePressed(0)){
-
+
float dx = (mouse.x - lastMouse.x) * sensitivityX;
float dy = (mouse.y - lastMouse.y) * sensitivityY;
targetXRot += dx;
@@ -121,11 +128,13 @@ void ofxGameCamera::begin(ofRectangle rect) {
}
lastMouse = mouse;
-
+
if(!ofGetMousePressed(0) && autosavePosition && (startPos != getPosition() || startRot != ofVec3f(rotationX, rotationY, rotationZ))){
saveCameraPosition();
}
+}
+void ofxGameCamera::begin(ofRectangle rect) {
ofCamera::begin(rect);
}
@@ -215,3 +224,16 @@ void ofxGameCamera::loadCameraPosition()
}
+void ofxGameCamera::reset(){
+ rotationX = 0.0f;
+ rotationY = 0.0f;
+ rotationZ = 0.0f;
+
+ targetXRot = 0.0f;
+ targetYRot = 0.0f;
+ targetZRot = 0.0f;
+
+ targetNode.setPosition(ofVec3f(0,0,0));
+ targetNode.setOrientation(ofQuaternion());
+
+}
7 src/ofxGameCamera.h
View
@@ -15,7 +15,11 @@ class ofxGameCamera : public ofCamera {
public:
ofxGameCamera();
-
+
+ void setup();
+
+ void update(ofEventArgs& args);
+
float sensitivityX;
float sensitivityY;
@@ -53,4 +57,5 @@ class ofxGameCamera : public ofCamera {
void loadCameraPosition();
void setAnglesFromOrientation();
+ void reset();
};

No commit comments for this range

Something went wrong with that request. Please try again.