青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

牽著老婆滿街逛

嚴以律己,寬以待人. 三思而后行.
GMail/GTalk: yanglinbo#google.com;
MSN/Email: tx7do#yahoo.com.cn;
QQ: 3 0 3 3 9 6 9 2 0 .

常用數學矩陣

來源:http://www.vbgamedev.com/Direct%20graphics/Matrix%20Maths.htm

常用數學矩陣
Author: Jack Hoxley


Contents of this lesson
1. Introduction
2. 2D Transformations
3. 3D Transformations


1. Introduction 介紹

   矩陣轉換通常就是三種東西-旋轉,縮放,平移。在3d graphics中幫你完成 99%的工作,我未見到比他更快的方法。矩陣使程序加速,也許每秒多渲染500個對象。

Transformation consists of 3 things - rotating (spinning things around), scaling (making things bigger/smaller) and translation (moving things around). With 3D graphics Direct3D will do 99% of the work for you, however, along my travels I've found a way of going faster - if you do the matrix maths calculations yourself you can go just that little bit faster (2.5x faster), we're talking the difference between 0.0001ms and 0.00005ms here, but if you're rendering 500+ objects a frame (several 1000 a second), it could be worth the extra effort. It also looks much cleverer! (if you open-source your code).

Onwards and upwards...


2. 2D Transformations 兩維轉換

 

  它在2D3D游戲中都很有用,數學方法這里不多解釋。This is the most useful part, using either DirectDraw (fully 2D) or Direct3D (quasi 2D) no transformations are done for you - you want to rotate, translate or scale something you're gonna have to do it yourself. The actual mathematical proof behind all of this is a little complicated, and to be honest - it really makes much difference why it works, all we want to know is how to make it work for us. Much of the pure maths is glossed over here, if you're interested in proofs or further explanations dig out your old maths books or go searching the web - much of the pure maths is too lengthy to explain here.

我們不用知道它是任何推導的,僅使用它。We're going to be using a mathematical technique known as matrix maths - the ideas behind matrices (plural of matrix) isn't too important, heck! I dont even know exactly how to use them - I just learnt what I need to know about them. Matrix maths allows us to do the transformations relatively quickly, and relatively simply as well - just what I like.

基本的結構向這樣[X,Y] --> [M] --> [X',Y']一個x,y坐標進去經過變化出來一個新坐標,可能是縮放、旋轉也可能是平移。The basic structure is like this [X,Y] ---} [M] ---} [X',Y'] (one set of coordinates goes in, something happens, and a new set of coordinates come out). [M] is the transformation matrix, it may scale the coordinates, rotate them, translate them or some combination of the 3. The best part is that you can combine all 3 transformations into one matrix (more on that later).

Translation 平移

2D平移需要3x3的矩陣。This is probably the easiest of the 3, and thus we'll start here. A 2D translation matrix for what we want is a 3x3 grid of numbers (known as a 3x3 matrix). for a translation it looks like this:

  平移一個點要將這個點與上面矩陣相乘,下圖為計算過程和結果。a bit weird really, isn't it. in order to translate a point by this matrix we must multiply the point by the matrix. Now this isn't as simple as it sounds, it's not quite like normal multiplication, and it's an awful lot more complicated. if we refer to all of the elements in row-column notation (ie, yx) and the rows are i and columns j, to get the FINAL value for element <i,j> we multiply each element in the row i (of the source matrix) with each element in the column j (of the destination matrix), we then add all of these values together and that is our final value. scared? look at this following example and see if you can understand what happened:

it aint too scary really, is it? the final results aren't particularly amazing - I'm pretty sure that without all this extra work you could of told me how to translate the original coordinates (the x' = x + dx part)... It'll come into it's own a little later on when we're combining rotation, scaling and translation into one big equation.

Rotation 旋轉
旋轉在游戲中使用非常頻繁下圖是旋轉使用的矩陣,X代表角度。Rotation is the big one - this is what everyone likes emailing me about. Rotating your sprite around is a very useful trick in games - and is often quite heavily used; therefore it obviously helps being able to do it! The following diagram shows you what the 2D rotation matrix should look like:

我們已經推導了平移矩陣,借鑒推導出旋轉矩陣,下面是將點(x,y)旋轉置(x',y')A little more scary this time - trig functions. The presence of these trig functions will bring the processing time for a rotation transformation up considerably - trig functions are slow. If you can optimise away any of the trig functions then do so - the only realistic optimisation to be done here is to pre-process CosX and SinX, as that will 1/2 the number of calls to Cos( ) or Sin( ). More on this later (when we do a bit of code).

Again, not too simple if you can see your way through the matrix multiplication algorithm. Be careful to differentiate between the X and the x, the X is the angle (usually denoted as theta, q), and x is the coordinate.

Scaling 縮放
This isn't used as often, but it's pretty simple - so I may as well explain it, and we can incorporate it into the big matrix later on. You may have noticed that all of the matrices so far have had the r=c values equal to 1 (unless replaced by another value), this is because the r=c values are the scaling values - in previous matrices they are set to 1 so that they dont intefere with the resultant values. a matrix where all the values are 0 except the r=c values which are 1 is called the "identity matrix", which is a useful type of matrix, but not really relevant here.

Not at all complicated, and neither is the resulting equations - you can probably guess them now!

Tell me you could see that coming? it's pretty obvious...

Combining Transformations
Up till this point, the use of matrices has been a little pointless - the derived equations are enough to rotate, translate and scale. you could quite easily apply each transformation individually like this:

x' = x + dx
y' = y + dy

x'' = x'Cosq - y'Sinq
y'' = x'Sinq + y'Cosq

x''' = x'' * sx
y''' = y'' * sy

the above code would translate the point, rotate it around the origin and then scale it by a given factor - not necessarily what you want (rotation before translation is more common), but you can juggle the lines around. BUT, using matrices we can combine all 3 transformations together, then split them out into two lines - generating x',y' from x,y instead of going all the way to x''',y''' - is that not better?

我們現在要制造一個平移-旋轉-縮放一起的復合矩陣。注意先旋轉再平移與先平移再旋轉是不同的。她能更適合你的程序。The way we do this is by creating a master matrix - we multiply (using matrix multiplication) the translation, rotation and scaling matrices together into one matrix, then multiply the point x,y by this master matrix. A prior note on multiplication order - as with the 6 equations just listed it matter what order they go in, rotation-translation is very different from translation-rotation (one will create an orbiting body, the other will create a spinning object). Normally you would scale the points, rotate them and then translate them - but you'll need to decide which is best for your application. here is the complete proof for the "master matrix":

[M] is the Master Matrix  '三種復合的矩陣
[S] is the scaling Matrix  '縮放矩陣
[R] is the rotation Matrix '旋轉矩陣
[T] is the translation Matrix  '平移矩陣

[M] = [S][R][T]
= ( [S]*[R] ) * [T]

[M] = [SR][T]

there we have the final "Master Matrix". How amazing, if we now multiply a point [x,y,1] by this matrix we should be left with an equation to transform x and an equation to transform y - which will result in a rotation, translation and scaling. Arguably, through substitution, you could of combined the original 3 equations, but this way is open to much more powerful calculations - there are quite a few other types of transformation that can be done using matrices, and a few shortcuts can be found along the way as well. The following illustration indicates how the final all-in-one formula works:

方程最后轉換了一個點——旋轉q角度—— 縮放(sx,sy)—— 平移(dx,dy)。驗證方程的正確性如下。So the final equation to transform the point (x,y) - rotating through q radians, scaling by (sx,sy) and translating by (dx,dy) units - is shown above. we can prove that this combined equation is actually correct by substituting in the previous set of equations - shown below.

Scale:
x' = x * sx
y' = y * sy

Rotate:
x'' = x'Cosq - y'Sinq
y'' = x'Sinq + y'Cosq

Translate:
x''' = x'' + dx
y''' = y'' + dy

Combined:
x' = ((x * sx)Cosq - (y * sy)Sinq) + dx
y' = ((x * sx)Sinq + (y * sy)Cosq) + dy

Simplified:
x' = xSxCosq - ySySinq + dx
y' = xSxSinq + ySyCosq + dy

通過這種方法直接得到了答案,我寫了一個與方程等價的簡單程序。and there, as if by magic - we've gotten the same formula back. The method you choose - by straight algebra or by matrix algebra - is your choice entirely; I personally prefer the matrix method as it allows for many 1000's of combinations; for example - scale, rotate, translate, rotate - will (given a flying saucer object) spin it around it's center and then spin it around the origin (like orbiting a planet) - you try doing that with those plain equations, it's still possible - but a little more complicated methinks. To finish things off, I've written a simple transformation function incorporating the overall equation.

Private Function Transform2DPoint(tX As Single, tY As Single, sX As Single, sY As Single, Theta As Single, SrcPt As Pt) As Pt
                                                '(tX,tY) describes the translation
                                                '(sX,sY) describes the scale
                                                'Theta describes the rotation
                                                'SrcPt is the point to be transformed
                                                '[RETURN] is the transformed point
                                                '   The general formulas:
                                                '   X' = xSxCosq - ySySinq + dx
                                                '   Y' = xSxSinq + ySyCosq + dy
                                                Dim Cosq As Single
                                                Dim Sinq As Single
                                                Cosq = Cos(Theta)
                                                Sinq = Sin(Theta)
                                                Transform2DPoint.X = (SrcPt.X * sX * Cosq) - (SrcPt.Y * sY * Sinq) + tX
                                                Transform2DPoint.Y = (SrcPt.X * sX * Sinq) + (SrcPt.Y * sY * Cosq) + tY
                                                End Function

 


3. 3D Transformations 三維轉換

我已經說了本章90%的內容了。I'm not going to say much on this topic - 90% of what was in the previous section is still relevant in this section. More importantly, however, is that Direct3D (or any other 3D API) will do matrix transformations for you - only the specialist/elite will need to play around with the transformation matrices manually.

根據你變換的需要推導出3D矩陣是非常重要的。硬件對矩陣會加速運算(1000倍于一些軟件運算)。The advantage of having D3D do the actual transformation is that all you need to do is present the overall matrix and it'll work out what needs to happen - and in some cases the hardware will actually do the mathematics on the geometry (which is going to be 10000x faster than any software implementation). As visitors to the VoodooVB message board will be aware, I actually worked this out a while back and posted a generalised matrix formula for a 3D transformation. During my tests on this it gave exactly the same results as using the built in D3DX functions, yet was 1.6-2.6x faster than them. The only trade off is actually working out the generalised matrix in the first place - this usually only ever has to be done once.

2D矩陣3D矩陣不同僅在于大小(4X4取代3X3)及2D一個旋轉軸,3D三個旋轉軸。The only two differences between the 2D matrices and the 3D matrices is their size (now 4x4 instead of 3x3) and there are 3 rotation matrices (x,y,z) - 2D rotation (on a plane) only requires you to have 1 rotation axis, 3D has 3 main rotation axis's...

5個組合矩陣如下The 5 matrices are shown below - this is for reference, given the information about 2D transformations you should quite easily be able to do some clever things with them...

- -

-

這是通用的變換矩陣Finally, As I already mentioned, I calculated the generalised matrix for this a while back - and it's shown below.

這是與變換矩陣相同的代碼Pretty isn't it! Here's the same transformation matrix but in code:

Private Function CreateMatrix(Rx As Single, Ry As Single, Rz As Single, Sx As Single, _
Sy As Single, Sz As Single, Tx As Single, Ty As Single, Tz As Single) As D3DMATRIX

Dim CosRx As Single, CosRy As Single, CosRz As Single
Dim SinRx As Single, SinRy As Single, SinRz As Single

CosRx = Cos(Rx) 'Used 6x
CosRy = Cos(Ry) 'Used 4x
CosRz = Cos(Rz) 'Used 4x
SinRx = Sin(Rx) 'Used 5x
SinRy = Sin(Ry) 'Used 5x
SinRz = Sin(Rz) 'Used 5x
'total of 29 trig functions
'23 trig functions cancelled out by
'this optimisation; hence the 2.6x speed increase.

With CreateMatrix
.m11 = (Sx * CosRy * CosRz)
.m12 = (Sx * CosRy * SinRz)
.m13 = -(Sx * SinRy)

.m21 = -(Sy * CosRx * SinRz) + (Sy * SinRx * SinRy * CosRz)
.m22 = (Sy * CosRx * CosRz) + (Sy * SinRx * SinRy * SinRz)
.m23 = (Sy * SinRx * CosRy)

.m31 = (Sz * SinRx * SinRz) + (Sz * CosRx * SinRy * CosRz)
.m32 = -(Sz * SinRx * CosRx) + (Sz * CosRx * SinRy * SinRz)
.m33 = (Sz * CosRx * CosRy)

.m41 = Tx
.m42 = Ty
.m43 = Tz
.m44 = 1#
End With
End Function

 

關于逆矩陣的定義:

V*M=V'

V=V'*M’

如果滿足上面兩個方程那么M'就是M的逆矩陣,從它的定義可看到逆矩陣可以使坐標向相反的方向變換,比如頂點由一矩陣旋轉,再經其逆矩陣就合產生反轉,函數原型:

Function D3DXMatrixInverse(MOut As D3DMATRIX, Determinant As Single, M As D3DMATRIX) As Long

 

'如何求一個矩陣(3*3)的逆陣  --作者kaiaili
'這是一個求矩陣的逆陣的簡例
'  但由于吾業不精,不知道如何利用二維數組(矩陣)作為函數的參數,并利用函數返回一個二維數組(逆陣)
'無法將它寫成函數,只好寫成一個過程來完成.
'  同時吾對遞歸也無研究,無法使它支持矩陣4*4,5*5...的逆陣轉換.
Sub main()
    Dim ci As Byte, cj As Byte, i As Byte, j As Byte, n As Byte  '循環,統計變量
    Dim a(2, 2) As Single  '矩陣數組
    Dim b(2, 2) As Single  '逆陣數組
    Dim t(3) As Single       '余子式數組
    Dim rValue As Single   '矩陣值變量
    '初始矩陣
    a(0, 0) = 1: a(0, 1) = -1: a(0, 2) = 3
    a(1, 0) = 2: a(1, 1) = -1: a(1, 2) = 4
    a(2, 0) = -1: a(2, 1) = 2: a(2, 2) = -4
    Debug.Print "原始矩陣為:  "
    For i = 0 To 2
        For j = 0 To 2
            Debug.Print a(i, j),
        Next j
        Debug.Print
    Next i
    '求伴隨陣
    For ci = 0 To 2
        For cj = 0 To 2
            '求余子式
            n = 0
            For i = 0 To 2
                For j = 0 To 2
                       If i <> ci And j <> cj Then t(n) = a(i, j): n = n + 1
                Next j
            Next i
            b(cj, ci) = ((-1) ^ (ci + cj)) * (t(0) * t(3) - t(1) * t(2))
        Next cj
    Next ci
    '求矩陣的值
    rValue = 0
    For i = 0 To 2
            rValue = rValue + a(i, 0) * b(0, i)
    Next i
    If rValue Then   '逆陣存在
     '求矩陣的逆陣
     Debug.Print "逆陣為:  "
     rValue = 1 / rValue
        For i = 0 To 2
            For j = 0 To 2
             b(i, j) = b(i, j) * rValue
                Debug.Print b(i, j),
            Next j
            Debug.Print
        Next i
    Else     '逆陣不?

posted on 2008-01-15 16:58 楊粼波 閱讀(213) 評論(0)  編輯 收藏 引用

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产一区二区日韩精品| 亚洲美女免费精品视频在线观看| 日韩午夜av电影| 亚洲精品网址在线观看| 亚洲国产高潮在线观看| 久久精品免费播放| 国内精品美女av在线播放| 免费观看一区| 欧美激情一区三区| 国产精品jizz在线观看美国 | 亚洲精品久久久久中文字幕欢迎你| 另类图片综合电影| 欧美激情一区二区三级高清视频| 老司机精品福利视频| 欧美成人中文字幕| 亚洲日本激情| 亚洲欧美另类综合偷拍| 久久久久久**毛片大全| 欧美激情女人20p| 国产欧美日韩综合| 亚洲国产精品999| 亚洲视频999| 欧美在线视频一区二区三区| 久久婷婷影院| 一区二区日韩精品| 久久综合九色| 国产精品日韩精品欧美精品| 狠狠色香婷婷久久亚洲精品| 亚洲国产小视频| 亚洲一区免费网站| 欧美国产精品v| 夜夜爽夜夜爽精品视频| 亚洲精品久久久久久久久久久久| 99精品国产在热久久下载| 先锋资源久久| 欧美激情第1页| 国产一级久久| 亚洲一区在线视频| 欧美激情在线狂野欧美精品| 亚洲欧美成人一区二区三区| 欧美精品尤物在线| 国产一区二区精品| 亚洲欧美在线视频观看| 亚洲国产日韩欧美一区二区三区| 亚洲视频专区在线| 欧美护士18xxxxhd| 亚洲区国产区| 久久久久久免费| 一本久久综合亚洲鲁鲁五月天| 久久伊人一区二区| 欧美性一区二区| 亚洲一区二区精品| 亚洲精品一区二区三区婷婷月| 久久国产日本精品| 国产一区二区三区精品欧美日韩一区二区三区| 亚洲精品中文在线| 欧美大片免费观看在线观看网站推荐| 亚洲欧美国产精品va在线观看 | 欧美高清视频免费观看| 欧美风情在线观看| 国产视频久久网| 亚洲男人的天堂在线| 欧美国产三区| 久久影院午夜论| 亚洲激情电影在线| 亚洲第一网站| 美女成人午夜| 亚洲人成7777| 免费久久99精品国产| 久久天堂成人| 亚洲精品久久久蜜桃| 亚洲国产精品黑人久久久| 欧美成人高清| 99精品视频一区二区三区| 最新国产精品拍自在线播放| 欧美大片在线观看一区二区| 亚洲精品国产精品国自产观看| 欧美成人一区二区三区| 久久久视频精品| 在线观看日韩av电影| 久久久久久九九九九| 久久亚洲电影| 中文欧美在线视频| 亚洲一区二区在线免费观看视频| 国产精品综合视频| 欧美成人精品在线视频| 欧美精品久久久久久| 亚洲制服av| 久久久噜噜噜久久中文字免| 日韩亚洲欧美中文三级| 一区二区欧美激情| 国产亚洲欧美另类一区二区三区| 老司机午夜精品视频| 欧美黄色视屏| 久久激五月天综合精品| 久久综合伊人77777| 在线午夜精品自拍| 欧美一二三区精品| 日韩午夜激情电影| 亚洲欧美激情视频| 亚洲精品国产精品国产自| 99国产精品久久久| 黑人一区二区三区四区五区| 亚洲第一精品福利| 国产精品久久| 欧美黄色影院| 国产亚洲日本欧美韩国| 欧美+日本+国产+在线a∨观看| 欧美视频免费在线| 亚洲第一在线综合在线| 欧美日韩国产一级| 男女激情视频一区| 国产乱子伦一区二区三区国色天香| 久久高清一区| 欧美性大战久久久久| 欧美成人精品一区| 国产欧美精品一区| 亚洲九九九在线观看| 亚洲国产精品久久久久婷婷884 | 精品51国产黑色丝袜高跟鞋| 亚洲自拍三区| 麻豆91精品| 久久久久久久久久看片| 欧美午夜精品久久久久久孕妇| 欧美国产精品v| 国产日韩欧美亚洲一区| 一区二区久久| 亚洲午夜精品一区二区| 久久免费国产精品| 久久精品国产免费看久久精品| 欧美色精品在线视频| 91久久线看在观草草青青| 亚洲电影第三页| 欧美一级成年大片在线观看| 午夜精品久久久久久久99黑人| 欧美日韩国产二区| 亚洲日本乱码在线观看| 99精品免费| 欧美日韩亚洲视频一区| 亚洲欧洲综合| 一区二区不卡在线视频 午夜欧美不卡'| 久久久精品网| 免费观看亚洲视频大全| 亚洲国产精品成人| 蜜桃久久精品乱码一区二区| 久久久国产精品亚洲一区| 国产嫩草影院久久久久 | 欧美一区二区啪啪| 久久精品国产清自在天天线| 国产农村妇女精品一二区| 正在播放亚洲一区| 午夜精品久久久久久久99樱桃| 国产精品成人久久久久| 性欧美8khd高清极品| 麻豆91精品| 亚洲日韩欧美视频| 欧美片第1页综合| 在线午夜精品| 性色av香蕉一区二区| 国产一区二区三区最好精华液| 久久不射网站| 最新日韩中文字幕| 亚洲欧美激情四射在线日| 国产精品人人做人人爽人人添| 亚洲免费在线观看视频| 久久精品一区二区| 亚洲精品女人| 国产精品欧美经典| 久久精品一区四区| 亚洲日韩欧美一区二区在线| 午夜精品视频一区| 亚洲国产高清自拍| 国产精品乱码一区二三区小蝌蚪 | 亚洲无毛电影| 久久综合九色九九| 亚洲美女电影在线| 国产嫩草一区二区三区在线观看| 久久综合一区二区| 亚洲欧美日本伦理| 最近中文字幕日韩精品 | 国产精品大片wwwwww| 久久精品国产久精国产思思| 亚洲激情视频网| 一区二区黄色| 日韩一区二区福利| 国产日韩欧美精品一区| 欧美成人自拍| 欧美在线观看天堂一区二区三区| 最新亚洲一区| 免费观看成人www动漫视频| 亚洲午夜国产成人av电影男同| 韩国成人理伦片免费播放| 欧美日韩亚洲一区在线观看| 久久九九热re6这里有精品| 中文欧美日韩| 日韩视频精品在线观看| 欧美成人中文| 狂野欧美性猛交xxxx巴西| 欧美一级在线播放| 亚洲影视中文字幕|