-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckCollision.m
88 lines (76 loc) · 2.35 KB
/
CheckCollision.m
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
function [ bool ] = CheckCollision(withplayer, obj , checkFriends ) %codegen
global ObjectsCoords;
global friends;
global LifeObjectCoords;
global numberOfFriendsObjects;
global numberOfLifeObjects;
global SCORE;
global LIFE;
coder.inline('never');
bool=0;
if withplayer==1
for i=2:length(ObjectsCoords)
if(CollisionAABB_Sphere(obj.Pmin,obj.Pmax,ObjectsCoords(i).C)==1)
bool=1;
if (length(obj)==1)
bool = 1;
end;
break;
end
end
if (bool ~= 1 && checkFriends == 1)
for i=2:length(friends)
if(CollisionAABB_Sphere(obj.Pmin,obj.Pmax,friends(i).C)==1)
[friends, numberOfFriendsObjects ] = removeElementByIndex( friends, numberOfFriendsObjects, i );
if (length(obj)==1)
SCORE=SCORE+1;
end;
break;
end
end
end
if (bool ~= 1 && checkFriends == 2)
for i=2:length(LifeObjectCoords)
if(CollisionAABB_Sphere(obj.Pmin,obj.Pmax,LifeObjectCoords(i).C)==1)
[LifeObjectCoords, numberOfLifeObjects ] = removeElementByIndex( LifeObjectCoords, numberOfLifeObjects, i );
if (length(obj)==1)
LIFE=LIFE+1;
end;
break;
end
end
end
else
for i=2:length(ObjectsCoords)
if(staticen_test_dve_sferi(ObjectsCoords(i).C,obj.C,1,1)==1)
bool=1;
if (length(obj)==1)
bool = 1;
end;
break;
end
end
if (bool ~= 1 && checkFriends == 1)
for i=2:length(friends)
if(staticen_test_dve_sferi(friends(i).C,obj.C,1,1)==1)
[friends, numberOfFriendsObjects ] = removeElementByIndex( friends, numberOfFriendsObjects, i );
if (length(obj)==1)
SCORE=SCORE+1;
end;
break;
end
end
end
if (bool ~= 1 && checkFriends == 2)
for i=2:length(LifeObjectCoords)
if(staticen_test_dve_sferi(LifeObjectCoords(i).C,obj.C,1,1)==1)
[LifeObjectCoords, numberOfLifeObjects ] = removeElementByIndex( LifeObjectCoords, numberOfLifeObjects, i );
if (length(obj)==1)
LIFE=LIFE+1;
end;
break;
end
end
end
end
end