aboutsummaryrefslogtreecommitdiff
path: root/js/lib/drawing
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/drawing
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/drawing')
-rwxr-xr-xjs/lib/drawing/world.js917
1 files changed, 917 insertions, 0 deletions
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js
new file mode 100755
index 00000000..3d6c6fc4
--- /dev/null
+++ b/js/lib/drawing/world.js
@@ -0,0 +1,917 @@
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// Useless Global variables.
8// TODO: Remove this as soon as QE test pass
9/*
10var shaderProgramArray = new Array;
11var glContextArray = new Array;
12var vertexShaderSource = "";
13var fragmentShaderSource = "";
14var rdgeStarted = false;
15*/
16
17var nodeCounter = 0;
18
19var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
20var Line = require("js/lib/geom/line").Line;
21var Rectangle = require("js/lib/geom/rectangle").Rectangle;
22var Circle = require("js/lib/geom/circle").Circle;
23var MaterialsModel = require("js/models/materials-model").MaterialsModel;
24
25///////////////////////////////////////////////////////////////////////
26// Class GLWorld
27// Manages display in a canvas
28///////////////////////////////////////////////////////////////////////
29var World = function GLWorld( canvas, use3D ) {
30 ///////////////////////////////////////////////////////////////////////
31 // Instance variables
32 ///////////////////////////////////////////////////////////////////////
33
34 // flag to do the drawing with WebGL
35 this._useWebGL = false;
36 if(use3D) {
37 this._useWebGL = use3D;
38 }
39
40 this._canvas = canvas;
41 if (this._useWebGL) {
42 this._glContext = canvas.getContext("experimental-webgl");
43 } else {
44 this._2DContext = canvas.getContext( "2d" );
45 }
46
47 this._viewportWidth = canvas.width;
48 this._viewportHeight = canvas.height;
49
50 // view parameters
51 this._fov = 45.0;
52 this._zNear = 0.1;
53 this._zFar = 100.0;
54 this._viewDist = 5.0;
55
56 // default light parameters
57 this._ambientLightColor = [0.1, 0.1, 0.1, 1.0];
58 this._diffuseLightColor = [0.1, 0.1, 0.1, 1.0];
59 this._specularLightColor = [0.6, 0.6, 0.6, 1.0];
60 this._pointLightLoc = [0.0, 0.0, 0.05];
61
62 // default material properties. Material properties should be overridden
63 // by the materials used by the objects
64 this._materialShininess = 20.0;
65
66 this._geomRoot = undefined;
67
68 this._cameraMat = Matrix.I(4);
69 this._cameraMat[14] = 5.0;
70 this._cameraMatInv = Matrix.I(4);
71 this._cameraMatInv[14] = -5.0;
72
73 this._camera = null;
74 // keep a flag indicating whether a render has been completed.
75 // this allows us to turn off automatic updating if there are
76 // no animated materials
77 this._firstRender = true;
78
79 ///////////////////////////////////////////////////////////////////////
80 // Property accessors
81 ///////////////////////////////////////////////////////////////////////
82 this.getGLContext = function() { return this._glContext; };
83 this.setGLContext = function(gl) { this._glContext = gl; };
84
85 this.get2DContext = function() { return this._2DContext; };
86 this.set2DContext = function(c) { this._2DContext = c; };
87
88 this.getCanvas = function() { return this._canvas; };
89 this.setCanvas = function(c) { this._canvas = c; };
90
91 this.getShaderProgram = function() { return this._shaderProgram; };
92
93 this.getViewportWidth = function() { return this._viewportWidth; };
94 this.getViewportHeight = function() { return this._viewportHeight; };
95
96 this.getAspect = function() { return this._viewportWidth/this._viewportHeight; };
97
98 this.getGeomRoot = function() { return this._geomRoot; };
99 this.getZNear = function() { return this._zNear; };
100 this.getZFar = function() { return this._zFar; };
101 this.getFOV = function() { return this._fov; };
102
103 this.getCamera = function() { return this._camera; };
104
105 this.getCameraMat = function() { return this._cameraMat.slice(0); };
106 this.setCameraMat = function(c) { this._cameraMat = c.slice(0); this._cameraMatInv = glmat4.inverse(c, []); };
107
108 this.getCameraMatInverse = function() { return this._cameraMatInv.slice(0); };
109
110 this.getViewDistance = function() { return this._viewDist; };
111
112 this.getRootNode = function() { return this._rootNode; };
113 this.setRootNode = function(r) { this._rootNode = r; };
114
115 this.isWebGL = function() { return this._useWebGL; };
116
117 this.getRenderer = function() { return this.renderer; };
118
119 ////////////////////////////////////////////////////////////////////////////////////
120 // RDGE
121 // local variables
122 this.myScene = null;
123 this.elapsed = 0;
124 this.light = null;
125 this.light2 = null;
126 this.fillShader = null;
127 this.strokeShader = null;
128 this.renderer = null;
129
130 // keep an array of texture maps that need to be loaded
131 this._texMapsToLoad = [];
132 this._allMapsLoaded = true;
133
134 // this is the node to which objects get hung
135 this._rootNode = null;
136
137 // set up the camera matrix
138 var camMat = Matrix.I(4);
139 camMat[14] = this.getViewDistance();
140 this.setCameraMat( camMat );
141
142 // post-load processing of the scene
143 this.init = function() {
144 var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle),
145 ctx2 = g_Engine.getContext();
146 if (ctx1 != ctx2) console.log( "***** different contexts *****" );
147 this.renderer = ctx1.renderer;
148 this.renderer._world = this;
149
150 // create a camera, set its perspective, and then point it at the origin
151 var cam = new camera();
152 this._camera = cam;
153 cam.setPerspective(this.getFOV(), this.getAspect(), this.getZNear(), this.getZFar());
154 cam.setLookAt([0, 0, this.getViewDistance()], [0, 0, 0], vec3.up());
155
156 // make this camera the active camera
157 this.renderer.cameraManager().setActiveCamera(cam);
158
159 // change clear color
160 //this.renderer.setClearFlags(g_Engine.getContext().DEPTH_BUFFER_BIT);
161 this.renderer.setClearColor([0.0, 0.0, 0.0, 0.0]);
162 //this.renderer.NinjaWorld = this;
163
164 // create an empty scene graph
165 this.myScene = new SceneGraph();
166
167 // create some lights
168 // light 1
169 this.light = createLightNode("myLight");
170 this.light.setPosition([0,0,1.2]);
171 this.light.setDiffuseColor([0.75,0.9,1.0,1.0]);
172
173 // light 2
174 this.light2 = createLightNode("myLight2");
175 this.light2.setPosition([-0.5,0,1.2]);
176 this.light2.setDiffuseColor([1.0,0.9,0.75,1.0]);
177
178 // create a light transform
179 var lightTr = createTransformNode("lightTr");
180
181 // create and attach a material - materials hold the light data
182 lightTr.attachMaterial(createMaterialNode("lights"));
183
184 // enable light channels 1, 2 - channel 0 is used by the default shader
185 lightTr.materialNode.enableLightChannel(1, this.light);
186 lightTr.materialNode.enableLightChannel(2, this.light2);
187
188 // all added objects are parented to the light node
189 this._rootNode = lightTr;
190
191 // add the light node to the scene
192 this.myScene.addNode(lightTr);
193
194 // Add the scene to the engine - necessary if you want the engine to draw for you
195 //g_Engine.AddScene("myScene" + this._canvas.id, this.myScene);
196 var name = this._canvas.getAttribute( "data-RDGE-id" );
197 g_Engine.AddScene("myScene" + name, this.myScene);
198 };
199
200 // main code for handling user interaction and updating the scene
201 this.update = function(dt) {
202 if (!dt) dt = 0.2;
203
204 dt = 0.01; // use our own internal throttle
205 this.elapsed += dt;
206
207 if (this._useWebGL) {
208 // changed the global position uniform of light 0, another way to change behavior of a light
209 rdgeGlobalParameters.u_light0Pos.set( [5*Math.cos(this.elapsed), 5*Math.sin(this.elapsed), 20]);
210
211 // orbit the light nodes around the boxes
212 this.light.setPosition([1.2*Math.cos(this.elapsed*2.0), 1.2*Math.sin(this.elapsed*2.0), 1.2*Math.cos(this.elapsed*2.0)]);