-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.cs
226 lines (192 loc) · 9.55 KB
/
Block.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
using System;
using System.Collections.Generic;
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.Generic;
using GoblinXNA.Device.Util;
using GoblinXNA.Physics;
using GoblinXNA.Helpers;
using GoblinXNA.UI.UI2D;
using GoblinXNA.UI.Events;
using GoblinXNA.Device.Capture;
using GoblinXNA.Device.Vision;
using GoblinXNA.Device.Vision.Marker;
namespace MARVIN
{
public class Block : Microsoft.Xna.Framework.Game
{
List<Building> buildingsInBlocks; //List of buildings
//Global references.
public GlobalVariables global;
//Markers
MarkerNode blockNode;
TransformNode blockTransNode;
public Block(MarkerNode markerNode, string[] names, ref GlobalVariables g)
{
global = g;
buildingsInBlocks = new List<Building>();
blockNode = markerNode;
float scale = 0.0073f;
blockTransNode = new TransformNode();
blockTransNode.Scale = Vector3.One * scale;
// blockTransNode.Translation = new Vector3(0.0f, -64.25f, 0.0f);
// blockTransNode.Translation = new Vector3(-33.5f, -54.25f, 0);
blockTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2);
blockNode.AddChild(blockTransNode);
foreach (string s in names)
{
//Note, this needs to be changed so we are able to add different buildings to a marker
Building tempBuilding = new Building(s, ref global);
tempBuilding.loadBuildingModel(true, 1.0f); //change scale factor if necessary
buildingsInBlocks.Add(tempBuilding);
blockTransNode.AddChild(tempBuilding.getBuildingNode()); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // blockTransNode.Scale = new Vector3(blockTransNode.Scale.X * 1.0f, blockTransNode.Scale.Y * 1.0f, blockTransNode.Scale.Z * 1.0f);
}
}
public Block(MarkerNode markerNode, string[] names, float scale, ref GlobalVariables g)
{
global = g;
buildingsInBlocks = new List<Building>();
blockNode = markerNode;
blockTransNode = new TransformNode();
blockTransNode.Scale = Vector3.One*scale;
//////////////////////////////////////////////////////////////////////blockTransNode.Translation = new Vector3(0.0f, -64.25f, 0.0f);
//blockTransNode.Translation = new Vector3(0.0f, -64.25f, 0.0f); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//blockTransNode.Translation = new Vector3(-33.5f, -54.25f, 0);
blockTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2);
blockNode.AddChild(blockTransNode);
foreach (string s in names)
{
//Note, this needs to be changed so we are able to add different buildings to a marker
Building tempBuilding = new Building(s, ref global);
tempBuilding.loadBuildingModel(true, 1.0f); //change scale factor if necessary
buildingsInBlocks.Add(tempBuilding);
//blockTransNode.AddChild(tempBuilding.getBuildingNode()); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// blockTransNode.Scale = new Vector3(blockTransNode.Scale.X * 1.0f, blockTransNode.Scale.Y * 1.0f, blockTransNode.Scale.Z * 1.0f);
// blockNode.AddChild(blockTransNode);
}
}
public void printBuildingCoordinates()
{
Vector4 homog_modelWorldCoords;// = Vector4.Transform(global.ORIGIN, global.pointerTip.WorldTransformation * global.toolbar1MarkerNode.WorldTransformation);
Vector3 inhomog_modelWorldCoords;// = new Vector3(homog_pointerWorldCoords.X, homog_pointerWorldCoords.Y, homog_pointerWorldCoords.Z);
Vector3 homog_modelScreenCoords;// = global.graphics.GraphicsDevice.Viewport.Project(inhomog_pointerWorldCoords,
//State.ProjectionMatrix, State.ViewMatrix, Matrix.Identity);
// GoblinXNA.UI.Notifier.AddMessage("" + global.ORIGIN.ToString());
//GoblinXNA.UI.Notifier.AddMessage("" + blockNode.MarkerFound);
GeometryNode tempBuilding;
foreach (Building s in buildingsInBlocks)
{
tempBuilding = s.getBuildingNode();
//homog_modelWorldCoords = Vector4.Transform(global.ORIGIN, blockNode.WorldTransformation);
homog_modelWorldCoords = Vector4.Transform(global.ORIGIN, tempBuilding.WorldTransformation * blockTransNode.WorldTransformation * blockNode.WorldTransformation);
//homog_modelWorldCoords = Vector4.Transform(global.ORIGIN, tempBuilding.Model.OffsetTransform * tempBuilding.WorldTransformation * blockTransNode.WorldTransformation * blockNode.WorldTransformation);
inhomog_modelWorldCoords = new Vector3(homog_modelWorldCoords.X, homog_modelWorldCoords.Y, homog_modelWorldCoords.Z);
homog_modelScreenCoords = global.graphics.GraphicsDevice.Viewport.Project(inhomog_modelWorldCoords,
State.ProjectionMatrix, State.ViewMatrix, Matrix.Identity);
GoblinXNA.UI.Notifier.AddMessage("Building " + s.getBuildingName() + " Screen Coords: " + homog_modelScreenCoords);
}
}
public Block(ref GlobalVariables g)
{
global = g;
float scale = 0.0073f;
// float scale = 0.073f;
buildingsInBlocks = new List<Building>();
blockTransNode = new TransformNode();
blockTransNode.Scale = Vector3.One*scale;
blockTransNode.Translation = new Vector3(0.0f, -64.25f, 0.0f);
// blockTransNode.Translation = new Vector3(33.5f, -54.25f, 0.0f);
blockTransNode.Rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2);
}
//Associate building marker with an ARTag
public void setMarkerNode(MarkerNode markerName)
{
blockNode = markerName;
}
public void addBuilding(Building _building)
{
buildingsInBlocks.Add(_building);
blockTransNode.AddChild(_building.getBuildingNode()); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
public void setBuildingMaterial(string address, Material newMat)
{
foreach (Building b in buildingsInBlocks)
{
if (b.getBuildingName() == address)
{
b.setBuildingMaterial(newMat);
}
}
}
public Building getBuilding(string address)
{
Building temp = new Building(ref global);
temp.setBuildingName("Error");
foreach (Building b in buildingsInBlocks)
{
if(b.getBuildingName() == address)
{
return b;
}
}
return temp;
}
public bool removeBuilding(string address)
{
foreach (Building b in buildingsInBlocks)
{
if (b.getBuildingName() == address)
{
buildingsInBlocks.Remove(b);
blockTransNode.RemoveChild(b.getBuildingNode());
return true;
}
}
return false;
}
//Detect presence of our marker
public bool isMarkerPresent()
{
return blockNode.MarkerFound;
}
public MarkerNode getMarkerNode()
{
return blockNode;
}
public void setBuildings(List<Building> buildings)
{
buildingsInBlocks = buildings;
}
public void setTranslation(float x, float y, float z)
{
blockTransNode.Translation = new Vector3(x, y, z);
}
public void setScaling(float x, float y, float z)
{
blockTransNode.Scale = new Vector3(blockTransNode.Scale.X * x, blockTransNode.Scale.Y * y, blockTransNode.Scale.Z * z);
}
public void setRotation(float xDegrees, float yDegrees, float zDegrees)
{
blockTransNode.Rotation = Quaternion.CreateFromYawPitchRoll(MathHelper.ToRadians(xDegrees),MathHelper.ToRadians(yDegrees),MathHelper.ToRadians(zDegrees)) * blockTransNode.Rotation;
}
public TransformNode getTransNode()
{
return blockTransNode;
}
public void placeBuildings()
{
}
}
}