aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/linear-gradient-material.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-06-19 10:25:16 -0700
committerJose Antonio Marquez2012-06-19 10:25:16 -0700
commit4d2a5acd1631f0cf4e38f127c886f481668ddce0 (patch)
tree3bc8f2b21826c0ee6d37bc77753d45a882783cbf /js/lib/rdge/materials/linear-gradient-material.js
parent616b31a644ee221edcbc19f821b2194e8edf9fad (diff)
parent483ad57efcd6475776f580c3af5b60e6deeaf781 (diff)
downloadninja-4d2a5acd1631f0cf4e38f127c886f481668ddce0.tar.gz
Merge branch 'refs/heads/Ninja-Internal' into FileIO
Diffstat (limited to 'js/lib/rdge/materials/linear-gradient-material.js')
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js250
1 files changed, 9 insertions, 241 deletions
diff --git a/js/lib/rdge/materials/linear-gradient-material.js b/js/lib/rdge/materials/linear-gradient-material.js
index 9b331fa7..7e53db84 100755
--- a/js/lib/rdge/materials/linear-gradient-material.js
+++ b/js/lib/rdge/materials/linear-gradient-material.js
@@ -12,7 +12,7 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
12 /////////////////////////////////////////////////////////////////////// 12 ///////////////////////////////////////////////////////////////////////
13 // Instance variables 13 // Instance variables
14 /////////////////////////////////////////////////////////////////////// 14 ///////////////////////////////////////////////////////////////////////
15 this._name = "LinearGradientMaterial"; 15 this._name = "Linear Gradient";
16 this._shaderName = "linearGradient"; 16 this._shaderName = "linearGradient";
17 17
18 this._color1 = [1, 0, 0, 1]; 18 this._color1 = [1, 0, 0, 1];
@@ -31,132 +31,14 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
31 /////////////////////////////////////////////////////////////////////// 31 ///////////////////////////////////////////////////////////////////////
32 // Property Accessors 32 // Property Accessors
33 /////////////////////////////////////////////////////////////////////// 33 ///////////////////////////////////////////////////////////////////////
34 this.getShaderName = function () { 34 this.getShaderDef = function() { return linearGradientMaterialDef; }
35 return this._shaderName;
36 };
37
38 this.getName = function () {
39 return this._name;
40 };
41
42 this.getColor1 = function () {
43 return this._color1;
44 };
45
46 this.setColor1 = function (c) {
47 this._color1 = c.slice();
48
49 if (this._shader && this._shader['default']) {
50 this._shader['default'].u_color1.set(c);
51 }
52 };
53
54 this.getColor2 = function () {
55 return this._color2;
56 };
57
58 this.setColor2 = function (c) {
59 this._color2 = c.slice();
60
61 if (this._shader && this._shader['default']) {
62 this._shader['default'].u_color2.set(c);
63 }
64 };
65
66 this.getColor3 = function () {
67 return this._color3;
68 };
69
70 this.setColor3 = function (c) {
71 this._color3 = c.slice();
72
73 if (this._shader && this._shader['default']) {
74 this._shader['default'].u_color3.set(c);
75 }
76 };
77
78 this.getColor4 = function () {
79 return this._color4;
80 };
81
82 this.setColor4 = function (c) {
83 this._color4 = c.slice();
84
85 if (this._shader && this._shader['default']) {
86 this._shader['default'].u_color4.set(c);
87 }
88 };
89
90 this.getColorStop1 = function () {
91 return this._colorStop1;
92 };
93
94 this.setColorStop1 = function (s) {
95 this._colorStop1 = s;
96
97 if (this._shader && this._shader['default']) {
98 this._shader['default'].u_colorStop1.set([s]);
99 }
100 };
101
102 this.getColorStop2 = function () {
103 return this._colorStop2;
104 };
105
106 this.setColorStop2 = function (s) {
107 this._colorStop2 = s;
108
109 if (this._shader && this._shader['default']) {
110 this._shader['default'].u_colorStop2.set([s]);
111 }
112 };
113
114 this.getColorStop3 = function () {
115 return this._colorStop3;
116 };
117
118 this.setColorStop3 = function (s) {
119 this._colorStop3 = s;
120
121 if (this._shader && this._shader['default']) {
122 this._shader['default'].u_colorStop3.set([s]);
123 }
124 };
125
126 this.getColorStop4 = function () {
127 return this._colorStop4;
128 };
129
130 this.setColorStop4 = function (s) {
131 this._colorStop4 = s;
132
133 if (this._shader && this._shader['default']) {
134 this._shader['default'].u_colorStop4.set([s]);
135 }
136 };
137
138 this.getAngle = function () {
139 return this._angle;
140 };
141
142 this.setAngle = function (a) {
143 this._angle = a;
144
145 if (this._shader && this._shader['default']) {
146 this._shader['default'].u_cos_sin_angle.set([Math.cos(a), Math.sin(a)]);
147 }
148 };
149
150 this.isAnimated = function () {
151 return false;
152 };
153 35
154 /////////////////////////////////////////////////////////////////////// 36 ///////////////////////////////////////////////////////////////////////
155 // Material Property Accessors 37 // Material Property Accessors
156 /////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////
157 this._propNames = ["color1", "color2", "color3", "color4", "colorStop1", "colorStop2", "colorStop3", "colorStop4", "angle"]; 39 this._propNames = ["u_color1", "u_color2", "u_color3", "u_color4", "u_colorStop1", "u_colorStop2", "u_colorStop3", "u_colorStop4", "u_cos_sin_angle"];
158 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4", "Angle"]; 40 this._propLabels = ["Color 1", "Color 2", "Color 3", "Color 4", "Color Stop 1", "Color Stop 2", "Color Stop 3", "Color Stop 4", "Angle"];
159 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float", "float"]; 41 this._propTypes = ["color", "color", "color", "color", "float", "float", "float", "float", "vector2d"];
160 this._propValues = []; 42 this._propValues = [];
161 43
162 this._propValues[this._propNames[0]] = this._color1.slice(0); 44 this._propValues[this._propNames[0]] = this._color1.slice(0);
@@ -169,49 +51,12 @@ var LinearGradientMaterial = function LinearGradientMaterial() {
169 this._propValues[this._propNames[6]] = this._colorStop3; 51 this._propValues[this._propNames[6]] = this._colorStop3;
170 this._propValues[this._propNames[7]] = this._colorStop4; 52 this._propValues[this._propNames[7]] = this._colorStop4;
171 53
172 this._propValues[this._propNames[8]] = this._angle; 54 this._propValues[this._propNames[8]] = [ Math.cos(this._angle), Math.sin(this._angle) ];
173
174 this.setProperty = function (prop, value) {
175 if (prop === "color") prop = "color1";
176
177 // make sure we have legitimate imput
178 var ok = this.validateProperty(prop, value);
179 if (!ok) {
180 console.log("invalid property in Linear Gradient Material" + prop + " : " + value);
181 }
182
183 switch (prop) {
184 case "color1": this.setColor1(value); break;
185 case "color2": this.setColor2(value); break;
186 case "color3": this.setColor3(value); break;
187 case "color4": this.setColor4(value); break;
188 case "colorStop1": this.setColorStop1(value); break;
189 case "colorStop2": this.setColorStop2(value); break;
190 case "colorStop3": this.setColorStop3(value); break;
191 case "colorStop4": this.setColorStop4(value); break;
192 case "angle": this.setAngle(value); break;
193 }
194 };
195 55
196 /////////////////////////////////////////////////////////////////////// 56 ///////////////////////////////////////////////////////////////////////
197 // Methods 57 // Methods
198 /////////////////////////////////////////////////////////////////////// 58 ///////////////////////////////////////////////////////////////////////
199 // duplcate method requirde 59 // duplcate method requirde
200 this.dup = function () {
201 // allocate a new material
202 var newMat = new LinearGradientMaterial();
203
204 // copy over the current values;
205 var propNames = [], propValues = [], propTypes = [], propLabels = [];
206 this.getAllProperties( propNames, propValues, propTypes, propLabels);
207 var n = propNames.length;
208 for (var i=0; i<n; i++) {
209 newMat.setProperty( propNames[i], propValues[i] );
210 }
211 newMat._textureTransform = this._textureTransform.slice();
212
213 return newMat;
214 };
215 60
216 this.init = function (world) { 61 this.init = function (world) {
217 this.setWorld(world); 62 this.setWorld(world);
@@ -225,91 +70,14 @@ var LinearGradien