WEBVTT

00:03.490 --> 00:08.530
Euclidean geometry is a branch of mathematics that we use for the most part in games.

00:08.560 --> 00:15.010
It's a mathematical system first devised by the Greek Euclid and comprises the works of numerous mathematicians

00:15.010 --> 00:17.890
of the time explaining the rules of geometry.

00:18.010 --> 00:21.580
His work is the basis of the mathematics we know of today.

00:21.610 --> 00:24.580
That includes plane geometry and algebra.

00:24.880 --> 00:31.210
Euclidean geometry and algebra were first linked by René Descartes days with the invention of coordinates

00:31.210 --> 00:34.360
that form the basis of the Cartesian coordinate system.

00:34.390 --> 00:40.090
This coordinate system should be fairly familiar to you as it's what we grow up learning in school whenever

00:40.090 --> 00:43.690
we need to create a graph with X and y values.

00:43.780 --> 00:49.900
A Cartesian coordinate defines a location of a single point according to reference axes that meet at

00:49.900 --> 00:56.140
a location called the Origin and extend away from that point perpendicular to each other in both the

00:56.140 --> 00:58.300
positive and negative directions.

00:58.330 --> 01:04.030
You should be familiar with the typical setup of the mapping of such a system with the Y axis extending

01:04.030 --> 01:10.930
upwards in a positive direction and the x axis extending to the right in a positive direction.

01:11.110 --> 01:17.470
A point in the Cartesian space is denoted by its distance along the x axis, followed by its distance

01:17.470 --> 01:18.700
along the Y.

01:18.730 --> 01:21.550
The coordinate for the point is written x.

01:21.550 --> 01:22.310
Y.

01:22.330 --> 01:31.630
For example, a 0.3 along the x axis and four along the y axis is written three four, whereas a point

01:31.630 --> 01:39.430
minus two along the Y and minus one along the x is minus one minus two.

01:39.670 --> 01:45.550
The x coordinate must and always comes first, followed by the Y.

01:45.850 --> 01:52.780
The defining property of Cartesian space is that a single coordinate only identifies a single location.

01:52.840 --> 02:00.160
If the coordinate three four is given, it cannot ever possibly be mistaken for any other location than

02:00.160 --> 02:05.320
the one that is three along the X and four along the Y.

02:05.350 --> 02:11.380
Cartesian coordinates can be defined for all dimensions of space from the one dimensional number line

02:11.380 --> 02:17.980
that has a single axis to the two dimensional system we've just looked at with the x and y axis to the

02:17.980 --> 02:24.550
three dimensional system that adds the addition of the Z axis to any number of dimensions that are difficult

02:24.550 --> 02:26.800
to visualize in games.

02:26.800 --> 02:33.490
We generally are most concerned with representations in two and three dimensions that is, points stored

02:33.490 --> 02:39.160
as Z for 2D and point stored as x, y, z for 3D.

02:39.160 --> 02:45.280
Simple data structures to hold the necessary information to define a point would look like this.

02:45.550 --> 02:51.460
There's a float to store each dimensional coordinate for 2D, there would be two, and for 3D there

02:51.460 --> 02:52.300
would be three.

02:52.300 --> 02:56.500
How many floats do you think you would need for a coordinate in four dimensional space?

02:56.530 --> 02:57.370
That's right.

02:57.370 --> 02:58.030
Four.

02:58.060 --> 03:04.270
There's always a value for each dimension, although we don't work with high value dimensions in games

03:04.270 --> 03:10.600
mathematicians do, and with each increase in dimension, it just means you need another value in your

03:10.600 --> 03:11.570
coordinate.

03:11.590 --> 03:16.660
Before we get started with some hands on practice with points, we first need to understand the nature

03:16.660 --> 03:18.550
of the space we will be working in.

03:18.730 --> 03:25.720
Basically, we can think of space as a large rectangular prism with X, Y and z dimensions like this.

03:25.720 --> 03:31.210
Of course, this is three dimensional space, the same that we ourselves live in for 2D space.

03:31.210 --> 03:35.680
We ignore the Z axis and work on the front plane of this prism.

03:35.680 --> 03:41.800
When space and computer graphics is represented by a cube or rectangular prism, it is called orthographic.

03:42.040 --> 03:47.110
Another type of space representation you'll be familiar with is called perspective.

03:47.140 --> 03:54.370
This warps space into a pyramid shape with the top cut off or what is also called a first stem.

03:54.370 --> 03:59.410
The shape of space impacts significantly on the way we deal with it mathematically.

03:59.500 --> 04:05.680
But we will leave these details for later in the course and begin first by using a simple orthographic

04:05.680 --> 04:08.230
space to explore points.

04:08.770 --> 04:16.510
We're going to begin our exploration of the Cartesian plane in unity so you can kind of get your hands

04:16.510 --> 04:17.020
dirty with it.

04:17.020 --> 04:22.000
Now, for this course, we're using Unity 2021.

04:22.000 --> 04:26.800
Now I'm using 2020 1.2. 16.

04:26.830 --> 04:30.280
If you use a slightly different version, it should be okay.

04:30.280 --> 04:34.030
I do recommend that you use the same version that I am.

04:34.420 --> 04:41.710
But most of this code, and that isn't specific to unity, it's what the interface that looks like is

04:41.710 --> 04:46.720
going to be an issue for you down the track if things change dramatically.

04:46.720 --> 04:47.170
Okay.

04:47.170 --> 04:52.690
So we're going to start with creating a new project and we're going to make a 2D project.

04:52.690 --> 04:54.550
So we want to go into unity.

04:54.550 --> 04:57.910
We're going to go file and new project.

04:57.940 --> 05:02.710
Now, when the new project window pops up, we want to select 2D.

05:03.150 --> 05:04.910
And you want to name your project.

05:04.920 --> 05:10.410
Well, I guess it doesn't really matter what you call it, but I'm going to call it points to D like

05:10.410 --> 05:14.190
that and then click on the create button.

05:14.700 --> 05:18.330
Now, when this opens up, it's going to give you a 2D view.

05:18.510 --> 05:18.900
All right.

05:18.900 --> 05:22.270
So here we are in our 2D view.

05:22.290 --> 05:28.770
Now we're going to work with the coordinates within this window that you can see here.

05:28.920 --> 05:34.380
First of all, what I'd like you to do, if we go over to the main camera, we're going to ensure that

05:34.380 --> 05:38.890
it's set to orthographic, which it will be because we selected a 2D project.

05:38.930 --> 05:45.220
Okay, now I want you to change the size that's just under here to 100 like that.

05:45.240 --> 05:52.140
Now, to find where that window was again, you might just want to zoom out until you can see that part

05:52.140 --> 05:53.450
around that border.

05:53.490 --> 05:59.100
And I'm just going to grab my game view so that we can see what's going on over here.

05:59.100 --> 06:05.880
And I'll set it up to 16 by nine as it's resolution.

06:06.480 --> 06:10.140
Then we'll just move this around a little bit so we can see it there.

06:10.350 --> 06:15.060
And the other thing I'll do, you don't have to do this, but I'm going to make the background of my

06:15.060 --> 06:19.120
camera black so that you can see it as I'm recording what I'm doing on there.

06:19.140 --> 06:27.510
So you want to set the camera to solid color in the clear flags and the color to black like that?

06:27.510 --> 06:34.410
If you want to follow on with me into our scene, we're going to add a circle.

06:34.410 --> 06:41.400
So in the hierarchy, right click to the object sprites and then you want to click circle, which is

06:41.400 --> 06:42.980
kind of off the screen there for you.

06:43.090 --> 06:46.660
If I can bring it over for you, circle like that.

06:46.680 --> 06:50.730
Now you're going to get a very tiny little dot in the middle.

06:50.740 --> 06:53.640
We're going to resize that so it's more visible.

06:53.760 --> 06:56.700
Select the circle and the scale.

06:56.700 --> 07:01.280
We want it to be ten in the X, ten in the Y.

07:01.290 --> 07:04.320
So we've got the X and the Y values.

07:04.800 --> 07:06.090
It doesn't matter about the Z.

07:06.120 --> 07:10.020
The Z is going in and out of the screen, so you don't resize it in the Z.

07:10.230 --> 07:11.700
It's not going to make any difference.

07:11.700 --> 07:21.330
And to position that sphere right in the center of our plane or coordinate system, we put zero zero.

07:21.330 --> 07:29.910
So that's the default setting that you're going to get your Cartesian plane set to in this orthographic

07:29.910 --> 07:32.520
view with a size of 100.

07:33.060 --> 07:38.880
Now, if you like me and you probably are, you went to school and you learnt some simple maths and

07:38.880 --> 07:46.950
you did graphing and we did a Cartesian plane which had an x and y axis system in it.

07:47.070 --> 07:53.700
This has an x and y axis system in it where we've got the y axis going up and down the screen and the

07:53.700 --> 07:57.570
x axis going back and forth between the left and the right.

07:57.600 --> 08:06.030
Now, if we move the circle using the Y value over here and grab my transform, I've lost, okay?

08:06.030 --> 08:08.100
And then just drag it around like this.

08:08.100 --> 08:12.480
You can see that we're actually moving up and down in the Y direction.

08:12.480 --> 08:20.040
And so if we go this way and we go up in the positive Y direction, then we get positive numbers going

08:20.040 --> 08:20.550
up this way.

08:20.550 --> 08:25.890
So we know that the positive y axis is up the x axis.

08:25.890 --> 08:31.570
The positive is going to go over to the right, which is what you would expect.

08:31.590 --> 08:35.000
Let me set this back to zero zero.

08:35.010 --> 08:41.220
So that means that this direction is going to be negative in the X and this direction is going to be

08:41.220 --> 08:42.990
negative in the Y.

08:43.410 --> 08:51.690
But that's not always the case in games because the camera moves around and therefore the axis system

08:51.690 --> 08:54.690
can be in any particular direction.

08:54.690 --> 09:04.560
So the y axis for the positive y could be going down the screen and the x axis could be positive in

09:04.560 --> 09:06.360
the other direction that it is.

09:06.360 --> 09:07.770
So the left direction.

09:07.770 --> 09:14.640
But the thing to remember is that those two axes, they always stay at 90 degrees to each other.

09:14.640 --> 09:20.970
And when you add in the Z axis as well, you end up with an orthogonal system.

09:20.970 --> 09:27.780
It's called where each of those axes is all at 90 degrees to each other, and they are always at 90

09:27.780 --> 09:29.070
degrees to each other.

09:30.830 --> 09:32.720
Why is that important?

09:32.750 --> 09:40.130
Well, as you'll see when we start looking at more maths and that we actually depend on those axes of

09:40.130 --> 09:44.690
the Cartesian plane being at 90 degrees with each other.

09:44.810 --> 09:45.290
All right.

09:45.290 --> 09:51.170
So before we finish up with this lecture, we're going to just investigate the size of this space.

09:51.170 --> 09:58.640
So the circle here, if I move it up like this towards the top of the screen, eventually it's going

09:58.640 --> 10:00.440
to hit the top of the screen.

10:00.590 --> 10:05.130
We've set this camera at an orthographic size of 100.

10:05.150 --> 10:10.190
So what do you think the Y position at the top here is?

10:10.190 --> 10:11.030
Well, yes.

10:11.030 --> 10:11.260
Okay.

10:11.270 --> 10:12.950
It's not rocket science.

10:12.950 --> 10:13.850
It is 100.

10:13.850 --> 10:16.930
So if we set it to 100, you'll see that the circle is up there.

10:16.940 --> 10:19.760
What is this value down here going to be?

10:20.270 --> 10:25.940
Well, if it's zero in the middle, then it's going to be -100 down there.

10:26.360 --> 10:26.930
Okay.

10:26.930 --> 10:31.040
So we've got 100 -100 down here.

10:31.040 --> 10:37.730
We know that we have an aspect ratio for this window of 16 to 9.

10:38.330 --> 10:45.160
What do you think the location in the X direction is for each of these things?

10:45.170 --> 10:49.160
Can you use some mathematics to work that out?

10:49.520 --> 10:51.590
Okay, so this is a challenge for you.

10:51.590 --> 10:55.700
Pause a video now, see if you can come up with that calculation.

10:55.700 --> 10:58.490
And when I come back, I'll give you the answer.

11:00.070 --> 11:00.880
Welcome back.

11:00.910 --> 11:03.300
How did you go with that calculation?

11:03.310 --> 11:11.680
If you moved the circle over to the X extremes and how to look in the transform, it might have given

11:11.680 --> 11:18.610
you a clue as to the calculation you're after, but what it is is going to be the orthographic size,

11:18.760 --> 11:20.350
which is 100.

11:20.350 --> 11:31.690
So it's 100 multiplied by 16 divided by nine, which is something like 177.7 something.

11:31.690 --> 11:42.430
So if we set our X to 178, you'll see that we end up on the extreme of the X side.

11:42.430 --> 11:45.910
And if we put our Y to zero, we'll be back in the middle.

11:45.910 --> 11:54.280
So this is going to be 178, which means this will be -178.

11:54.490 --> 11:55.600
How did you go with that?

11:56.230 --> 12:04.600
It's really important that you understand the principles of the Cartesian plane and get it, I guess,

12:04.600 --> 12:09.220
into your imagination, what's going on in these kinds of spaces.

12:09.220 --> 12:10.480
And this is only 2D.

12:10.480 --> 12:18.490
When you move into 3D, it becomes way more complex, but it's really about understanding these fundamental

12:18.490 --> 12:24.370
things because they're going to underpin everything that you do in a I.

12:24.670 --> 12:30.850
When we come back in the next lecture, we're going to look at something else that really sits underneath

12:30.850 --> 12:35.770
of most of the algorithms you're about to learn about, and that is vectors.

12:36.310 --> 12:39.910
You're going to find vectors everywhere throughout this course.

12:39.910 --> 12:45.070
And so it's a really good idea that you have a firm foundation in them.
