aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
authorhwc4872012-05-11 13:52:55 -0700
committerhwc4872012-05-11 13:52:55 -0700
commit137bfc9d4c41cc918d969565bec28a834fe10472 (patch)
treee9fa109fc65218f45e386df48b713ff5858f3d62 /js/lib/geom/rectangle.js
parentd21aaca3d7093b6af968b7f9f764ab54e004f02b (diff)
parent27f4cacb39de1c2e3910748dadc9fc16d0655480 (diff)
downloadninja-137bfc9d4c41cc918d969565bec28a834fe10472.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts: js/lib/geom/geom-obj.js js/lib/geom/rectangle.js js/tools/TagTool.js
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js1407
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///////////////////////////////////////////////////////////////////////
16var Rectangle = function GLRectangle() 16exports.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() {