Skip to content
Browse files

added rotation smoothing

  • Loading branch information...
1 parent 85b6dde commit e6534d6e1ae2b6ebc197adbe086cbe9b7bab2e50 @obviousjim obviousjim committed
Showing with 23 additions and 12 deletions.
  1. +2 −1 example/GameCameraExample.xcodeproj/project.pbxproj
  2. +18 −11 src/ofxGameCamera.cpp
  3. +3 −0 src/ofxGameCamera.h
View
3 example/GameCameraExample.xcodeproj/project.pbxproj
@@ -189,8 +189,8 @@
isa = PBXGroup;
children = (
E4B69E1D0A3A1BDC003C02F2 /* main.cpp */,
- E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */,
E4B69E1F0A3A1BDC003C02F2 /* testApp.h */,
+ E4B69E1E0A3A1BDC003C02F2 /* testApp.cpp */,
);
path = src;
sourceTree = SOURCE_ROOT;
@@ -282,6 +282,7 @@
isa = PBXProject;
buildConfigurationList = E4B69B4D0A3A1720003C02F2 /* Build configuration list for PBXProject "GameCameraExample" */;
compatibilityVersion = "Xcode 2.4";
+ developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
View
29 src/ofxGameCamera.cpp
@@ -104,12 +104,19 @@ void ofxGameCamera::begin(ofRectangle rect)
ofVec2f mouse( ofGetMouseX(), ofGetMouseY() );
if(usemouse && ofGetMousePressed(0) && applyRotation){
+
- rotationX += (mouse.x - lastMouse.x) * sensitivityX;
- rotationX = ClampAngle(rotationX, minimumX, maximumX);
+ targetXRot += (mouse.x - lastMouse.x) * sensitivityX;
+ targetXRot = ClampAngle(targetXRot, minimumX, maximumX);
- rotationY += (mouse.y - lastMouse.y) * sensitivityY;
- rotationY = ClampAngle(rotationY, minimumY, maximumY);
+ targetYRot += (mouse.y - lastMouse.y) * sensitivityY;
+ targetYRot = ClampAngle(targetYRot, minimumY, maximumY);
+
+// rotationX += (mouse.x - lastMouse.x) * sensitivityX;
+// rotationX = ClampAngle(rotationX, minimumX, maximumX);
+//
+// rotationY += (mouse.y - lastMouse.y) * sensitivityY;
+// rotationY = ClampAngle(rotationY, minimumY, maximumY);
// cout << "Rotation X " << rotationX << " Rotation Y " << rotationY << " Rotation Z " << rotationZ << " up vec " << getYAxis() << endl;
// cout << "Rotation X " << rotationX << " Rotation Y " << rotationY << " Rotation Z " << rotationZ << endl;
@@ -130,15 +137,14 @@ void ofxGameCamera::begin(ofRectangle rect)
void ofxGameCamera::updateRotation()
{
+ rotationX += (targetXRot - rotationX) *.2;
+ rotationY += (targetYRot - rotationY) *.2;
+
setOrientation(ofQuaternion(0,0,0,1)); //reset
rotate(ofQuaternion(-rotationX, getYAxis()));
rotate(ofQuaternion(-rotationY, getXAxis()));
rotate(ofQuaternion(-rotationZ, getZAxis()));
targetNode.setOrientation(getOrientationQuat());
-
- //lookAt(getPosition()+getLookAtDir()*3, ofVec3f(0,1,0));
-
-// targetNode.lookAt(getPosition()+getXAxis()*3, ofVec3f(0,1,0));
}
void ofxGameCamera::saveCameraPosition()
@@ -162,6 +168,7 @@ void ofxGameCamera::saveCameraPosition()
savePosition.addValue("X", rotationX);
savePosition.addValue("Y", rotationY);
savePosition.addValue("Z", rotationZ);
+
// savePosition.addValue("FOV", getFov());
savePosition.popTag(); //pop rotation
@@ -186,9 +193,9 @@ void ofxGameCamera::loadCameraPosition()
loadPosition.popTag();
loadPosition.pushTag("rotation");
- rotationX = loadPosition.getValue("X", 0.);
- rotationY = loadPosition.getValue("Y", 0.);
- rotationZ = loadPosition.getValue("Z", 0.);
+ targetXRot = rotationX = loadPosition.getValue("X", 0.);
+ targetYRot = rotationY = loadPosition.getValue("Y", 0.);
+ targetZRot = rotationZ = loadPosition.getValue("Z", 0.);
float fov = loadPosition.getValue("FOV", -1);
if(fov != -1){
setFov(fov);
View
3 src/ofxGameCamera.h
@@ -28,6 +28,9 @@ class ofxGameCamera : public ofCamera {
float rotationX;
float rotationY;
float rotationZ;
+ float targetXRot;
+ float targetYRot;
+ float targetZRot;
float speed;

0 comments on commit e6534d6

Please sign in to comment.
Something went wrong with that request. Please try again.