周一到周五,每天一篇,北京時間早上7點準時更新~
創(chuàng)新互聯(lián)公司服務項目包括興隆臺網(wǎng)站建設、興隆臺網(wǎng)站制作、興隆臺網(wǎng)頁制作以及興隆臺網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網(wǎng)行業(yè)的解決方案,興隆臺網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到興隆臺省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!As you have learned, coordinate transforms can be represented by matrices, and transformation of a vector from one space to another involves a simple matrix–vector multiplication operation(坐標的轉換可以用矩陣來表示,把一個向量從一個坐標系轉換到另外一個坐標系涉及到一個矩陣乘以向量的操作). Multiplying by a sequence of matrices can apply a sequence of transformations. It is not necessary to store the intermediate vectors after each matrix– vector multiplication(如果你使用一堆矩陣對向量進行轉換的話,就牽涉到一堆的轉換,你不必邀存儲向量與這一堆矩陣相乘時每個階段的向量狀態(tài)). Rather, it is possible and generally preferable to first multiply together all of the matrices making up a single set of related transformations to produce a single matrix representing the entire transformation sequence(你可以先把所有的矩陣相乘,得到最終矩陣,然后再拿這個最后的結果去與向量相乘). This matrix can then be used to transform vectors directly from the source to the destination coordinate spaces. Remember, order is important(你要記住的是,矩陣相乘的順序不能隨意改變). When writing code with vmath or in GLSL, you should always multiply a matrix by a vector and read the sequence of transformations in reverse order. For example, consider the following code sequence:(在GLSL中,你通常會使用矩陣乘以向量的操作,并且矩陣的相乘順序與正確的數(shù)學邏輯意義上的順序是反著來的,比如下面的)
vmath::mat4 translation_matrix = vmath::translate(4.0f, 10.0f, -20.0f);vmath::mat4 rotation_matrix = vmath::rotate(45.0f,
vmath::vec3(0.0f, 1.0f,
0.0f));
vmath::vec4 input_vertex = vmath::vec4(...);
vmath::vec4 transformed_vertex = translation_matrix
rotation_matrix
input_vertex;
This code first rotates a model 45° around the y axis (due to rotation_matrix) and then translates it by 4 units in the x axis, 10 units in the y axis, and negative 20 units in the z axis (due to translation_matrix)(上面的代碼先繞y軸旋轉45度,然后再沿x、y、z方向分別平移了4,10,-20). This places the model in a particular orientation and then moves it into position. Reading the sequence of transformations backward gives the order of operations (rotation, then translation). We could rewrite this code as follows:(請注意矩陣書寫時候的順序,與我們邏輯上的順序是反的,我們也可以把代碼寫成下面這樣)
vmath::mat4 translation_matrix = vmath::translate(4.0f, 10.0f, -20.0f);
vmath::mat4 rotation_matrix = vmath::rotate(45.0f,
vmath::vec3(0.0f, 1.0f,
0.0f));
vmath::mat4 composite_matrix = translation_matrix rotation_matrix;
vmath::vec4 input_vertex = vmath::vec4(...);
vmath::vec4 transformed_vertex = composite_matrix
input_vertex;
Here, composite_matrix is formed by multiplying the translation matrix by the rotation matrix, forming a composite that represents the rotation followed by the translation(這里,我們先得到了合成后的矩陣,然后我們拿這個合成后的矩陣去乘以向量). This matrix can then be used to transform any number of vertices or other vectors. If you have a lot of vertices to transform, this can greatly speed up your calculation. Each vertex now takes only one matrix–vector multiplication operation rather than two.(如果你的點比較多的時候,這種方式會提高效率,每個向量只需要乘以最后的合成矩陣,而不用依次去乘以兩個矩陣) Care must be taken here. It’s too easy to read (or write) the sequence of transformations left-to-right as you would code. If we were to multiply our translation and rotation matrices together in that order, then in the first transform we would move the origin of the model; the rotation operation would then take place around that new origin, potentially sending our model flying off into space!(這一大坨英文的意思就是,這里你需要注意矩陣的相乘順序,如果你順序?qū)戝e了,那就得不到你想要的結果,比如你總想著先旋轉再移動, 于是乎代碼很容易寫成rotation_matrix*translate_matrix)
Quaternions(四元數(shù))
A quaternion is a four-dimensional quantity that is similar in some ways to a complex number(四元數(shù)跟復數(shù)有點類似,它有一個實部和三個虛部,這個跟腎虛無關,有人就說腎虛也會引發(fā)失眠和頭疼,所以小伙子們應該保持良好的生活習慣). It has a real part and three imaginary parts (as compared to a complex number’s one imaginary part). Just as a complex number has an imaginary part i, a quaternion has three imaginary parts, i, j, and k. Mathematically, a quaternion q is represented as(如同復數(shù)有一個虛部i一樣,四元數(shù)有三個虛部i、j、k,數(shù)學上,四元數(shù)q可以寫成下面的樣子)
The imaginary parts of the quaternion have properties similar to the imaginary part of a complex number. In particular:(四元數(shù)的虛部跟復數(shù)的虛部有著相似的性質(zhì),特別是:)
Also, the product of any two of i, j, and k gives whichever one was not part of that product. Thus:(并且,i、j、k的兩兩乘積等于除開這倆個參與乘法的第三者,如下:)
Given this, we can see that it is possible to multiply two quaternions together as follows:(有了這些理論之后,四元數(shù)的乘法公式如下:)
As with complex numbers, multiplication of quaternions is non-commutative(如同復數(shù)一樣,四元數(shù)的乘法也是不可交換的). Addition and subtraction for quaternions is defined as simple vector addition and subtraction, with the terms being added or subtracted on a component-by-component basis(四元數(shù)的加減法就直接用對應元素進行加減操作就可以了). Other functions such as unary negation and magnitude also behave as expected for a four component vector(四元數(shù)求反和求長度就跟四維向量一樣操作就可以). Although a quaternion is a four-component entity, it is common practice to represent a quaternion as a real scalar part and a three-component imaginary vector part. Such representation is often written(雖然四元數(shù)是個四維的數(shù)據(jù),但是通常我們使用一個標量和三維虛部的向量表示它,這樣的表述通??梢赃@么來寫:)
Okay, great—but this isn’t the dreaded math chapter, right?(OK,屌爆了,可以看到這并不是一個很狗帶的數(shù)學章節(jié)) This is about computer graphics, OpenGL, and all that fun stuff(這是關于圖形學、OpenGL和所有那些有趣的玩意,有趣個卵啊,頭都快禿了,搞不好寫書的就是個禿友亮). Well, here’s where quaternions get really useful. Recall that our rotation functions take an angle and an axis to rotate around(Well,我們來瞅瞅四元數(shù)為何有用吧,讓我們回想起旋轉的那些操作). Well, we can represent those two quantities as a quaternion by stuffing the angle in the real part and the axis in the vector part, yielding a quaternion that represents a rotation around any axis(我們可以使用實部去記錄旋轉,虛部去記錄旋轉軸,這樣一來一個四元數(shù)就可以表達繞任意軸旋轉這個概念了). A sequence of rotations can be represented by a series of quaternions multiplied together, producing a single resulting quaternion that encodes the whole lot in one go(四元數(shù)的乘法也是可以累加的,你可以把多次旋轉讓多個四元數(shù)相乘之后存到一個結果四元數(shù)里). While it’s possible to make a bunch of matrices that represent rotation around the various Cartesian axes and then multiply them all together, that method is susceptible to gimbal lock(使用四元數(shù)就很好的解決了在使用旋轉矩陣去表達旋轉時,會產(chǎn)生萬向鎖的問題). If you do the same thing with a sequence of quaternions, gimbal lock cannot occur. For your coding pleasure, vmath includes the vmath::quaternion class that implements most of the functionality described here(如果你使用四元數(shù)的話,就不會有萬向鎖的問題,我們的vmath是個好青年,我們這里講的這些玩意它都實現(xiàn)了)
本日的翻譯就到這里,明天見,拜拜~~
第一時間獲取最新橋段,請關注東漢書院以及圖形之心公眾號
東漢書院,等你來玩哦
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
標題名稱:ConcatenatingTransformations(變換的累加)-創(chuàng)新互聯(lián)
分享地址:http://www.rwnh.cn/article44/dcicee.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站制作、網(wǎng)站營銷、App設計、做網(wǎng)站、網(wǎng)站設計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容