CoordinateTransformations(坐標(biāo)系的變換)-創(chuàng)新互聯(lián)

周一到周五,每天一篇,北京時(shí)間早上7點(diǎn)準(zhǔn)時(shí)更新~

站在用戶的角度思考問題,與客戶深入溝通,找到通州網(wǎng)站設(shè)計(jì)與通州網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、申請(qǐng)域名、雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋通州地區(qū)。

As noted, coordinates may be moved from space to space by multiplying their vector representations by transformation matrices(如同提到過的那樣,坐標(biāo)可以通過乘以變換矩陣從一個(gè)空間轉(zhuǎn)換到另一個(gè)空間). Transformations are used to manipulate your model and the particular objects within it(變換主要是用來(lái)去計(jì)算特定空間中你的模型以及某些特定的物體). These transformations move objects into place, rotate them, and scale them(這些變換把物體移動(dòng)到某個(gè)位置,旋轉(zhuǎn)他們,縮放他們). Figure 4.8 illustrates three of the most common modeling transformations that you will apply to your objects(圖4.8顯示了三個(gè)最常見的你會(huì)應(yīng)用到你物體上的模型變換). Figure 4.8(a) shows translation, in which an object is moved along a given axis(圖4.8a顯示了平移,這里是把一個(gè)物體沿著一個(gè)給定的坐標(biāo)軸平移). Figure 4.8(b) shows a rotation, in which an object is rotated about one of the axes(圖4.8b顯示了旋轉(zhuǎn),物體繞著某個(gè)軸旋轉(zhuǎn)). Finally, Figure 4.8(c) shows the effects of scaling, where the dimensions of the object are increased or decreased by a specified amount(最后圖4.8c中顯示了縮放物體). Scaling can occur non-uniformly (the various dimensions can be scaled by different amounts), so you can use scaling to stretch and shrink objects(各方向上的縮放可以不一樣,這樣一來(lái)你就可以來(lái)擠壓物體)
Coordinate Transformations(坐標(biāo)系的變換)
Each of these standard transforms can be represented as a matrix by which you can multiply your vertex coordinates to calculate their positions after the transformation(每一個(gè)標(biāo)準(zhǔn)變換可以表示成為使用一個(gè)矩陣乘以你的坐標(biāo)). The following subsections discuss the construction of those matrices, both mathematically and using the functions provided in the vmath library(接下來(lái)的章節(jié)從數(shù)學(xué)意義上以及vmath庫(kù)的角度討論矩陣的構(gòu)造)

The Identity Matrix(單位矩陣)

There are a number of important types of transformation matrices you need to be familiar with before we start trying to use them(在你開始使用矩陣之前,你需要先了解一些非常重要的矩陣類型). The first is the identity matrix(第一個(gè)就是單位矩陣). As shown below, the identity matrix contains all zeros except a series of ones that traverse the matrix diagonally. The 4 × 4 identity matrix looks like this:(如同下面展示的這樣,單位矩陣是一個(gè)對(duì)角陣,除了對(duì)角線上的元素以外,其他地方都是0,,4x4的單位矩陣長(zhǎng)相如此:)
Coordinate Transformations(坐標(biāo)系的變換)
Multiplying a vertex by the identity matrix is equivalent to multiplying it by 1; it does nothing to it(與單位矩陣相乘,向量不變)

Coordinate Transformations(坐標(biāo)系的變換)
Objects drawn using the identity matrix are untransformed; they are at the origin (last column), and the x, y, and z axes are defined to be the same as those in eye coordinates(使用單位矩陣去對(duì)物體進(jìn)行變換,物體不會(huì)有什么變化). Obviously, identity matrices for 2 × 2 matrices, 3 × 3 matrices, and matrices of other dimensions exist and simply have ones in their diagonal(很顯然,2、3和其他維度的單位矩陣也是存在的,所有的單位矩陣都是方陣,所有單位矩陣都是它自己的轉(zhuǎn)置矩陣). All identity matrices are square. There are no non-square identity matrices. Any identity matrix is its own transpose. You can make an identity matrix for OpenGL in C++ code like this(你可以在C++中來(lái)這么定義一個(gè)OpenGL中的單位矩陣):

// Using a raw array:
GLfloat m1[] = { 1.0f, 0.0f, 0.0f, 0.0f, // X Column
0.0f, 1.0f, 0.0f, 0.0f, // Y Column
0.0f, 0.0f, 1.0f, 0.0f, // Z Column
0.0f, 0.0f, 0.0f, 1.0f }; // W Column
// Or using the vmath::mat4 constructor:
vmath::mat4 m2{ vmath::vec4(1.0f, 0.0f, 0.0f, 0.0f), // X Column
vmath::vec4(0.0f, 1.0f, 0.0f, 0.0f), // Y Column
vmath::vec4(0.0f, 0.0f, 1.0f, 0.0f), // Z Column
vmath::vec4(0.0f, 0.0f, 0.0f, 1.0f) }; // W Column
There are also shortcut functions in the vmath library that construct identity matrices for you. Each matrix class has a static member function that produces an identity matrix of the appropriate dimensions:(下面展示了vmath庫(kù)中,vmath提供的生成單位矩陣的接口)

vmath::mat2 m2 = vmath::mat2::identity();
vmath::mat3 m3 = vmath::mat3::identity();
vmath::mat4 m4 = vmath::mat4::identity();

If you recall, the very first vertex shader we used in Chapter 2, “Our First OpenGL Program,” was a pass-through shader. It did not transform the vertices at all, but simply passed the hard-coded data on untouched in the default coordinate system with no matrix applied to the vertices at all(回想起咱第2章中的shader,它里面沒有對(duì)頂點(diǎn)進(jìn)行任何變化,簡(jiǎn)單的將數(shù)據(jù)傳遞給了渲染管線的下一個(gè)階段). We could have multiplied all of the vertices by the identity matrix, but that would have been a wasteful and pointless operation(我們可以讓所有點(diǎn)都乘以單位矩陣,但這沒什么卵用).

The Translation Matrix(平移矩陣)

A translation matrix simply moves the vertices along one or more of the three axes. Figure 4.9 shows, for example, translating a cube up the y axis by ten units(一個(gè)平移矩陣會(huì)將頂點(diǎn)沿著一個(gè)或者多個(gè)坐標(biāo)軸移動(dòng),圖4.9展示了沿著y軸正方向移動(dòng)一個(gè)立方體10個(gè)單位)
Coordinate Transformations(坐標(biāo)系的變換)
The formulation of a 4 × 4 translation matrix is as follows:(平移矩陣的長(zhǎng)相如下)
Coordinate Transformations(坐標(biāo)系的變換)
Here, tx, ty, and tz represent the translation in the x, y, and z axes, respectively(這里,tx、ty、tz代表的是平移的相對(duì)距離). Examining the structure of the translation matrix reveals one of the reasons why we need to use four-dimensional homogeneous coordinates to represent positions in 3D graphics(觀察平移矩陣的結(jié)構(gòu)不難發(fā)現(xiàn),為何俺們要使用w分量為1的齊次坐標(biāo)去表示一個(gè)三維坐標(biāo)了). Consider the position vector v, whose w component is 1.0. Multiplying by a translation matrix of the form above yields(乘以一個(gè)上面的平移矩陣后,會(huì)產(chǎn)生下面這樣的一個(gè)玩意)
Coordinate Transformations(坐標(biāo)系的變換)
As you can see, tx, ty, and tz have been added to the components of v, producing translation. Had the w component of v not been 1.0, then using this matrix for translation would have resulted in t x, ty, and tz being scaled by that value, affecting the output of the transformation(如同你看到的,tx、ty、tz已經(jīng)被加到向量v上去了,產(chǎn)生了平移。如果w不是1的話,那么這個(gè)結(jié)果就會(huì)不一樣,tx、ty、tz就被縮放了). In practice, position vectors are almost always encoded using four components with w (the last) being 1.0, whereas direction vectors are encoded either simply using three components, or as four components with w being zero(在實(shí)踐中,表達(dá)位置的向量通常將w分量設(shè)置成1,表達(dá)方向的向量要么是三位向量,要么w分量是0). Thus, multiplying a four-component direction vector by a translation matrix doesn’t change it at all(也就是說(shuō),乘以一個(gè)四維的方向向量,不會(huì)改變它). The vmath library contains two functions that will construct a 4 × 4 translation matrix for you using either three separate components or a 3D vector(vmath庫(kù)包含了使用三個(gè)分量或者一個(gè)三維向量去構(gòu)建4x4平移矩陣的API):

template
static inline Tmat4 translate(T x, T y, T z) { ... }
template
static inline Tmat4 translate(const vecN& v) { ... }
The Rotation Matrix(旋轉(zhuǎn)矩陣)

To rotate an object about one of the three coordinate axes, or indeed any arbitrary vector, you have to devise a rotation matrix(為了繞著某個(gè)軸去旋轉(zhuǎn)物體,你此時(shí)就需要旋轉(zhuǎn)矩陣). The form of a rotation matrix depends on the axis about which we wish to rotate. To rotate about the x axis, we use(旋轉(zhuǎn)矩陣的結(jié)構(gòu)因旋轉(zhuǎn)軸的不同而不同,下面啊我們展示了一個(gè)繞x軸旋轉(zhuǎn)的旋轉(zhuǎn)矩陣的結(jié)構(gòu))

Coordinate Transformations(坐標(biāo)系的變換)
Here, Rx(θ) represents a rotation around the x axis by an angle of θ. Likewise, to rotate around the y or z axes, we can use(這里Rx(θ)表示繞x軸旋轉(zhuǎn) θ角度,繞y、z軸旋轉(zhuǎn)如下圖所示)
Coordinate Transformations(坐標(biāo)系的變換)
It is possible to multiply these three matrices together to produce a composite transform matrix and then rotate by a given amount around each of the three axes in a single matrix–vector multiplication operation. The matrix to do this is(你也可以把這仨個(gè)軸向的旋轉(zhuǎn)矩陣合體成一個(gè),計(jì)算方法如下)
Coordinate Transformations(坐標(biāo)系的變換)
Here, sψ, sθ, and sφ indicate the sine of ψ, θ, and φ, respectively, and cψ, cθ, and cφ indicate the cosine of ψ, θ, and φ, respectively. If this seems like a huge chunk of math, don’t worry—again, a couple of vmath functions come to the rescue:(這里sψ, sθ, sφ表示的是ψ,θ,φ的正弦值,cψ, cθ, cφ表示的是ψ,θ,φ的余弦值,看起來(lái)好多數(shù)學(xué)公式,頭好大啊,不怕,有vmath)

template
static inline Tmat4 rotate(T angle_x, T angle_y, T_angle_z);
You can also perform a rotation around an arbitrary axis by specifying x, y, and z values for that vector. To see the axis of rotation, you can just draw a line from the origin to the point represented by (x,y,z). The vmath library also includes code to produce this matrix from an angle-axis representation:(你也可以繞著任意坐標(biāo)軸旋轉(zhuǎn),這個(gè)坐標(biāo)軸是從原點(diǎn)指向x、y、z的向量,vmath也有這方面的操作API)

template
static inline Tmat4 rotate(T angle, T x, T y, T z);
template
static inline Tmat4 rotate(T angle, const vecN& axis);
These two overloads of the vmath::rotate function produce a rotation matrix representing a rotation of angle degrees round the axis specified by x, y, and z for the first variant, or by the vector v for the second(這倆重載的函數(shù)可以產(chǎn)生一個(gè)繞x、y、z軸旋轉(zhuǎn)angle讀的旋轉(zhuǎn)矩陣). Here, we perform a rotation around the vector specified by the x, y, and z arguments. The angle of rotation is in the counterclockwise direction measured in degrees and specified by the argument angle(這里要注意的是angle是按照逆時(shí)針方向定義的). In the simplest of cases, the rotation is around only one of the coordinate system’s cardinal axes (x, y, or z)(最簡(jiǎn)單的情況就是,繞著x、y、z中的某一個(gè)軸進(jìn)行旋轉(zhuǎn)). The following code, for example, creates a rotation matrix that rotates vertices 45° around an arbitrary axis specified by (1,1,1), as illustrated in Figure 4.10(下面的代碼展示了創(chuàng)建一個(gè)繞(1,1,1)軸旋轉(zhuǎn)45度的例子)

vmath::mat4 rotation_matrix = vmath::rotate(45.0, 1.0, 1.0, 1.0);
Coordinate Transformations(坐標(biāo)系的變換)
Notice in this example the use of degrees. This function internally converts degrees to radians because, unlike computers, many programmers prefer to think in terms of degrees(再次強(qiáng)調(diào)這里的單位是角度,底層會(huì)把他們轉(zhuǎn)化成弧度。這里用角度是因?yàn)榇蟛糠执a農(nóng)都習(xí)慣用角度去思考人生)

Euler Angles(歐拉角)

Euler angles are a set of three angles that represent orientation in space. Each angle represents a rotation around one of three orthogonal vectors that define our frame (for example, the x, y, and z axes)(歐拉角在空間中使用三個(gè)角度來(lái)表達(dá)旋轉(zhuǎn),每一個(gè)角度表示的是繞某一個(gè)定義了某個(gè)坐標(biāo)系的坐標(biāo)軸旋轉(zhuǎn)的角度). As you have read, the order in which matrix transformations are performed is important, as performing some transformations (such as rotations) in different orders will produce different results(使用歐拉角來(lái)表達(dá)旋轉(zhuǎn)的時(shí)候,旋轉(zhuǎn)的順序會(huì)影響最終結(jié)果). This is due to the noncommutative nature of matrix multiplication(這都是因?yàn)榫仃嚨某朔ㄊ遣豢山粨Q的). Thus, given a set of Euler angles, should you rotate first around the x axis, then around y, and then z, or should you perform the rotations in the opposite order, or even do y first? Well, so long as you’re consistent, it doesn’t really matter(因此,給你一組歐拉角,你是x、y、z軸這樣的順序進(jìn)行旋轉(zhuǎn)還是反著來(lái),甚至先y再其他呢?實(shí)際上這并沒什么影響)

Representation of orientations as a set of three angles has some advantages. For example, this type of representation is fairly intuitive, which is important if you plan to hook the angles up to a user interface(使用歐拉角去表達(dá)旋轉(zhuǎn)還是有一些優(yōu)勢(shì)的,比如它比較直觀). Another benefit is that it’s pretty straightforward to interpolate angles, construct a rotation matrix at each point, and see smooth,consistent motion in your final animation. However, Euler angles also come with a serious pitfall—gimbal lock(另一個(gè)優(yōu)勢(shì)就是,是用歐拉角進(jìn)行插值比較直觀,插出來(lái)之后,再構(gòu)建矩陣,然后做成動(dòng)畫是那么的平滑。然而歐拉角也存在很多問題,比如萬(wàn)向鎖). Gimbal lock occurs when a rotation by one angle reorients one of the axes to be aligned with another of the axes(當(dāng)歐拉角旋轉(zhuǎn)坐標(biāo)軸使得它與另一個(gè)坐標(biāo)軸重合的時(shí)候,萬(wàn)向鎖就出現(xiàn)了). Any further rotation around either of the two now-colinear axes will result in the same transformation of the model, removing a degree of freedom from the system. Thus, Euler angles are not suitable for concatenating transforms or accumulating rotations(從此之后,你再也別想繞著這個(gè)方向轉(zhuǎn)動(dòng)物體了。也就是說(shuō),歐拉角不適合做矩陣的累加). To avoid this, our vmath::rotate functions are able to take an angle by which to rotate and an axis about which to rotate(為了避免這一點(diǎn),所以vmath提供的接口是繞某個(gè)軸轉(zhuǎn)某個(gè)角度的這種API,而不是矩陣的方式). Of course, stacking three rotations together— one in each of the x, y, and z axes—allows you to use Euler angles if you must, but it is much preferable to use angle-axis representation for rotations, or to use quaternions to represent transformations and convert them to matrices as needed(使用繞什么軸旋轉(zhuǎn)多少度的這種方式實(shí)際上是更推薦的,或者你也可以使用四元數(shù)去表達(dá)旋轉(zhuǎn), 如果你需要矩陣的時(shí)候再把他們轉(zhuǎn)成矩陣就行)

The Scaling Matrix(縮放矩陣)

Our final “standard” transformation matrix is a scaling matrix(我們最后一個(gè)標(biāo)準(zhǔn)的變換矩陣就是縮放矩陣了). A scaling transform changes the size of an object by expanding or contracting all the vertices along the three axes by the factors specified. A scaling matrix has the following form(一個(gè)縮放變換矩陣會(huì)沿著各個(gè)坐標(biāo)軸按照各個(gè)軸向的縮放因子去改變頂點(diǎn)的位置達(dá)到改變物體大小的效果,縮放矩陣的結(jié)構(gòu)如下所示)
Coordinate Transformations(坐標(biāo)系的變換)
Here, sx, sy, and sz represent the scaling factor in the x, y, and z dimensions, respectively. Creating a scaling matrix with the vmath library is similar to the method for creating a translation or rotation matrix. Three functions exist to construct this matrix for you:(這里sx、sy、sz分別表示x、y、z軸向上的縮放因子,我們vmath庫(kù)也提供了方法去創(chuàng)建縮放矩陣,如下圖所示:)

template
static inline Tmat4 scale(T x, T y, T z) { ... }
template
static inline Tmat4 scale(const Tvec3& v) { ... }
template
static inline Tmat4 scale(T x) { ... }
The first of these scales independently in the x, y, and z axes by the values given in the x, y, and z parameters. The second performs the same function but uses a threecomponent vector rather than three separate parameters to represent the scale factors. The final function scales by the same amount, x, in all three dimensions(第一個(gè)傳入的是x、y、z方向上的縮放因子,第二個(gè)傳入的是一個(gè)向量,向量的x、y、z分別表示縮放因子,第三個(gè)創(chuàng)建的縮放矩陣 所有軸向上的縮放因子一樣). Scaling does not have to be uniform, and you can use it to both stretch and squeeze objects alongdifferent directions. (縮放不一定在各個(gè)方向上需要保持一致,所以你可以使用縮放去擠壓物體,比如一個(gè)10x10x10的立方體可以被如下的方式進(jìn)行縮放,x、z方向上的縮放因子是2)For example, a 10 × 10 × 10 cube could be scaled by two in the x and z directions as shown in Figure 4.11.

Coordinate Transformations(坐標(biāo)系的變換)
本日的翻譯就到這里,明天見,拜拜~~

第一時(shí)間獲取最新橋段,請(qǐng)關(guān)注東漢書院以及圖形之心公眾號(hào)

東漢書院,等你來(lái)玩哦

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

名稱欄目:CoordinateTransformations(坐標(biāo)系的變換)-創(chuàng)新互聯(lián)
地址分享:http://muchs.cn/article4/dphjoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、網(wǎng)站策劃、網(wǎng)站維護(hù)、Google域名注冊(cè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)公司