?? c2dmatrix.vb
字號:
Public Class C2DMatrix
Private Structure Matrix
Public _11, _12, _13 As Double
Public _21, _22, _23 As Double
Public _31, _32, _33 As Double
End Structure
Dim m_Matrix As Matrix
Private Sub MatrixMultiply(ByVal mIn As Matrix)
Dim mat_temp As Matrix
'//first row
mat_temp._11 = (m_Matrix._11 * mIn._11) + (m_Matrix._12 * mIn._21) + (m_Matrix._13 * mIn._31)
mat_temp._12 = (m_Matrix._11 * mIn._12) + (m_Matrix._12 * mIn._22) + (m_Matrix._13 * mIn._32)
mat_temp._13 = (m_Matrix._11 * mIn._13) + (m_Matrix._12 * mIn._23) + (m_Matrix._13 * mIn._33)
'//second
mat_temp._21 = (m_Matrix._21 * mIn._11) + (m_Matrix._22 * mIn._21) + (m_Matrix._23 * mIn._31)
mat_temp._22 = (m_Matrix._21 * mIn._12) + (m_Matrix._22 * mIn._22) + (m_Matrix._23 * mIn._32)
mat_temp._23 = (m_Matrix._21 * mIn._13) + (m_Matrix._22 * mIn._23) + (m_Matrix._23 * mIn._33)
'//third
mat_temp._31 = (m_Matrix._31 * mIn._11) + (m_Matrix._32 * mIn._21) + (m_Matrix._33 * mIn._31)
mat_temp._32 = (m_Matrix._31 * mIn._12) + (m_Matrix._32 * mIn._22) + (m_Matrix._33 * mIn._32)
mat_temp._33 = (m_Matrix._31 * mIn._13) + (m_Matrix._32 * mIn._23) + (m_Matrix._33 * mIn._33)
m_Matrix = mat_temp
End Sub
Public Sub New()
'//initialize the matrix to an identity matrix
Identity()
End Sub
'//create an identity matrix
Public Sub Identity()
m_Matrix._11 = 1
m_Matrix._12 = 0
m_Matrix._13 = 0
m_Matrix._21 = 0
m_Matrix._22 = 1
m_Matrix._23 = 0
m_Matrix._31 = 0
m_Matrix._32 = 0
m_Matrix._33 = 1
End Sub
'//create a transformation matrix
Public Sub Translate(ByVal x As Double, ByVal y As Double)
Dim mat As Matrix
mat._11 = 1
mat._12 = 0
mat._13 = 0
mat._21 = 0
mat._22 = 1
mat._23 = 0
mat._31 = x
mat._32 = y
mat._33 = 1
'//and multiply
MatrixMultiply(mat)
End Sub
'//create a scale matrix
Public Sub Scale(ByVal xScale As Double, ByVal yScale As Double)
Dim mat As Matrix
mat._11 = xScale
mat._12 = 0
mat._13 = 0
mat._21 = 0
mat._22 = yScale
mat._23 = 0
mat._31 = 0
mat._32 = 0
mat._33 = 1
'//and multiply
MatrixMultiply(mat)
End Sub
'//create a rotation matrix
Public Sub Rotate(ByVal rot As Double)
Dim mat As Matrix
Dim sin As Double = Math.Sin(rot)
Dim cos = Math.Cos(rot)
mat._11 = cos
mat._12 = sin
mat._13 = 0
mat._21 = -sin
mat._22 = cos
mat._23 = 0
mat._31 = 0
mat._32 = 0
mat._33 = 1
'//and multiply
MatrixMultiply(mat)
End Sub
'//create a rotation matrix from a fwd and side 2D vector
Public Sub Rotate(ByVal fwd As Vector2D, ByVal side As Vector2D)
Dim mat As Matrix
mat._11 = fwd.x
mat._12 = fwd.y
mat._13 = 0
mat._21 = side.x
mat._22 = side.y
mat._23 = 0
mat._31 = 0
mat._32 = 0
mat._33 = 1
' //and multiply
MatrixMultiply(mat)
End Sub
'//applys a transformation matrix to a std::vector of points
Public Sub TransformVector2Ds(ByVal vPoint As ArrayList)
Dim i As Integer
For i = 0 To vPoint.Count - 1
Dim tempX As Double = (m_Matrix._11 * CType(vPoint(i), Vector2D).x) + (m_Matrix._21 * CType(vPoint(i), Vector2D).y) + (m_Matrix._31)
Dim tempY As Double = (m_Matrix._12 * CType(vPoint(i), Vector2D).x) + (m_Matrix._22 * CType(vPoint(i), Vector2D).y) + (m_Matrix._32)
CType(vPoint(i), Vector2D).x = tempX
CType(vPoint(i), Vector2D).y = tempY
Next
End Sub
'//applys a transformation matrix to a point
Public Sub TransformVector2Ds(ByVal vPoint As Vector2D)
Dim tempX As Double = (m_Matrix._11 * vPoint.x) + (m_Matrix._21 * vPoint.y) + (m_Matrix._31)
Dim tempY As Double = (m_Matrix._12 * vPoint.x) + (m_Matrix._22 * vPoint.y) + (m_Matrix._32)
vPoint.x = tempX
vPoint.y = tempY
End Sub
'//accessors to the matrix elements
Public Sub _11(ByVal val As Double)
m_Matrix._11 = val
End Sub
Public Sub _12(ByVal val As Double)
m_Matrix._12 = val
End Sub
Public Sub _13(ByVal val As Double)
m_Matrix._13 = val
End Sub
Public Sub _21(ByVal val As Double)
m_Matrix._21 = val
End Sub
Public Sub _22(ByVal val As Double)
m_Matrix._22 = val
End Sub
Public Sub _23(ByVal val As Double)
m_Matrix._23 = val
End Sub
Public Sub _31(ByVal val As Double)
m_Matrix._31 = val
End Sub
Public Sub _32(ByVal val As Double)
m_Matrix._32 = val
End Sub
Public Sub _33(ByVal val As Double)
m_Matrix._33 = val
End Sub
End Class
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -