Камеры

Страницы работы

Содержание работы

Cameras - Камеры

Cameras are needed in the 3d world to view the objects. They are needed if we want to move around in the world, and they are needed for many other things too. But nomatter what, we nearly always need cameras when we do 3d programming. Cameras can have many functions like zoom, targeting, field of view, eg. But we just need the basic routines. To start with, we need martices and everything we do, will be about matrices. If you do not know how matrices work, please visit the math cornor where they are described. Now, lets look at some of the features we get with cameras. When we include camera in our code we can make a "walkable" 3d world. With that I mean we can use e.g the cursor keys to move forward and to the sides, look up and down, and roll. This is what many 3d programmers wish to do, since this gives the most impressive results. But all we need to know to do all this is very simple, and we will end up with one simple matrix, which should do the trick. But for now, lets take a look at cameras, and how they are defined.

Камеры необходимы в 3D мире, чтобы смотреть объекты. Они необходимы, если мы хотим двигаться в мире, и они необходимы для многих других вещей также. Но безразлично, что, мы почти всегда нуждаемся в камерах, когда мы делаем 3D программирование. Камеры могут иметь много функций подобно масштабированию, наведению, области просмотра, т.д. Но мы только нуждаемся в базисных подпрограммах. Чтобы начинать мы нуждаемся в матрицах и всем, что мы делаем, будем относительно матриц. Если Вы не знаете, как работают матрицы, пожалуйста посетите математический уголок, где они описаны. Теперь, допустим, рассматрим некоторых из особенностей, которые мы получаем с камерами. Когда мы включаем камеру в наш код, мы можем делать "путешествие" в 3D мире. Под этим я подразумеваю, что мы можем использовать клавиши курсора, чтобы двигаться вперед и в стороны, смотреть вверх и вниз , и вращаться. Это - то, что много 3D программистов желают делать, так как это дает наиболее внушительные результаты. Но все, что мы должны знать, чтобы делать все, это очень просто, и мы закончим с одной простой матрицей, которая должна делать этот трюк. Но теперь, допустим, смотрим на камеры, и как они определены.

Any camera can be defined by a position and the angles yaw, pitch and roll, where yaw is the angle around y, pitch around x and roll around z. with the position we know where the camera is and with the angles we know in which direction it's looking. KNow all we have to do with all the vertices in our world is to translate them from WCS (world coordinate system) to CCS (camera coordinate system). This is done by first moving all the vertices, so they match the camera position. To put this in a matrix it looks like this:

Любая камера может быть определена при помощи позиции и углов yaw, шагом и вращением, где yaw - угол вокруг y, шаг вокруг x и вращение вокруг z. По позиции мы знаем, где камера находиться, по углам мы знаем, в котором направлении она смотрит. ЗАПОМНИТЕ все, что мы должны делать с всеми вершинами в нашем мире, это перенести их с WCS (мировая система координат) к CCS (система координат камеры). Это выполняется вначале перемещением всех вершин, так что они соответствовали положению камеры. Чтобы помещать все это в матрицу, подобно этому:

[x'] [1 0 0 -camerax] [x]

[y'] [0 1 0 -cameray] [y]

[z'] [0 0 1 -cameraz] [z]

[ 1] [0 0 0     1   ] [1]

Now we have moved all the vertices in the WCC to the CCS, but we still have to think of the rotation angles. Therefore we make three new matrices, each rotating around an axis:

Теперь мы переместим все вершины из WCC к CCS, но мы все еще должны думать о углах вращения. Следовательно мы делаем три новых матрицы, на каждое вращение вокруг оси:

Around yaw - the y axis

Вокруг оси y:

[x'] [cos(-yaw)        0           sin(-yaw)] [x]

[y'] [   0             1              0     ] [y]

[z'] [-sin(-yaw)       0           cos(-yaw)] [z]

Around pitch - the x axis

Вокруг оси x:

[x'] [   1             0              0     ] [x]

[y'] [   0        cos(-pitch)   -sin(-pitch)] [y]

[z'] [   0        sin(-pitch)    cos(-pitch)] [z]

Around roll - the z axis

Вокруг оси Z:

[x'] [cos(-roll)  -sin(-roll)         0     ] [x]

[y'] [sin(-roll)   cos(-roll)         0     ] [y]

[z'] [   0             0              1     ] [z]

Now as with the rotation matrix, we know that:

Теперь мы знаем что:

-sin(angle) = sin(-angle)

cos(angle)  = cos(-angle)

and therefore we can change the above matrices to the following:

Тогда:

Around yaw - the y axis

Вокруг оси y:

[x'] [cos(yaw)         0           -sin(yaw)] [x]

[y'] [   0             1              0     ] [y]

[z'] [sin(yaw)         0            cos(yaw)] [z]

Around pitch - the x axis

Вокруг оси x:

[x'] [   1             0              0     ] [x]

[y'] [   0        cos(pitch)      sin(pitch)] [y]

[z'] [   0        -sin(pitch)     cos(pitch)] [z]

Around roll - the z axis

Вокруг оси z:

[x'] [cos(roll)     sin(roll)         0     ] [x]

[y'] [-sin(roll)    cos(roll)         0     ] [y]

[z'] [   0             0              1     ] [z]

These rotation matrices we know from ordinary rotations, where we also end up with one big matrix. Now, lets make that big matrix. If we calculate all the matrices together we would end up with the following matrix:

Эти матрицы вращения, которые мы знаем из обычных вращений, где мы также заканчиваемся с одной большой матрицей. Теперь, сделаем большую матрицу. Если мы вычисляем все матрицы, вместе мы получили следующую матрицу:

[x'] [m11 m12 m13 m14] [x]

[y'] [m21 m22 m23 m24] [y]

[z'] [m31 m32 m33 m34] [z]

[1'] [m41 m42 m43 m44] [1]

where:

где:

m11 = cos(yaw)sin(roll) + sin(yaw)sin(pitch)sin(roll)

m12 = sin(pitch)sin(roll)

m13 = -sin(yaw)cos(roll) + cos(yaw)sin(pitch)sin(roll)

m14 = -(cx*m11 + cy*m12 + cz*m13)

m21 = -cos(yaw)sin(roll) + sin(yaw)sin(pitch)cos(roll)

m22 = cos(pitch)cos(roll)

m23 = sin(yaw)sin(roll) + cos(yaw)sin(pitch)cos(roll)

m24 = -(cx*m21 + cy*m22 + cz*m23)

m31 = sin(yaw)cos(pitch)

m32 = -sin(pitch)

m33 = cos(yaw)cos(pitch)

m34 = -(cx*m31 + cy*m32 + cz*m33)

m41 = 0

m42 = 0

m43 = 0

m44 = 1

As you can see there is very little diffrence from normal rotation to camera converting. Note that cx, cy and cz equals camera x, y and z position in space. Поскольку Вы можете видеть, что имеются очень немного различий от нормального вращения до преобразования камеры. Заметьте, что cx, cy и cz равны x, y и z положению камеры в пространстве.

Информация о работе