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