OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010, Google Inc. | 2 * Copyright 2010, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 for (var i = 0; i < 2; i++) { | 140 for (var i = 0; i < 2; i++) { |
141 o3d.ParamObject.setUpO3DParam_( | 141 o3d.ParamObject.setUpO3DParam_( |
142 o3d.ParamOp2FloatsToFloat2, "input"+i, "ParamFloat"); | 142 o3d.ParamOp2FloatsToFloat2, "input"+i, "ParamFloat"); |
143 } | 143 } |
144 o3d.ParamObject.setUpO3DParam_( | 144 o3d.ParamObject.setUpO3DParam_( |
145 o3d.ParamOp2FloatsToFloat2, "output", "ParamMatrix4Output"); | 145 o3d.ParamOp2FloatsToFloat2, "output", "ParamMatrix4Output"); |
146 })(); | 146 })(); |
147 | 147 |
148 /** | 148 /** |
149 * Called by o3d.Param*Output whenever its value gets read. | 149 * Called by o3d.Param*Output whenever its value gets read. |
150 * @return {Array<number>} 2-element array equal to [input0,input1] | 150 * @return {!Array<number>} 2-element array equal to [input0,input1] |
151 */ | 151 */ |
152 o3d.ParamOp2FloatsToFloat2.prototype.updateOutputs = function() { | 152 o3d.ParamOp2FloatsToFloat2.prototype.updateOutputs = function() { |
153 this.last_output_value_[0] = this.getParam("input0").value; | 153 this.last_output_value_[0] = this.getParam("input0").value; |
154 this.last_output_value_[1] = this.getParam("input1").value; | 154 this.last_output_value_[1] = this.getParam("input1").value; |
155 return this.last_output_value_; | 155 return this.last_output_value_; |
156 }; | 156 }; |
157 | 157 |
158 /** | 158 /** |
159 * A Param operation that takes 3 floats to produce a float3. | 159 * A Param operation that takes 3 floats to produce a float3. |
160 * @constructor | 160 * @constructor |
161 * @extends {o3d.ParamObject} | 161 * @extends {o3d.ParamObject} |
162 */ | 162 */ |
163 o3d.ParamOp3FloatsToFloat3 = function() { | 163 o3d.ParamOp3FloatsToFloat3 = function() { |
164 o3d.ParamObject.call(this); | 164 o3d.ParamObject.call(this); |
165 this.last_output_value_ = [0,0,0]; | 165 this.last_output_value_ = [0,0,0]; |
166 }; | 166 }; |
167 o3d.inherit('ParamOp3FloatsToFloat3', 'ParamObject'); | 167 o3d.inherit('ParamOp3FloatsToFloat3', 'ParamObject'); |
168 | 168 |
169 (function(){ | 169 (function(){ |
170 for (var i = 0; i < 3; i++) { | 170 for (var i = 0; i < 3; i++) { |
171 o3d.ParamObject.setUpO3DParam_( | 171 o3d.ParamObject.setUpO3DParam_( |
172 o3d.ParamOp3FloatsToFloat3, "input"+i, "ParamFloat"); | 172 o3d.ParamOp3FloatsToFloat3, "input"+i, "ParamFloat"); |
173 } | 173 } |
174 o3d.ParamObject.setUpO3DParam_( | 174 o3d.ParamObject.setUpO3DParam_( |
175 o3d.ParamOp3FloatsToFloat3, "output", "ParamMatrix4Output"); | 175 o3d.ParamOp3FloatsToFloat3, "output", "ParamMatrix4Output"); |
176 })(); | 176 })(); |
177 | 177 |
178 /** | 178 /** |
179 * Called by o3d.Param*Output whenever its value gets read. | 179 * Called by o3d.Param*Output whenever its value gets read. |
180 * @return {Array<number>} 3-element array equal to [input0,input1,input2] | 180 * @return {!Array<number>} 3-element array equal to [input0,input1,input2] |
181 */ | 181 */ |
182 o3d.ParamOp3FloatsToFloat3.prototype.updateOutputs = function() { | 182 o3d.ParamOp3FloatsToFloat3.prototype.updateOutputs = function() { |
183 this.last_output_value_[0] = this.getParam("input0").value; | 183 this.last_output_value_[0] = this.getParam("input0").value; |
184 this.last_output_value_[1] = this.getParam("input1").value; | 184 this.last_output_value_[1] = this.getParam("input1").value; |
185 this.last_output_value_[2] = this.getParam("input2").value; | 185 this.last_output_value_[2] = this.getParam("input2").value; |
186 return this.last_output_value_; | 186 return this.last_output_value_; |
187 }; | 187 }; |
188 | 188 |
189 /** | 189 /** |
190 * A Param operation that takes 4 floats to produce a float4. | 190 * A Param operation that takes 4 floats to produce a float4. |
(...skipping 10 matching lines...) Expand all Loading... |
201 for (var i = 0; i < 4; i++) { | 201 for (var i = 0; i < 4; i++) { |
202 o3d.ParamObject.setUpO3DParam_( | 202 o3d.ParamObject.setUpO3DParam_( |
203 o3d.ParamOp4FloatsToFloat4, "input"+i, "ParamFloat"); | 203 o3d.ParamOp4FloatsToFloat4, "input"+i, "ParamFloat"); |
204 } | 204 } |
205 o3d.ParamObject.setUpO3DParam_( | 205 o3d.ParamObject.setUpO3DParam_( |
206 o3d.ParamOp4FloatsToFloat4, "output", "ParamMatrix4Output"); | 206 o3d.ParamOp4FloatsToFloat4, "output", "ParamMatrix4Output"); |
207 })(); | 207 })(); |
208 | 208 |
209 /** | 209 /** |
210 * Called by o3d.Param*Output whenever its value gets read. | 210 * Called by o3d.Param*Output whenever its value gets read. |
211 * @return {Array<number>} 4-element array equal to | 211 * @return {!Array<number>} 4-element array equal to |
212 * [input0,input1,input2,input3] | 212 * [input0,input1,input2,input3] |
213 */ | 213 */ |
214 o3d.ParamOp4FloatsToFloat4.prototype.updateOutputs = function() { | 214 o3d.ParamOp4FloatsToFloat4.prototype.updateOutputs = function() { |
215 this.last_output_value_[0] = this.getParam("input0").value; | 215 this.last_output_value_[0] = this.getParam("input0").value; |
216 this.last_output_value_[1] = this.getParam("input1").value; | 216 this.last_output_value_[1] = this.getParam("input1").value; |
217 this.last_output_value_[2] = this.getParam("input2").value; | 217 this.last_output_value_[2] = this.getParam("input2").value; |
218 this.last_output_value_[3] = this.getParam("input3").value; | 218 this.last_output_value_[3] = this.getParam("input3").value; |
219 return this.last_output_value_; | 219 return this.last_output_value_; |
220 }; | 220 }; |
221 | 221 |
(...skipping 12 matching lines...) Expand all Loading... |
234 for (var i = 0; i < 16; i++) { | 234 for (var i = 0; i < 16; i++) { |
235 o3d.ParamObject.setUpO3DParam_( | 235 o3d.ParamObject.setUpO3DParam_( |
236 o3d.ParamOp16FloatsToMatrix4, "input"+i, "ParamFloat"); | 236 o3d.ParamOp16FloatsToMatrix4, "input"+i, "ParamFloat"); |
237 } | 237 } |
238 o3d.ParamObject.setUpO3DParam_( | 238 o3d.ParamObject.setUpO3DParam_( |
239 o3d.ParamOp16FloatsToMatrix4, "output", "ParamMatrix4Output"); | 239 o3d.ParamOp16FloatsToMatrix4, "output", "ParamMatrix4Output"); |
240 })(); | 240 })(); |
241 | 241 |
242 /** | 242 /** |
243 * Called by o3d.Param*Output whenever its value gets read. | 243 * Called by o3d.Param*Output whenever its value gets read. |
244 * @return {Array<Array<number>>} 4x4 array equal to | 244 * @return {!Array<!Array<number>>} 4x4 array equal to |
245 * [[i0,i1,i2,i3],[i4,i5,i6,i7],[i8,i9,i10,i11],[i12,i13,i14,i15]] | 245 * [[i0,i1,i2,i3],[i4,i5,i6,i7],[i8,i9,i10,i11],[i12,i13,i14,i15]] |
246 */ | 246 */ |
247 o3d.ParamOp16FloatsToMatrix4.prototype.updateOutputs = function() { | 247 o3d.ParamOp16FloatsToMatrix4.prototype.updateOutputs = function() { |
248 for (var i = 0; i < 16; i++) { | 248 for (var i = 0; i < 16; i++) { |
249 this.last_output_value_[i/4][i%4] = this.getParam("input"+i).value; | 249 this.last_output_value_[Math.floor(i/4)][i%4] = |
| 250 this.getParam("input"+i).value; |
250 } | 251 } |
251 return this.last_output_value_; | 252 return this.last_output_value_; |
252 }; | 253 }; |
253 | 254 |
254 /** | 255 /** |
255 * A Param operation that takes 9 floats to produce a 4-by-4 matrix. | 256 * A Param operation that takes 9 floats to produce a 4-by-4 matrix. |
256 * The 9 floats encode a translation vector, angles of rotation around | 257 * The 9 floats encode a translation vector, angles of rotation around |
257 * the x, y, and z axes, and three scaling factors. The resulting | 258 * the x, y, and z axes, and three scaling factors. The resulting |
258 * transformation scales first, then then rotates around the z-axis, | 259 * transformation scales first, then then rotates around the z-axis, |
259 * then the y-axis, then the x-axis, then translates. | 260 * then the y-axis, then the x-axis, then translates. |
(...skipping 14 matching lines...) Expand all Loading... |
274 | 275 |
275 this.translateX = 0; | 276 this.translateX = 0; |
276 this.translateY = 0; | 277 this.translateY = 0; |
277 this.translateZ = 0; | 278 this.translateZ = 0; |
278 | 279 |
279 this.scaleX = 1; | 280 this.scaleX = 1; |
280 this.scaleY = 1; | 281 this.scaleY = 1; |
281 this.scaleZ = 1; | 282 this.scaleZ = 1; |
282 | 283 |
283 this.last_output_value_ = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]; | 284 this.last_output_value_ = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]; |
284 | |
285 this.createParam("output", "ParamMatrix4Output"); | |
286 }; | 285 }; |
287 o3d.inherit('TRSToMatrix4', 'ParamObject'); | 286 o3d.inherit('TRSToMatrix4', 'ParamObject'); |
288 | 287 |
289 (function(){ | 288 (function(){ |
290 var proplist = ["rotateX", "rotateY", "rotateZ", | 289 var proplist = ["rotateX", "rotateY", "rotateZ", |
291 "translateX", "translateY", "translateZ", | 290 "translateX", "translateY", "translateZ", |
292 "scaleX", "scaleY", "scaleZ"]; | 291 "scaleX", "scaleY", "scaleZ"]; |
293 for (var i = 0; i < proplist.length; i++) { | 292 for (var i = 0; i < proplist.length; i++) { |
294 o3d.ParamObject.setUpO3DParam_(o3d.TRSToMatrix4, proplist[i], "ParamFloat"); | 293 o3d.ParamObject.setUpO3DParam_(o3d.TRSToMatrix4, proplist[i], "ParamFloat"); |
295 } | 294 } |
296 o3d.ParamObject.setUpO3DParam_( | 295 o3d.ParamObject.setUpO3DParam_( |
297 o3d.TRSToMatrix4, "output", "ParamMatrix4Output"); | 296 o3d.TRSToMatrix4, "output", "ParamMatrix4Output"); |
298 })(); | 297 })(); |
299 | 298 |
300 /** | 299 /** |
301 * Called by o3d.Param*Output whenever its value gets read. | 300 * Called by o3d.Param*Output whenever its value gets read. |
302 * @return {matrix4} 4x4 array equal to Translate * Rotate * Scale. | 301 * @return {!Array<!Array<number>>} Matrix4 equal to Translate * Rotate * Scale. |
303 */ | 302 */ |
304 o3d.TRSToMatrix4.prototype.updateOutputs = function () { | 303 o3d.TRSToMatrix4.prototype.updateOutputs = function () { |
305 var ret = this.last_output_value_; | 304 var ret = this.last_output_value_; |
306 var rX = this.rotateX; | 305 var rX = this.rotateX; |
307 var rY = this.rotateY; | 306 var rY = this.rotateY; |
308 var rZ = this.rotateZ; | 307 var rZ = this.rotateZ; |
309 var sX = this.scaleX; | 308 var sX = this.scaleX; |
310 var sY = this.scaleY; | 309 var sY = this.scaleY; |
311 var sZ = this.scaleZ; | 310 var sZ = this.scaleZ; |
312 var sinX = Math.sin(rX); | 311 var sinX = Math.sin(rX); |
(...skipping 16 matching lines...) Expand all Loading... |
329 ret[2].splice(0, 4, (cosZSinY * cosX + sinZ * sinX) * sZ, | 328 ret[2].splice(0, 4, (cosZSinY * cosX + sinZ * sinX) * sZ, |
330 (sinZSinY * cosX - cosZ * sinX) * sZ, | 329 (sinZSinY * cosX - cosZ * sinX) * sZ, |
331 cosY * cosX * sZ, | 330 cosY * cosX * sZ, |
332 0); | 331 0); |
333 ret[3].splice(0, 4, this.translateX, | 332 ret[3].splice(0, 4, this.translateX, |
334 this.translateY, | 333 this.translateY, |
335 this.translateZ, | 334 this.translateZ, |
336 1); | 335 1); |
337 return ret; | 336 return ret; |
338 }; | 337 }; |
| 338 |
| 339 /** |
| 340 * A Param operation that takes 16 floats to produce a 4-by-4 matrix. |
| 341 * @constructor |
| 342 * @extends {o3d.ParamObject} |
| 343 */ |
| 344 o3d.Matrix4Composition = function() { |
| 345 o3d.ParamObject.call(this); |
| 346 this.last_output_value_ = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]; |
| 347 }; |
| 348 o3d.inherit('Matrix4Composition', 'ParamObject'); |
| 349 |
| 350 o3d.ParamObject.setUpO3DParam_( |
| 351 o3d.Matrix4Composition, "inputMatrix", "ParamMatrix4"); |
| 352 |
| 353 o3d.ParamObject.setUpO3DParam_( |
| 354 o3d.Matrix4Composition, "localMatrix", "ParamMatrix4"); |
| 355 |
| 356 o3d.ParamObject.setUpO3DParam_( |
| 357 o3d.Matrix4Composition, "outputMatrix", "ParamMatrix4Output"); |
| 358 |
| 359 /** |
| 360 * Called by o3d.Param*Output whenever its value gets read. |
| 361 * @return {!Array<!Array<number>>} 4x4 array equal to |
| 362 * [[i0,i1,i2,i3],[i4,i5,i6,i7],[i8,i9,i10,i11],[i12,i13,i14,i15]] |
| 363 */ |
| 364 o3d.Matrix4Composition.prototype.updateOutputs = function() { |
| 365 o3d.Transform.compose(this.inputMatrix, this.localMatrix, |
| 366 this.last_output_value_); |
| 367 return this.last_output_value_; |
| 368 }; |
| 369 |
| 370 |
OLD | NEW |