-
Notifications
You must be signed in to change notification settings - Fork 2
/
GlassSlab.cs
322 lines (206 loc) · 7.12 KB
/
GlassSlab.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
using UnityEngine.UI;
using System;
[RequireComponent(typeof(ARRaycastManager))]
public class GlassSlab : MonoBehaviour
{
public GameObject obj;
public GameObject obj2;
public GameObject obj3;
private GameObject spwn3;
private GameObject spwn2;
private GameObject spwn;
private ARRaycastManager arcman;
private Vector2 pos;
public Text aforce;
public Text bforce;
public Text angle;
public Text DotProduct;
static List<ARRaycastHit> hits = new List<ARRaycastHit>();
private float change;
private float change2;
//Incresing the angle between two vectors
public void increaseangle()
{
change = PlayerPrefs.GetFloat("rotation");
change2 = PlayerPrefs.GetFloat("rotation2");
if (change <= 359)
{
change += 1;
spwn2.transform.rotation = Quaternion.Euler(change2, change, 0);
spwn3.transform.rotation = Quaternion.Euler(change2, 90 - change, 0);
PlayerPrefs.SetFloat("rotation", change);
if (change == 360)
{
PlayerPrefs.SetFloat("rotation", 0.0f);
}
}
}
public void increaseanglex()
{
change = PlayerPrefs.GetFloat("rotation2");
change2 = PlayerPrefs.GetFloat("rotation");
if (change <= 359)
{
change += 1;
spwn2.transform.rotation = Quaternion.Euler(change, change2, 0);
spwn3.transform.rotation = Quaternion.Euler(change, 90 - change2, 0);
PlayerPrefs.SetFloat("rotation2", change);
if (change == 360)
{
PlayerPrefs.SetFloat("rotation2", 0.0f);
}
}
}
//Decreasing the angle between the vectors
public void decreaseangle()
{
change2 = PlayerPrefs.GetFloat("rotation2");
change = PlayerPrefs.GetFloat("rotation");
if (change >= 0)
{
change -= 1;
spwn2.transform.rotation = Quaternion.Euler(change2, change, 0);
spwn3.transform.rotation = Quaternion.Euler(change2, 90 - change, 0);
PlayerPrefs.SetFloat("rotation", change);
}
}
public void decreaseanglex()
{
change2 = PlayerPrefs.GetFloat("rotation");
change = PlayerPrefs.GetFloat("rotation2");
if (change >= 0)
{
change -= 1;
spwn2.transform.rotation = Quaternion.Euler(change, change2, 0);
spwn3.transform.rotation = Quaternion.Euler(change, 90 - change2, 0);
PlayerPrefs.SetFloat("rotation2", change);
}
}
//Fixing the location of the vectors placed
public void fix()
{
PlayerPrefs.SetInt("placed1", 1);
PlayerPrefs.SetInt("a", 1);
PlayerPrefs.SetInt("b", 1);
PlayerPrefs.SetInt("angle", 0);
}
//Increasing the magnitude of one vector
public void increase1()
{
int change = PlayerPrefs.GetInt("a");
{
change += 1;
spwn2.transform.position += new Vector3(0.03f, 0.0f, 0.0f);
PlayerPrefs.SetInt("a", change);
}
}
//Increasing the magnitude of second vector
public void increase2()
{
int change = PlayerPrefs.GetInt("b");
{
change += 1;
spwn2.transform.position += new Vector3(0.0f, 0.0f, 0.005f);
PlayerPrefs.SetInt("b", change);
}
}
//Decreasing the magnitude of one vector
public void decrease1()
{
int change = PlayerPrefs.GetInt("a");
{
change -= 1;
spwn2.transform.position -= new Vector3(0.005f, 0.0f, 0.0f);
//spwn.transform.localScale -= new Vector3(0.02f, 0.0f, 0.0f);
// spwn.transform.position -=new Vector3(-0.02f,0f,0f);
PlayerPrefs.SetInt("a", change);
}
}
//Decreasing the magnitude of second vector
public void decerase2()
{
int change = PlayerPrefs.GetInt("b");
{
change -= 1;
spwn2.transform.position -= new Vector3(0.0f, 0.0f, 0.005f);
// spwn2.transform.position-=new Vector3(-0.02f,0f,0f);
PlayerPrefs.SetInt("b", change);
}
}
//Setting the initial Values
void Start()
{
PlayerPrefs.SetFloat("rotation", 45);
PlayerPrefs.SetFloat("rotation2", 45);
PlayerPrefs.SetInt("placed1", 0);
}
//constantly updating the information to be displayed
void FixedUpdate()
{
if (spwn != null)
{
int avalue = PlayerPrefs.GetInt("a");
int bvalue = PlayerPrefs.GetInt("b");
float anglevalue = PlayerPrefs.GetFloat("rotation");
aforce.text = "Vector A: " + avalue;
bforce.text = "Vector B: " + bvalue;
angle.text = "Angle: " + anglevalue;
float resultant = avalue * bvalue * (float)(Math.Cos(anglevalue));
DotProduct.text = "Dot Product = " + resultant;
}
}
//Getting the components from the manager
private void Awake()
{
arcman = GetComponent<ARRaycastManager>();
}
bool getpos(out Vector2 pos)
{
if (Input.touchCount > 0)
{
pos = Input.GetTouch(0).position;
return true;
}
pos = default;
return false;
}
//Placing the vectors and moving them around
void Update()
{
int fix;
fix = PlayerPrefs.GetInt("placed1");
if (!getpos(out Vector2 pos))
return;
if (arcman.Raycast(pos, hits, TrackableType.PlaneWithinPolygon))
{
{
var hitPose = hits[0].pose;
if (fix == 0)
{
if (spwn == null)
{
hitPose.rotation = Quaternion.Euler(0, 0, 0);
spwn = Instantiate(obj, hitPose.position, hitPose.rotation);
Vector3 raypos = new Vector3(hitPose.position.x - 0.13f, hitPose.position.y, hitPose.position.z - 0.1f);
Vector3 raypos2 = new Vector3(hitPose.position.x + 0.13f, hitPose.position.y, hitPose.position.z - 0.1f);
spwn2 = Instantiate(obj2, raypos, hitPose.rotation);
spwn3 = Instantiate(obj3, raypos2, hitPose.rotation);
}
else
{
Vector3 raypos = new Vector3(hitPose.position.x - 0.1f + 0.03f, hitPose.position.y, hitPose.position.z - 0.07f);
Vector3 raypos2 = new Vector3(hitPose.position.x + 0.1f - 0.03f, hitPose.position.y, hitPose.position.z + 0.07f);
spwn.transform.position = hitPose.position;
spwn2.transform.position = raypos;
spwn3.transform.position = raypos2;
}
}
}
}
}
}