diff options
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/particle.js')
-rwxr-xr-x | js/helper-classes/RDGE/src/core/script/particle.js | 1594 |
1 files changed, 797 insertions, 797 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/particle.js b/js/helper-classes/RDGE/src/core/script/particle.js index d1ab6239..59894e9a 100755 --- a/js/helper-classes/RDGE/src/core/script/particle.js +++ b/js/helper-classes/RDGE/src/core/script/particle.js | |||
@@ -1,797 +1,797 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility, Inc |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | 4 | BSD License. |
5 | 5 | ||
6 | Redistribution and use in source and binary forms, with or without | 6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 7 | modification, are permitted provided that the following conditions are met: |
8 | 8 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 9 | - Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 10 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 11 | - Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the | 12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. | 13 | documentation and/or other materials provided with the distribution. |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 14 | - Neither the name of Motorola Mobility nor the names of its contributors |
15 | may be used to endorse or promote products derived from this software | 15 | may be used to endorse or promote products derived from this software |
16 | without specific prior written permission. | 16 | without specific prior written permission. |
17 | 17 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 25 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 26 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 27 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
28 | POSSIBILITY OF SUCH DAMAGE. | 28 | POSSIBILITY OF SUCH DAMAGE. |
29 | </copyright> */ | 29 | </copyright> */ |
30 | 30 | ||
31 | var RDGE = RDGE || {}; | 31 | var RDGE = RDGE || {}; |
32 | 32 | ||
33 | RDGE.particle = function (def, id) { | 33 | RDGE.particle = function (def, id) { |
34 | this.id = id; | 34 | this.id = id; |
35 | this.def = def; | 35 | this.def = def; |
36 | if (this.def.numFrames == undefined) { | 36 | if (this.def.numFrames == undefined) { |
37 | if (this.def.textureSize && this.def.frameSize) { | 37 | if (this.def.textureSize && this.def.frameSize) { |
38 | this.def.numFrames = (this.def.textureSize[0] / this.def.frameSize[0]) * (this.def.textureSize[1] / this.def.frameSize[1]); | 38 | this.def.numFrames = (this.def.textureSize[0] / this.def.frameSize[0]) * (this.def.textureSize[1] / this.def.frameSize[1]); |
39 | } else { | 39 | } else { |
40 | this.def.numFrames = 0; | 40 | this.def.numFrames = 0; |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | this.pos = RDGE.vec3.zero(); | 44 | this.pos = RDGE.vec3.zero(); |
45 | this.delta = RDGE.vec3.zero(); | 45 | this.delta = RDGE.vec3.zero(); |
46 | this.rotate = 0.0; | 46 | this.rotate = 0.0; |
47 | this.age = 0.0; | 47 | this.age = 0.0; |
48 | this.lifespan = 0.0; | 48 | this.lifespan = 0.0; |
49 | this.velocity = RDGE.vec3.zero(); | 49 | this.velocity = RDGE.vec3.zero(); |
50 | this.gravity = RDGE.vec3.zero(); | 50 | this.gravity = RDGE.vec3.zero(); |
51 | this.frame = 0; | 51 | this.frame = 0; |
52 | this.frameCount = 0; | 52 | this.frameCount = 0; |
53 | this.lastPos = RDGE.vec3.zero(); | 53 | this.lastPos = RDGE.vec3.zero(); |
54 | this.state = 0; | 54 | this.state = 0; |
55 | this.hide = false; | 55 | this.hide = false; |
56 | this.color = RDGE.vec4.zero(); | 56 | this.color = RDGE.vec4.zero(); |
57 | 57 | ||
58 | this.randomize = function (min, max) { | 58 | this.randomize = function (min, max) { |
59 | return min + (max - min) * Math.random(); | 59 | return min + (max - min) * Math.random(); |
60 | }; | 60 | }; |
61 | this.rate = this.randomize(-1.0, 1.0); | 61 | this.rate = this.randomize(-1.0, 1.0); |
62 | 62 | ||
63 | this.randomize3 = function (min, max) { | 63 | this.randomize3 = function (min, max) { |
64 | return [this.randomize(min[0], max[0]), | 64 | return [this.randomize(min[0], max[0]), |
65 | this.randomize(min[1], max[1]), | 65 | this.randomize(min[1], max[1]), |
66 | this.randomize(min[2], max[2])]; | 66 | this.randomize(min[2], max[2])]; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | this.spawn = function (spawnMatrix) { | 69 | this.spawn = function (spawnMatrix) { |
70 | if (this.def.initialframe == undefined) { | 70 | if (this.def.initialframe == undefined) { |
71 | this.frame = this.id % this.def.numFrames; | 71 | this.frame = this.id % this.def.numFrames; |
72 | } else { | 72 | } else { |
73 | this.frame = this.randomize(this.def.initialframe[0], this.def.initialframe[1]); | 73 | this.frame = this.randomize(this.def.initialframe[0], this.def.initialframe[1]); |
74 | } | 74 | } |
75 | this.pos = this.randomize3(this.def.initialpos[0], this.def.initialpos[1]); | 75 | this.pos = this.randomize3(this.def.initialpos[0], this.def.initialpos[1]); |
76 | if (this.def.worldSpace) { | 76 | if (this.def.worldSpace) { |
77 | // calculate the initial position in world space. | 77 | // calculate the initial position in world space. |
78 | this.pos = RDGE.mat4.transformPoint(spawnMatrix, this.pos); | 78 | this.pos = RDGE.mat4.transformPoint(spawnMatrix, this.pos); |
79 | } | 79 | } |
80 | // all other values are assumed to be defined in local or world space depending on | 80 | // all other values are assumed to be defined in local or world space depending on |
81 | // the particles worldSpace designation. | 81 | // the particles worldSpace designation. |
82 | var toRadians = Math.PI / 180.0; | 82 | var toRadians = Math.PI / 180.0; |
83 | if (this.def.initialsize) { | 83 | if (this.def.initialsize) { |
84 | this.size = this.randomize(this.def.initialsize[0], this.def.initialsize[1]); | 84 | this.size = this.randomize(this.def.initialsize[0], this.def.initialsize[1]); |
85 | } else { | 85 | } else { |
86 | this.size = 1.0; | 86 | this.size = 1.0; |
87 | } | 87 | } |
88 | this.velocity = this.randomize3(this.def.initialvel[0], this.def.initialvel[1]); | 88 | this.velocity = this.randomize3(this.def.initialvel[0], this.def.initialvel[1]); |
89 | this.gravity = [this.def.gravity[0], this.def.gravity[1], this.def.gravity[2]]; | 89 | this.gravity = [this.def.gravity[0], this.def.gravity[1], this.def.gravity[2]]; |
90 | this.rotate = this.randomize(this.def.initialrot[0] * toRadians, this.def.initialrot[1] * toRadians); | 90 | this.rotate = this.randomize(this.def.initialrot[0] * toRadians, this.def.initialrot[1] * toRadians); |
91 | this.lifespan = this.randomize(this.def.lifespan[0], this.def.lifespan[1]); | 91 | this.lifespan = this.randomize(this.def.lifespan[0], this.def.lifespan[1]); |
92 | this.age = 0.0; | 92 | this.age = 0.0; |
93 | this.delta = [0.0, 0.0, 0.0]; | 93 | this.delta = [0.0, 0.0, 0.0]; |
94 | this.lastPos = RDGE.vec3.add(this.pos, RDGE.vec3.scale(this.velocity, -1.0 / 30.0)); | 94 | this.lastPos = RDGE.vec3.add(this.pos, RDGE.vec3.scale(this.velocity, -1.0 / 30.0)); |
95 | this.color = [1, 1, 1, 1]; //RDGE.vec4.random( [0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0] ); | 95 | this.color = [1, 1, 1, 1]; //RDGE.vec4.random( [0.0, 0.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0] ); |
96 | }; | 96 | }; |
97 | }; | 97 | }; |
98 | 98 | ||
99 | // double buffered array utility class | 99 | // double buffered array utility class |
100 | RDGE.DoubleBuffer = function (arrType, size) { | 100 | RDGE.DoubleBuffer = function (arrType, size) { |
101 | this.buffer = {}; | 101 | this.buffer = {}; |
102 | this.buffer[0] = new arrType(size); | 102 | this.buffer[0] = new arrType(size); |
103 | this.buffer[1] = new arrType(size); | 103 | this.buffer[1] = new arrType(size); |
104 | this.bufferIndex = 0; | 104 | this.bufferIndex = 0; |
105 | 105 | ||
106 | this.flip = function () { | 106 | this.flip = function () { |
107 | this.bufferIndex = 1 - this.bufferIndex; | 107 | this.bufferIndex = 1 - this.bufferIndex; |
108 | } | 108 | } |
109 | this.front = function () { | 109 | this.front = function () { |
110 | return this.buffer[this.bufferIndex]; | 110 | return this.buffer[this.bufferIndex]; |
111 | } | 111 | } |
112 | this.back = function () { | 112 | this.back = function () { |
113 | return this.buffer[1 - this.bufferIndex]; | 113 | return this.buffer[1 - this.bufferIndex]; |
114 | } | 114 | } |
115 | }; | 115 | }; |
116 | 116 | ||
117 | 117 | ||
118 | // cycling buffer | 118 | // cycling buffer |
119 | RDGE.particleBuffer = function (pdef, emitter, size) { | 119 | RDGE.particleBuffer = function (pdef, emitter, size) { |
120 | var renderer = RDGE.globals.engine.getContext().renderer; | 120 | var renderer = RDGE.globals.engine.getContext().renderer; |
121 | var ctx = renderer.ctx; | 121 | var ctx = renderer.ctx; |
122 | 122 | ||
123 | s_particleShader = new RDGE.jshader(); | 123 | s_particleShader = new RDGE.jshader(); |
124 | s_particleShader.def = { | 124 | s_particleShader.def = { |
125 | 'shaders': { | 125 | 'shaders': { |
126 | 'defaultVShader': "assets/shaders/particle_vshader.glsl", |