From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- js/helper-classes/RDGE/GLAnchorPoint.js | 150 ++ js/helper-classes/RDGE/GLBrushStroke.js | 242 +++ js/helper-classes/RDGE/GLCircle.js | 754 +++++++++ js/helper-classes/RDGE/GLGeomObj.js | 224 +++ js/helper-classes/RDGE/GLLight.js | 30 + js/helper-classes/RDGE/GLLine.js | 446 +++++ js/helper-classes/RDGE/GLMaterial.js | 268 ++++ js/helper-classes/RDGE/GLPath.js | 232 +++ js/helper-classes/RDGE/GLRectangle.js | 1251 +++++++++++++++ js/helper-classes/RDGE/GLSubpath.js | 1671 +++++++++++++++++++ js/helper-classes/RDGE/GLWorld.js | 834 ++++++++++ js/helper-classes/RDGE/Materials/BrickMaterial.js | 231 +++ .../RDGE/Materials/BumpMetalMaterial.js | 270 ++++ js/helper-classes/RDGE/Materials/FlatMaterial.js | 149 ++ .../RDGE/Materials/IridescentScalesMaterial.js | 212 +++ js/helper-classes/RDGE/Materials/JuliaMaterial.js | 147 ++ .../RDGE/Materials/KeleidoscopeMaterial.js | 146 ++ .../RDGE/Materials/LinearGradientMaterial.js | 339 ++++ js/helper-classes/RDGE/Materials/MandelMaterial.js | 147 ++ js/helper-classes/RDGE/Materials/PlasmaMaterial.js | 132 ++ js/helper-classes/RDGE/Materials/PulseMaterial.js | 226 +++ js/helper-classes/RDGE/Materials/QuiltMaterial.js | 168 ++ .../RDGE/Materials/RadialBlurMaterial.js | 241 +++ .../RDGE/Materials/RadialGradientMaterial.js | 240 +++ js/helper-classes/RDGE/Materials/StitchMaterial.js | 119 ++ js/helper-classes/RDGE/Materials/TunnelMaterial.js | 130 ++ js/helper-classes/RDGE/Materials/TwistMaterial.js | 146 ++ js/helper-classes/RDGE/Materials/UberMaterial.js | 658 ++++++++ js/helper-classes/RDGE/MaterialsLibrary.js | 197 +++ js/helper-classes/RDGE/precompiled.js | 17 + js/helper-classes/RDGE/rdge-compiled.js | 467 ++++++ .../RDGE/src/core/script/MeshManager.js | 242 +++ .../RDGE/src/core/script/RenderInitProcs.js | 263 +++ .../RDGE/src/core/script/RenderProcs.js | 536 +++++++ .../RDGE/src/core/script/ScreenQuad.js | 31 + .../RDGE/src/core/script/ShaderManager.js | 96 ++ .../RDGE/src/core/script/TextureManager.js | 6 + .../RDGE/src/core/script/animation.js | 322 ++++ js/helper-classes/RDGE/src/core/script/box.js | 143 ++ js/helper-classes/RDGE/src/core/script/camera.js | 251 +++ js/helper-classes/RDGE/src/core/script/engine.js | 482 ++++++ js/helper-classes/RDGE/src/core/script/fx/blur.js | 196 +++ js/helper-classes/RDGE/src/core/script/fx/ssao.js | 116 ++ .../RDGE/src/core/script/init_state.js | 342 ++++ js/helper-classes/RDGE/src/core/script/input.js | 117 ++ js/helper-classes/RDGE/src/core/script/jpass.js | 710 ++++++++ js/helper-classes/RDGE/src/core/script/jshader.js | 750 +++++++++ .../RDGE/src/core/script/lightmanager.js | 97 ++ .../RDGE/src/core/script/math/mat4.js | 754 +++++++++ .../RDGE/src/core/script/math/quat.js | 225 +++ .../RDGE/src/core/script/math/vec2.js | 191 +++ .../RDGE/src/core/script/math/vec3.js | 351 ++++ .../RDGE/src/core/script/math/vec4.js | 258 +++ .../RDGE/src/core/script/objectManager.js | 72 + js/helper-classes/RDGE/src/core/script/particle.js | 842 ++++++++++ .../RDGE/src/core/script/precompiled.js | 69 + .../RDGE/src/core/script/renderUtils.js | 386 +++++ .../RDGE/src/core/script/rendercontext.js | 268 ++++ js/helper-classes/RDGE/src/core/script/renderer.js | 1696 ++++++++++++++++++++ .../RDGE/src/core/script/run_state.js | 456 ++++++ js/helper-classes/RDGE/src/core/script/runtime.js | 237 +++ .../RDGE/src/core/script/scenegraph.js | 1123 +++++++++++++ .../RDGE/src/core/script/scenegraphNodes.js | 649 ++++++++ .../RDGE/src/core/script/shadowLight.js | 54 + js/helper-classes/RDGE/src/core/script/sockets.js | 166 ++ .../RDGE/src/core/script/ubershader.js | 159 ++ .../RDGE/src/core/script/util/dbgpanel.js | 237 +++ .../RDGE/src/core/script/util/fpsTracker.js | 51 + .../RDGE/src/core/script/util/statTracker.js | 338 ++++ .../RDGE/src/core/script/utilities.js | 245 +++ 70 files changed, 24011 insertions(+) create mode 100644 js/helper-classes/RDGE/GLAnchorPoint.js create mode 100644 js/helper-classes/RDGE/GLBrushStroke.js create mode 100644 js/helper-classes/RDGE/GLCircle.js create mode 100644 js/helper-classes/RDGE/GLGeomObj.js create mode 100644 js/helper-classes/RDGE/GLLight.js create mode 100644 js/helper-classes/RDGE/GLLine.js create mode 100644 js/helper-classes/RDGE/GLMaterial.js create mode 100644 js/helper-classes/RDGE/GLPath.js create mode 100644 js/helper-classes/RDGE/GLRectangle.js create mode 100644 js/helper-classes/RDGE/GLSubpath.js create mode 100644 js/helper-classes/RDGE/GLWorld.js create mode 100644 js/helper-classes/RDGE/Materials/BrickMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/BumpMetalMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/FlatMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/IridescentScalesMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/JuliaMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/KeleidoscopeMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/LinearGradientMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/MandelMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/PlasmaMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/PulseMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/QuiltMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/RadialBlurMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/RadialGradientMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/StitchMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/TunnelMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/TwistMaterial.js create mode 100644 js/helper-classes/RDGE/Materials/UberMaterial.js create mode 100644 js/helper-classes/RDGE/MaterialsLibrary.js create mode 100644 js/helper-classes/RDGE/precompiled.js create mode 100644 js/helper-classes/RDGE/rdge-compiled.js create mode 100644 js/helper-classes/RDGE/src/core/script/MeshManager.js create mode 100644 js/helper-classes/RDGE/src/core/script/RenderInitProcs.js create mode 100644 js/helper-classes/RDGE/src/core/script/RenderProcs.js create mode 100644 js/helper-classes/RDGE/src/core/script/ScreenQuad.js create mode 100644 js/helper-classes/RDGE/src/core/script/ShaderManager.js create mode 100644 js/helper-classes/RDGE/src/core/script/TextureManager.js create mode 100644 js/helper-classes/RDGE/src/core/script/animation.js create mode 100644 js/helper-classes/RDGE/src/core/script/box.js create mode 100644 js/helper-classes/RDGE/src/core/script/camera.js create mode 100644 js/helper-classes/RDGE/src/core/script/engine.js create mode 100644 js/helper-classes/RDGE/src/core/script/fx/blur.js create mode 100644 js/helper-classes/RDGE/src/core/script/fx/ssao.js create mode 100644 js/helper-classes/RDGE/src/core/script/init_state.js create mode 100644 js/helper-classes/RDGE/src/core/script/input.js create mode 100644 js/helper-classes/RDGE/src/core/script/jpass.js create mode 100644 js/helper-classes/RDGE/src/core/script/jshader.js create mode 100644 js/helper-classes/RDGE/src/core/script/lightmanager.js create mode 100644 js/helper-classes/RDGE/src/core/script/math/mat4.js create mode 100644 js/helper-classes/RDGE/src/core/script/math/quat.js create mode 100644 js/helper-classes/RDGE/src/core/script/math/vec2.js create mode 100644 js/helper-classes/RDGE/src/core/script/math/vec3.js create mode 100644 js/helper-classes/RDGE/src/core/script/math/vec4.js create mode 100644 js/helper-classes/RDGE/src/core/script/objectManager.js create mode 100644 js/helper-classes/RDGE/src/core/script/particle.js create mode 100644 js/helper-classes/RDGE/src/core/script/precompiled.js create mode 100644 js/helper-classes/RDGE/src/core/script/renderUtils.js create mode 100644 js/helper-classes/RDGE/src/core/script/rendercontext.js create mode 100644 js/helper-classes/RDGE/src/core/script/renderer.js create mode 100644 js/helper-classes/RDGE/src/core/script/run_state.js create mode 100644 js/helper-classes/RDGE/src/core/script/runtime.js create mode 100644 js/helper-classes/RDGE/src/core/script/scenegraph.js create mode 100644 js/helper-classes/RDGE/src/core/script/scenegraphNodes.js create mode 100644 js/helper-classes/RDGE/src/core/script/shadowLight.js create mode 100644 js/helper-classes/RDGE/src/core/script/sockets.js create mode 100644 js/helper-classes/RDGE/src/core/script/ubershader.js create mode 100644 js/helper-classes/RDGE/src/core/script/util/dbgpanel.js create mode 100644 js/helper-classes/RDGE/src/core/script/util/fpsTracker.js create mode 100644 js/helper-classes/RDGE/src/core/script/util/statTracker.js create mode 100644 js/helper-classes/RDGE/src/core/script/utilities.js (limited to 'js/helper-classes/RDGE') diff --git a/js/helper-classes/RDGE/GLAnchorPoint.js b/js/helper-classes/RDGE/GLAnchorPoint.js new file mode 100644 index 00000000..496b6f60 --- /dev/null +++ b/js/helper-classes/RDGE/GLAnchorPoint.js @@ -0,0 +1,150 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +///////////////////////////////////////////// +// Class GLAnchorPoint +// GL representation of a point clicked +// and dragged during pen tool +// +// +///////////////////////////////////////////// +function GLAnchorPoint() { + ///////////////////////////////////////// + // Instance variables + ///////////////////////////////////////// + this._x = 0.0; + this._y = 0.0; + this._z = 0.0; + + this._prevX = 0.0; + this._prevY = 0.0; + this._prevZ = 0.0; + + this._nextX = 0.0; + this._nextY = 0.0; + this._nextZ = 0.0; + + // *********** setters ************ + this.setPos = function (x, y, z) { this._x = x; this._y = y; this._z = z; } + this.setPrevPos = function (x, y, z) { this._prevX = x; this._prevY = y; this._prevZ = z; } + this.setNextPos = function (x, y, z) { this._nextX = x; this._nextY = y; this._nextZ = z; } + + this.setPrevFromNext = function () { + //set the previous control point by reflecting the next control point + var dispX = this._nextX - this._x; + var dispY = this._nextY - this._y; + var dispZ = this._nextZ - this._z; + + this._prevX = this._x - dispX; + this._prevY = this._y - dispY; + this._prevZ = this._z - dispZ; + } + this.setNextFromPrev = function () { + //set the previous control point by reflecting the next control point + var dispX = this._prevX - this._x; + var dispY = this._prevY - this._y; + var dispZ = this._prevZ - this._z; + + this._nextX = this._x - dispX; + this._nextY = this._y - dispY; + this._nextZ = this._z - dispZ; + } + + //translate the next point from the translation that was applied to the prev. point + this.translateNextFromPrev = function (tx, ty, tz) { + // *** compute the rotation of the prev vector *** + var oldP = Vector.create([this._prevX + tx - this._x, this._prevY + ty - this._y, this._prevZ + tz - this._z]); + var newP = Vector.create([this._prevX - this._x, this._prevY - this._y, this._prevZ - this._z]); + //compute angle between the two vectors + var axis = Vector.create([0, 0, 0]); + var angle = MathUtils.getAxisAngleBetween3DVectors(oldP, newP, axis); + if (angle === 0) + return; + + // *** compute the vector from anchor to next + var oldN = Vector.create([this._nextX - this._x, this._nextY - this._y, this._nextZ - this._z]); + var rotMat = Matrix.Rotation(-angle, axis); + var newN = MathUtils.transformVector(oldN, rotMat); + + //TEMP for some situations the axis angle computation returns NaNs + if (isNaN(newN[0]) || isNaN(newN[1]) || isNaN(newN[2])) { + return; + } + //end TEMP + this._nextX = this._x + newN[0]; + this._nextY = this._y + newN[1]; + this._nextZ = this._z + newN[2]; + } + //translate the next point from the translation that was applied to the prev. point + this.translatePrevFromNext = function (tx, ty, tz) { + // *** compute the rotation of the next vector *** + var oldN = Vector.create([this._nextX + tx - this._x, this._nextY + ty - this._y, this._nextZ + tz - this._z]); + var newN = Vector.create([this._nextX - this._x, this._nextY - this._y, this._nextZ - this._z]); + //compute angle between the two vectors + var axis = Vector.create([0, 0, 0]); + var angle = MathUtils.getAxisAngleBetween3DVectors(oldN, newN, axis); + if (angle === 0) + return; + + // *** compute the vector from anchor to prev + var oldP = Vector.create([this._prevX - this._x, this._prevY - this._y, this._prevZ - this._z]); + var rotMat = Matrix.Rotation(-angle, axis); + var newP = MathUtils.transformVector(oldP, rotMat); + + //TEMP for some situations the axis angle computation returns NaNs + if (isNaN(newP[0]) || isNaN(newP[1]) || isNaN(newP[2])) { + return; + } + //end TEMP + this._prevX = this._x + newP[0]; + this._prevY = this._y + newP[1]; + this._prevZ = this._z + newP[2]; + } + + + // ******* modifiers ******* + this.translatePrev = function (x, y, z) { + this._prevX += x; this._prevY += y; this._prevZ += z; + } + this.translateNext = function (x, y, z) { + this._nextX += x; this._nextY += y; this._nextZ += z; + } + this.translate = function (x, y, z) { + this._x += x; this._y += y; this._z += z; + } + this.translateAll = function (x, y, z) { + this.translate(x, y, z); + this.translatePrev(x, y, z); + this.translateNext(x, y, z); + } + + + // ********* getters ********** + this.getPosX = function () { return this._x; } + this.getPosY = function () { return this._y; } + this.getPosZ = function () { return this._z; } + this.getPrevX = function () { return this._prevX; } + this.getPrevY = function () { return this._prevY; } + this.getPrevZ = function () { return this._prevZ; } + this.getNextX = function () { return this._nextX; } + this.getNextY = function () { return this._nextY; } + this.getNextZ = function () { return this._nextZ; } + this.getPos = function() { return Vector.create([this._x, this._y, this._z]);} + this.getPrev = function() { return Vector.create([this._prevX, this._prevY, this._prevZ]);} + this.getNext = function() { return Vector.create([this._nextX, this._nextY, this._nextZ]);} + //return the square of distance from passed in point to the anchor position + this.getDistanceSq = function (x, y, z) { + return (this._x - x) * (this._x - x) + (this._y - y) * (this._y - y) + (this._z - z) * (this._z - z); + } + //return sq. of distance to prev. + this.getPrevDistanceSq = function (x, y, z) { + return (this._prevX - x) * (this._prevX - x) + (this._prevY - y) * (this._prevY - y) + (this._prevZ - z) * (this._prevZ - z); + } + //return sq. of distance to next + this.getNextDistanceSq = function (x, y, z) { + return (this._nextX - x) * (this._nextX - x) + (this._nextY - y) * (this._nextY - y) + (this._nextZ - z) * (this._nextZ - z); + } +} diff --git a/js/helper-classes/RDGE/GLBrushStroke.js b/js/helper-classes/RDGE/GLBrushStroke.js new file mode 100644 index 00000000..89292ad8 --- /dev/null +++ b/js/helper-classes/RDGE/GLBrushStroke.js @@ -0,0 +1,242 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; + + +/////////////////////////////////////////////////////////////////////// +// Class GLBrushStroke +// representation a sequence points (polyline) created by brush tool. +// Derived from class GLGeomObj +/////////////////////////////////////////////////////////////////////// +function GLBrushStroke() { + /////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////// + this._Points = []; + this._BBoxMin = [0, 0, 0]; + this._BBoxMax = [0, 0, 0]; + this._dirty = true; + + //whether or not to use the canvas drawing to stroke/fill + this._useCanvasDrawing = true; + + //the X and Y location of this subpath's canvas in stage world space of Ninja + this._canvasX = 0; + this._canvasY = 0; + + //stroke information + this._strokeWidth = 0.0; + this._strokeColor = [0.4, 0.4, 0.4, 1.0]; + this._strokeMaterial; + this._strokeStyle = "Solid"; + + //drawing context + this._world = null; + + //tool that owns this brushstroke + this._drawingTool = null; + this._planeMat = null; + this._planeMatInv = null; + this._planeCenter = null; + + // initialize the inherited members + this.inheritedFrom = GLGeomObj; + this.inheritedFrom(); + + ///////////////////////////////////////////////////////// + // Property Accessors/Setters + ///////////////////////////////////////////////////////// + this.setWorld = function (world) { this._world = world; } + this.getWorld = function () { return this._world; } + this.geomType = function () { return this.GEOM_TYPE_CUBIC_BEZIER; } + this.setDrawingTool = function (tool) {this._drawingTool = tool;} + this.getDrawingTool = function () {return this._drawingTool;} + this.setPlaneMatrix = function(planeMat){this._planeMat = planeMat;} + this.setPlaneMatrixInverse = function(planeMatInv){this._planeMatInv = planeMatInv;} + this.setPlaneCenter = function(pc){this._planeCenter = pc;} + + this.getCanvasX = function(){return this._canvasX;} + this.getCanvasY = function(){return this._canvasY;} + this.setCanvasX = function(cx){this._canvasX=cx;} + this.setCanvasY = function(cy){this._canvasY=cy;} + + + this.getNumPoints = function () { return this._Points.length; } + this.getPoint = function (index) { return this._Points[index]; } + this.addPoint = function (anchorPt) { this._Points.push(anchorPt); this._dirty=true; } + this.insertPoint = function(pt, index){ this._Points.splice(index, 0, pt); this._dirty=true;} + this.isDirty = function(){return this._dirty;} + this.makeDirty = function(){this._dirty=true;} + + this.getBBoxMin = function () { return this._BBoxMin; } + this.getBBoxMax = function () { return this._BBoxMax; } + + this.getStrokeWidth = function () { return this._strokeWidth; } + this.setStrokeWidth = function (w) { this._strokeWidth = w; this._dirty=true;} + this.getStrokeMaterial = function () { return this._strokeMaterial; } + this.setStrokeMaterial = function (m) { this._strokeMaterial = m; } + this.getStrokeColor = function () { return this._strokeColor; } + this.setStrokeColor = function (c) { this._strokeColor = c; } + this.getStrokeStyle = function () { return this._strokeStyle; } + this.setStrokeStyle = function (s) { this._strokeStyle = s; } + + this.setWidth = function () { }//NO-OP for now + this.setHeight = function () {}//NO-OP for now + + + //remove and return anchor at specified index, return null on error + this.removePoint = function (index) { + var retAnchor = null; + if (index < this._Points.length) { + retPt = this._Points.splice(index, 1); + this._dirty=true; + } + return retPoint; + } + + //remove all the points + this.clear = function () { this._Points = []; this._dirty=true;} + + this.translate = function (tx, ty, tz) { + for (var i=0;i pt[d]) { + this._BBoxMin[d] = pt[d]; + } + if (this._BBoxMax[d] < pt[d]) { + this._BBoxMax[d] = pt[d]; + } + }//for every dimension d from 0 to 2 + } + } + //increase the bbox given the stroke width + for (var d = 0; d < 3; d++) { + this._BBoxMin[d]-= this._strokeWidth/2; + this._BBoxMax[d]+= this._strokeWidth/2; + }//for every dimension d from 0 to 2 + } + this._dirty = false; + } + + //render + // specify how to render the subpath in Canvas2D + this.render = function () { + // get the world + var world = this.getWorld(); + if (!world) throw( "null world in brushstroke render" ); + + // get the context + var ctx = world.get2DContext(); + if (!ctx) throw ("null context in brushstroke render") + + var numPoints = this.getNumPoints(); + if (numPoints === 0) + return; //nothing to do for empty paths + + ctx.save(); + + this.computeMetaGeometry(); + var bboxMin = this.getBBoxMin(); + var bboxMax = this.getBBoxMax(); + var bboxWidth = bboxMax[0] - bboxMin[0]; + var bboxHeight = bboxMax[1] - bboxMin[1]; + ctx.clearRect(0, 0, bboxWidth, bboxHeight); +/* + ctx.lineWidth = this._strokeWidth; + ctx.strokeStyle = "black"; + if (this._strokeColor) + ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); + ctx.fillStyle = "blue"; + if (this._fillColor) + ctx.fillStyle = MathUtils.colorToHex( this._fillColor ); + var lineCap = ['butt','round','square']; + ctx.lineCap = lineCap[1]; + ctx.beginPath(); + var firstPoint = this._Points[0]; + ctx.moveTo(firstPoint[0]-bboxMin[0], firstPoint[1]-bboxMin[1]); + for (var i = 1; i < numPoints; i++) { + var pt = this._Points[i]; + ctx.lineTo(pt[0]-bboxMin[0], pt[1]-bboxMin[1]); + } + ctx.stroke(); + */ + var R2 = this._strokeWidth; + var R = R2*0.5; + var hardness = 0.25; //for a pencil, this is always 1 //TODO get hardness parameter from user interface + var innerRadius = (hardness*R)-1; + if (innerRadius<1) + innerRadius=1; + + for (var i = 0; i < numPoints; i++) { + var pt = this._Points[i]; + ctx.globalCompositeOperation = 'source-over'; + var x = pt[0]-bboxMin[0]; + var y = pt[1]-bboxMin[1]; + var r = ctx.createRadialGradient(x, y, innerRadius, x, y, R); + r.addColorStop(0, 'rgba(255,0,0,0.5)'); + //r.addColorStop(0.5, 'rgba(255,0,0,0.5)'); // prevent aggregation of semi-opaque pixels + r.addColorStop(1, 'rgba(255,0,0,0.0)'); + ctx.fillStyle = r; + //ctx.fillRect(x-R, y-R, R2, R2); + ctx.arc(x, y, R, 0, 2 * Math.PI, false); + ctx.fill(); + //ctx.globalCompositeOperation = 'source-in'; + //ctx.rect(x-R, y-R, R2, R2); + } + ctx.restore(); + } //render() + + + this.export = function() + { + var rtnStr = "type: " + this.geomType() + "\n"; + return rtnStr; + } + + this.import = function( importStr ) + { + } + + this.collidesWithPoint = function (x, y, z) { + if (x < this._BBoxMin[0]) return false; + if (x > this._BBoxMax[0]) return false; + if (y < this._BBoxMin[1]) return false; + if (y > this._BBoxMax[1]) return false; + if (z < this._BBoxMin[2]) return false; + if (z > this._BBoxMax[2]) return false; + + return true; + } + + this.collidesWithPoint = function (x, y) { + if (x < this._BBoxMin[0]) return false; + if (x > this._BBoxMax[0]) return false; + if (y < this._BBoxMin[1]) return false; + if (y > this._BBoxMax[1]) return false; + + return true; + } + +} //function GLSubpath ...class definition \ No newline at end of file diff --git a/js/helper-classes/RDGE/GLCircle.js b/js/helper-classes/RDGE/GLCircle.js new file mode 100644 index 00000000..fc2e6460 --- /dev/null +++ b/js/helper-classes/RDGE/GLCircle.js @@ -0,0 +1,754 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +/////////////////////////////////////////////////////////////////////// +// Class GLCircle +// GL representation of a circle. +// Derived from class GLGeomObj +// The position and dimensions of the stroke, fill, and inner Radius should be in pixels +/////////////////////////////////////////////////////////////////////// +function GLCircle() +{ + + // initialize the inherited members + this.inheritedFrom = GLGeomObj; + this.inheritedFrom(); + + this.init = function( world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) + { + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._width = 2.0; + this._height = 2.0; + this._xOffset = 0; + this._yOffset = 0; + + this._radius = 2.0; + this._strokeWidth = 0.25; + this._innerRadius = 0; + + this._ovalHeight = this._ovalHeight = 2.0*this.radius; + + // stroke and fill colors + this._strokeColor = [0.4, 0.4, 0.4, 1.0]; + this._fillColor = [0.0, 0.6, 0.0, 1.0]; + + // stroke and fill materials + this._fillMaterial; + this._strokeMaterial; + + this._strokeStyle = "Solid"; + + this._aspectRatio = 1.0; + + + if (arguments.length > 0) + { + this._width = width; + this._height = height; + this._xOffset = xOffset; + this._yOffset = yOffset; + + this._strokeWidth = strokeSize; + this._innerRadius = innerRadius; + this._strokeColor = strokeColor; + this._fillColor = fillColor; + + this._strokeStyle = strokeStyle; + } + + this.m_world = world; + + if(strokeMaterial) + { + this._strokeMaterial = strokeMaterial; + } + if(fillMaterial) + { + this._fillMaterial = fillMaterial; + } + } + + /////////////////////////////////////////////////////////////////////// + // Property Accessors + /////////////////////////////////////////////////////////////////////// + this.getStrokeWidth = function() { return this._strokeWidth; } + this.setStrokeWidth = function(w) { this._strokeWidth = w; } + + this.getStrokeMaterial = function() { return this._strokeMaterial; } + this.setStrokeMaterial = function(m) { this._strokeMaterial = m; } + + this.getFillMaterial = function() { return this._fillMaterial; } + this.setFillMaterial = function(m) { this._fillMaterial = m; } + + this.getRadius = function() { return this._radius; } + this.setRadius = function(r) { this._radius = r; } + + this.getWorld = function() { return this._world; } + this.setWorld = function(w) { this._world = w; } + + this.getInnerRadius = function() { return this._innerRadius; } + this.setInnerRadius = function(r) { this._innerRadius = r; } + + this.getStrokeStyle = function() { return this._strokeStyle; } + this.setStrokeStyle = function(s) { this._strokeStyle = s; } + + this.getWidth = function() { return this._width; } + this.setWidth = function(w) { this._width = w; } + + this.getHeight = function() { return this._height; } + this.setHeight = function(h) { this._height = h; } + + this.geomType = function() { return this.GEOM_TYPE_CIRCLE; } + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////////// + // update the "color of the material + this.getFillColor = function() + { + return this._fillColor; + } + +// this.setFillColor = function(c) +// { +// this._fillColor = c; +// } + + this.getStrokeColor = function() + { + return this._strokeColor; + } + +// this.setStrokeColor = function(c) +// { +// this._strokeColor = c; +// } + /////////////////////////////////////////////////////////////////////// + + this.buildBuffers = function() + { + // get the world + var world = this.getWorld(); + if (!world) throw( "null world in buildBuffers" ); + + if (!world._useWebGL) return; + + // create the gl buffer + var gl = world.getGLContext(); + + // determine the number of triangles to generate + var nTriangles = 60; // yes, we will do better than this + + // get the normalized device coordinates (NDC) for + // all position and dimensions. + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, + xRadNDC = this._width/vpw, yRadNDC = this._height/vph, + xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph, + xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC; + + var aspect = world.getAspect(); + var zn = world.getZNear(), zf = world.getZFar(); + var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), + b = -t, + r = aspect*t, + l = -r; + + // calculate the object coordinates from their NDC coordinates + var z = -world.getViewDistance(); + + // get the position of the origin + var x = -z*(r-l)/(2.0*zn)*xNDC, + y = -z*(t-b)/(2.0*zn)*yNDC; + + // get the x and y radii + var xRad = -z*(r-l)/(2.0*zn)*xRadNDC, + yRad = -z*(t-b)/(2.0*zn)*yRadNDC; + + // save the overall dimensions to be used in the uv calculations + this._ovalWidth = xRad; this._ovalHeight = yRad; + + // get the x & y stroke size + var xStroke = -z*(r-l)/(2.0*zn)*xStrokeNDC, + yStroke = -z*(t-b)/(2.0*zn)*yStrokeNDC; + + // get the inner radius + var xInnRad = -z*(r-l)/(2.0*zn)*xInnRadNDC, + yInnRad = -z*(t-b)/(2.0*zn)*yInnRadNDC; + + // get a matrix to rotate a point around the circle + var angle = 2.0*Math.PI/Number(nTriangles); + var mat = Matrix.RotationZ( angle ); + var reverseRotMat = Matrix.RotationZ( -angle ); + + // calculate matrices to scale the circle and stroke to fit the bounds of the ellipse + strokeScaleMat = Matrix.I(4); + strokeScaleMat[0] = xRad; + strokeScaleMat[5] = yRad; + + fillScaleMat = Matrix.I(4); + fillScaleMat[0] = xRad - xStroke; + fillScaleMat[5] = yRad - yStroke; + + innerRadiusScaleMat = Matrix.I(4); + innerRadiusScaleMat[0] = xInnRad; + innerRadiusScaleMat[5] = yInnRad; + + innerStrokeScaleMat = Matrix.I(4); + innerStrokeScaleMat[0] = xInnRad - xStroke; + innerStrokeScaleMat[5] = yInnRad - yStroke; + + var fillPrim, strokePrim0, strokePrim1; + var fillMaterial, strokeMaterial0, strokeMaterial2; + + this._primArray = []; + this._materialArray = []; + this._materialTypeArray = []; + this._materialNodeArray = []; + + ///////////////////////////////////////////////////////////// + // Strokes + if(this._strokeWidth > 0) + { + var numStrokes = 1; + if(this._innerRadius !== 0) + strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles); + + strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles); + } + + ///////////////////////////////////////////////////////////// + // Fill + if(this._innerRadius === 0) + fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles); + else + fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles); + + if (fillPrim) + { + this._primArray.push( fillPrim ); + + if (this.getFillMaterial()) + fillMaterial = this.getFillMaterial().dup(); + else + fillMaterial = new FlatMaterial(); + + if (fillMaterial) + { + fillMaterial.init( this.getWorld() ); + if(!this.getFillMaterial() && this._fillColor) + { + fillMaterial.setProperty("color", this._fillColor); + } + this._materialArray.push( fillMaterial ); + this._materialTypeArray.push( "fill" ); + var matNode = fillMaterial.getMaterialNode(); + this._materialNodeArray.push( matNode ); + } + } + if (strokePrim0) + { + if (this.getStrokeMaterial()) + strokeMaterial = this.getStrokeMaterial().dup(); + else + strokeMaterial = new FlatMaterial(); + + if (strokeMaterial) + { + strokeMaterial.init( this.getWorld() ); + if(!this.getStrokeMaterial() && this._strokeColor) + { + strokeMaterial.setProperty("color", this._strokeColor); + } + this._primArray.push( strokePrim0 ); + + var materialNode = createMaterialNode("ovalFillMaterial"); + this._materialArray.push( strokeMaterial ); + this._materialTypeArray.push( "stroke" ); + this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); + } + } + if (strokePrim1) + { + if (this.getStrokeMaterial()) + strokeMaterial = this.getStrokeMaterial().dup(); + else + strokeMaterial = new FlatMaterial(); + + if (strokeMaterial) + { + strokeMaterial.init( this.getWorld() ); + if(!this.getStrokeMaterial() && this._strokeColor) + { + strokeMaterial.setProperty("color", this._strokeColor); + } + this._primArray.push( strokePrim1 ); + + var materialNode = createMaterialNode("ovalFillMaterial"); + this._materialArray.push( strokeMaterial ); + this._materialTypeArray.push( "stroke" ); + this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); + } + } + + world.updateObject(this); + } + + + this.generateOval = function(xOff, yOff, rotationMat, scaleMat, nTriangles) + { + var pt = [1.0, 0.0, 0.0]; + //var pts = scaleMat.multiply(pt); + var pts = glmat4.multiplyVec3( scaleMat, pt, []); + var x = pts[0], y = pts[1], z = 0; + var xs = scaleMat[0], ys = scaleMat[4]; + + var vrts = [], nrms = [], uvs = [], indices = []; + var index = 0; + for (var i=0; i 0) + { + xScale = 0.5*innerRad*this._width; + yScale = 0.5*innerRad*this._height; + mat[0] = xScale; + mat[5] = yScale; + + // get the bezier points + var bezPts = MathUtils.circularArcToBezier( Vector.create([0,0,0]), Vector.create([1,0,0]), -2.0*Math.PI ); + if (bezPts) + { + var n = bezPts.length; + p = MathUtils.transformPoint( bezPts[0], mat ); + ctx.moveTo( p[0], p[1] ); + index = 1; + while (index < n) + { + p0 = MathUtils.transformPoint( bezPts[index], mat ); + p1 = MathUtils.transformPoint( bezPts[index+1], mat ); + + var x0 = p0[0], y0 = p0[1], + x1 = p1[0], y1 = p1[1]; + ctx.quadraticCurveTo( x0, y0, x1, y1 ); + index += 2; + } + } + } + + // fill the path + ctx.fill(); + + // calculate the stroke matrix + xScale = 0.5*this._width - 0.5*lineWidth; + yScale = 0.5*this._height - 0.5*lineWidth; + mat[0] = xScale; + mat[5] = yScale; + + // set up the stroke style + ctx.beginPath(); + ctx.lineWidth = lineWidth; + ctx.strokeStyle = "#0000ff"; + if (this._strokeColor) + ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); + + // draw the stroke + p = MathUtils.transformPoint( bezPts[0], mat ); + ctx.moveTo( p[0], p[1] ); + index = 1; + while (index < n) + { + var p0 = MathUtils.transformPoint( bezPts[index], mat ); + var p1 = MathUtils.transformPoint( bezPts[index+1], mat ); + + var x0 = p0[0], y0 = p0[1], + x1 = p1[0], y1 = p1[1]; + ctx.quadraticCurveTo( x0, y0, x1, y1 ); + index += 2; + } + + if (MathUtils.fpSign(innerRad) > 0) + { + // calculate the stroke matrix + xScale = 0.5*innerRad*this._width - 0.5*lineWidth; + yScale = 0.5*innerRad*this._height - 0.5*lineWidth; + mat[0] = xScale; + mat[5] = yScale; + + // draw the stroke + p = MathUtils.transformPoint( bezPts[0], mat ); + ctx.moveTo( p[0], p[1] ); + index = 1; + while (index < n) + { + var p0 = MathUtils.transformPoint( bezPts[index], mat ); + var p1 = MathUtils.transformPoint( bezPts[index+1], mat ); + + var x0 = p0[0], y0 = p0[1], + x1 = p1[0], y1 = p1[1]; + ctx.quadraticCurveTo( x0, y0, x1, y1 ); + index += 2; + } + } + + // render the stroke + ctx.stroke(); + } + } + + this.export = function() + { + var rtnStr = "type: " + this.geomType() + "\n"; + + rtnStr += "xoff: " + this._xOffset + "\n"; + rtnStr += "yoff: " + this._yOffset + "\n"; + rtnStr += "width: " + this._width + "\n"; + rtnStr += "height: " + this._height + "\n"; + rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; + rtnStr += "innerRadius: " + this._innerRadius + "\n"; + rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; + rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; + rtnStr += "fillColor: " + String(this._fillColor) + "\n"; + + rtnStr += "strokeMat: "; + if (this._strokeMaterial) + rtnStr += this._strokeMaterial.getName(); + else + rtnStr += "flatMaterial"; + rtnStr += "\n"; + + rtnStr += "fillMat: "; + if (this._fillMaterial) + rtnStr += this._fillMaterial.getName(); + else + rtnStr += "flatMaterial"; + rtnStr += "\n"; + + return rtnStr; + } + + this.import = function( importStr ) + { + this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); + this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); + this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); + this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); + this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); + this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); + this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); + var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); + var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); + this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); + this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); + + var strokeMat = MaterialsLibrary.getMaterial( strokeMaterialName ); + if (!strokeMat) + { + console.log( "object material not found in library: " + strokeMaterialName ); + strokeMat = new FlatMaterial(); + } + this._strokeMaterial = strokeMat; + + var fillMat = MaterialsLibrary.getMaterial( fillMaterialName ); + if (!fillMat) + { + console.log( "object material not found in library: " + fillMaterialName ); + fillMat = new FlatMaterial(); + } + this._fillMaterial = fillMat; + } + + this.collidesWithPoint = function( x, y ) + { +// if(x < this._xOffset) return false; +// if(x > (this._xOffset + this._width)) return false; +// if(y < this._yOffset) return false; +// if(y > (this._yOffset + this._height)) return false; + + return true; + } + + this.containsPoint = function( pt, dir ) + { + var world = this.getWorld(); + if (!world) throw( "null world in containsPoint" ); + + // get a point on the plane of the circle + // the point is in NDC, as is the input parameters + var mat = this.getMatrix(); + var plane = [0,0,1,0]; + plane = MathUtils.transformPlane( plane, mat ); + var projPt = MathUtils.vecIntersectPlane ( pt, dir, plane ); + + // transform the projected point back to the XY plane + //var invMat = mat.inverse(); + var invMat = glmat4.inverse( mat, [] ); + var planePt = MathUtils.transformPoint( projPt, invMat ); + + // get the normalized device coordinates (NDC) for + // the position and radii. + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, + xRadNDC = this._width/vpw, yRadNDC = this._height/vph; + var projMat = world.makePerspectiveMatrix(); + var z = -world.getViewDistance(); + var planePtNDC = planePt.slice(0); + planePtNDC[2] = z; + planePtNDC = MathUtils.transformHomogeneousPoint( planePtNDC, projMat ); + planePtNDC = MathUtils.applyHomogeneousCoordinate( planePtNDC ); + + // get the gl coordinates + var aspect = world.getAspect(); + var zn = world.getZNear(), zf = world.getZFar(); + var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), + b = -t, + r = aspect*t, + l = -r; + + var angle = Math.atan2( planePtNDC[1] - yNDC, planePtNDC[0] - xNDC ); + var degrees = angle*180.0/Math.PI; + var objPtNDC = [Math.cos(angle)*xRadNDC + xNDC, Math.sin(angle)*yRadNDC + yNDC, 0]; + + var ctrNDC = [xNDC, yNDC]; + + var distToBoundary = VecUtils.vecDist( 2, ctrNDC, objPtNDC ), + distToPt = VecUtils.vecDist( 2, ctrNDC, planePtNDC ); + + return (MathUtils.fpCmp(distToPt,distToBoundary) <= 0); + } + + this.getNearPoint = function( pt, dir ) + { + var world = this.getWorld(); + if (!world) throw( "null world in getNearPoint" ); + + // get a point on the plane of the circle + // the point is in NDC, as is the input parameters + var mat = this.getMatrix(); + var plane = [0,0,1,0]; + plane = MathUtils.transformPlane( plane, mat ); + var projPt = MathUtils.vecIntersectPlane ( pt, dir, plane ); + + // transform the projected point back to the XY plane + //var invMat = mat.inverse(); + var invMat = glmat4.inverse( mat, [] ); + var planePt = MathUtils.transformPoint( projPt, invMat ); + + // get the normalized device coordinates (NDC) for + // the position and radii. + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, + xRadNDC = this._width/vpw, yRadNDC = this._height/vph; + var projMat = world.makePerspectiveMatrix(); + var z = -world.getViewDistance(); + var planePtNDC = planePt.slice(0); + planePtNDC[2] = z; + planePtNDC = MathUtils.transformHomogeneousPoint( planePtNDC, projMat ); + planePtNDC = MathUtils.applyHomogeneousCoordinate( planePtNDC ); + + // get the gl coordinates + var aspect = world.getAspect(); + var zn = world.getZNear(), zf = world.getZFar(); + var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), + b = -t, + r = aspect*t, + l = -r; + + var angle = Math.atan2( planePtNDC[1] - yNDC, planePtNDC[0] - xNDC ); + var degrees = angle*180.0/Math.PI; + var objPt = [Math.cos(angle)*xRadNDC + xNDC, Math.sin(angle)*yRadNDC + yNDC, 0]; + + // convert to GL coordinates + objPt[0] = -z*(r-l)/(2.0*zn)*objPt[0]; + objPt[1] = -z*(t-b)/(2.0*zn)*objPt[1]; + + // re-apply the transform + objPt = MathUtils.transformPoint( objPt, mat ); + + return objPt; + } + + this.recalcTexMapCoords = function( vrts, uvs ) + { + var n = vrts.length/3; + var ivrt = 0, iuv = 0; + var uMin = 1.e8, uMax = -1.e8, + vMin = 1.e8, vMax = -1.e8 + for (var i=0; i uMax) uMax = uvs[iuv]; + + iuv++; ivrt++; + uvs[iuv] = 0.5*(vrts[ivrt]/this._ovalHeight + 1); + if (uvs[iuv] < vMin) vMin = uvs[iuv]; + if (uvs[iuv] > vMax) vMax = uvs[iuv]; + iuv++; ivrt += 2; + } + + //console.log( "remap: " + uvs ); + //console.log( "uRange: " + uMin + " => " + uMax ); + //console.log( "vRange: " + vMin + " => " + vMax ); + } + } + + 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 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +/////////////////////////////////////////////////////////////////////// +// Class GLGeomObj +// Super class for all geometry classes +/////////////////////////////////////////////////////////////////////// +function GLGeomObj() +{ + /////////////////////////////////////////////////////////////////////// + // Constants + /////////////////////////////////////////////////////////////////////// + this.GEOM_TYPE_RECTANGLE = 1; + this.GEOM_TYPE_CIRCLE = 2; + this.GEOM_TYPE_LINE = 3; + this.GEOM_TYPE_PATH = 4; + this.GEOM_TYPE_CUBIC_BEZIER = 5; + this.GEOM_TYPE_UNDEFINED = -1; + + // Needed for calculating dashed/dotted strokes + this.DASH_LENGTH = 0.15; + this.DOT_LENGTH = 0.05; + this.GAP_LENGTH = 0.05; + + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._matrix = Matrix.I(4); + + this._next = undefined; + this._prev = undefined; + this._child = undefined; + this._parent = undefined; + + this.m_world = null; + + // stroke and fill materials + this._fillMaterial; + this._strokeMaterial; + + // array of primitives - used in RDGE + this._primArray = []; + this._materialNodeArray = []; + this._materialArray = []; + this._materialTypeArray = []; + + // the transform node used by RDGE + this._trNode = null; + + + /////////////////////////////////////////////////////////////////////// + // Property accessors + /////////////////////////////////////////////////////////////////////// + this.setWorld = function( world ) { this.m_world = world; } + this.getWorld = function() { return this.m_world; } + + this.getMatrix = function() { return this._matrix.slice(0); } + this.setMatrix = function(m) { this._matrix = m.slice(0); } + + this.setNext = function( next ) { this._next = next; } + this.getNext = function() { return this._next; } + this.setPrev = function( prev ) { this._prev = prev; } + this.getPrev = function() { return this._prev; } + this.setChild = function( child ) { this._child = child; } + this.getChild = function() { return this._child; } + this.setParent = function( parent ) { this._parent = parent; } + this.getParent = function() { return this._parent; } + + this.geomType = function() { return this.GEOM_TYPE_UNDEFINED; } + + this.getPrimitiveArray = function() { return this._primArray; } + this.getMaterialNodeArray = function() { return this._materialNodeArray; } + this.getMaterialArray = function() { return this._materialArray; } + + this.getTransformNode = function() { return this._trNode; } + this.setTransformNode = function(t) { this._trNode = t; } + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + this.setMaterialColor = function(c, type) + { + if (type == "fill") + this._fillColor = c.slice(0); + else + this._strokeColor = c.slice(0); + if (this._materialArray && this._materialTypeArray) + { + var nMats = this._materialArray.length; + if (nMats === this._materialTypeArray.length) + { + for (var i=0; i= 0) + rtnStr = rtnStr.substr(0, index); + + return rtnStr; + } + + this.export = function() + { + var rtnStr; + + /* + var matNodeArr = this.getMaterialNodeArray(); + if (matNodeArr) + { + var nMats = matNodeArr.length; + if (nMats > 0) + { + for (var i=0; i +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. + */ + +/////////////////////////////////////////////////////////////////////// +// Class GLMaterial +// GL representation of a material. +/////////////////////////////////////////////////////////////////////// +function GLLight() +{ + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._type = 0; + this._color = [0.1, 0.1, 0.1, 1]; + + /////////////////////////////////////////////////////////////////////// + // Property Accessors + /////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + +} + + diff --git a/js/helper-classes/RDGE/GLLine.js b/js/helper-classes/RDGE/GLLine.js new file mode 100644 index 00000000..9eaa69d1 --- /dev/null +++ b/js/helper-classes/RDGE/GLLine.js @@ -0,0 +1,446 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +/////////////////////////////////////////////////////////////////////// +// Class GLLine +// GL representation of a line. +// Derived from class GLGeomObj +/////////////////////////////////////////////////////////////////////// +function GLLine( world, xOffset, yOffset, width, height, slope, strokeSize, strokeColor, strokeMaterial, strokeStyle, xAdj, yAdj) +{ + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// + this._width = 2.0; + this._height = 2.0; + this._xOffset = 0; + this._yOffset = 0; + + // If line doesn't fit in canvas world, we had to grow the canvas by this much on either side + this._xAdj = 0; + this._yAdj = 0; + + this._slope = 0; + + this._strokeWidth = 0.25; + + // stroke colors + this._strokeColor = [0.4, 0.4, 0.4, 1.0]; + + // stroke materials + this._strokeMaterial; + + this._strokeStyle = "Solid"; + + if (arguments.length > 0) + { + this._width = width; + this._height = height; + this._xOffset = xOffset; + this._yOffset = yOffset; + + this._xAdj = xAdj; + this._yAdj = yAdj; + + this._slope = slope; + this._strokeWidth = strokeSize; + this._strokeColor = strokeColor; + + this._strokeStyle = strokeStyle; + } + + this._scaleX = 1.0; + this._scaleY = 1.0; + + this._scaleX = (world._viewportWidth)/(world._viewportHeight); + + this._strokeVerticesLen = 0; + + this.m_world = world; + + this._materialAmbient = [0.2, 0.2, 0.2, 1.0]; + this._materialDiffuse = [0.4, 0.4, 0.4, 1.0]; + this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; + + // initialize the inherited members + this.inheritedFrom = GLGeomObj; + this.inheritedFrom(); + + if(strokeMaterial) + { + this._strokeMaterial = strokeMaterial; + } + + /////////////////////////////////////////////////////////////////////// + // Property Accessors + /////////////////////////////////////////////////////////////////////// + this.getStrokeWidth = function() { return this._strokeWidth; } + this.setStrokeWidth = function(w) { this._strokeWidth = w; } + + this.getStrokeMaterial = function() { return this._strokeMaterial; } + this.setStrokeMaterial = function(m) { this._strokeMaterial = m; } + + this.getStrokeColor = function() { return this._strokeColor; } + //this.setStrokeColor = function(c) { this._strokeColor = c; } + + this.getStrokeStyle = function() { return this._strokeStyle; } + this.setStrokeStyle = function(s) { this._strokeStyle = s; } + + this.getWidth = function() { return this._width; } + this.setWidth = function(w) { this._width = w; } + + this.getHeight = function() { return this._height; } + this.setHeight = function(h) { this._height = h; } + + this.getXAdj = function() { return this._xAdj; } + this.setXAdj = function(x) { this._xAdj = x; } + + this.getYAdj = function() { return this._yAdj; } + this.setYAdj = function(y) { this._yAdj = y; } + + this.getSlope = function() { return this._slope; } + this.setSlope = function(m) { this._slope = m; } + + this.geomType = function() { return this.GEOM_TYPE_LINE; } + + /////////////////////////////////////////////////////////////////////// + // Methods + /////////////////////////////////////////////////////////////////////// + this.buildBuffers = function() + { + // get the world + var world = this.getWorld(); + if (!world) throw( "null world in buildBuffers" ); + if (!world._useWebGL) return; + + // create the gl buffer + var gl = world.getGLContext(); + + this._strokeVerticesLen = 0; + + var strokeVertices = []; + var strokeTextures = []; + var strokeNormals = []; + var strokeColors = []; + +// var scaleMat = Matrix.I(3); +// scaleMat.elements[0][0] = this._scaleX; +// scaleMat.elements[1][1] = this._scaleY; + + +// get the normalized device coordinates (NDC) for + // all position and dimensions. + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, + xFillNDC = this._wi