-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuilding.cs
344 lines (291 loc) · 11 KB
/
Building.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using GoblinXNA;
using GoblinXNA.Graphics;
using GoblinXNA.SceneGraph;
using Model = GoblinXNA.Graphics.Model;
using GoblinXNA.Graphics.Geometry;
using GoblinXNA.Device.Capture;
using GoblinXNA.Device.Vision;
using GoblinXNA.Device.Vision.Marker;
using GoblinXNA.Device.Util;
using GoblinXNA.Physics;
using GoblinXNA.Helpers;
namespace MARVIN
{
public class Building : Microsoft.Xna.Framework.Game
{
public GlobalVariables global;
//Nodes and trackers
GeometryNode buildingGeomNode; //Geometry Node
Material buildingMaterial; //Building Material
TransformNode buildingTransNode; //Transform node for this building.
//Building properties
String buildingName = ""; //Building Name
String buildingAddress = ""; //Building Address
String yearBuilt = ""; //Year building was built;
String stories = ""; // Number of stories
String saleDate = ""; // sale Date of building
String buildingType = ""; // building type
String buildingClass = ""; // building class
String toxicSites = ""; //Toxic Sites
String airRights = ""; //air Rights
System.String buildingInfo = ""; //Building info
List<Attribute> attributes = new List<Attribute>(); //size 8
//Constructors
public Building(ref GlobalVariables g)
{
global = g;
buildingGeomNode = new GeometryNode();
buildingMaterial = new Material();
buildingTransNode = new TransformNode();
}
public Building(System.String name, ref GlobalVariables g)
{
global = g;
buildingName = name;
buildingGeomNode = new GeometryNode();
buildingMaterial = new Material();
buildingTransNode = new TransformNode();
}
public Attribute getAttribute(String attributeName)
{
for (int i = 0; i < attributes.Count; i++)
{
if (attributes[i].name.CompareTo(attributeName) == 0)
{
return attributes[i];
}
}
return null;
}
public int getAttributeValue(String attributeName)
{
Attribute a = getAttribute(attributeName);
return a.value;
}
public void setAttribute(Attribute a)
{
for (int i = 0; i < attributes.Count; i++)
{
if (attributes[i].name.CompareTo(a.name) == 0)
{
attributes[i] = a;
return;
}
}
attributes.Add(a);
attributes.Sort();
}
public void setAttribute(String name, int value, int minVal, int maxVal)
{
Attribute a = new Attribute(name, value, minVal, maxVal);
setAttribute(a);
}
public void setAttributeValue(String attributeName, int val)
{
for (int i = 0; i < attributes.Count; i++)
{
if (attributes[i].name.CompareTo(attributeName) == 0)
{
attributes[i].value = val;
return;
}
}
}
public GeometryNode getBuildingNode()
{
return buildingGeomNode;
}
public TransformNode getBuildingTransNode()
{
return buildingTransNode;
}
public void setBuildingMaterial(Material material)
{
buildingMaterial = material;
buildingGeomNode.Material = buildingMaterial;
}
public void setTransforms(TransformNode thisTransform)
{
buildingTransNode = thisTransform;
buildingTransNode.AddChild(buildingGeomNode);
}
//Get & set building name
public System.String getBuildingName()
{
return buildingName;
}
public String getAddress()
{
return buildingAddress;
}
public String getYearBuilt()
{
return yearBuilt;
}
public String getToxicSites()
{
return toxicSites;
}
public String getStories()
{
return stories;
}
public String getSaleDate()
{
return saleDate;
}
public String getType()
{
return buildingType;
}
public String getClass()
{
return buildingClass;
}
public String getAirRights()
{
return airRights;
}
public String getDescription()
{
return buildingInfo;
}
public void setBuildingName(System.String _name)
{
buildingName = _name;
}
public void setAddress(String _address)
{
buildingAddress = _address;
}
public void setStories(String _stories)
{
stories = _stories;
}
public void setYearBuilt(String _year)
{
yearBuilt = _year;
}
public void setSaleDate(String _date)
{
saleDate = _date;
}
public void setType(String _type)
{
buildingType = _type;
}
public void setClass(String _class)
{
buildingClass = _class;
}
public void setToxicSites(String _sites)
{
toxicSites = _sites;
}
public void setAirRights(String _rights)
{
airRights = _rights;
}
public void setDescription(String _info)
{
buildingInfo = _info;
}
public void loadBuildingModel(bool plainOrDetailed, float factor)
{
FileStream file;
StreamReader sr;
if(plainOrDetailed)
{
file = new FileStream("buildings_detailed.csv", FileMode.Open, FileAccess.Read);
sr = new StreamReader(file);
}
else
{
file = new FileStream("buildings_plain.csv", FileMode.Open,
FileAccess.Read);
sr = new StreamReader(file);
}
ModelLoader loader = new ModelLoader();
float zRot, x, y, z;
String[] chunks;
char[] seps = { ',' };
String s = "";
try
{
// Skip the first line which has column names
sr.ReadLine();
while (!sr.EndOfStream)
{
s = sr.ReadLine();
if (s.Length > 0)
{
chunks = s.Split(seps);
if (chunks[0].Equals(buildingName))
{
buildingGeomNode = new GeometryNode(chunks[0]);
buildingGeomNode.Model = (Model)loader.Load("", "Detailed/" + chunks[0]);
//buildingGeomNode.Model.OffsetTransform
/////////////////////////////////////////////////buildingGeomNode.Model.OffsetToOrigin = false;
buildingGeomNode.Model.OffsetToOrigin = true; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
buildingGeomNode.Physics.Pickable = true;
buildingGeomNode.AddToPhysicsEngine = true;
buildingGeomNode.Physics.Shape = ShapeType.Box;
buildingGeomNode.Model.CastShadows = true;
//buildingGeomNode.Model.OffsetToOrigin = true; ///////////////////////////////////////////////////////////////////
buildingMaterial = new Material();
buildingMaterial.Diffuse = Color.White.ToVector4();
buildingMaterial.Specular = Color.White.ToVector4();
buildingMaterial.SpecularPower = 10;
/* if ((buildingName.Equals("3221_Broadway")) || (buildingName.Equals("623_W129st")))
{
Console.WriteLine("I got here!");
buildingTransNode = new TransformNode();
buildingTransNode.Translation = new Vector3(100.0f, 0.0f, 100.0f);
buildingTransNode.Scale = new Vector3(5, 5, 5);
buildingMaterial.Diffuse = Color.Green.ToVector4();
buildingMaterial.Specular = Color.Green.ToVector4();
}
*/
buildingGeomNode.Material = buildingMaterial;
zRot = (float)Double.Parse(chunks[1]);
x = -1*((buildingGeomNode.Model.MinimumBoundingBox.Max.X + buildingGeomNode.Model.MinimumBoundingBox.Min.X) / 2) + global.calibrateCoords.X;
y = -1*((buildingGeomNode.Model.MinimumBoundingBox.Max.Y + buildingGeomNode.Model.MinimumBoundingBox.Min.Y) / 2) + global.calibrateCoords.Y;
z = -1 * ((buildingGeomNode.Model.MinimumBoundingBox.Max.Z + buildingGeomNode.Model.MinimumBoundingBox.Min.Z) / 2) + global.calibrateCoords.Z;
/*
buildingTransNode = new TransformNode();
buildingTransNode.Translation = new Vector3(x, y, z * factor);
buildingTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ,
(float)(zRot * Math.PI / 180)) * Quaternion.CreateFromAxisAngle(Vector3.UnitX,
MathHelper.PiOver2);
buildingTransNode.
buildingTransNode.AddChild(buildingGeomNode);
buildingGeomNode.Model.OffsetToOrigin = true;
*/
}
}
}
}
catch (Exception exp)
{
Console.WriteLine("buildings.csv has wrong format: " + s);
}
sr.Close();
file.Close();
}
public void setBuildingOffset()
{
}
}
}