comparison nodejs/mbapp.js @ 1379:f0a156705977

Implement changeScene for the scribbo animation.
author wycc
date Tue, 22 Mar 2011 01:03:59 +0800
parents 4c5bcaba28ea
children 76d2aad5da35
comparison
equal deleted inserted replaced
1378:9ce82873d406 1379:f0a156705977
144 } 144 }
145 } 145 }
146 } 146 }
147 147
148 app.prototype.generateScaleTween=function(src,dest,p) { 148 app.prototype.generateScaleTween=function(src,dest,p) {
149 sys.puts("p="+ p); 149 //sys.puts("p="+ p);
150 if (p == 0) {
151 if (src.dup) src.dup.hide();
152 src.show();
153 return;
154 }
155 src.hide(); 150 src.hide();
156 // Duplicate the group 151 // Duplicate the group
152 var nodes = src.node.childNodes();
157 if (src.dup == null) { 153 if (src.dup == null) {
158 dup = src.parent.clone_from_subtree(src); 154 dup = this.mb_rt.coord_new(src.parent);
155 for (i in nodes) {
156 n = nodes[i];
157 g = dup.clone_from_subtree(n.coord);
158 n.coord.dup = g;
159 }
159 src.dup = dup; 160 src.dup = dup;
160 } else { 161 } else {
161 dup = src.dup; 162 dup = src.dup;
162 } 163 src.dup.show();
163 dup.hide(); 164 }
164 sys.puts(dup); 165 //dup.hide();
165 166 //dest.hide();
166 167 //sys.puts(dup);
167 for(n in dup) { 168
168 169 for(i in nodes) {
169 170 n= nodes[i];
170 } 171 coord = n.coord;
172 var attr = n.attr('id');
173 if (attr == null) continue;
174 var id = attr.value();
175 this.generateScaleTweenObject(coord.dup,coord,coord.target,p);
176 }
177 }
178 function printcoord(s)
179 {
180 sys.puts(s[0]+" "+s[1]+" "+s[2]+" "+s[3]+" "+s[4]+" "+s[5]);
181 }
182
183 function mul(a,b)
184 {
185 return [a[0]*b[0]+a[1]*b[3], a[0]*b[1]+a[1]*b[4], a[0]*b[2]+a[1]*b[5]+a[2],
186 a[3]*b[0]+a[4]*b[3], a[3]*b[1]+a[4]*b[4], a[3]*b[2]+a[4]*b[5]+a[5]];
187 }
188
189 app.prototype.generateScaleTweenObject=function(coord,src,dest,p) {
190 sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty);
191 sys.puts("dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty);
192 var p1 = 1-p;
193 var sx = src.sx*p+dest.sx*p1;
194 var sy = src.sy*p+dest.sy*p1;
195 var r = src.r*p+dest.r*p1;
196 var tx = src.tx*p+dest.tx*p1;
197 var ty = src.ty*p+dest.ty*p1;
198 var mt = [1, 0, -src.tx, 0, 1, -src.ty];
199 var ms;
200 if (r == 0) {
201 m = mt;
202 } else {
203 ms= [Math.cos(r), -Math.sin(r),0,Math.sin(r), Math.cos(r),0];
204 m = mul(ms,mt);
205 }
206 m = mul([sx,0,0,0,sy,0],m);
207 m = mul([1,0,tx,0,1,ty],m);
208 //m[2] = -m[2];
209 coord[0] = m[0];
210 coord[1] = m[1];
211 coord[2] = m[2];
212 coord[3] = m[3];
213 coord[4] = m[4];
214 coord[5] = m[5];
215 //sys.puts(coord);
216 sys.puts(m[0]+","+m[1]+","+m[2]+","+m[3]+","+m[4]+","+m[5]);
171 } 217 }
172 218
173 app.prototype.changeScene=function(s) { 219 app.prototype.changeScene=function(s) {
174 var nth; 220 var nth;
175 if (typeof(s)=='number') { 221 if (typeof(s)=='number') {
185 if (nth >=scenes[i].start && nth <=scenes[i].end) { 231 if (nth >=scenes[i].start && nth <=scenes[i].end) {
186 if (scenes[i].type == 'normal' || i == scenes.length-1) { 232 if (scenes[i].type == 'normal' || i == scenes.length-1) {
187 this.get(scenes[i].ref).show(); 233 this.get(scenes[i].ref).show();
188 } else if (scenes[i].type == 'scale') { 234 } else if (scenes[i].type == 'scale') {
189 if (scenes[i].end == (scenes[i+1].start-1)) { 235 if (scenes[i].end == (scenes[i+1].start-1)) {
190 var p = (nth-scenes[i].start)/(scenes[i].end-scenes[i].start+1); 236 var p = 1-(nth-scenes[i].start)/(scenes[i].end-scenes[i].start+1);
191 this.generateScaleTween(this.get(scenes[i].ref),this.get(scenes[i+1].ref),p); 237 this.generateScaleTween(this.get(scenes[i].ref),this.get(scenes[i+1].ref),p);
192 } else { 238 } else {
193 // If there is no second key frame defined, fall back to the normal 239 // If there is no second key frame defined, fall back to the normal
194 this.get(scenes[i].ref).show(); 240 this.get(scenes[i].ref).show();
195 } 241 }
242 this.get(scenes[i+1].ref).hide();
196 } 243 }
197 244
198 } else { 245 } else {
199 this.get(scenes[i].ref).hide(); 246 this.get(scenes[i].ref).hide();
200 } 247 }
201 } catch(e) { 248 } catch(e) {
202 sys.puts(e); 249 sys.puts(e);
203 sys.puts(scenes[i].ref); 250 sys.puts(scenes[i].ref);
204 } 251 }
205 } 252 }
253 this.refresh();
206 } 254 }
207 255
208 app.prototype.runToScene=function(n) { 256 app.prototype.runToScene=function(n) {
209 257
210 } 258 }