-
Notifications
You must be signed in to change notification settings - Fork 0
/
InteractiveModel.cs
337 lines (310 loc) · 11.4 KB
/
InteractiveModel.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GlmNet;
using Tao.OpenGl;
using System.IO;
using Assimp;
using System.Threading;
namespace Graphics
{
enum modelType
{
DOOR,
LIGHT,
TEXT,
PILLS,
RADIO,
BARRELS,
GARBAGE,
GUN,
MAX_MODELS,
NULL
}
class InteractiveModel
{
public Model3D obj;
public float range;
public vec3 position;
public Boolean isDrawn;
public vec3 interactionBoundingBox; //x: width, y: height, z: depth
public modelType type;
public int objID;
public static bool radio_ON = false; // for the interaction with the radio
System.Media.SoundPlayer radio_sound = new System.Media.SoundPlayer(Renderer.projectPath + @"\Sounds\radio-recording.wav");
System.Media.SoundPlayer player;
vec3 old_scaling = new vec3(1, 1, 1);
public InteractiveModel(String folderName, String modelName, int texUnit, float rangeOfInteraction, modelType t, int ID)
{
obj = new Model3D();
obj.LoadFile(Renderer.projectPath + "\\ModelFiles\\" + folderName, texUnit, modelName + ".obj");
position = new vec3(0, 0, 0);
range = rangeOfInteraction;
type = t;
objID = ID;
isDrawn = false;
#region Interaction BoundingBox intialization
interactionBoundingBox = new vec3();
float minWidth = float.MaxValue, maxWidth = float.MinValue;
float minHeight = float.MaxValue, maxHeight = float.MinValue;
float minDepth = float.MaxValue, maxDepth = float.MinValue;
foreach (Model m in obj.meshes)
foreach(vec3 v in m.vertices)
{
minWidth = Math.Min(minWidth, v.x);
maxWidth = Math.Max(maxWidth, v.x);
minHeight = Math.Min(minHeight, v.y);
maxHeight = Math.Max(maxHeight, v.y);
minDepth = Math.Min(minDepth, v.z);
maxDepth = Math.Max(maxDepth, v.z);
}
interactionBoundingBox.x = range * (maxWidth - minWidth);
interactionBoundingBox.y = range * (maxHeight - minHeight);
interactionBoundingBox.z = range * (maxDepth - minDepth);
#endregion
}
public void Scale(float x, float y, float z)
{
obj.scalematrix = glm.scale(new mat4(1), new vec3(x, y, z));
interactionBoundingBox.x /= old_scaling.x;
interactionBoundingBox.y /= old_scaling.y;
interactionBoundingBox.z /= old_scaling.z;
interactionBoundingBox *= new vec3(x, y, z);
old_scaling = new vec3(x, y, z);
}
public void Rotate(float angle, vec3 v)
{
obj.rotmatrix = glm.rotate((angle) / 180 * 3.141592f, v);
//Rotation is 90'deg, swap width and length
float tmp = interactionBoundingBox.x;
interactionBoundingBox.x = interactionBoundingBox.z;
interactionBoundingBox.z = tmp;
}
public void Translate(float x, float y, float z)
{
obj.transmatrix = glm.translate(new mat4(1), new vec3(x, y, z));
position = new vec3(x, y, z);
}
public void Draw(int matID)
{
obj.Draw(matID);
isDrawn = true;
}
public void Event()
{
switch (type)
{
case modelType.DOOR:
DOOR_Event();
break;
case modelType.GARBAGE:
GARBAGE_Event();
break;
case modelType.BARRELS:
BARRELS_Event();
break;
case modelType.LIGHT:
LIGHT_Event();
break;
case modelType.PILLS:
PILLS_Event();
break;
case modelType.RADIO:
RADIO_Event();
break;
case modelType.TEXT:
TEXT_Event();
break;
case modelType.GUN:
GUN_Event();
break;
}
}
public void DOOR_Event()
{
//access current loaded skybox,
//update it, and set the renderer
//which room is the current
switch (objID)
{
case 0:
if (Renderer.playerHasKey)
{
if (Renderer.currentSkyboxID == 0)
{
Renderer.currentSkyboxID = 1;
//interactionBoundingBox /= range;
//range = 7;
//interactionBoundingBox *= range;
}
else if (Renderer.currentSkyboxID == 1)
{
Renderer.currentSkyboxID = 0;
//interactionBoundingBox /= range;
//range = 20;
//interactionBoundingBox *= range;
}
}
break;
case 1:
Renderer.currentSkyboxID = (Renderer.currentSkyboxID == 1) ? 2 : 1;
break;
case 2:
Renderer.currentSkyboxID = (Renderer.currentSkyboxID == 1) ? 3 : 1;
break;
case 3:
Renderer.currentSkyboxID = (Renderer.currentSkyboxID == 2) ? 4 : 2;
break;
case 4:
Renderer.currentSkyboxID = (Renderer.currentSkyboxID == 2) ? 5 : 2;
break;
case 5:
Renderer.currentSkyboxID = 6;
break;
}
switch (Renderer.currentSkyboxID)
{
case 0: //0: forest skybox
if (Renderer.playerHasKey)
{
Renderer.cam.Reset(612, 30, 500, 20, 20, 150, 0, 1, 0);
Scale(.5f, .5f, .5f);
Translate(700, 0, 500);
}
break;
case 1: //1: livingroom skybox
if (objID == 0)
{
Renderer.cam.Reset(95, 105, 280, 95, 50, 150, 0, 1, 0);
Scale(1f, 1.3f, 1f);
Translate(245, -17, 355);
}
else if (objID == 1) //bed -> living
{
Renderer.cam.Reset(270, 105, 245, 20, 50, 245, 0, 1, 0);
Translate(300, 0, 245);
}
else if (objID == 2) //kitchen -> living
{
Renderer.cam.Reset(80, 105, 20, 80, 50, 150, 0, 1, 0);
Translate(80, 0, 0);
}
break;
case 2: //2: bedroom skybox
Scale(1f, 1.3f, 1f);
if (objID == 1)
{
Renderer.cam.Reset(20, 105, 245, 50, 50, 245, 0, 1, 0);
Translate(0, 0, 245);
}
else if (objID == 3)
{
Renderer.cam.Reset(80, 105, 20, 50, 50, 245, 0, 1, 0);
Translate(80, 0, 0);
}
else if (objID == 4)
{
Renderer.cam.Reset(270, 105, 280, 50, 50, 245, 0, 1, 0);
Translate(270, 0, 300);
}
break;
case 3: //3: kitchen skybox
Renderer.cam.Reset(95, 105, 280, 20, 20, 150, 0, 1, 0);
Translate(80, 0, 300);
break;
case 4: //4: bathroom skybox
Renderer.cam.Reset(80, 105, 190, 50, 50, 245, 0, 1, 0);
Translate(80, 0, 200);
break;
case 5: //5: closet skybox(has a trapdoor)
Renderer.cam.Reset(100, 105, 20, 20, 20, 150, 0, 1, 0);
Translate(100, 0, 0);
break;
case 6: //6: basement skybox
Renderer.cam.Reset(95, 50, 280, 20, 20, 150, 0, 1, 0);
break;
}
#region SFX
if (Renderer.playerHasKey)
{
player = new System.Media.SoundPlayer(Renderer.projectPath + @"\Sounds\door open with a squeak.wav");
player.Play();
Thread.Sleep(2948);
player = new System.Media.SoundPlayer(Renderer.projectPath + @"\Sounds\door close with a squeak.wav");
player.Play();
}
#endregion
}
public void GUN_Event()
{
}
public void GARBAGE_Event()
{
#region SFX
player = new System.Media.SoundPlayer(Renderer.projectPath + @"\Sounds\light_plasticbag_search.wav");
player.Play();
Thread.Sleep(4000);
player.Stop();
#endregion
if (objID == Renderer.key_garbageID)
{
Renderer.playerHasKey = true;
player = new System.Media.SoundPlayer(Renderer.projectPath + @"\Sounds\keys.wav");
player.Play();
}
}
public void BARRELS_Event()
{
//random event based on the barrels ID
}
public void LIGHT_Event()
{
//recharge the light intensity?
//when the light ison
//player = new System.Media.SoundPlayer(Renderer.projectPath + @"\Sounds\LightOn.wav");
//player.Play();
//when light is about to pop
//MP3_player bulb = new MP3_player();
//bulb.open(Renderer.projectPath + @"\Sounds\light_plasticbag_search.mp3");
//bulb.play();
//Thread.Sleep(2980);
//bulb.open(Renderer.projectPath + @"\Sounds\light-bulb-pop.mp3");
//bulb.play();
}
public void PILLS_Event()
{
//refill the sanity bar
//check to see if the bottle is full or not
//player = new System.Media.SoundPlayer(Renderer.projectPath + @"\Sounds\shaking-pill-bottle.wav");
//player.Play();
//actual size 3779
//Thread.Sleep(3500);
//take a pill
//player = new System.Media.SoundPlayer(Renderer.projectPath + @"\Sounds\taking-pills.wav");
//player.Play();
}
public void RADIO_Event()
{
//turn on or off
//the static noise
if (radio_ON)
{
radio_sound.Stop();
radio_ON = false;
}
else
{
radio_sound.PlayLooping();
radio_ON = true;
}
}
public void TEXT_Event()
{
//open a certain text file and display
//its text on the screen
Renderer.text_shown = true;
}
}
}