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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
#include "chainImage.h"
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
float distance(ofPoint p1,ofPoint p2){
return pow(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2),0.5);
}
void chainImage::init(ofPoint _linkPos,float _linkScale,float _linkRot){
linkPos=_linkPos;
linkScale=_linkScale;
linkRot=_linkRot;
setAnchorPercent(0.5,0.5);
}
void chainImage::start(bool reverse){
transition=reverse?1.0f:0.0f;
time=ofGetElapsedTimef();
setUseTexture(true);
scale=reverse?linkScale*link->linkScale:linkScale;
}
int chainImage::updateOutput(float decayRatio){
//where there is rotation of the link, the path needs to be rotated
path.clear();
path.addVertex(linkPos);
//path.addVertex(linkPos+(link->linkPos*linkScale));
ofPoint rotated_destination=ofPoint(
(link->linkPos.x*cos(linkRot*(PI/180)))-(link->linkPos.y*sin(linkRot*(PI/180))),
(link->linkPos.y*cos(linkRot*(PI/180)))+(link->linkPos.x*sin(linkRot*(PI/180)))
);
ofPoint destination=linkPos+(rotated_destination*linkScale);
ofPoint previous=linkPos+(rotated_destination*linkScale*(1.0f-BEZIER_IN));
path.bezierTo(
linkPos.x*(1.0f+BEZIER_OUT),linkPos.y*(1.0f+BEZIER_OUT),
previous.x,previous.y,
destination.x,destination.y);
//totalframes=log(1.0f/256)/log(decayRatio);
scale*=decayRatio;
//framecount++;
//find n such that decayRatio^n=1/256
//logarithm of x base b = log(x)/log(b)
//log(decayRatio,decayRatio^n)
//n = log(decayRatio,1/256)
transition=-(scale-linkScale)/(linkScale-(linkScale*link->linkScale));
//transition=min(1.0f,((float)framecount)/totalframes);
if (scale>linkScale){
transition = 0.0f;
return SWITCH_REVERSE;
}
if (scale>linkScale*link->linkScale){
return SWITCH_NONE;
}
transition = 1.0f;
return SWITCH_FORWARD;
}
ofVec3f chainImage::getTransform(){
//ofVec3f _scaledTarget = link->linkPos * linkScale;
//return linkPos + ( _scaledTarget * transition );
//ofPoint
return path.getPointAtPercent(transition);
}
float chainImage::getScale(){
return scale;
}
float chainImage::getRotation(){
//this is the camera rotation
//at the beginning of the transition
//this should rotate to match linkRot
//at the end, it should match link->linkRot
//when we switch image, link->linkRot becomes linkRot
//linkRot is no longer seen
return linkRot+(transition*link->linkRot); //linkRot+
};
void chainImage::makeThumbnail(){
thumbnail=(const ofImage)*this; //copy the ofImage itself
float thumbheight=THUMB_SIZE; //ofGetWindowHeight()*THUMB_BORDER_RATIO;
float thumbwidth=(thumbnail.getWidth()/thumbnail.getHeight())*thumbheight;
float borderwidth=ofGetWindowHeight()*(1.0-THUMB_BORDER_RATIO)*0.5;
printf("Rescaling: %fx%f to %fx%f for screen %fx%f, border %f\n",
thumbnail.getWidth(),thumbnail.getHeight(),
thumbwidth,thumbheight,
(float)ofGetWindowWidth(),(float)ofGetWindowHeight(),
borderwidth);
thumbnail.resize(thumbwidth,thumbheight);
thumbnail.setAnchorPoint(thumbnail.getWidth()/2,thumbnail.getHeight()/2);
}
void chainImage::drawChain(float fadeIn,bool additive, float intensity){
//printf("Drawing chain transition: %f\n",transition);
//we are correctly geting to 1
//the transformw don't quite add up?
glPushMatrix();
if (additive){
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
ofSetColor(255,255,255,255*(1.0f-min(1.0,transition/fadeIn))*intensity);
}
else {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ofSetColor(255,255,255,255*intensity);
}
//ofDisableAlphaBlending();
setAnchorPoint(getWidth()/2,getHeight()/2);
draw(0,0,getWidth(),getHeight());
glTranslatef(linkPos.x,linkPos.y,0);
glRotatef(linkRot,0,0,1);
glScalef(linkScale,linkScale,linkScale);
//ofEnableAlphaBlending();
glEnable(GL_BLEND);
ofSetColor(255,255,255,255*min(1.0,transition/fadeIn)*intensity);
link->setAnchorPoint(link->getWidth()/2,link->getHeight()/2);
link->draw(0,0,link->getWidth(),link->getHeight());
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glPopMatrix();
}
Json::Value chainImage::toJson(){
Json::Value json=Json::Value(Json::objectValue);
json["linkPos"]=Json::Value(Json::arrayValue);
json["linkPos"].append(linkPos.x);
json["linkPos"].append(linkPos.y);
json["linkScale"]=linkScale;
json["linkRot"]=linkRot;
json["filename"]=filename;
return json;
}
bool chainImage::fromJson(Json::Value json){
if (load(json["filename"].asString())){
linkPos=ofPoint(json["linkPos"][0].asDouble(),json["linkPos"][1].asDouble());
linkScale=json["linkScale"].asDouble();
linkRot=json["linkRot"].asDouble();
return true;
}
return false;
}
|