-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectsManager.cs
241 lines (210 loc) · 6.83 KB
/
ObjectsManager.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
//05-05-2010
//Kamil Hawdziejuk
using System.Collections.Generic;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace InteractingMeshes
{
/// <summary>
/// For managing objects in the application
/// </summary>
public class ObjectsManager
{
#region --- Private fields ---
/// <summary>
/// Device
/// </summary>
private readonly Device device;
/// <summary>
/// Movement of active object
/// </summary>
public Vector3 Move = new Vector3(0, 0, 0);
/// <summary>
/// Rotation of active objects on all axies
/// </summary>
public Vector3 Rotate = new Vector3(0, 0, 0);
/// <summary>
/// Active object to manipulate
/// </summary>
private GeometricObject activeObject;
/// <summary>
/// Objects in scene
/// </summary>
private List<GeometricObject> objects = new List<GeometricObject>();
#endregion
#region --- Constructing and destroying objects ---
/// <summary>
/// Constructor
/// </summary>
/// <param name="_device"></param>
public ObjectsManager(Device _device)
{
device = _device;
}
#endregion
#region --- Public properties ---
/// <summary>
/// Operating object
/// </summary>
public GeometricObject ActiveObject
{
get { return activeObject; }
set
{
if (activeObject != null)
{
activeObject.Mesh = MeshUtils.ChangeMeshColor(activeObject.Mesh, Color.White, device);
}
if (value != null)
{
value.Mesh = MeshUtils.ChangeMeshColor(value.Mesh, Color.Green, device);
activeObject = value;
}
}
}
public List<GeometricObject> Objects
{
get { return objects; }
set { objects = value; }
}
#endregion
#region --- Public methods ---
public bool ResizeActiveObject(int res)
{
if (res > 0)
{
//if (this.ActiveObject.id.Equals("torus"))
{
// this.RemoveActiveObject();
}
// this.Mesh = Direct3D.Mesh.Torus(device, 1.0f, 1.5f, 8, 8);
// obj.ScaleMatrix.Scale(50.0f, 50.0f, 50.0f);
/// if (this.ActiveObject.Mesh Direct3D.Mesh.)
}
return true;
}
public bool RemoveActiveObject()
{
objects.Remove(ActiveObject);
ActiveObject = GetObject(0);
return true;
}
public bool RemoveObject(GeometricObject _obj)
{
objects.Remove(_obj);
ActiveObject = GetObject(0);
return true;
}
public GeometricObject GetObject(int nr)
{
if (Objects.Count == 0)
{
return null;
}
else if (nr >= objects.Count)
{
return Objects[0];
}
else
{
return Objects[nr];
}
}
/// <summary>
/// Adding the mesh
/// </summary>
/// <param name="_name"></param>
/// <returns></returns>
public bool AddSphere(double radius, int slices, int stacks)
{
var obj = new GeometricObject("sphere", new Vector3(0, 0, 0), Matrix.Identity, new Vector3(0, 0, 0));
obj.Mesh = Mesh.Sphere(device, (float)radius, slices, stacks);
return this.AddObject(obj);
}
/// <summary>
/// Adding the mesh
/// </summary>
/// <param name="_name"></param>
/// <returns></returns>
public bool AddTorus(double innerRadius, double outerRadius, int sides, int rings)
{
var obj = new GeometricObject("torus", new Vector3(0, 0, 0), Matrix.Identity, new Vector3(0, 0, 0));
obj.Mesh = Mesh.Torus(device, (float)innerRadius, (float) outerRadius, sides, rings);
return this.AddObject(obj);
}
/// <summary>
/// Adding the objects to the collection
/// </summary>
/// <param name="_obj"></param>
/// <returns></returns>
public bool AddObject(GeometricObject _obj)
{
if (_obj.Mesh != null)
{
objects.Add(_obj);
SpaceApplication.Options.ListObjects.Items.Add(_obj);
activeObject = _obj;
activeObject.IsChanged = true;
return true;
}
return false;
}
/// <summary>
/// Adding the mesh
/// </summary>
/// <param name="_name"></param>
/// <returns></returns>
public bool Add(string _name)
{
var obj = new GeometricObject(_name, new Vector3(0, 0, 0), Matrix.Identity, new Vector3(0, 0, 0));
if (_name.Equals("torus"))
{
obj.Mesh = Mesh.Torus(device, 2.0f, 3.5f, 8, 8);
//obj.ScaleMatrix.Scale(50.0f, 50.0f, 50.0f);
}
else if (_name.Equals("torus2"))
{
obj.Mesh = Mesh.Torus(device, 1.0f, 4.5f, 10, 10);
}
else if (_name.Equals("sphere"))
{
obj.Mesh = Mesh.Sphere(device, 5, 8, 8);
}
else if (_name.Equals("box"))
{
obj.Mesh = Mesh.Box(device, 4, 3, 2);
}
else if (_name.Equals("polygon"))
{
obj.Mesh = Mesh.Polygon(device, 10, 4);
}
else if (_name.Equals("teapot"))
{
obj.Mesh = Mesh.Teapot(device);
obj.ScaleMatrix.Scale(50.0f, 50.0f, 50.0f);
}
if (obj.Mesh != null)
{
objects.Add(obj);
SpaceApplication.Options.ListObjects.Items.Add(obj);
activeObject = obj;
return true;
}
return false;
}
/// <summary>
/// Resets the meshes
/// </summary>
public void Reset()
{
//Add("torus");
//this.Add("spehere");
//this.Add("box");
//this.Add("polygon");
//this.Add("teapot");
//ActiveObject = objects[0];
}
#endregion
}
}