1
00:00:00,570 --> 00:00:06,050
This exercise is actually a kind of wrap up for everything we learn in this section.

2
00:00:06,090 --> 00:00:12,390
It's actually a very demanding exercise on the goal of it is this you have to find a way to use a combination

3
00:00:12,390 --> 00:00:16,470
of touches to do a transform on a given object.

4
00:00:16,620 --> 00:00:22,810
You want to be able to a scale an object using touches as well as a rotating object using touches.

5
00:00:22,830 --> 00:00:29,580
So if user puts one finger down on one top on the device and moves that that's going to essentially

6
00:00:29,580 --> 00:00:30,960
rotate an object.

7
00:00:30,960 --> 00:00:35,550
And if those two types sound you have to be able to scale that object.

8
00:00:35,700 --> 00:00:37,410
Or let's call it a UI view.

9
00:00:37,440 --> 00:00:43,830
For instance there is and I said it's a demanding exercise is simply because you have to be able to

10
00:00:44,310 --> 00:00:50,220
find your way around finding how many touches are there and then finding the distance between them.

11
00:00:50,220 --> 00:00:56,250
If you're going to scale something as well as finding the angle that is being used at any given time

12
00:00:56,420 --> 00:01:02,430
if there's just one touch Now I know it's a difficult one perhaps and you might want to spend some time

13
00:01:03,030 --> 00:01:08,070
researching it online but they still suggest that you actually give it a try on your own and try to

14
00:01:08,070 --> 00:01:11,310
find some references outside before you look out.

15
00:01:11,310 --> 00:01:18,720
My solution for this exercise really help you in any situation that comes to using C.G. transform.

16
00:01:18,740 --> 00:01:20,430
And the combination of touches.

17
00:01:20,700 --> 00:01:26,030
And of course you could do all of these simply by using gestures but they want to make sure that you

18
00:01:26,040 --> 00:01:29,650
get a sense of everything that touches they do for us as well.

19
00:01:29,820 --> 00:01:34,810
So I'm going to pause the video for a few seconds that you can pause it now and get it started.

20
00:01:34,900 --> 00:01:41,120
And once you have done it hopefully or if you want to look at my solution you can resume the play by

21
00:01:43,060 --> 00:01:43,590
OK.

22
00:01:43,690 --> 00:01:47,360
This code works code and I'm going to start a new project.

23
00:01:47,390 --> 00:01:52,170
Then I call it transform it.

24
00:01:52,180 --> 00:01:52,840
Touch

25
00:01:56,250 --> 00:02:01,810
and in my transform with Tadhg I'm actually going to do everything in the programming side so I don't

26
00:02:01,810 --> 00:02:06,350
need to go back and forth between the Interface Builder and here.

27
00:02:06,610 --> 00:02:13,930
So in here I'm going to go ahead and say I have a variable let's call it that red box which is of the

28
00:02:13,930 --> 00:02:15,910
type you I view.

29
00:02:16,330 --> 00:02:24,820
And then in my view the load I'm going to go ahead and say red box becomes a UI view of a frame that

30
00:02:24,820 --> 00:02:34,780
is going to be let him auto complete those for me that say 0 0 0 200 and 200.

31
00:02:35,170 --> 00:02:39,900
And the reason I stick it at 0 0 because it's a it's something I'm really used to.

32
00:02:39,910 --> 00:02:43,200
Which is what I would want to do this kind of test stuff.

33
00:02:43,210 --> 00:02:47,830
I just say my main object in this case red box.

34
00:02:47,830 --> 00:02:51,200
It becomes at the center of the scene.

35
00:02:51,430 --> 00:02:56,140
So it gets a red box that sento self that you that center.

36
00:02:56,230 --> 00:02:57,980
So you put it wherever you like it.

37
00:02:58,030 --> 00:03:07,020
And then we center it against against the view and then self-taught if you add the sup you read you

38
00:03:07,750 --> 00:03:14,790
or a box and then the red box the background color becomes a color dot right.

39
00:03:14,890 --> 00:03:19,150
I'm also going to add one more thing which really you don't have to for you I use.

40
00:03:19,170 --> 00:03:26,800
Just in case some of us have forgotten and I'm going to say red box start user interaction enabled is

41
00:03:26,800 --> 00:03:27,410
true.

42
00:03:27,820 --> 00:03:34,810
So it makes sure that this object is user interactive and if you run the application by now we should

43
00:03:34,810 --> 00:03:43,420
see a red box of the size 200 and 200 somewhere in the middle of our our simulator which is exactly

44
00:03:43,420 --> 00:03:44,570
what we expect it to be.

45
00:03:45,760 --> 00:03:46,730
That's that.

46
00:03:46,790 --> 00:03:54,740
So now the important thing we want to do next is finding the two ways that this thing will be manipulated.

47
00:03:54,740 --> 00:04:00,500
So I'm going to say such as move it because that's what I care about.

48
00:04:00,740 --> 00:04:05,570
And then the touch has moved I'm going to have two distinct situations.

49
00:04:05,570 --> 00:04:11,860
One is if one touches that counts was the one.

50
00:04:12,260 --> 00:04:21,530
So in this situation I'm going to write it rotate and then I'm going to have another one else if touches

51
00:04:21,590 --> 00:04:27,130
that the count was two and then I'm going to say the OK.

52
00:04:27,500 --> 00:04:29,460
So if there's only one touchdown.

53
00:04:29,490 --> 00:04:30,280
When I wrote it.

54
00:04:30,290 --> 00:04:37,640
If the two touches down we want to escape now in both of these I'm going to get my touches so I'm going

55
00:04:37,640 --> 00:04:47,180
to say touches one then let's say let's touch one or might touch one or touch one is better then obviously

56
00:04:47,180 --> 00:04:50,050
it becomes a touch as does the first.

57
00:04:50,060 --> 00:04:55,640
That's the simpler one because simply we know there's only one touch.

58
00:04:55,700 --> 00:05:02,960
Now if there are more torture's because this is a set we can't just get the touches from it we have

59
00:05:02,960 --> 00:05:09,470
to actually either iterate through all the touches or we have to convert all stages into an array of

60
00:05:09,470 --> 00:05:11,800
touches which is what I'm gonna do.

61
00:05:11,900 --> 00:05:20,140
And when I say let's touch as array for instance that becomes an array of touches.

62
00:05:20,570 --> 00:05:25,180
So we get all of our touches on we place them inside an array.

63
00:05:25,400 --> 00:05:30,100
And since now they are in an array we can get them by number essentially.

64
00:05:30,230 --> 00:05:33,290
So I could say touch one.

65
00:05:33,320 --> 00:05:38,930
I actually don't like the naming that has numeric values and it was kind of contemplating in my head

66
00:05:39,200 --> 00:05:47,990
I'm going to call it touch of one so down that I have that I'm going to say here touch one becomes touches

67
00:05:48,660 --> 00:05:52,640
Ray and that become the zero object of it.

68
00:05:52,880 --> 00:06:02,080
And then I have touch too which becomes the first object or an object as a location one.

69
00:06:02,480 --> 00:06:05,420
So Dawan that part is taken care of.

70
00:06:05,420 --> 00:06:10,400
Now the important thing and the next important thing that you have to do is you have to make sure that

71
00:06:10,460 --> 00:06:19,940
in most of these situations things only happen if we are touching the red box or the red the view or

72
00:06:19,940 --> 00:06:21,200
the red box.

73
00:06:21,200 --> 00:06:34,650
So yes I'm going to say you touch one dot view is not red box then let's do this let's return.

74
00:06:34,970 --> 00:06:37,140
You don't have to continue on anymore.

75
00:06:37,370 --> 00:06:42,670
So if there was only one touchdown but that one touch of wasn't on the red box don't need to do anything.

76
00:06:43,130 --> 00:06:46,070
I'm actually going to do the same thing in here.

77
00:06:46,220 --> 00:06:49,030
What in the in the scale.

78
00:06:49,020 --> 00:06:56,050
Because the two touches I have to say touch one and touch two.

79
00:06:56,210 --> 00:07:00,620
If both on not on the red box then returned.

80
00:07:00,950 --> 00:07:04,640
So that really takes care of a big chunk of the problem.

81
00:07:04,640 --> 00:07:12,140
It makes sure that we only do things if we are absolutely on the on the red box.

82
00:07:12,220 --> 00:07:15,930
Now is also giving us an error I think is because of the optional thing.

83
00:07:15,950 --> 00:07:19,620
Yes because our touch has a rate is not an option.

84
00:07:19,670 --> 00:07:24,530
So we don't have to have the question mark for the touches.

85
00:07:24,680 --> 00:07:27,310
The Post absolutely do exist.

86
00:07:27,620 --> 00:07:29,370
So that wasn't taken care of.

87
00:07:29,390 --> 00:07:35,950
Now it becomes about actually doing the rotation or a scale.

88
00:07:36,140 --> 00:07:41,780
In this case during the rotation if there was only one touch and in this case doing this scale if there

89
00:07:41,780 --> 00:07:48,650
was two touches essentially reformat things a little bit so I know what I'm typing because it's going

90
00:07:48,650 --> 00:07:51,050
to become a longer code.

91
00:07:51,050 --> 00:07:55,450
So I want to make sure that you know I have it easier for you guys to view.

92
00:07:55,520 --> 00:08:01,190
So the view of the is taking care of the touches are taken just now the next thing is you have to actually

93
00:08:01,190 --> 00:08:05,220
calculate the values for the rotation and for a scale.

94
00:08:05,450 --> 00:08:10,850
I'm going to go ahead and deal with the rotation first and for that I'm going to write a new function

95
00:08:11,470 --> 00:08:18,050
and then say function let's call it one rotate action and then rotate the action is going to do.

96
00:08:18,050 --> 00:08:25,730
This is going to get two values in one of them being the touch that we landed and the other one being

97
00:08:25,730 --> 00:08:31,470
the view that you want to rotate and then it's going to give us a value.

98
00:08:31,730 --> 00:08:37,130
Not before I tell you what all those input arguments and what's the value you want to get back.

99
00:08:37,160 --> 00:08:41,120
Let's have a quick look at how this is going to be processed.

100
00:08:41,120 --> 00:08:47,880
So imagine your user taps on this location which is the last point and then pushes down the finger or

101
00:08:47,880 --> 00:08:49,340
the top goes down.

102
00:08:49,590 --> 00:08:51,380
And then you get to the end point.

103
00:08:51,510 --> 00:08:56,870
And that team is out for that angle is the one that we want to calculate.

104
00:08:56,880 --> 00:09:04,170
So the difference between the angle between the start point and the center of the main view compared

105
00:09:04,170 --> 00:09:09,100
to the angle of the end and the center of the main view.

106
00:09:09,300 --> 00:09:11,100
That's what you want to calculate.

107
00:09:11,100 --> 00:09:16,350
Now here's the thing there's a little bit of mathematics involved and I don't expect you guys to know

108
00:09:16,350 --> 00:09:21,450
it or if you are like me you would just go online and Google it and that's what I did.

109
00:09:21,450 --> 00:09:22,920
I'll try to find out.

110
00:09:23,010 --> 00:09:26,380
How do you calculate the angle between two points.

111
00:09:26,460 --> 00:09:32,520
And it turns out the arctangent move is a very good formula for it like there was actually the first

112
00:09:32,520 --> 00:09:37,800
head showed me there's an arctangent 2 and there's my discussions on a stack overflow that you can read

113
00:09:37,800 --> 00:09:39,040
them again.

114
00:09:39,050 --> 00:09:42,660
You're not supposed to know these things is just another off.

115
00:09:42,720 --> 00:09:48,870
Once you once you reach a place that you need to find it you should be able to go online and find the

116
00:09:48,870 --> 00:09:54,180
answers if you ask me to calculate the distance between these two or the rotation between them.

117
00:09:54,180 --> 00:09:58,060
I would definitely want to be able to do it now with that in mind.

118
00:09:58,060 --> 00:10:00,910
This goes back to school and save for a rotation.

119
00:10:01,020 --> 00:10:07,330
I want to have the torch that is going to essentially give me the values of the locations.

120
00:10:07,470 --> 00:10:13,800
I also want to have a view which is the UI view that is our main view or the view that we want to compare

121
00:10:13,860 --> 00:10:15,030
against.

122
00:10:15,150 --> 00:10:18,030
And once that is done I want to get a C.G. float.

123
00:10:18,040 --> 00:10:20,730
I want to get the amount of rotation.

124
00:10:20,730 --> 00:10:25,530
Now here there's going to be a little bit of a code but most of it is actually very simple on the part

125
00:10:25,530 --> 00:10:30,780
that is a little bit difficult which is that mathematical side of it we just get it from some online

126
00:10:30,780 --> 00:10:31,680
resource.

127
00:10:31,680 --> 00:10:39,250
So the first thing I'm going to say let's kind of point wishes the current location of the top that

128
00:10:39,260 --> 00:10:46,120
would be touch dot location in view and the view is this input.

129
00:10:46,380 --> 00:10:50,130
So this is the current location at any point.

130
00:10:50,220 --> 00:10:56,820
So I'm going to go ahead and say if that's the case thing give me the previous point that's going to

131
00:10:56,820 --> 00:11:01,810
be touch dart previous location in view the same.

132
00:11:02,130 --> 00:11:08,340
So essentially if you were to translate it here this would be the very first one previous location.

133
00:11:08,340 --> 00:11:09,520
This is the kind location.

134
00:11:09,530 --> 00:11:11,120
Of course it doesn't happen like this.

135
00:11:11,130 --> 00:11:13,230
It doesn't have such a big jump.

136
00:11:13,290 --> 00:11:16,560
It is being collected in every drop count.

137
00:11:16,560 --> 00:11:19,780
But for now we can assume this is kind of an illustration of it.

138
00:11:19,800 --> 00:11:22,890
So we get these two points was we got the two points.

139
00:11:22,890 --> 00:11:32,100
I also want to get the center of the view so I'm going to say let's center to be view data center.

140
00:11:32,340 --> 00:11:37,500
So I'm going to get the center of this view and the reason I gather this one is even though this is

141
00:11:37,500 --> 00:11:44,160
going to be self cut view I want you to have it in case you want it to rotate against a different center

142
00:11:44,190 --> 00:11:45,120
essentially.

143
00:11:45,360 --> 00:11:52,980
So with that I'm going to go ahead and say let current why this is the Quine's location of X or Y doesn't

144
00:11:52,980 --> 00:11:53,860
matter.

145
00:11:53,900 --> 00:12:01,960
Y is going to be center dot y minus the point that y.

146
00:12:02,000 --> 00:12:03,480
So that's the light.

147
00:12:03,480 --> 00:12:11,120
So I'm going to copy and paste that make it current X is going to be X and X.

148
00:12:11,160 --> 00:12:18,800
So what these two values show for us is essentially dislocation dislocation devoir x and y are feet

149
00:12:18,870 --> 00:12:24,930
compared to the center is in my screen right now those values for instance.

150
00:12:24,930 --> 00:12:27,950
So that's what these two values represent for us.

151
00:12:28,050 --> 00:12:31,880
And since we have the current ones we also have to get the previous ones.

152
00:12:32,030 --> 00:12:39,120
I was going to say give me previous y to B and previous Y to be.

153
00:12:39,130 --> 00:12:41,890
And those are the same thing as before.

154
00:12:42,150 --> 00:12:45,280
Previous point and previous ones.

155
00:12:45,600 --> 00:12:49,730
So we find that wherever we used to be and whatever we are now.

156
00:12:49,770 --> 00:12:55,000
So the next thing is finding the actual angle between these two at any given point.

157
00:12:55,020 --> 00:13:05,450
So I'm going to say let client angle be arctangent to all the current Y and current x.

158
00:13:05,540 --> 00:13:12,760
So there's a formula that essentially gets you the angle of any point against the center of the view.

159
00:13:12,990 --> 00:13:19,270
And then I want to get the same thing for just a socket or B she's going to be the previous angle.

160
00:13:19,530 --> 00:13:24,730
So the previous one is going to be previous Y and previous x.

161
00:13:24,760 --> 00:13:31,230
Now again I'm going to have to emphasize on this that the mathematical part of this is not a is not

162
00:13:31,230 --> 00:13:32,390
the goal of this lesson.

163
00:13:32,400 --> 00:13:36,360
Essentially this is a formula you can simply find it anywhere online.

164
00:13:36,600 --> 00:13:41,040
But for us we found the contango we found the previous Nanga.

165
00:13:41,100 --> 00:13:49,160
So what we have to do is we have to say return anger minus previous Sinar.

166
00:13:49,340 --> 00:13:53,680
So we have to get what has changed because the new one.

167
00:13:53,690 --> 00:13:55,780
Verby before return.

168
00:13:55,790 --> 00:13:57,560
The difference between these two.

169
00:13:57,770 --> 00:14:03,590
And that's exactly what we needed because we needed to have a CGI float that is the rotation that we

170
00:14:03,590 --> 00:14:04,910
have.

171
00:14:04,910 --> 00:14:08,720
So now that you have that let's go ahead and use it in our teachers.

172
00:14:09,200 --> 00:14:12,850
You know touches off if there was only one touch fish we have to rotate.

173
00:14:12,860 --> 00:14:15,290
I'm going to go ahead and say let.

174
00:14:15,490 --> 00:14:17,350
New rotation.

175
00:14:17,580 --> 00:14:26,830
And maybe the whole thing would become rotate action for each one between self.

176
00:14:26,960 --> 00:14:32,970
You remember I said that since we are using so that we could simply use it in here.

177
00:14:33,140 --> 00:14:39,590
But I wanted it to be a separate value about so if we can actually make sure that you could use it for

178
00:14:39,680 --> 00:14:41,180
other things as well.

179
00:14:41,750 --> 00:14:45,740
And he's giving you a warning about touch one being on wrapped or not.

180
00:14:45,750 --> 00:14:47,380
I mean aren't up this actually.

181
00:14:47,390 --> 00:14:51,860
So this is the new rotation that gets calculated every time the touch moves.

182
00:14:51,860 --> 00:14:55,650
Now we have to use it to actually rotate the red box.

183
00:14:55,650 --> 00:15:07,800
So I'm going to say Redbox thought transform becomes Redbox that transform that rotated by their value

184
00:15:07,820 --> 00:15:10,380
you know new rotation.

185
00:15:10,690 --> 00:15:18,530
So the value of the new rotation is going to be the amount of rotation that we want to rotate the Redbox.

186
00:15:18,940 --> 00:15:24,220
Ok then so a lot of call with the let's see what you have done I'm going to run the app to make sure

187
00:15:24,220 --> 00:15:27,040
that we haven't done something terribly wrong.

188
00:15:27,070 --> 00:15:32,610
I know something is coming up and I have to explain to you guys but let's see the rotation first and

189
00:15:32,650 --> 00:15:33,220
I rotate.

190
00:15:33,220 --> 00:15:34,550
It rotates perfectly.

191
00:15:34,570 --> 00:15:40,510
So when I tap someone on the red one it rotates based on the movement of my mouse at the moment or a

192
00:15:40,510 --> 00:15:42,250
tap on the actual device.

193
00:15:42,280 --> 00:15:44,810
If I touch outside nothing happens.

194
00:15:44,860 --> 00:15:47,440
Now the next thing we have that I get is the escape.

195
00:15:47,500 --> 00:15:54,440
And look what happens when I try to escape now which we haven't really done a scale part than I type.

196
00:15:54,580 --> 00:15:58,810
It is still rotates even though it has two taps down on the device.

197
00:15:58,960 --> 00:16:03,490
It actually is still thinks there is only one rotates the object.

198
00:16:03,610 --> 00:16:10,000
And the reason for that is there is something called multiple touch and the multiple touch is not enabled

199
00:16:10,000 --> 00:16:10,630
yet.

200
00:16:10,630 --> 00:16:17,960
So here in the view that lot I'm going to go ahead and say the red box doth multiple touch enabled.

201
00:16:18,050 --> 00:16:18,670
True.

202
00:16:18,910 --> 00:16:23,540
So for you my view is user interaction is by default.

203
00:16:23,540 --> 00:16:29,120
True but multiple times is not for most other outlets such as you or I.

204
00:16:29,140 --> 00:16:33,590
You make you view even the user interaction is not by default enabled.

205
00:16:33,730 --> 00:16:35,490
So what about your neighbors.

206
00:16:35,530 --> 00:16:37,810
And if you read on it now.

207
00:16:37,830 --> 00:16:40,920
Now when I do two taps nothing happens.

208
00:16:41,050 --> 00:16:46,780
So even I try to do with the toothaches it knows that if you are here and obviously nothing is going

209
00:16:46,780 --> 00:16:48,490
to nothing is going to happen.

210
00:16:48,490 --> 00:16:50,090
So that's where we have to.

211
00:16:50,380 --> 00:16:55,840
What we have to do now we have to find a way to scale this object and scaling is actually going to be

212
00:16:55,840 --> 00:16:57,140
a lot of code.

213
00:16:57,340 --> 00:17:01,550
But the good news is is actually going to be a lot easier than the rotation.

214
00:17:01,720 --> 00:17:04,660
So use that function I want to use for a scale.

215
00:17:04,720 --> 00:17:08,610
This was the route that I can go ahead and say function.

216
00:17:08,920 --> 00:17:15,130
And this one is going to be on a scale action and for a scale like shit I need to give parameters all

217
00:17:15,130 --> 00:17:18,740
three inputs values one of them is the first touch.

218
00:17:18,760 --> 00:17:23,270
So I'm going to say Tyche let's call it impotent.

219
00:17:23,290 --> 00:17:29,090
One input Tajh because the other ones are called Touch one and was well.

220
00:17:29,260 --> 00:17:35,100
So that's going to be a touch and that I have input touch to.

221
00:17:35,300 --> 00:17:40,180
And I have a name put to view which is going to be the UI view.

222
00:17:40,480 --> 00:17:43,130
And then at the end we come back with a CGI float.

223
00:17:43,150 --> 00:17:48,790
The amount of a scale like that actually a stack them so it's a little bit easier to read everything.

224
00:17:49,270 --> 00:17:50,680
So that's about that.

225
00:17:50,680 --> 00:17:53,550
So we have to touch as I should have had that.

226
00:17:53,590 --> 00:18:00,990
Here we have the two touches and we have the view that we want to calculate the scale against.

227
00:18:01,000 --> 00:18:04,900
So with that this go ahead and get a few things in here.

228
00:18:05,140 --> 00:18:12,490
First of all I need to find the current location of the torch one and current location of touch to and

229
00:18:12,730 --> 00:18:17,060
the previous location of touch 1 and previous location of the arch.

230
00:18:17,260 --> 00:18:18,690
So a lot of our stuff.

231
00:18:18,750 --> 00:18:24,710
So a lot of let's call it the one that becomes input.

232
00:18:24,730 --> 00:18:31,840
Touch one dot location in view and that's going to be an input value.

233
00:18:32,140 --> 00:18:38,820
So let's first get the current location of touch 1 and I'm going to say Get me the second one touch

234
00:18:38,810 --> 00:18:39,380
to.

235
00:18:39,640 --> 00:18:43,240
And that becomes touch to perfect.

236
00:18:43,240 --> 00:18:49,660
Now let's go ahead and get the previous locations and for this also I have a little and illustration

237
00:18:49,660 --> 00:18:50,590
I can show you.

238
00:18:50,800 --> 00:18:53,380
And the illustration is this one.

239
00:18:53,380 --> 00:19:00,110
Imagine this is the starting point the top one and top two and these are the kinds of points type 1

240
00:19:00,190 --> 00:19:00,940
and top two.

241
00:19:00,940 --> 00:19:04,290
So the rotation is kind of irrelevant in this example.

242
00:19:04,300 --> 00:19:11,020
It's just an out of the distance between the two taps at the beginning which becomes the previous locations

243
00:19:11,440 --> 00:19:14,650
and the current ones I have named them be the start.

244
00:19:14,700 --> 00:19:19,240
And so tap one and top two and end up one on top two.

245
00:19:19,240 --> 00:19:24,320
So we have to find their complications as well as their previous locations.

246
00:19:24,340 --> 00:19:31,360
I'm going to go in here and say give me these two coffee then I'm going to call them previous location

247
00:19:31,360 --> 00:19:38,200
1 pre location 1 and that's going to be previous location.

248
00:19:38,860 --> 00:19:39,880
Perfect.

249
00:19:39,920 --> 00:19:44,420
And when I replaced that there and that becomes pretty as well.

250
00:19:44,470 --> 00:19:51,380
So by now we have managed to get that complication of touch 1 and previous location of such fun as well

251
00:19:51,400 --> 00:19:53,940
as the same for type 2.

252
00:19:53,980 --> 00:20:01,650
The other thing we have to do is we have to now get that distance between chose 1 and 2 in the past

253
00:20:01,860 --> 00:20:06,270
and the distance between the touches 1 and 2 in the current time.

254
00:20:06,270 --> 00:20:10,550
So we have to kind of get that distance between them to get to the stands.

255
00:20:10,560 --> 00:20:12,920
I'm actually going to write a different function.

256
00:20:12,960 --> 00:20:18,670
Going write it down here so we can kind of see everything together at the same time.

257
00:20:18,730 --> 00:20:28,230
So yes I'm going to go ahead and say Give me a function called this sounds action friend stance and

258
00:20:28,270 --> 00:20:31,460
the distance action essentially gets two points.

259
00:20:31,470 --> 00:20:34,970
So I'm going to say points 1 or input points.

260
00:20:34,990 --> 00:20:46,530
One important points one that's going to be a C.G. point and input point two and that's going to be

261
00:20:46,530 --> 00:20:48,540
a CGU point as well.

262
00:20:48,970 --> 00:20:56,430
Either it has a CD flossed so it gets two locations and gets me the distance between those two.

263
00:20:56,670 --> 00:21:06,100
So know I'm going to say rather this dance this is going to be a CGI float.

264
00:21:06,140 --> 00:21:13,220
And I have to make it up on and off it then I'm going to say the calculation between the distance it

265
00:21:13,220 --> 00:21:14,610
needs a firm.

266
00:21:14,820 --> 00:21:20,150
This is a much simpler formula and if you remember it from any time in high school it's essentially

267
00:21:20,480 --> 00:21:28,070
the square root of the square of the difference between the excess plus squared off the difference between

268
00:21:28,070 --> 00:21:33,190
the winds and the very quake you know search online can get you down.

269
00:21:33,320 --> 00:21:38,680
So that's essentially the point A and Point B and the distance between get access under ROIs and the

270
00:21:38,690 --> 00:21:42,160
square root of that it gets you by the distance between them.

271
00:21:42,170 --> 00:21:50,470
So that's what I'm going to write so I'm going to go in and say let's let's call it X def right.

272
00:21:50,480 --> 00:21:54,350
That's going to be I have to get the point.

273
00:21:54,380 --> 00:22:06,680
One input point one dot X minus input point to aim point who Dauth x.

274
00:22:06,680 --> 00:22:08,930
That's the difference between the axis.

275
00:22:09,020 --> 00:22:12,700
Let's go ahead and get Devoy difference.

276
00:22:12,710 --> 00:22:17,130
So that's going to be input difference between the VI and voice.

277
00:22:17,210 --> 00:22:23,450
So essentially So far we have managed to get that little part inside the Panthers and this one inside

278
00:22:23,450 --> 00:22:24,630
the two parties.

279
00:22:24,800 --> 00:22:28,200
So we got the differences between the x and y.

280
00:22:28,460 --> 00:22:40,940
Then I'm going to say Let x square down would become P or W of X difference to the power of two.

281
00:22:41,540 --> 00:22:43,690
So that's essentially powering it up.

282
00:22:43,790 --> 00:22:50,790
And then I'm going to say why Esquith becomes Y difference which is this one the power of two.

283
00:22:50,990 --> 00:22:57,530
And then the value that are actually interested in is adding these two together and getting a square

284
00:22:57,530 --> 00:22:58,320
root of it.

285
00:22:58,490 --> 00:23:10,000
So I'm going to go ahead and say Give me the distance to be this q r t of X A squirt plus y a cyclist.

286
00:23:10,280 --> 00:23:16,200
So this task becomes the square root of the added value of both of these.

287
00:23:16,460 --> 00:23:23,930
And then you obviously have to return the distance and the moment I do that we have to this error should

288
00:23:23,930 --> 00:23:26,280
disappear essentially perfect.

289
00:23:26,380 --> 00:23:33,080
And now I could go ahead into my scale action the action that's going to calculate these distances for

290
00:23:33,080 --> 00:23:44,780
me and say let current stance to be dishtowels action between the current distances between the crimes

291
00:23:44,780 --> 00:23:51,050
locations so collocation one Quine's location off point two.

292
00:23:51,380 --> 00:23:54,770
And that's going to give me the current distance between them.

293
00:23:55,010 --> 00:24:02,030
So let's go ahead and duplicate this or let me rewrite it so it's a bit more expensive.

294
00:24:02,080 --> 00:24:09,200
So I'm worried I'm not going to say let previous this time is going to be this town's action between

295
00:24:09,710 --> 00:24:14,190
previous location one and previous location.

296
00:24:14,420 --> 00:24:20,230
And as you can imagine because we're going to get them through the power of two sometime later it doesn't

297
00:24:20,230 --> 00:24:23,180
matter which is it first which means within seconds.

298
00:24:23,180 --> 00:24:27,170
It's essentially a distance between them which is always an absolute value.

299
00:24:27,180 --> 00:24:28,720
It sort of has a positive value.

300
00:24:29,000 --> 00:24:36,440
So I'm going to go ahead and say well let's let's call this one how to put a scale or a scale ratio

301
00:24:36,440 --> 00:24:38,450
which is a much better name for it.

302
00:24:38,540 --> 00:24:43,390
That would essentially become current stars divided by previous distance.

303
00:24:43,670 --> 00:24:46,550
So this is the value I'm interested in.

304
00:24:46,550 --> 00:24:53,150
The value of how far they are against each other now compared to before.

305
00:24:53,480 --> 00:24:59,570
And once we have that value was when I'm going to say a return to scale ratio.

306
00:24:59,720 --> 00:25:04,800
So that's my scale action and that's perfectly taken care of now.

307
00:25:04,820 --> 00:25:12,370
So the next thing you have to do is finally essentially using that value in our touch has moved so much

308
00:25:12,380 --> 00:25:17,660
has moved is here the first touch we have taken off the second touch is the one that you still have

309
00:25:17,660 --> 00:25:19,490
to do things about it.

310
00:25:19,490 --> 00:25:28,540
So if you had that I'm going to go ahead and say let's call it let in your new race you're not just

311
00:25:28,550 --> 00:25:32,580
going to become the name of my action scale auction.

312
00:25:32,600 --> 00:25:48,640
So your issue is a scale auction between touch one and touch to get even with Team self to view and

313
00:25:48,640 --> 00:25:50,810
then and then that's it.

314
00:25:50,830 --> 00:25:52,990
And then calculate the ratio.

315
00:25:53,090 --> 00:26:01,840
And once you race you I'm going to say Redbox that transformed becomes red box that transformed the

316
00:26:01,840 --> 00:26:07,910
scale by giving me how much do you want to skate on X and how much on the Y.

317
00:26:08,000 --> 00:26:10,540
When I say new ratio on.

318
00:26:11,260 --> 00:26:14,780
So that's about that's that's running this up now.

319
00:26:14,790 --> 00:26:22,300
And if all works we should have a functioning that rotates and Askins any object or essentially the

320
00:26:22,300 --> 00:26:23,220
red one for an hour.

321
00:26:23,440 --> 00:26:27,340
So that's the rotation and that's the scale.

322
00:26:27,520 --> 00:26:28,880
Perfect.

323
00:26:28,930 --> 00:26:31,320
So everything is working on that.

324
00:26:31,350 --> 00:26:37,120
We have very quick clean up of the code and it's a very good exercise and something that I really recommend

325
00:26:37,120 --> 00:26:38,280
that you guys do it.

326
00:26:38,530 --> 00:26:46,280
So there's a lot of code in my view control and I want to put them in separate extensions so that I

327
00:26:46,280 --> 00:26:49,590
say give me a new file.

328
00:26:49,590 --> 00:27:00,010
This is going to be a swift file of the $0.00 Plus let's call it a scale action so you want to enter

329
00:27:00,090 --> 00:27:08,650
up there I'm going to say you like shit and I'm going to say this is an extension to view controller.

330
00:27:08,800 --> 00:27:13,140
And within it we have this scale action.

331
00:27:13,330 --> 00:27:16,480
So I'm going to cut this fart with it there.

332
00:27:17,080 --> 00:27:23,170
So the code becomes a lot easier to read because every file in here will have only a limited amount

333
00:27:23,170 --> 00:27:25,080
of stuff in it.

334
00:27:25,090 --> 00:27:30,030
I'm going to copy this one because I know it is going to happen again and I'm going to say command and

335
00:27:30,270 --> 00:27:35,510
you've me on file and this one is going to be a view controller.

336
00:27:36,010 --> 00:27:38,400
Plus this sounds action.

337
00:27:38,410 --> 00:27:41,360
This is the one that calculates the distances for us.

338
00:27:41,650 --> 00:27:49,930
And again it's an extension of view controller and within it we have the distance action going to cut

339
00:27:49,990 --> 00:27:50,460
that.

340
00:27:50,500 --> 00:27:51,370
Put it here.

341
00:27:53,510 --> 00:27:55,690
So that part is taking off.

342
00:27:55,750 --> 00:27:58,100
Another copy of these commands.

343
00:27:58,140 --> 00:27:59,530
And swift fine.

344
00:27:59,540 --> 00:28:12,460
I'm going to call the view controller plus rotate action rotate action and he has a forcefield going

345
00:28:12,460 --> 00:28:24,040
to put all rotate action which is this one so perfect and if I go back to my view controller I now only

346
00:28:24,040 --> 00:28:31,450
have the view that lot which are the things that are kind of neat them yeah as well as the touches are

347
00:28:31,450 --> 00:28:32,530
moved if you wanted.

348
00:28:32,530 --> 00:28:36,020
You could even push the touches and move somewhere else.

349
00:28:36,100 --> 00:28:44,350
But I usually keep the kids Mather's VTM the main class declaration but it depends on the complexity

350
00:28:44,350 --> 00:28:45,340
of what you have.

351
00:28:45,460 --> 00:28:51,800
If you wanted to you could actually separate them even fair that is essentially an exercise of marginalising

352
00:28:51,890 --> 00:28:57,940
or partitioning your code which surely simplifies reading the parts of the code to understand.

353
00:28:58,240 --> 00:29:05,020
A They are very independent pieces which is the core understanding and the core concept of object oriented

354
00:29:05,020 --> 00:29:10,440
programming and B that you can you can use them separately whenever you need them.

355
00:29:10,510 --> 00:29:11,530
So that's about that.

356
00:29:11,530 --> 00:29:15,420
The app is working properly or the way you expected it.

357
00:29:15,430 --> 00:29:17,590
It's a kind of scale or rotating object.

358
00:29:17,590 --> 00:29:23,260
A very good exercise in understanding are different things that you could do graphically and using a

359
00:29:23,260 --> 00:29:27,040
combination of instructions and obviously in the next lesson.
