-
Notifications
You must be signed in to change notification settings - Fork 3
/
CloudsRGBDCamera.cpp
executable file
·131 lines (104 loc) · 3.7 KB
/
CloudsRGBDCamera.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// CloudsCamera.cpp
// CLOUDS
//
// Created by James George on 6/14/13.
//
//
#include "CloudsRGBDCamera.h"
CloudsRGBDCamera::CloudsRGBDCamera(){
targetNode = NULL;
startNode = NULL;
sideDistance = 100;
frontDistance = 147.54;
sidePullback = -48;
liftAmount = 20;
liftRange = 65;
dropAmount = 33;
isSetup = false;
damp = .1;
driftNoisePosition = 0;
maxDriftAngle = 0;
// driftNoiseDensity = 0;
// driftNoiseSpeed = ;
}
void CloudsRGBDCamera::setup(){
if(!isSetup){
isSetup = true;
setPositionFromMouse();
currentPosition = targetPosition;
ofAddListener(ofEvents().update, this, &CloudsRGBDCamera::update);
}
}
void CloudsRGBDCamera::remove(){
if(isSetup){
isSetup = false;
ofRemoveListener(ofEvents().update, this, &CloudsRGBDCamera::update);
}
}
void CloudsRGBDCamera::update(ofEventArgs& args){
setPositionFromMouse();
if( targetNode != NULL && startNode != NULL ){
//cout << " transitioning" << endl;
//update transition
float t = transitionAmount;
ofQuaternion rotQuat;
rotQuat.slerp( t, startNode->getOrientationQuat(), targetNode->getOrientationQuat() );
setOrientation( ofQuaternion() );
setPosition( targetNode->getPosition()*t + startNode->getPosition()*(1.-t) );
setOrientation( rotQuat );
}
else{
setPosition( mouseBasedNode.getPosition() );
setOrientation( mouseBasedNode.getOrientationQuat() );
}
}
void CloudsRGBDCamera::setPositionFromMouse(){
float percentOnCurve = ofMap(ofGetMouseX(), ofGetWidth()*.2, ofGetWidth()*.8, 0, 1, true);
ofVec3f sidePositionLeft = lookTarget + ofVec3f(-sideDistance,0,sidePullback);
ofVec3f sidePositionRight = lookTarget + ofVec3f(sideDistance,0,sidePullback);
ofVec3f frontPosition = lookTarget + ofVec3f(0,0,-frontDistance);
ofVec3f position;
if(percentOnCurve > .5){
position = frontPosition.getInterpolated(sidePositionRight, ofMap(percentOnCurve, .5, 1.0, 0, 1.0) );
}
else{
position = sidePositionLeft.getInterpolated(frontPosition, ofMap(percentOnCurve, 0, .5, 0, 1.0) );
}
float liftDrift = ofMap(ofGetMouseY(), ofGetHeight()*.2, ofGetHeight()*.8, -liftRange,liftRange, true);
position.y += ofMap(abs(.5 - percentOnCurve), 0, .5, (liftDrift + liftAmount), (liftDrift-liftAmount)*.5);
position.z -= MAX(liftDrift,0) * .5; // zoom in on mouse up
targetPosition = position;
currentPosition += (targetPosition - currentPosition) * damp;
currentLookTarget = lookTarget - ofVec3f(0,dropAmount,0);
//calculate drift;
//ofVec3f driftOffset(0,0,0);
ofVec3f driftPosition = currentPosition;
float channelA = 1000;
float channelB = 1500;
if(maxDriftAngle > 0){
ofVec3f toCamera = currentPosition - currentLookTarget;
ofQuaternion driftQuatX,driftQuatY;
driftNoisePosition += driftNoiseSpeed;// * (ofGetElapsedTimef() - ofGetLastFrameTime());
float driftX = ofSignedNoise( channelA, driftNoisePosition );
float driftY = ofSignedNoise( channelB, driftNoisePosition );
driftPosition.rotate(driftX*maxDriftAngle, currentLookTarget, ofVec3f(0,1,0));
driftPosition.rotate(driftY*maxDriftAngle, currentLookTarget, ofVec3f(1,0,0));
// driftQuatX.makeRotate(maxDriftAngle*driftX, 0, 1, 0);
// driftQuatY.makeRotate(maxDriftAngle*driftY, 1, 0, 0);
// driftOffset = driftQuatX * driftQuatY * (ofVec3f(0,0,1) * toCamera.length());
}
mouseBasedNode.setPosition(driftPosition);
mouseBasedNode.lookAt(currentLookTarget);
}
void CloudsRGBDCamera::setTransitionStartNode( ofNode* _startNode ){
cout << "CloudsRGBDCamera::setStartNode: " << endl;
startNode = _startNode;
}
void CloudsRGBDCamera::setTransitionTargetNode( ofNode* _targetNode ){
cout << "CloudsRGBDCamera::setTargetNode: " << endl;
targetNode = _targetNode;
}
void CloudsRGBDCamera::setTransitionPercent( float t ){
transitionAmount = t;
}