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