aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLGeomObj.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLGeomObj.js')
-rw-r--r--js/helper-classes/RDGE/GLGeomObj.js224
1 files changed, 224 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/GLGeomObj.js b/js/helper-classes/RDGE/GLGeomObj.js
new file mode 100644
index 00000000..72019703
--- /dev/null
+++ b/js/helper-classes/RDGE/GLGeomObj.js
@@ -0,0 +1,224 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7///////////////////////////////////////////////////////////////////////
8// Class GLGeomObj
9// Super class for all geometry classes
10///////////////////////////////////////////////////////////////////////
11function GLGeomObj()
12{
13 ///////////////////////////////////////////////////////////////////////
14 // Constants
15 ///////////////////////////////////////////////////////////////////////
16 this.GEOM_TYPE_RECTANGLE = 1;
17 this.GEOM_TYPE_CIRCLE = 2;
18 this.GEOM_TYPE_LINE = 3;
19 this.GEOM_TYPE_PATH = 4;
20 this.GEOM_TYPE_CUBIC_BEZIER = 5;
21 this.GEOM_TYPE_UNDEFINED = -1;
22
23 // Needed for calculating dashed/dotted strokes
24 this.DASH_LENGTH = 0.15;
25 this.DOT_LENGTH = 0.05;
26 this.GAP_LENGTH = 0.05;
27
28 ///////////////////////////////////////////////////////////////////////
29 // Instance variables
30 ///////////////////////////////////////////////////////////////////////
31 this._matrix = Matrix.I(4);
32
33 this._next = undefined;
34 this._prev = undefined;
35 this._child = undefined;
36 this._parent = undefined;
37
38 this.m_world = null;
39
40 // stroke and fill materials
41 this._fillMaterial;
42 this._strokeMaterial;
43
44 // array of primitives - used in RDGE
45 this._primArray = [];
46 this._materialNodeArray = [];
47 this._materialArray = [];
48 this._materialTypeArray = [];
49
50 // the transform node used by RDGE
51 this._trNode = null;
52
53
54 ///////////////////////////////////////////////////////////////////////
55 // Property accessors
56 ///////////////////////////////////////////////////////////////////////
57 this.setWorld = function( world ) { this.m_world = world; }
58 this.getWorld = function() { return this.m_world; }
59
60 this.getMatrix = function() { return this._matrix.slice(0); }
61 this.setMatrix = function(m) { this._matrix = m.slice(0); }
62
63 this.setNext = function( next ) { this._next = next; }
64 this.getNext = function() { return this._next; }
65 this.setPrev = function( prev ) { this._prev = prev; }
66 this.getPrev = function() { return this._prev; }
67 this.setChild = function( child ) { this._child = child; }
68 this.getChild = function() { return this._child; }
69 this.setParent = function( parent ) { this._parent = parent; }
70 this.getParent = function() { return this._parent; }
71
72 this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; }
73
74 this.getPrimitiveArray = function() { return this._primArray; }
75 this.getMaterialNodeArray = function() { return this._materialNodeArray; }
76 this.getMaterialArray = function() { return this._materialArray; }
77
78 this.getTransformNode = function() { return this._trNode; }
79 this.setTransformNode = function(t) { this._trNode = t; }
80
81 ///////////////////////////////////////////////////////////////////////
82 // Methods
83 ///////////////////////////////////////////////////////////////////////
84 this.setMaterialColor = function(c, type)
85 {
86 if (type == "fill")
87 this._fillColor = c.slice(0);
88 else
89 this._strokeColor = c.slice(0);
90 if (this._materialArray && this._materialTypeArray)
91 {
92 var nMats = this._materialArray.length;
93 if (nMats === this._materialTypeArray.length)
94 {
95 for (var i=0; i<nMats; i++)
96 {
97 if (this._materialTypeArray[i] == type)
98 this._materialArray[i].setProperty( "color", c.slice(0) );
99 }
100 }
101 }
102 }
103
104 this.setFillColor = function(c) { this.setMaterialColor(c, "fill"); }
105 this.setStrokeColor = function(c) { this.setMaterialColor(c, "stroke"); }
106
107
108 this.translate = function(v)
109 {
110 var mat = Matrix.Translation( v );
111 //var mat2 = mat.multiply( this._matrix );
112 //this._matrix = mat2;
113 glmat4.multiply(mat, this._matrix, this._matrix);
114 }
115
116 this.transform = function( mat )
117 {
118 if (mat)
119 {
120 //this._matrix = mat.multiply( this._matrix );
121 glmat4.multiply(mat, this._matrix, this._matrix);
122 }
123 }
124
125 this.setMatrix = function(mat)
126 {
127 var gl = this.getWorld().getGLContext();
128 if (gl)
129 {
130 gl.uniformMatrix4fv(this.getWorld().getShaderProgram().mvMatrixUniform, false, new Float32Array(mat));
131 }
132 }
133
134 this.buildBuffers = function()
135 {
136 // this function must be overridden by the base class
137 alert( "GLGeomObj.buildBuffers must be overridden by base class" );
138 }
139
140 this.render = function()
141 {
142 alert( "GLGeomObj.render method must be overridden by sub class" );
143 }
144
145 this.collidesWithPoint = function( x, y )
146 {
147 alert( "GLGeomObj.collidesWithPoint method must be overridden by sub class" );
148 }
149
150
151 this.getNearPoint = function( pt, dir )
152 {
153 // the alert is not displayed. Objects may choose not to implement this method.
154 //alert( "GLGeomObj.getNearPoint method must be overridden by sub class" );
155 }
156
157 this.getNearVertex = function( pt, dir )
158 {
159 // this should be overridden by objects (such as rectangles) that have corners
160 }
161
162 this.containsPoint = function( pt, dir )
163 {
164 // the alert is not displayed. Objects may choose not to implement this method.
165 //alert( "GLGeomObj.containsPoint method must be overridden by sub class" );
166 }
167
168 this.getPropertyFromString = function( prop, str )
169 {
170 var index = str.indexOf( prop );
171 if (index < 0) throw new Error( "property " + prop + " not found in string: " + str);
172
173 var rtnStr = str.substr( index+prop.length );
174 index = rtnStr.indexOf( "\n" );
175 if (index >= 0)
176 rtnStr = rtnStr.substr(0, index);
177
178 return rtnStr;
179 }
180
181 this.export = function()
182 {
183 var rtnStr;
184
185 /*
186 var matNodeArr = this.getMaterialNodeArray();
187 if (matNodeArr)
188 {
189 var nMats = matNodeArr.length;
190 if (nMats > 0)
191 {
192 for (var i=0; i<nMats; i++)
193 {
194 var trNode = this.getWorld().findTransformNodeByMaterial( matNodeArr[i] );
195 if (trNode)
196 {
197 var meshNode = trNode.transformNode.meshes[i];
198 if (meshNode)
199 {
200 var matNode = trNode.transformNode.materialNode;
201 if (matNode)
202 {
203 if (!rtnStr)
204 rtnStr = "type: " + this.geomType() + "\n";
205
206 var jsonMeshText = JSON.stringify( meshNode );
207
208 rtnStr += "mesh: " + jsonMeshText + "endMesh\n";
209
210 //var jsonMatDef = JSON.parse( matNode.shaderProgram.exportShader() );
211 var jsonMatText = matNode.shaderProgram.exportShader();
212 rtnStr += "material: " + jsonMatText + "endMat\n";
213 }
214 }
215 }
216 }
217 }
218 }
219 */
220
221 return rtnStr;
222 }
223}
224