|
@@ -5,12 +5,16 @@ Namespace std.geom
|
|
#end
|
|
#end
|
|
Alias AffineMat3f:AffineMat3<Float>
|
|
Alias AffineMat3f:AffineMat3<Float>
|
|
|
|
|
|
-#rem monkeydoc Affine 3x3 matrix class.
|
|
|
|
|
|
+#rem monkeydoc The generic AffineMat3f class provides support for affine 3x3 matrices.
|
|
|
|
|
|
An affine 3x3 matrix is a 3x3 matrix whose right hand column is always 0,0,1.
|
|
An affine 3x3 matrix is a 3x3 matrix whose right hand column is always 0,0,1.
|
|
|
|
|
|
Affine 3x3 matrices are often used for 2d transformations such as scaling, rotation and translation.
|
|
Affine 3x3 matrices are often used for 2d transformations such as scaling, rotation and translation.
|
|
|
|
|
|
|
|
+Unless otherwise noted, methods and operators always return a new vec3 containing the result, without modifying any parameters or 'self'.
|
|
|
|
+
|
|
|
|
+This allows you to chain operators together easily just like 'real' expressions.
|
|
|
|
+
|
|
#end
|
|
#end
|
|
Struct AffineMat3<T>
|
|
Struct AffineMat3<T>
|
|
|
|
|
|
@@ -40,7 +44,7 @@ Struct AffineMat3<T>
|
|
Self.i.x=ix;Self.i.y=iy;Self.j.x=jx;Self.j.y=jy;Self.t.x=tx;Self.t.y=ty
|
|
Self.i.x=ix;Self.i.y=iy;Self.j.x=jx;Self.j.y=jy;Self.t.x=tx;Self.t.y=ty
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Converts the matrix to a matrix of a different type.
|
|
|
|
|
|
+ #rem monkeydoc Converts the matrix to a matrix of a different type, or a printable string.
|
|
#end
|
|
#end
|
|
Operator To<C>:AffineMat3<C>()
|
|
Operator To<C>:AffineMat3<C>()
|
|
Return New AffineMat3<C>( i.x,i.y,j.x,j.y,t.x,t.y )
|
|
Return New AffineMat3<C>( i.x,i.y,j.x,j.y,t.x,t.y )
|
|
@@ -52,7 +56,7 @@ Struct AffineMat3<T>
|
|
Return "AffineMat3("+i.x+","+i.y+","+j.x+","+j.y+","+t.x+","+t.y+")"
|
|
Return "AffineMat3("+i.x+","+i.y+","+j.x+","+j.y+","+t.x+","+t.y+")"
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Returns the inverse of the matrix.
|
|
|
|
|
|
+ #rem monkeydoc Inverts the matrix.
|
|
#end
|
|
#end
|
|
Operator-:AffineMat3()
|
|
Operator-:AffineMat3()
|
|
Local idet:=1.0/(i.x*j.y-i.y*j.x)
|
|
Local idet:=1.0/(i.x*j.y-i.y*j.x)
|
|
@@ -62,13 +66,13 @@ Struct AffineMat3<T>
|
|
(j.x*t.y-j.y*t.x)*idet , (i.y*t.x-i.x*t.y)*idet )
|
|
(j.x*t.y-j.y*t.x)*idet , (i.y*t.x-i.x*t.y)*idet )
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Multiplies a vector by the matrix and returns the result.
|
|
|
|
|
|
+ #rem monkeydoc Multiplies a vector by the matrix.
|
|
#end
|
|
#end
|
|
Operator*:Vec2<T>( v:Vec2<T> )
|
|
Operator*:Vec2<T>( v:Vec2<T> )
|
|
Return New Vec2<T>( i.x*v.x + j.x*v.y + t.x , i.y*v.x + j.y*v.y + t.y )
|
|
Return New Vec2<T>( i.x*v.x + j.x*v.y + t.x , i.y*v.x + j.y*v.y + t.y )
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Multiplies the matrix by another matrix and returns the result.
|
|
|
|
|
|
+ #rem monkeydoc Multiplies the matrix by another matrix.
|
|
#end
|
|
#end
|
|
Operator*:AffineMat3( m:AffineMat3 )
|
|
Operator*:AffineMat3( m:AffineMat3 )
|
|
Return New AffineMat3(
|
|
Return New AffineMat3(
|
|
@@ -77,19 +81,19 @@ Struct AffineMat3<T>
|
|
i.x*m.t.x + j.x*m.t.y + t.x , i.y*m.t.x + j.y*m.t.y + t.y )
|
|
i.x*m.t.x + j.x*m.t.y + t.x , i.y*m.t.x + j.y*m.t.y + t.y )
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Multiplies a vector by the matrix and returns the result.
|
|
|
|
|
|
+ #rem monkeydoc Multiplies a vector by the matrix.
|
|
#end
|
|
#end
|
|
Method Transform:Vec2<T>( v:Vec2<T> )
|
|
Method Transform:Vec2<T>( v:Vec2<T> )
|
|
Return New Vec2<T>( i.x*v.x + j.x*v.y + t.x , i.y*v.x + j.y*v.y + t.y )
|
|
Return New Vec2<T>( i.x*v.x + j.x*v.y + t.x , i.y*v.x + j.y*v.y + t.y )
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Multiplies a vector by the matrix and returns the result.
|
|
|
|
|
|
+ #rem monkeydoc Multiplies a vector by the matrix.
|
|
#end
|
|
#end
|
|
Method Transform:Vec2<T>( x:T,y:T )
|
|
Method Transform:Vec2<T>( x:T,y:T )
|
|
Return New Vec2<T>( i.x*x + j.x*y + t.x , i.y*x + j.y*y + t.y )
|
|
Return New Vec2<T>( i.x*x + j.x*y + t.x , i.y*x + j.y*y + t.y )
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Multiplies the matrix by another matrix and returns the result.
|
|
|
|
|
|
+ #rem monkeydoc Multiplies the matrix by another matrix.
|
|
#end
|
|
#end
|
|
Method Transform:AffineMat3( ix:Float,iy:Float,jx:Float,jy:Float,tx:Float,ty:Float )
|
|
Method Transform:AffineMat3( ix:Float,iy:Float,jx:Float,jy:Float,tx:Float,ty:Float )
|
|
Return New AffineMat3(
|
|
Return New AffineMat3(
|
|
@@ -98,7 +102,7 @@ Struct AffineMat3<T>
|
|
i.x*tx + j.x*ty + t.x , i.y*tx + j.y*ty + t.y )
|
|
i.x*tx + j.x*ty + t.x , i.y*tx + j.y*ty + t.y )
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Applies a translation transformation to the matrix and returns the result.
|
|
|
|
|
|
+ #rem monkeydoc Applies a translation transformation to the matrix.
|
|
#end
|
|
#end
|
|
Method Translate:AffineMat3( tx:T,ty:T )
|
|
Method Translate:AffineMat3( tx:T,ty:T )
|
|
Return Transform( 1,0,0,1,tx,ty )
|
|
Return Transform( 1,0,0,1,tx,ty )
|
|
@@ -108,13 +112,13 @@ Struct AffineMat3<T>
|
|
Return Transform( 1,0,0,1,tv.x,tv.y )
|
|
Return Transform( 1,0,0,1,tv.x,tv.y )
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Applies a rotation transformation to the matrix and returns the result.
|
|
|
|
|
|
+ #rem monkeydoc Applies a rotation transformation to the matrix.
|
|
#end
|
|
#end
|
|
Method Rotate:AffineMat3( rz:Double )
|
|
Method Rotate:AffineMat3( rz:Double )
|
|
Return Transform( Cos( rz ),-Sin( rz ),Sin( rz ),Cos( rz ),0,0 )
|
|
Return Transform( Cos( rz ),-Sin( rz ),Sin( rz ),Cos( rz ),0,0 )
|
|
End
|
|
End
|
|
|
|
|
|
- #rem monkeydoc Applies a scale transformation to the matrix and returns the result.
|
|
|
|
|
|
+ #rem monkeydoc Applies a scale transformation to the matrix.
|
|
#end
|
|
#end
|
|
Method Scale:AffineMat3( sx:T,sy:T )
|
|
Method Scale:AffineMat3( sx:T,sy:T )
|
|
Return Transform( sx,0,0,sy,0,0 )
|
|
Return Transform( sx,0,0,sy,0,0 )
|
|
@@ -124,6 +128,8 @@ Struct AffineMat3<T>
|
|
Return Transform( sv.x,0,0,sv.y,0,0 )
|
|
Return Transform( sv.x,0,0,sv.y,0,0 )
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ #rem monkeydoc Creates a matrix representing a translation.
|
|
|
|
+ #end
|
|
Function Translation:AffineMat3( tx:T,ty:T )
|
|
Function Translation:AffineMat3( tx:T,ty:T )
|
|
Return New AffineMat3( 1,0,0,1,tx,ty )
|
|
Return New AffineMat3( 1,0,0,1,tx,ty )
|
|
End
|
|
End
|
|
@@ -132,10 +138,17 @@ Struct AffineMat3<T>
|
|
Return New AffineMat3( 1,0,0,1,tv.x,tv.y )
|
|
Return New AffineMat3( 1,0,0,1,tv.x,tv.y )
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ #rem monkeydoc Creates a matrix representing a rotation.
|
|
|
|
+
|
|
|
|
+ The `rotation` parameter is in radians.
|
|
|
|
+
|
|
|
|
+ #end
|
|
Function Rotation:AffineMat3( rz:Double )
|
|
Function Rotation:AffineMat3( rz:Double )
|
|
Return New AffineMat3( Cos( rz ),-Sin( rz ),Sin( rz ),Cos( rz ),0,0 )
|
|
Return New AffineMat3( Cos( rz ),-Sin( rz ),Sin( rz ),Cos( rz ),0,0 )
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ #rem monkeydoc Creates a matrix representing a scaling.
|
|
|
|
+ #end
|
|
Function Scaling:AffineMat3( sx:T,sy:T )
|
|
Function Scaling:AffineMat3( sx:T,sy:T )
|
|
Return New AffineMat3( sx,0,0,sy,0,0 )
|
|
Return New AffineMat3( sx,0,0,sy,0,0 )
|
|
End
|
|
End
|
|
@@ -144,6 +157,8 @@ Struct AffineMat3<T>
|
|
Return New AffineMat3( sv.x,0,0,sv.y,0,0 )
|
|
Return New AffineMat3( sv.x,0,0,sv.y,0,0 )
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ #rem monkeydoc Creates a matrix representing an orthographic projection.
|
|
|
|
+ #end
|
|
Function Ortho:AffineMat3( left:T,right:T,bottom:T,top:T )
|
|
Function Ortho:AffineMat3( left:T,right:T,bottom:T,top:T )
|
|
|
|
|
|
Local w:=right-left,h:=top-bottom
|
|
Local w:=right-left,h:=top-bottom
|