forked from Zoytx/PhysicsAR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tapexp2.cs
232 lines (147 loc) · 4.46 KB
/
tapexp2.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
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 tapexp2 : MonoBehaviour
{
public GameObject obj;
public GameObject obj2;
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;
//Incresing the angle between two vectors
public void increaseangle(){
change=PlayerPrefs.GetFloat("rotation");
if(change<=359){
change+=1;
spwn2.transform.rotation = Quaternion.Euler(0, change, 0);
PlayerPrefs.SetFloat("rotation",change);
if(change==360){
PlayerPrefs.SetFloat("rotation",0.0f);
}
}
}
//Decreasing the angle between the vectors
public void decreaseangle(){
change=PlayerPrefs.GetFloat("rotation");
if(change>=0){
change-=1;
spwn2.transform.rotation = Quaternion.Euler(0, change, 0);
PlayerPrefs.SetFloat("rotation",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");
if(change<=9 || change==1){
change+=1;
spwn.transform.localScale += new Vector3(0.02f, 0.0f, 0.0f);
PlayerPrefs.SetInt("a",change);}
}
//Increasing the magnitude of second vector
public void increase2(){
int change=PlayerPrefs.GetInt("b");
if(change<=9 || change==1){
change+=1;
spwn2.transform.localScale += new Vector3(0.02f, 0.0f, 0.0f);
PlayerPrefs.SetInt("b",change);
}
}
//Decreasing the magnitude of one vector
public void decrease1(){
int change=PlayerPrefs.GetInt("a");
if(change>=2 || change==10){
change-=1;
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");
if(change>=2 || change==10){
change-=1;
spwn2.transform.localScale -= new Vector3(0.02f, 0.0f, 0.0f);
// spwn2.transform.position-=new Vector3(-0.02f,0f,0f);
PlayerPrefs.SetInt("b",change);
}
}
//Setting the initial Values
void Start(){
PlayerPrefs.SetFloat("rotation",0);
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);
spwn2 = Instantiate(obj2, hitPose.position, hitPose.rotation);
}
else
{
spwn.transform.position = hitPose.position;
spwn2.transform.position = hitPose.position;
}}
}
}
}
}