aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/geom-obj.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 11:38:39 -0800
committerJonathan Duran2012-03-06 11:38:39 -0800
commit342fb451bd251358068a0dcb10e9dc218b79a176 (patch)
treeaa0195d581c3934fb6dc09981506b3c070002806 /js/lib/geom/geom-obj.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
downloadninja-342fb451bd251358068a0dcb10e9dc218b79a176.tar.gz
Squashed commit of the following:
commit 1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f Author: Jose Antonio Marquez <kgq387@motorola.com> Date: Tue Mar 6 11:24:25 2012 -0800 Fixing WebGL not available bug commit 84332ab81c1b445195f1d9be8bbeae0725c8e758 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Mar 6 10:58:25 2012 -0800 Squashed commit of preload-fix into Master - Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 13f52cf0c74f53a919fa864f86669e8155f82961 Merge: dced508 abc04f3 Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:46:11 2012 -0800 Merge pull request #93 from imix23ways/Timeline Timeline: Critical bug fixes commit dced508bb19a7bcd467ff1b86b5df5bbec4be794 Merge: 0aeb400 cc772ef Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:45:35 2012 -0800 Merge pull request #92 from mqg734/WebGLFixes Selection Tool Fixes for elements flying off into space when they overlap commit 0aeb400070762cf01d83cf9f9ee25a5595098b7f Merge: ff0a956 aabb48a Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 14:05:21 2012 -0800 Merge pull request #94 from ericguzman/PresetsPanel Presets Panel - Fix single-click activation, and transition cut-off bug. commit cc772ef3333ed419d269a2bda7aea5b0150a7bd9 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:34:58 2012 -0800 Fixing flying off into space bug for translate tool too. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit abc04f3d50311ed1c21067344bc7e448686f8c5c Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:26:25 2012 -0800 Timeline Fix timing function Signed-off-by: Jonathan Duran <jduran@motorola.com> commit aabb48a1c8d34bc968f4c6b0ffee4e31c1d5d286 Author: Eric Guzman <ericg@motorola.com> Date: Fri Mar 2 11:22:44 2012 -0800 Presets Panel - Fix single-click activation, and transition cut-off bug. Use double-click as the activation event for transition presets. Also fixed the bug when applying a style preset before the transition preset, which disabled transitions after the first one. commit f3207f39ea9d8c1c34246217a23d3a689671903d Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:21:29 2012 -0800 Don't draw transform handles if the stage is the target element. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 5425be91e7125c22955b4459a62412ff574e49a8 Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:11:48 2012 -0800 Timeline: Fix for animation iteration count Add default webkit css properties to allow animations with integer iteration counts. Signed-off-by: Jonathan Duran <jduran@motorola.com> commit 1760bac1da9218315ad1bacdcf3a157495a049e8 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 10:48:41 2012 -0800 Fix for jumping issue when moving items that have any 3d on them. We can't translate 3d moves into 2d space due to perspective, so we must update the matrix3d values instead of the top-left values if items have 3d. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 2c04935f0ccb1cb7c98371fc10b43155f2d956c4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 22:20:06 2012 -0800 Fix for elements flying off into space when moving elements that overlap. This was happening because our hit record's element and the browser's element from point did not match. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 50058746779f714ed9b0287f49e56c9f0d35593e Merge: 500426d ff0a956 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 21:49:44 2012 -0800 Merge branch 'refs/heads/ninja-internal' into WebGLFixes commit 500426dea0ca95a6b45be8ea8d132cfdb4d2c940 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:11:39 2012 -0800 Fixed logic error when resizing with the top-left transform handles. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 7980d9bde2b43aa5a494ddf6f1db5c4959a57b91 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:04:15 2012 -0800 Re-fixing IKNinja-940 - Can't select objects when in side/top view. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit f04cc0146d8f7573628678613a99c270116768e4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Feb 29 16:45:40 2012 -0800 Last-used material (instead of FlatMaterial) is applied to shape when turning on use WebGL checkbox in the PI. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-xjs/lib/geom/geom-obj.js280
1 files changed, 280 insertions, 0 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
new file mode 100755
index 00000000..c5880843
--- /dev/null
+++ b/js/lib/geom/geom-obj.js
@@ -0,0 +1,280 @@
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
7var MaterialsModel = require("js/models/materials-model").MaterialsModel;
8///////////////////////////////////////////////////////////////////////
9// Class GLGeomObj
10// Super class for all geometry classes
11///////////////////////////////////////////////////////////////////////
12var GeomObj = function GLGeomObj() {
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 colors
41 this._strokeColor = [0,0,0,0];
42 this._fillColor = [0,0,0,0];
43
44 // stroke and fill materials
45 this._fillMaterial = null;
46 this._strokeMaterial = null;
47
48 // array of primitives - used in RDGE
49 this._primArray = [];
50 this._materialNodeArray = [];
51 this._materialArray = [];
52 this._materialTypeArray = [];
53
54 // the transform node used by RDGE
55 this._trNode = null;
56
57 ///////////////////////////////////////////////////////////////////////
58 // Property accessors
59 ///////////////////////////////////////////////////////////////////////
60 this.setWorld = function( world ) {
61 this.m_world = world;
62 };
63
64 this.getWorld = function() {
65 return this.m_world;
66 };
67
68 this.getMatrix = function() {
69 return this._matrix.slice(0);
70 };
71
72 this.setMatrix = function(m) {
73 this._matrix = m.slice(0);
74 };
75
76 this.setNext = function( next ) {
77 this._next = next;
78 };
79
80 this.getNext = function() {
81 return this._next;
82 };
83
84 this.setPrev = function( prev ) {
85 this._prev = prev;
86 };
87
88 this.getPrev = function() {
89 return this._prev;
90 };
91
92 this.setChild = function( child ) {
93 this._child = child;
94 };
95
96 this.getChild = function() {
97 return this._child;
98 };
99
100 this.setParent = function( parent ) {
101 this._parent = parent;
102 };
103
104 this.getParent = function() {
105 return this._parent;
106 };
107
108 this.geomType = function() {
109 return this.GEOM_TYPE_UNDEFINED;
110 };
111
112 this.getPrimitiveArray = function() { return this._primArray;
113 };
114
115 this.getMaterialNodeArray = function() {
116 return this._materialNodeArray;
117 };
118
119 this.getMaterialArray = function() { return this._materialArray;
120 };
121
122 this.getTransformNode = function() {
123 return this._trNode;
124 };
125
126 this.setTransformNode = function(t) {
127 this._trNode = t;
128 };
129
130 this.setFillColor = function(c) {
131 this.setMaterialColor(c, "fill");
132 };
133
134 this.setStrokeColor = function(c) {
135 this.setMaterialColor(c, "stroke");
136 };
137 ///////////////////////////////////////////////////////////////////////
138 // Methods
139 ///////////////////////////////////////////////////////////////////////
140 this.setMaterialColor = function(c, type) {
141 if (type == "fill") {
142 this._fillColor = c.slice(0);
143 } else {
144 this._strokeColor = c.slice(0);
145 }
146
147 if (this._materialArray && this._materialTypeArray) {
148 var nMats = this._materialArray.length;
149 if (nMats === this._materialTypeArray.length) {
150 for (var i=0; i<nMats; i++) {
151 if (this._materialTypeArray[i] == type) {
152 this._materialArray[i].setProperty( "color", c.slice(0) );
153 }
154 }
155 }
156 }
157
158 var world = this.getWorld();
159 if (world) {
160 world.restartRenderLoop();
161 }
162 };
163
164 this.makeStrokeMaterial = function() {
165 var strokeMaterial;
166 if (this.getStrokeMaterial()){
167 strokeMaterial = this.getStrokeMaterial().dup();
168 } else {
169 strokeMaterial = MaterialsModel.exportFlatMaterial();
170 }
171
172 if (strokeMaterial) {
173 strokeMaterial.init( this.getWorld() );
174 if(this._strokeColor) {
175 strokeMaterial.setProperty("color", this._strokeColor);
176 }
177 }
178
179 this._materialArray.push( strokeMaterial );
180 this._materialTypeArray.push( "stroke" );
181
182 return strokeMaterial;
183 };
184
185 this.makeFillMaterial = function() {
186 var fillMaterial;
187 if (this.getFillMaterial()) {
188 fillMaterial = this.getFillMaterial().dup();
189 } else {
190 fillMaterial = MaterialsModel.exportFlatMaterial();
191 }
192
193 if (fillMaterial) {
194 fillMaterial.init( this.getWorld() );
195 //if(!this.getFillMaterial() && this._fillColor)
196 if (this._fillColor) {
197 fillMaterial.setProperty("color", this._fillColor);
198 }
199 }
200
201 this._materialArray.push( fillMaterial );
202 this._materialTypeArray.push( "fill" );
203
204 return fillMaterial;
205 };
206
207 this.translate = function(v) {
208 var mat = Matrix.Translation( v );
209 //var mat2 = mat.multiply( this._matrix );
210 //this._matrix = mat2;
211 glmat4.multiply(mat, this._matrix, this._matrix);
212 };
213
214 this.transform = function( mat ) {
215 if (mat) {
216 //this._matrix = mat.multiply( this._matrix );
217 glmat4.multiply(mat, this._matrix, this._matrix);
218 }
219 };
220
221 this.setMatrix = function(mat) {
222 var gl = this.getWorld().getGLContext();
223 if (gl) {
224 gl.uniformMatrix4fv(this.getWorld().getShaderProgram().mvMatrixUniform, false, new Float32Array(mat));