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