0:00

[MUSIC]

Â In this video, we'll discuss a bit about the mathematical concepts related to

Â working in three dimensional space.

Â The first thing that

Â we need to understand is a little bit about the coordinate systems.

Â A lot of times as you're working with Bitmap graphics tools such as Photoshop or

Â GIMP you might familiar with a coordinate system like we see on the left.

Â In this coordinate system we've got in the upper left hand corner,

Â we have the 0, 0 position, as we move horizontally, we go up in pixels.

Â 0:39

The first pixel position, the second pixel position, and so forth.

Â As we move from the top of the screen or

Â the top of the image down, we move up once again in pixel position.

Â So the first row, the second row,

Â the third row or you can view these as rows and columns as I was saying.

Â So this is what we might consider an integer-based coordinate

Â system where there is no in between, you're on 1 or you're on 2 or

Â you're on 3, there's no halfway between 1 and 2, for example.

Â You might also call this device specific, so it maps very clearly to your display.

Â On the right hand side of the screen is a 2D Cartesian coordinate system.

Â This is a type of coordinate system that you might have experienced before in

Â a math class like geometry where we've got the 0,

Â 0 position at the origin or in the middle.

Â And as you go up, you go into the positive y direction.

Â As you go to the right, you go into the positive x direction, and

Â we also have negatives.

Â So you can go below the origin which would be the negative y direction and

Â you can go to the left of the origin which would be the negative x direction.

Â This is real based or a floating point based number system.

Â So that between 0 and

Â 1 for example there's actually an infinite number of positions.

Â So you can go to 0.5, you can go to 0.55, you can go to 0.5555, and so forth.

Â So there's an infinite number of mathematical points between any two

Â points, unlike the 2D Bitmap coordinate system that we just spoke of a minute ago.

Â In this coordinate system rather than talking about pixels,

Â we're often talking about a unit of measurement.

Â So one might mean one meter, like it does in Unity or

Â it could be one mile or it could be one inch, or one centimeter.

Â But like I said in Unity, we typically work in meters as our unit of measurement.

Â 2:48

So using this coordinate system,

Â the next important concept is to talk about points and vectors.

Â So a point is a location within your coordinate system.

Â So A and B are points for example.

Â Whereas a vector is a displacement in space.

Â So D and C in this diagram are vectors.

Â 3:09

So let's talk a little bit more about this.

Â So when we're defining a point we need to know the x and the y position.

Â So how many units over in the x and how many units up or down in the y?

Â For a vector, they're really defined by a direction and magnitude.

Â So the question is how do we define direction and

Â magnitude in order to define a vector.

Â 3:32

So one thing that we can actually do is we can actually use two points.

Â So one way to define the vector D would be to define the initial,

Â the beginning of the vector or the x1, y1 and then the end of the vector,

Â which would be another point out in space such as x2, y2.

Â 3:55

But it turns out that vectors are a little bit unique.

Â So unlike a point or a location in space, vectors really are about the direction and

Â the magnitude rather than the location of space.

Â So here you can see that the vector D is represented in two locations,

Â and the question is are these the same vector?

Â And yes, it turns out that they actually are the same vectors even though they look

Â like they're in very different locations within the coordinate system.

Â 4:43

So in that sense we can simplify rather than talking about two locations,

Â we could just simply talk about a vector x and y.

Â So we've got a location which would just be x and y, and

Â then we have a vector x and y which those two single pieces of

Â information you can define the direction or angel off of the origin.

Â And you can define the magnitude or really the length of that arrow line.

Â 5:18

All of those things are implicit off the origin.

Â So of course, with games and unity 3D and most 3D systems,

Â we're using a three dimensional Cartesian coordinate system rather than 2D.

Â So we go ahead and add the z axis which is typically represented froward and back.

Â So the positive z direction would be towards your face and

Â the negative z direction would be out away from your eyes, moving forward.

Â 5:58

So just as sort of a nice aside,

Â the visual representation of the coordinate system, the x,

Â the y, and the z is shown in the same colors as we see in Unity 3D.

Â So the x axis is red, the y axis is green, and the z axis is blue.

Â So one quick way to remember these is RGB = XYZ.

Â RGB of course, is the common abbreviation for red, green, blue.

Â So red is x, green is y, and blue is z.

Â So that's one quick way,

Â in my mind that I remember when I see the little gizmos in unity and

Â they have the color coding I quickly know oh that's the blue, that's the z axis.

Â [COUGH] So how do we define a models position rotation and

Â scale and three dimensional space.

Â Cuz that's really what we're working up to,

Â because we need to start to build our solar system and of course,

Â we need to position our planets, rotate them and scale them accordingly.

Â 7:04

So we can actually use multiple vectors to do this.

Â So position, we've already talked about is just an x ,y, z location.

Â We can actually use a vector to define the displacement off of the origin and

Â the x, the y, and the z location to define where that position is.

Â 7:24

The rotation, we can use a vector three as well x, y, and z in the scale.

Â So let's talk a little bit more about that.

Â Like I said the position is the displacement from the origin

Â of the world coordinate system.

Â How many units over in the x up or down in the y and in and out in the z?

Â Rotation is how many degrees of rotation around each axis.

Â So how many degrees do we rotate around the x axis, the y axis or the z axis.

Â And then scale is a little bit unique.

Â Really, we're talking about how much a model is scaled from

Â its default size along each of the axis x, y or z.

Â So it's really a scale factor where 1 equals a 100%.

Â So 0.5 would be a 50% scale of regular size as an example,

Â maybe regular size as one or one meter.

Â So 0.5 would be half of a meter in scale along the respective axis

Â that you're defining.

Â 8:29

So it turns out that there's a mathematical concept called the transform.

Â And what the transform does is it packages together these three vectors.

Â So the position, the rotation and

Â the scale are all combined into what's called a transform.

Â This is also a standard component of game objects in Unity.

Â So any game object as we'll see soon,

Â has a transform component that defines the position, the rotation in the scale.

Â 9:01

So now, that we understand a bit about 3D space, vectors and transforms.

Â In the next video, we'll get into Unity kind of see how these concepts apply and

Â begin to build our solar system.

Â [MUSIC]

Â