diff options
author | hwc487 | 2012-05-11 11:28:15 -0700 |
---|---|---|
committer | hwc487 | 2012-05-11 11:28:15 -0700 |
commit | 634194bf87744dd6f693380ec878cc5dd42207a1 (patch) | |
tree | 9652bf677abb71b56582deb9c46fb2dcb7d9a687 /js/lib/geom/rectangle.js | |
parent | d1bcb47ba34f2f2b8db5fa310a9e9a9bd7973988 (diff) | |
parent | e2ef92008a39a67d4f7db0627c7352bdc06ed476 (diff) | |
download | ninja-634194bf87744dd6f693380ec878cc5dd42207a1.tar.gz |
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into 3DBugs
Conflicts:
js/lib/geom/circle.js
js/lib/geom/rectangle.js
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 1400 |
1 files changed, 737 insertions, 663 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 296ed024..cf0e7fc8 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -13,361 +13,426 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel; | |||
13 | // GL representation of a rectangle. | 13 | // GL representation of a rectangle. |
14 | // Derived from class GeomObj | 14 | // Derived from class GeomObj |
15 | /////////////////////////////////////////////////////////////////////// | 15 | /////////////////////////////////////////////////////////////////////// |
16 | var Rectangle = function GLRectangle() { | 16 | exports.Rectangle = Object.create(GeomObj, { |
17 | // CONSTANTS | 17 | // CONSTANTS |
18 | this.N_TRIANGLES = 15; | 18 | N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? |
19 | 19 | ||
20 | /////////////////////////////////////////////////////////////////////// | 20 | /////////////////////////////////////////////////////////////////////// |
21 | // Instance variables | 21 | // Instance variables |
22 | /////////////////////////////////////////////////////////////////////// | 22 | /////////////////////////////////////////////////////////////////////// |
23 | this._width = 2.0; | 23 | _width: { value : 2.0, writable: true }, |
24 | this._height = 2.0; | 24 | _height: { value : 2.0, writable: true }, |
25 | this._xOffset = 0; | 25 | _xOffset: { value : 0, writable: true }, |
26 | this._yOffset = 0; | 26 | _yOffset: { value : 0, writable: true }, |
27 | 27 | ||
28 | this._tlRadius = 0; | 28 | _tlRadius: { value : 0, writable: true }, |
29 | this._trRadius = 0; | 29 | _trRadius: { value : 0, writable: true }, |
30 | this._blRadius = 0; | 30 | _blRadius: { value : 0, writable: true }, |
31 | this._brRadius = 0; | 31 | _brRadius: { value : 0, writable: true }, |
32 | 32 | ||
33 | this._strokeWidth = 0.25; | 33 | _strokeWidth: { value : 0.25, writable: true }, |
34 | _strokeStyle: { value : "Solid", writable: true }, | ||
34 | 35 | ||
35 | this._strokeStyle = "Solid"; | 36 | init: { |
36 | this.init = function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, | 37 | value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, |
37 | tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle) { | 38 | tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle) { |
39 | this.m_world = world; | ||
38 | 40 | ||
41 | if (arguments.length > 0) { | ||
42 | this._width = width; | ||
43 | this._height = height; | ||
44 | this._xOffset = xOffset; | ||
45 | this._yOffset = yOffset; | ||
39 | 46 | ||
40 | this.m_world = world; | 47 | this._strokeWidth = strokeSize; |
48 | this._strokeColor = strokeColor; | ||
49 | this._fillColor = fillColor; | ||
41 | 50 | ||
42 | if (arguments.length > 0) { | 51 | this.setTLRadius(tlRadius); |
43 | this._width = width; | 52 | this.setTRRadius(trRadius); |
44 | this._height = height; | 53 | this.setBLRadius(blRadius); |
45 | this._xOffset = xOffset; | 54 | this.setBRRadius(brRadius); |
46 | this._yOffset = yOffset; | ||
47 | 55 | ||
48 | this._strokeWidth = strokeSize; | 56 | this._strokeStyle = strokeStyle; |
49 | this._strokeColor = strokeColor; | ||
50 | this._fillColor = fillColor; | ||
51 | |||
52 | this.setTLRadius(tlRadius); | ||
53 | this.setTRRadius(trRadius); | ||
54 | this.setBLRadius(blRadius); | ||
55 | this.setBRRadius(brRadius); | ||
56 | |||
57 | this._strokeStyle = strokeStyle; | ||
58 | 57 | ||
59 | this._matrix = Matrix.I(4); | 58 | this._matrix = Matrix.I(4); |
60 | } | 59 | } |
61 | 60 | ||
62 | // the overall radius includes the fill and the stroke. separate the two based onthe stroke width | 61 | // the overall radius includes the fill and the stroke. separate the two based on the stroke width |
63 | // this._fillRad = this._radius - this._strokeWidth; | 62 | // this._fillRad = this._radius - this._strokeWidth; |
64 | var err = 0; | 63 | // var err = 0.05; |
65 | this._fillWidth = this._width - this._strokeWidth + err; | 64 | var err = 0; |
66 | this._fillHeight = this._height - this._strokeWidth + err; | 65 | this._fillWidth = this._width - this._strokeWidth + err; |
66 | this._fillHeight = this._height - this._strokeWidth + err; | ||
67 | 67 | ||
68 | this._materialAmbient = [0.2, 0.2, 0.2, 1.0]; | 68 | this._materialAmbient = [0.2, 0.2, 0.2, 1.0]; |
69 | this._materialDiffuse = [0.4, 0.4, 0.4, 1.0]; | 69 | this._materialDiffuse = [0.4, 0.4, 0.4, 1.0]; |
70 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; | 70 | this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; |
71 | 71 | ||
72 | if(strokeMaterial) { | 72 | if(strokeMaterial) { |
73 | this._strokeMaterial = strokeMaterial; | 73 | this._strokeMaterial = strokeMaterial; |
74 | } else { | 74 | } else { |
75 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 75 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
76 | } | 76 | } |
77 | 77 | ||
78 | if(fillMaterial) { | 78 | if(fillMaterial) { |
79 | this._fillMaterial = fillMaterial; | 79 | this._fillMaterial = fillMaterial; |
80 | } else { | 80 | } else { |
81 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | 81 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
82 | } | ||
82 | } | 83 | } |
83 | }; | 84 | }, |
84 | 85 | ||
85 | /////////////////////////////////////////////////////////////////////// | 86 | /////////////////////////////////////////////////////////////////////// |
86 | // Property Accessors | 87 | // Property Accessors |
87 | /////////////////////////////////////////////////////////////////////// | 88 | /////////////////////////////////////////////////////////////////////// |
88 | this.getStrokeWidth = function() { | 89 | // TODO - Use getters/setters in the future |
89 | return this._strokeWidth; | 90 | getStrokeWidth: { |
90 | }; | 91 | value: function() { |
91 | 92 | return this._strokeWidth; | |
92 | this.setStrokeWidth = function(w) { | 93 | } |
93 | this._strokeWidth = w; | 94 | }, |
94 | }; | ||
95 | |||
96 | this.getStrokeMaterial = function() { | ||
97 | return this._strokeMaterial; | ||
98 | }; | ||
99 | |||
100 | this.setStrokeMaterial = function(m) { | ||
101 | this._strokeMaterial = m; | ||
102 | }; | ||
103 | |||
104 | this.getFillMaterial = function() { | ||
105 | return this._fillMaterial; | ||
106 | }; | ||
107 | 95 | ||
108 | this.setFillMaterial = function(m) { | 96 | setStrokeWidth: { |
109 | this._fillMaterial = m; | 97 | value: function(w) { |
110 | }; | 98 | this._strokeWidth = w; |
99 | } | ||
100 | }, | ||
111 | 101 | ||
112 | this.getStrokeColor = function() { | 102 | getStrokeMaterial: { |
113 | return this._strokeColor; | 103 | value: function() { |
114 | }; | 104 | return this._strokeMaterial; |
105 | } | ||
106 | }, | ||
115 | 107 | ||
116 | this.getFillColor = function() { | 108 | setStrokeMaterial: { |
117 | return this._fillColor; | 109 | value: function(m) { |
118 | }; | 110 | this._strokeMaterial = m; |
111 | } | ||
112 | }, | ||
119 | 113 | ||
120 | this.getTLRadius = function() { | 114 | getFillMaterial: { |
121 | return this._tlRadius; | 115 | value: function() { |
122 | }; | 116 | return this._fillMaterial; |
117 | } | ||
118 | }, | ||
123 | 119 | ||
124 | this.setTLRadius = function(r) { | 120 | setFillMaterial: { |
125 | this._tlRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); | 121 | value: function(m) { |
126 | }; | 122 | this._fillMaterial = m; |
123 | } | ||
124 | }, | ||
125 | /////////////////////////////////////////////////////////////////////// | ||
126 | // update the "color of the material | ||
127 | getFillColor: { | ||
128 | value: function() { | ||
129 | return this._fillColor; | ||
130 | } | ||
131 | }, | ||
132 | |||
133 | // setFillColor: { | ||
134 | // value: function(c) { | ||
135 | // this._fillColor = c; | ||
136 | // } | ||
137 | // }, | ||
138 | getStrokeColor: { | ||
139 | value: function() { | ||
140 | return this._strokeColor; | ||
141 | } | ||
142 | }, | ||
143 | |||
144 | // setStrokeColor: { | ||
145 | // value: function(c) { | ||
146 | // this._strokeColor = c; | ||
147 | // } | ||
148 | // }, | ||
149 | /////////////////////////////////////////////////////////////////////// | ||
150 | getTLRadius: { | ||
151 | value: function() { | ||
152 | return this._tlRadius; | ||
153 | } | ||
154 | }, | ||
127 | 155 | ||
128 | this.getTRRadius = function() { | 156 | setTLRadius: { |
129 | return this._trRadius; | 157 | value: function(r) { |
130 | }; | 158 | this._tlRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); |
159 | } | ||
160 | }, | ||
131 | 161 | ||
132 | this.setTRRadius = function(r) { | 162 | getTRRadius: { |
133 | this._trRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - |