diff options
Diffstat (limited to 'js/lib/rdge/runtime/RuntimeGeomObj.js')
-rw-r--r-- | js/lib/rdge/runtime/RuntimeGeomObj.js | 633 |
1 files changed, 0 insertions, 633 deletions
diff --git a/js/lib/rdge/runtime/RuntimeGeomObj.js b/js/lib/rdge/runtime/RuntimeGeomObj.js deleted file mode 100644 index 3dc81be2..00000000 --- a/js/lib/rdge/runtime/RuntimeGeomObj.js +++ /dev/null | |||
@@ -1,633 +0,0 @@ | |||
1 | |||
2 | /* <copyright> | ||
3 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
4 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
5 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
6 | </copyright> */ | ||
7 | |||
8 | var RuntimeMaterial = require("js/lib/rdge/runtime/RuntimeMaterial"); | ||
9 | var RuntimeFlatMaterial = RuntimeMaterial.RuntimeFlatMaterial, | ||
10 | RuntimeRadialGradientMaterial = RuntimeMaterial.RuntimeRadialGradientMaterial, | ||
11 | RuntimeLinearGradientMaterial = RuntimeMaterial.RuntimeLinearGradientMaterial, | ||
12 | RuntimeBumpMetalMaterial = RuntimeMaterial.RuntimeBumpMetalMaterial, | ||
13 | RuntimeUberMaterial = RuntimeMaterial.RuntimeUberMaterial, | ||
14 | RuntimePulseMaterial = RuntimeMaterial.RuntimePulseMaterial, | ||
15 | RuntimePlasmaMaterial = RuntimeMaterial.RuntimePlasmaMaterial; | ||
16 | |||
17 | |||
18 | |||
19 | /////////////////////////////////////////////////////////////////////// | ||
20 | // Class RuntimeGeomObj | ||
21 | // Super class for all geometry classes | ||
22 | /////////////////////////////////////////////////////////////////////// | ||
23 | var RuntimeGeomObj = function RuntimeGeomObj() | ||
24 | { | ||
25 | /////////////////////////////////////////////////////////////////////// | ||
26 | // Constants | ||
27 | /////////////////////////////////////////////////////////////////////// | ||
28 | this.GEOM_TYPE_RECTANGLE = 1; | ||
29 | this.GEOM_TYPE_CIRCLE = 2; | ||
30 | this.GEOM_TYPE_LINE = 3; | ||
31 | this.GEOM_TYPE_PATH = 4; | ||
32 | this.GEOM_TYPE_CUBIC_BEZIER = 5; | ||
33 | this.GEOM_TYPE_UNDEFINED = -1; | ||
34 | |||
35 | /////////////////////////////////////////////////////////////////////// | ||
36 | // Instance variables | ||
37 | /////////////////////////////////////////////////////////////////////// | ||
38 | this._children; | ||
39 | |||
40 | // stroke and fill colors | ||
41 | this._strokeColor = [0,0,0,0]; | ||
42 | this._fillColor = [0,0,0,0]; | ||
43 | |||
44 | // array of materials | ||
45 | this._materials = []; | ||
46 | |||
47 | /////////////////////////////////////////////////////////////////////// | ||
48 | // Property accessors | ||
49 | /////////////////////////////////////////////////////////////////////// | ||
50 | |||
51 | this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; } | ||
52 | |||
53 | this.setWorld = function(w) { this._world = w; } | ||
54 | this.getWorld = function() { return this._world; } | ||
55 | |||
56 | /////////////////////////////////////////////////////////////////////// | ||
57 | // Methods | ||
58 | /////////////////////////////////////////////////////////////////////// | ||
59 | this.makeStrokeMaterial = function() | ||
60 | { | ||
61 | } | ||
62 | |||
63 | this.makeFillMaterial = function() | ||
64 | { | ||
65 | } | ||
66 | |||
67 | |||
68 | this.render = function() | ||
69 | { | ||
70 | } | ||
71 | |||
72 | this.addChild = function( child ) | ||
73 | { | ||
74 | if (!this._children) this._children = []; | ||
75 | this._children.push( child ); | ||
76 | } | ||
77 | |||
78 | this.import = function() | ||
79 | { | ||
80 | } | ||
81 | |||
82 | this.importMaterials = function(importStr) | ||
83 | { | ||
84 | var nMaterials = Number( getPropertyFromString( "nMaterials: ", importStr ) ); | ||
85 | for (var i=0; i<nMaterials; i++) | ||
86 | { | ||
87 | var matNodeName = getPropertyFromString( "materialNodeName: ", importStr ); | ||
88 | |||
89 | var mat; | ||
90 | var materialType = getPropertyFromString( "material: ", importStr ); | ||
91 | switch (materialType) | ||
92 | { | ||
93 | case "flat": mat = new RuntimeFlatMaterial(); break; | ||
94 | case "radialGradient": mat = new RuntimeRadialGradientMaterial(); break; | ||
95 | case "linearGradient": mat = new RuntimeLinearGradientMaterial(); break; | ||
96 | case "bumpMetal": mat = new RuntimeBumpMetalMaterial(); break; | ||
97 | case "uber": mat = new RuntimeUberMaterial(); break; | ||
98 | case "plasma": mat = new RuntimePlasmaMaterial(); break; | ||
99 | |||
100 | case "deform": | ||
101 | case "water": | ||
102 | case "tunnel": | ||
103 | case "reliefTunnel": | ||
104 | case "squareTunnel": | ||
105 | case "twist": | ||
106 | case "fly": | ||
107 | case "julia": | ||
108 | case "mandel": | ||
109 | case "star": | ||
110 | case "zinvert": | ||
111 | case "keleidoscope": | ||
112 | case "radialBlur": | ||
113 | case "pulse": mat = new RuntimePulseMaterial(); break; | ||
114 | |||
115 | default: | ||
116 | console.log( "material type: " + materialType + " is not supported" ); | ||
117 | break; | ||
118 | } | ||
119 | |||
120 | if (mat) | ||
121 | { | ||
122 | mat.import( importStr ); | ||
123 | mat._materialNodeName = matNodeName; | ||
124 | this._materials.push( mat ); | ||
125 | } | ||
126 | |||
127 | var endIndex = importStr.indexOf( "endMaterial\n" ); | ||
128 | if (endIndex < 0) break; | ||
129 | importStr = importStr.substr( endIndex ); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | //////////////////////////////////////////////////////////////////// | ||
134 | // vector function | ||
135 | |||
136 | this.vecAdd = function( dimen, a, b ) | ||
137 | { | ||
138 | var rtnVec; | ||
139 | if ((a.length < dimen) || (b.length < dimen)) | ||
140 | { | ||
141 | throw new Error( "dimension error in vecAdd" ); | ||
142 | } | ||
143 | |||
144 | rtnVec = []; | ||
145 | for (var i=0; i<dimen; i++) | ||
146 | rtnVec[i] = a[i] + b[i]; | ||
147 | |||
148 | return rtnVec; | ||
149 | } | ||
150 | |||
151 | |||
152 | this.vecSubtract = function( dimen, a, b ) | ||
153 | { | ||
154 | var rtnVec; | ||
155 | if ((a.length < dimen) || (b.length < dimen)) | ||
156 | { | ||
157 | throw new Error( "dimension error in vecSubtract" ); | ||
158 | } | ||
159 | |||
160 | rtnVec = []; | ||
161 | for (var i=0; i<dimen; i++) | ||
162 | rtnVec[i] = a[i] - b[i]; | ||
163 | |||
164 | return rtnVec; | ||
165 | } | ||
166 | |||
167 | this.vecDot = function( dimen, v0, v1 ) | ||
168 | { | ||
169 | if ((v0.length < dimen) || (v1.length < dimen)) | ||
170 | { | ||
171 | throw new Error( "dimension error in vecDot" ); | ||
172 | } | ||
173 | |||
174 | var sum = 0.0; | ||
175 | for (var i=0; i<dimen; i++) | ||
176 | sum += v0[i] * v1[i]; | ||
177 | |||
178 | return sum; | ||
179 | } | ||
180 | |||
181 | this.vecMag = function( dimen, vec ) | ||
182 | { | ||
183 | var sum = 0.0; | ||
184 | for (var i=0; i<dimen; i++) | ||
185 | sum += vec[i]*vec[i]; | ||
186 | return Math.sqrt( sum ); | ||
187 | } | ||
188 | |||
189 | this.vecScale = function(dimen, vec, scale) | ||
190 | { | ||
191 | for (var i=0; i<dimen; i++) | ||
192 | vec[i] *= scale; | ||
193 | |||
194 | return vec; | ||
195 | } | ||
196 | |||
197 | this.vecNormalize = function(dimen, vec, len) | ||
198 | { | ||
199 | var rtnVec; | ||
200 | if (!len) len = 1.0; | ||
201 | |||
202 | var sum = 0.0; | ||
203 | for (var i=0; i<dimen; i++) | ||
204 | sum += vec[i]*vec[i]; | ||
205 | sum = Math.sqrt( sum ); | ||
206 | |||
207 | if (Math.abs(sum) >= 0.001) | ||
208 | { | ||
209 | var scale = len/sum; | ||
210 | rtnVec = []; | ||
211 | for (var i=0; i<dimen; i++) | ||
212 | rtnVec[i] = vec[i]*scale; | ||
213 | } | ||
214 | |||
215 | return rtnVec; | ||
216 | }, | ||
217 | |||
218 | this.transformPoint = function( srcPt, mat ) | ||
219 | { | ||
220 | var pt = srcPt.slice(0); | ||
221 | var x = this.vecDot(3, pt, [mat[0], mat[4], mat[ 8]] ) + mat[12], | ||
222 | y = this.vecDot(3, pt, [mat[1], mat[5], mat[ 9]] ) + mat[13], | ||
223 | z = this.vecDot(3, pt, [mat[2], mat[6], mat[10]] ) + mat[14]; | ||
224 | |||
225 | return [x, y, z]; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | var getPropertyFromString = function getPropertyFromString( prop, str ) | ||
230 | { | ||
231 | var index = str.indexOf( prop ); | ||
232 | if (index < 0) throw new Error( "property " + prop + " not found in |