aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js1433
1 files changed, 749 insertions, 684 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index 490a9a6f..b85433a0 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -13,370 +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///////////////////////////////////////////////////////////////////////
16var Rectangle = function GLRectangle() { 16exports.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 //this._matrix[12] = xoffset; 59 }
61 //this._matrix[13] = yoffset;
62 }
63 60
64 // 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
65 // this._fillRad = this._radius - this._strokeWidth; 62 // this._fillRad = this._radius - this._strokeWidth;
66 // var err = 0.05; 63 // var err = 0.05;
67 var err = 0; 64 var err = 0;
68 this._fillWidth = this._width - this._strokeWidth + err; 65 this._fillWidth = this._width - this._strokeWidth + err;
69 this._fillHeight = this._height - this._strokeWidth + err; 66 this._fillHeight = this._height - this._strokeWidth + err;
70 67
71 this._materialAmbient = [0.2, 0.2, 0.2, 1.0]; 68 this._materialAmbient = [0.2, 0.2, 0.2, 1.0];
72 this._materialDiffuse = [0.4, 0.4, 0.4, 1.0]; 69 this._materialDiffuse = [0.4, 0.4, 0.4, 1.0];
73 this._materialSpecular = [0.4, 0.4, 0.4, 1.0]; 70 this._materialSpecular = [0.4, 0.4, 0.4, 1.0];
74 71
75 if(strokeMaterial) { 72 if(strokeMaterial) {
76 this._strokeMaterial = strokeMaterial; 73 this._strokeMaterial = strokeMaterial;
77 } else { 74 } else {
78 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); 75 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
79 } 76 }
80 77
81 if(fillMaterial) { 78 if(fillMaterial) {
82 this._fillMaterial = fillMaterial; 79 this._fillMaterial = fillMaterial;
83 } else { 80 } else {
84 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); 81 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() );
82 }
85 } 83 }
86 }; 84 },
87 85
88 /////////////////////////////////////////////////////////////////////// 86 ///////////////////////////////////////////////////////////////////////
89 // Property Accessors 87 // Property Accessors
90 /////////////////////////////////////////////////////////////////////// 88 ///////////////////////////////////////////////////////////////////////
91 this.getStrokeWidth = function() { 89 // TODO - Use getters/setters in the future
92 return this._strokeWidth; 90 getStrokeWidth: {
93 }; 91 value: function() {
94 92 return this._strokeWidth;
95 this.setStrokeWidth = function(w) { 93 }
96 this._strokeWidth = w; 94 },
97 };
98
99 this.getStrokeMaterial = function() {
100 return this._strokeMaterial;
101 };
102
103 this.setStrokeMaterial = function(m) {
104 this._strokeMaterial = m;
105 };
106
107 this.getFillMaterial = function() {
108 return this._fillMaterial;
109 };
110
111 this.setFillMaterial = function(m) {
112 this._fillMaterial = m;
113 };
114
115 this.getStrokeColor = function() {
116 return this._strokeColor;
117 };
118 95
119 //this.setStrokeColor = function(c) { 96 setStrokeWidth: {
120 // this._strokeColor = c; 97 value: function(w) {
121 // }; 98 this._strokeWidth = w;
99 }
100 },
122 101
123 this.getFillColor = function() { 102 getStrokeMaterial: {
124 return this._fillColor; 103 value: function() {
125 }; 104 return this._strokeMaterial;
105 }
106 },
126 107
127 //this.setFillColor = function(c) { 108 setStrokeMaterial: {
128 // this._fillColor = c.slice(0); 109 value: function(m) {
129 // }; 110 this._strokeMaterial = m;
111 }
112 },
130 113
131 this.getTLRadius = function() { 114 getFillMaterial: {
132 return this._tlRadius; 115 value: function() {
133 }; 116 return this._fillMaterial;
117 }
118 },
134 119
135 this.setTLRadius = function(r) { 120 setFillMaterial: {
136 this._tlRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2); 121 value: function(m) {
137 }; 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 },
138 155
139 this.getTRRadius = function() { 156 setTLRadius: {
140 return this._trRadius; 157 value: function(r) {
141 }; 158 this._tlRadius = Math.min(r, (this._height - this._strokeWidth)/2, (this._width - this._strokeWidth)/2);
159 }