aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/line.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/line.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/line.js')
-rwxr-xr-xjs/lib/geom/line.js488
1 files changed, 488 insertions, 0 deletions
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js
new file mode 100755
index 00000000..da63b21c
--- /dev/null
+++ b/js/lib/geom/line.js
@@ -0,0 +1,488 @@
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 GeomObj = require("js/lib/geom/geom-obj").GeomObj;
8var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive;
9var MaterialsModel = require("js/models/materials-model").MaterialsModel;
10///////////////////////////////////////////////////////////////////////
11// Class GLLine
12// GL representation of a line.
13// Derived from class GeomObj
14///////////////////////////////////////////////////////////////////////
15var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, strokeColor, strokeMaterial, strokeStyle, xAdj, yAdj) {
16 ///////////////////////////////////////////////////////////////////////
17 // Instance variables
18 ///////////////////////////////////////////////////////////////////////
19 this._width = 2.0;
20 this._height = 2.0;
21 this._xOffset = 0;
22 this._yOffset = 0;
23
24 // If line doesn't fit in canvas world, we had to grow the canvas by this much on either side
25 this._xAdj = 0;
26 this._yAdj = 0;
27
28 this._slope = 0;
29
30 this._strokeWidth = 0.25;
31
32 this._strokeStyle = "Solid";
33 this._scaleX = 1.0;
34 this._scaleY = 1.0;
35
36 if (arguments.length > 0) {
37 this._width = width;
38 this._height = height;
39 this._xOffset = xOffset;
40 this._yOffset = yOffset;
41
42 this._xAdj = xAdj;
43 this._yAdj = yAdj;
44
45 this._slope = slope;
46 this._strokeWidth = strokeSize;
47 if (strokeColor) this._strokeColor = strokeColor.slice();
48
49 this._strokeStyle = strokeStyle;
50 this._scaleX = (world.getViewportWidth())/(world.getViewportHeight());
51 }
52
53 this._strokeVerticesLen = 0;
54
55 this.m_world = world;
56
57 this._materialAmbient = [0.2, 0.2, 0.2, 1.0];
58 this._materialDiffuse = [0.4, 0.4, 0.4, 1.0];
59 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
60
61 if(strokeMaterial) {
62 this._strokeMaterial = strokeMaterial;
63 }
64
65 ///////////////////////////////////////////////////////////////////////
66 // Property Accessors
67 ///////////////////////////////////////////////////////////////////////
68 this.getStrokeWidth = function() { return this._strokeWidth; }
69 this.setStrokeWidth = function(w) { this._strokeWidth = w; }
70
71 this.getStrokeMaterial = function() { return this._strokeMaterial; }
72 this.setStrokeMaterial = function(m) { this._strokeMaterial = m; }
73
74 this.getStrokeColor = function() { return this._strokeColor; }
75 //this.setStrokeColor = function(c) { this._strokeColor = c; }
76
77 this.getStrokeStyle = function() { return this._strokeStyle; }
78 this.setStrokeStyle = function(s) { this._strokeStyle = s; }
79
80 this.getFillMaterial = function() { return null; }
81
82 this.setStrokeMaterial = function(m) { this._strokeMaterial = m; }
83 this.getStrokeMaterial = function() { return this._strokeMaterial; }
84
85 this.getWidth = function() { return this._width; }
86 this.setWidth = function(w) { this._width = w; }
87
88 this.getHeight = function() { return this._height; }
89 this.setHeight = function(h) { this._height = h; }
90
91 this.getXAdj = function() { return this._xAdj; }
92 this.setXAdj = function(x) { this._xAdj = x; }
93
94 this.getYAdj = function() { return this._yAdj; }
95 this.setYAdj = function(y) { this._yAdj = y; }
96
97 this.getSlope = function() { return this._slope; }
98 this.setSlope = function(m) { this._slope = m; }
99
100 this.geomType = function() { return this.GEOM_TYPE_LINE; }
101
102 ///////////////////////////////////////////////////////////////////////
103 // Methods
104 ///////////////////////////////////////////////////////////////////////
105 this.export = function() {
106 var rtnStr = "type: " + this.geomType() + "\n";
107
108 rtnStr += "xoff: " + this._xOffset + "\n";
109 rtnStr += "yoff: " + this._yOffset + "\n";
110 rtnStr += "width: " + this._width + "\n";
111 rtnStr += "height: " + this._height + "\n";
112 rtnStr += "xAdj: " + this._xAdj + "\n";
113 rtnStr += "yAdj: " + this._yAdj + "\n";
114 rtnStr += "strokeWidth: " + this._strokeWidth + "\n";
115 rtnStr += "strokeColor: " + String(this._strokeColor) + "\n";
116 rtnStr += "strokeStyle: " + this._strokeStyle + "\n";
117 rtnStr += "slope: " + String(this._slope) + "\n";
118
119 rtnStr += "strokeMat: ";
120 if (this._strokeMaterial) {
121 rtnStr += this._strokeMaterial.getName();
122 } else {
123 rtnStr += "flatMaterial";
124 }
125
126 rtnStr += "\n";
127 return rtnStr;
128 };
129
130 this.import = function( importStr ) {
131 this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) );
132 this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) );
133 this._width = Number( this.getPropertyFromString( "width: ", importStr ) );
134 this._height = Number( this.getPropertyFromString( "height: ", importStr ) );
135 this._xAdj = Number( this.getPropertyFromString( "xAdj: ", importStr ) );
136 this._yAdj = Number( this.getPropertyFromString( "yAdj: ", importStr ) );
137 this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) );
138 var slope = this.getPropertyFromString( "slope: ", importStr );
139
140 if(isNaN(Number(slope))) {
141 this._slope = slope;
142 } else {
143 this._slope = Number(slope);
144 }
145
146 var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr );
147 this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr );
148 this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" );
149
150 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName );
151 if (!strokeMat) {
152 console.log( "object material not found in library: " + strokeMaterialName );
153 strokeMat = MaterialsModel.exportFlatMaterial();
154 }
155
156 this._strokeMaterial = strokeMat;
157
158 };
159
160 ///////////////////////////////////////////////////////////////////////
161 // Methods
162 ///////////////////////////////////////////////////////////////////////
163 this.buildBuffers = function() {
164 // get the world
165 var world = this.getWorld();
166 if (!world) throw( "null world in buildBuffers" );
167 if (!world._useWebGL) return;
168
169 // make sure RDGE has the correct context
170 g_Engine.setContext( world.getCanvas().rdgeid );
171
172 // create the gl buffer
173 var gl = world.getGLContext();
174
175 this._strokeVerticesLen = 0;
176
177 var strokeVertices = [];
178 var strokeTextures = [];
179 var strokeNormals = [];
180 var strokeColors = [];
181
182// var scaleMat = Matrix.I(3);
183// scaleMat.elements[0][0] = this._scaleX;
184// scaleMat.elements[1][1] = this._scaleY;
185
186
187 // get the normalized device coordinates (NDC) for
188 // all position and dimensions.
189 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
190 var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph,
191 xFillNDC = this._width/vpw, yFillNDC = this._height/vph,
192 xAdjNDC = this._xAdj/vpw, yAdjNDC = this._yAdj/vph,
193 xStrokeNDC = this._strokeWidth/vpw, yStrokeNDC = this._strokeWidth/vph;
194
195 var aspect = world.getAspect();
196 var zn = world.getZNear(), zf = world.getZFar();
197 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
198 b = -t,
199 r = aspect*t,
200 l = -r;
201
202 // calculate the object coordinates from their NDC coordinates
203 var z = -world.getViewDistance();
204
205 // get the position of the origin
206 var x = -z*(r-l)/(2.0*zn)*xNDC,
207 y = -z*(t-b)/(2.0*zn)*yNDC;
208
209 // get the x and y fill
210 var xFill = -z*(r-l)/(2.0*zn)*xFillNDC,
211 yFill = -z*(t-b)/(2.0*zn)*yFillNDC;