Mark Sibly 8 năm trước cách đây
mục cha
commit
22ba469369

+ 26 - 12
modules/std/geom/affinemat4.monkey2

@@ -1,11 +1,11 @@
 
 
 Namespace std.geom
 Namespace std.geom
 
 
-#rem monkeydoc @hidden Convenience type alias for AffineMat4\<Float\>
+#rem monkeydoc Convenience type alias for AffineMat4\<Float\>
 #end
 #end
 Alias AffineMat4f:AffineMat4<Float>
 Alias AffineMat4f:AffineMat4<Float>
 
 
-#rem monkeydoc @hidden Affine 4x4 matrix class.
+#rem monkeydoc Affine 4x4 matrix class.
 
 
 An affine 4x4 matrix is a 4x4 matrix whose right hand column is always 0,0,0,1.
 An affine 4x4 matrix is a 4x4 matrix whose right hand column is always 0,0,0,1.
 
 
@@ -21,10 +21,6 @@ Struct AffineMat4<T>
 		m.i.x=1; m.j.y=1; m.k.z=1
 		m.i.x=1; m.j.y=1; m.k.z=1
 	End
 	End
 	
 	
-	Method New( m:Mat3<T>,t:Vec3<T> )
-		Self.m=m; Self.t=t
-	End
-	
 	Method New( m:Mat3<T> )
 	Method New( m:Mat3<T> )
 		Self.m=m
 		Self.m=m
 	End
 	End
@@ -33,6 +29,10 @@ Struct AffineMat4<T>
 		m.i.x=1; m.j.y=1; m.k.z=1 ; Self.t=t
 		m.i.x=1; m.j.y=1; m.k.z=1 ; Self.t=t
 	End
 	End
 	
 	
+	Method New( m:Mat3<T>,t:Vec3<T> )
+		Self.m=m; Self.t=t
+	End
+	
 	Method New( i:Vec3<T>,j:Vec3<T>,k:Vec3<T>,t:Vec3<T> )
 	Method New( i:Vec3<T>,j:Vec3<T>,k:Vec3<T>,t:Vec3<T> )
 		m.i=i; m.j=j; m.k=k; Self.t=t
 		m.i=i; m.j=j; m.k=k; Self.t=t
 	End
 	End
@@ -44,11 +44,25 @@ Struct AffineMat4<T>
 		t.x=vx; t.y=vy; t.z=vz
 		t.x=vx; t.y=vy; t.z=vz
 	End
 	End
 	
 	
+	Method new( m:AffineMat3<T> )
+		Self.m.i=New Vec3<T>( m.i,0 )
+		Self.m.j=New Vec3<T>( m.j,0 )
+		Self.m.k=New Vec3<T>( 0,0,1 )
+		Self.t=  New Vec3<T>( m.t,1 )
+	End
+	
+	Method New( m:Mat4<T> )
+		Self.m.i=m.i.XYZ
+		Self.m.j=m.j.XYZ
+		Self.m.k=m.k.XYZ
+		Self.t=m.t.XYZ
+	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.
 	#end
 	#end
 	Operator To<C>:AffineMat4<C>()
 	Operator To<C>:AffineMat4<C>()
 		Return New AffineMat4<C>( m,t )
 		Return New AffineMat4<C>( m,t )
-	End 
+	End
 	
 	
 	#rem monkeydoc Converts the matrix to a printable string.
 	#rem monkeydoc Converts the matrix to a printable string.
 	#end
 	#end
@@ -105,8 +119,8 @@ Struct AffineMat4<T>
 		Return Self * Rotation( rv )
 		Return Self * Rotation( rv )
 	End
 	End
 	
 	
-	Method Rotate:AffineMat4( quat:Quat<T> )
-		Return Self * Rotation( quat )
+	Method Rotate:AffineMat4( q:Quat<T> )
+		Return Self * Rotation( q )
 	End
 	End
 	
 	
 	#rem monkeydoc Applies a scaling transformation to the matrix and returns the result.
 	#rem monkeydoc Applies a scaling transformation to the matrix and returns the result.
@@ -133,7 +147,7 @@ Struct AffineMat4<T>
 		Return New AffineMat4( New Vec3<T>( tx,ty,tz ) )
 		Return New AffineMat4( New Vec3<T>( tx,ty,tz ) )
 	End
 	End
 
 
-	#rem monkeydoc Creates a rotation matrix from euler angles or a quaternion.
+	#rem monkeydoc Creates a rotation matrix from euler angles.
 	
 	
 	Order of rotation is Yaw * Pitch * Roll.
 	Order of rotation is Yaw * Pitch * Roll.
 	
 	
@@ -146,8 +160,8 @@ Struct AffineMat4<T>
 		Return New AffineMat4( Mat3<T>.Rotation( rx,ry,rz ) )
 		Return New AffineMat4( Mat3<T>.Rotation( rx,ry,rz ) )
 	End
 	End
 	
 	
-	Function Rotation:AffineMat4( quat:Quat<T> )
-		Return New AffineMat4( Mat3<T>.Rotation( quat ) )
+	Function Rotation:AffineMat4( q:Quat<T> )
+		Return New AffineMat4( q )
 	End
 	End
 	
 	
 	#rem monkeydoc Creates a scaling matrix.
 	#rem monkeydoc Creates a scaling matrix.

+ 39 - 66
modules/std/geom/mat3.monkey2

@@ -1,11 +1,12 @@
 
 
 Namespace std.geom
 Namespace std.geom
 
 
-#rem monkeydoc @hidden
+#rem monkeydoc Convenience type alias for Mat3\<Float\>.
 #end
 #end
 Alias Mat3f:Mat3<Float>
 Alias Mat3f:Mat3<Float>
 
 
-#rem monkeydoc @hidden
+#rem monkeydoc The Mat3 class provides support for 3x3 matrices.
+
 #end
 #end
 Struct Mat3<T>
 Struct Mat3<T>
 
 
@@ -21,16 +22,16 @@ Struct Mat3<T>
 		i.x=ix; j.y=jy; k.z=kz
 		i.x=ix; j.y=jy; k.z=kz
 	End
 	End
 	
 	
-	Method New( i:Vec3<T>,j:Vec3<T>,k:Vec3<T> )
-		Self.i=i; Self.j=j; Self.k=k
-	End
-	
 	Method New( ix:T,iy:T,iz:T,jx:T,jy:T,jz:T,kx:T,ky:T,kz:T )
 	Method New( ix:T,iy:T,iz:T,jx:T,jy:T,jz:T,kx:T,ky:T,kz:T )
 		i.x=ix; i.y=iy; i.z=iz
 		i.x=ix; i.y=iy; i.z=iz
 		j.x=jx; j.y=jy; j.z=jz
 		j.x=jx; j.y=jy; j.z=jz
 		k.x=kx; k.y=ky; k.z=kz
 		k.x=kx; k.y=ky; k.z=kz
 	End
 	End
 
 
+	Method New( i:Vec3<T>,j:Vec3<T>,k:Vec3<T> )
+		Self.i=i; Self.j=j; Self.k=k
+	End
+	
 	Method New( quat:Quat<T> )
 	Method New( quat:Quat<T> )
 		Local xx:=quat.v.x*quat.v.x , yy:=quat.v.y*quat.v.y , zz:=quat.v.z*quat.v.z
 		Local xx:=quat.v.x*quat.v.x , yy:=quat.v.y*quat.v.y , zz:=quat.v.z*quat.v.z
 		Local xy:=quat.v.x*quat.v.y , xz:=quat.v.x*quat.v.z , yz:=quat.v.y*quat.v.z
 		Local xy:=quat.v.x*quat.v.y , xz:=quat.v.x*quat.v.z , yz:=quat.v.y*quat.v.z
@@ -44,6 +45,10 @@ Struct Mat3<T>
 		Return New Mat3<C>( i,j,k )
 		Return New Mat3<C>( i,j,k )
 	End
 	End
 	
 	
+	Operator To:Quat<T>()
+		Return New Quat<T>( Self )
+	End
+	
 	Operator To:String()
 	Operator To:String()
 		Return "Mat3("+i+","+j+","+k+")"
 		Return "Mat3("+i+","+j+","+k+")"
 	End
 	End
@@ -110,38 +115,6 @@ Struct Mat3<T>
 		Return New Vec3<T>( GetPitch(),GetYaw(),GetRoll() )
 		Return New Vec3<T>( GetPitch(),GetYaw(),GetRoll() )
 	End
 	End
 	
 	
-	Method GetQuat:Quat<T>()
-		Local r:Quat<T>
-		Local m:=Orthogonalize()
-		Local t:=m.i.x+m.j.y+m.k.z
-		If t>EPSILON
-			t=Sqrt( t+1 )*2
-			r.v.x=(m.k.y-m.j.z)/t
-			r.v.y=(m.i.z-m.k.x)/t
-			r.v.z=(m.j.x-m.i.y)/t
-			r.w=t/4
-		Else If m.i.x>m.j.y And m.i.x>m.k.z
-			t=Sqrt( m.i.x-m.j.y-m.k.z+1 )*2
-			r.v.x=t/4
-			r.v.y=(m.j.x+m.i.y)/t
-			r.v.z=(m.i.z+m.k.x)/t
-			r.w=(m.k.y-m.j.z)/t
-		Else If m.j.y>m.k.z
-			t=Sqrt( m.j.y-m.k.z-m.i.x+1 )*2
-			r.v.x=(m.j.x+m.i.y)/t
-			r.v.y=t/4
-			r.v.z=(m.k.y+m.j.z)/t
-			r.w=(m.i.z-m.k.x)/t
-		Else
-			t=Sqrt( m.k.z-m.j.y-m.i.x+1 )*2
-			r.v.x=(m.i.z+m.k.x)/t
-			r.v.y=(m.k.y+m.j.z)/t
-			r.v.z=t/4
-			r.w=(m.j.x-m.i.y)/t
-		Endif
-		Return r
-	End
-	
 	Method GetScaling:Vec3<T>()
 	Method GetScaling:Vec3<T>()
 		Return New Vec3<T>( i.Length,j.Length,k.Length )
 		Return New Vec3<T>( i.Length,j.Length,k.Length )
 	End
 	End
@@ -154,8 +127,8 @@ Struct Mat3<T>
 		Return Self * Rotation( rx,ry,rz )
 		Return Self * Rotation( rx,ry,rz )
 	End
 	End
 	
 	
-	Method Rotate:Mat3( quat:Quat<T> )
-		Return Self * Rotation( quat )
+	Method Rotate:Mat3( q:Quat<T> )
+		Return Self * Rotation( q )
 	End
 	End
 	
 	
 	Method Scale:Mat3( rv:Vec3<T> )
 	Method Scale:Mat3( rv:Vec3<T> )
@@ -175,28 +148,40 @@ Struct Mat3<T>
 		Return New Mat3( j.Cross( k ).Normalize(),k.Cross( i ).Normalize(),k )
 		Return New Mat3( j.Cross( k ).Normalize(),k.Cross( i ).Normalize(),k )
 	End
 	End
 	
 	
-	#rem monkeydoc Creates a rotation matrix from euler angles.
+	#rem monkeydoc Creates a yaw rotation matrix.
+	
+	Returns a matrix representing a rotation around the Y axis of `angle` radians.
+	
 	#end
 	#end
-	Function Yaw:Mat3( an:Double )
-		Local sin:=Sin(an),cos:=Cos(an)
+	Function Yaw:Mat3( angle:Double )
+		Local sin:=Sin(angle),cos:=Cos(angle)
 		Return New Mat3( cos,0,sin, 0,1,0, -sin,0,cos )
 		Return New Mat3( cos,0,sin, 0,1,0, -sin,0,cos )
 	End
 	End
 	
 	
-	#rem monkeydoc Creates a rotation matrix from euler angles.
+	#rem monkeydoc Creates a pitch rotation matrix.
+	
+	Returns a matrix representing a rotation around the X axis of `angle` radians.
+	
 	#end
 	#end
-	Function Pitch:Mat3( an:Double )
-		Local sin:=Sin(an),cos:=Cos(an)
+	Function Pitch:Mat3( angle:Double )
+		Local sin:=Sin(angle),cos:=Cos(angle)
 		return New Mat3( 1,0,0, 0,cos,sin, 0,-sin,cos )
 		return New Mat3( 1,0,0, 0,cos,sin, 0,-sin,cos )
 	End
 	End
 	
 	
-	#rem monkeydoc Creates a rotation matrix from euler angles.
+	#rem monkeydoc Creates a yaw rotation matrix.
+	
+	Returns a matrix representing a rotation around the Y axis of `an` radians.
+	
 	#end
 	#end
-	Function Roll:Mat3( an:Double )
-		Local sin:=Sin(an),cos:=Cos(an)
+	Function Roll:Mat3( angle:Double )
+		Local sin:=Sin(angle),cos:=Cos(angle)
 		Return New Mat3( cos,sin,0, -sin,cos,0, 0,0,1 )
 		Return New Mat3( cos,sin,0, -sin,cos,0, 0,0,1 )
 	End
 	End
 	
 	
-	#rem monkeydoc Creates a rotation matrix from euler angles or a quaternion.
+	#rem monkeydoc Creates a rotation matrix from euler angles or a quat.
+	
+	For euler angles, the order of rotation is Yaw * Pitch * Roll.
+	
 	#end
 	#end
 	Function Rotation:Mat3( rv:Vec3<Double> )
 	Function Rotation:Mat3( rv:Vec3<Double> )
 		Return Yaw( rv.y ) * Pitch( rv.x ) * Roll( rv.z )
 		Return Yaw( rv.y ) * Pitch( rv.x ) * Roll( rv.z )
@@ -205,23 +190,11 @@ Struct Mat3<T>
 	Function Rotation:Mat3( rx:Double,ry:Double,rz:Double )
 	Function Rotation:Mat3( rx:Double,ry:Double,rz:Double )
 		Return Yaw( ry ) * Pitch( rx ) * Roll( rz )
 		Return Yaw( ry ) * Pitch( rx ) * Roll( rz )
 	End
 	End
-
-	Function Rotation:Mat3( quat:Quat<T> )
-		Local r:Mat3
-		Local xx:=quat.v.x*quat.v.x , yy:=quat.v.y*quat.v.y , zz:=quat.v.z*quat.v.z
-		Local xy:=quat.v.x*quat.v.y , xz:=quat.v.x*quat.v.z , yz:=quat.v.y*quat.v.z
-		Local wx:=quat.w*quat.v.x   , wy:=quat.w*quat.v.y   , wz:=quat.w*quat.v.z
-		r.i.x=1-2*(yy+zz) ; r.i.y=  2*(xy-wz) ; r.i.z=  2*(xz+wy)
-		r.j.x=  2*(xy+wz) ; r.j.y=1-2*(xx+zz) ; r.j.z=  2*(yz-wx)
-		r.k.x=  2*(xz-wy) ; r.k.y=  2*(yz+wx) ; r.k.z=1-2*(xx+yy)
-		Return r
-	End
-	
-	#rem monkeydoc Creates a rotation matrix from euler angles.
-	
-	Order of rotation is Yaw * Pitch * Roll.
 	
 	
-	#end
+	Function Rotation:Mat3( q:Quat<T> )
+		Return New Mat3( q )
+	End
+
 	#rem monkeydoc Creates a scaling matrix.
 	#rem monkeydoc Creates a scaling matrix.
 	#end
 	#end
 	Function Scaling:Mat3( sv:Vec3<T> )
 	Function Scaling:Mat3( sv:Vec3<T> )

+ 4 - 14
modules/std/geom/mat4.monkey2

@@ -1,12 +1,10 @@
 
 
 Namespace std.geom
 Namespace std.geom
 
 
-#rem monkeydoc @hidden
+#rem monkeydoc Convenience type alias for Mat4\<Float\>.
 #end
 #end
 Alias Mat4f:Mat4<Float>
 Alias Mat4f:Mat4<Float>
 
 
-#rem monkeydoc @hidden
-#end
 Struct Mat4<T>
 Struct Mat4<T>
 
 
 	Field i:Vec4<T>
 	Field i:Vec4<T>
@@ -42,14 +40,6 @@ Struct Mat4<T>
 		Return New Mat4<C>( i,j,k,t )
 		Return New Mat4<C>( i,j,k,t )
 	End
 	End
 	
 	
-	Operator To:Mat3<T>()
-		Return New Mat3<T>( Cast<Vec3<T>>( i ),Cast<Vec3<T>>( j ),Cast<Vec3<T>>( k ) )
-	End
-	
-	Operator To:AffineMat4<T>()
-		Return New AffineMat4<T>( Cast<Mat3<T>>( Self ),Cast<Vec3<T>>( t ) )
-	End
-		
 	Operator To:String()
 	Operator To:String()
 		Return "Mat4("+i+","+j+","+k+","+t+")"
 		Return "Mat4("+i+","+j+","+k+","+t+")"
 	End
 	End
@@ -196,7 +186,7 @@ Struct Mat4<T>
 		Return r
 		Return r
 	End
 	End
 
 
-	#rem monkeydoc Creates a rotation matrix for euler angles or a quaternion.
+	#rem monkeydoc Creates a rotation matrix for euler angles or a quat.
 	#end
 	#end
 	Function Rotation:Mat4( rv:Vec3<Double> )
 	Function Rotation:Mat4( rv:Vec3<Double> )
 		Return Rotation( rv.x,rv.y,rv.z )
 		Return Rotation( rv.x,rv.y,rv.z )
@@ -206,8 +196,8 @@ Struct Mat4<T>
 		Return New Mat4( Mat3<T>.Rotation( rx,ry,rz ) )
 		Return New Mat4( Mat3<T>.Rotation( rx,ry,rz ) )
 	End
 	End
 	
 	
-	Function Rotation:Mat4( quat:Quat<T> )
-		Return New Mat4( Mat3<T>.Rotation( quat ) )
+	Function Rotation:Mat4( q:Quat<T> )
+		Return New Mat4( q )
 	End
 	End
 	
 	
 	#rem monkeydoc Creates a scaling matrix.
 	#rem monkeydoc Creates a scaling matrix.

+ 45 - 6
modules/std/geom/quat.monkey2

@@ -1,15 +1,11 @@
 
 
 Namespace std.geom
 Namespace std.geom
 
 
-#rem monkeydoc @hidden
-#end
-Const EPSILON:=0
-
-#rem monkeydoc @hidden
+#rem monkeydoc Convenience type alias for Quat\<Float\>.
 #end
 #end
 Alias Quatf:Quat<Float>
 Alias Quatf:Quat<Float>
 
 
-#rem monkeydoc @hidden
+#rem monkeydoc The Quat class provides support for quaternions.
 #end
 #end
 Class Quat<T>
 Class Quat<T>
 
 
@@ -28,10 +24,50 @@ Class Quat<T>
 		v.x=vx ; v.y=vy ; v.z=vz ; Self.w=w
 		v.x=vx ; v.y=vy ; v.z=vz ; Self.w=w
 	End
 	End
 	
 	
+	Method New( m:Mat3<T> )
+	
+		'Note: assumes m is orthogonalized
+		'
+		Const EPSILON:=0
+	
+		Local t:=m.i.x+m.j.y+m.k.z
+		
+		If t>EPSILON
+			t=Sqrt( t+1 )*2
+			v.x=(m.k.y-m.j.z)/t
+			v.y=(m.i.z-m.k.x)/t
+			v.z=(m.j.x-m.i.y)/t
+			w=t/4
+		Else If m.i.x>m.j.y And m.i.x>m.k.z
+			t=Sqrt( m.i.x-m.j.y-m.k.z+1 )*2
+			v.x=t/4
+			v.y=(m.j.x+m.i.y)/t
+			v.z=(m.i.z+m.k.x)/t
+			w=(m.k.y-m.j.z)/t
+		Else If m.j.y>m.k.z
+			t=Sqrt( m.j.y-m.k.z-m.i.x+1 )*2
+			v.x=(m.j.x+m.i.y)/t
+			v.y=t/4
+			v.z=(m.k.y+m.j.z)/t
+			w=(m.i.z-m.k.x)/t
+		Else
+			t=Sqrt( m.k.z-m.j.y-m.i.x+1 )*2
+			v.x=(m.i.z+m.k.x)/t
+			v.y=(m.k.y+m.j.z)/t
+			v.z=t/4
+			w=(m.j.x-m.i.y)/t
+		Endif
+		
+	End
+	
 	Operator To<C>:Quat<C>()
 	Operator To<C>:Quat<C>()
 		Return New Quat<C>( v,w )
 		Return New Quat<C>( v,w )
 	End
 	End
 	
 	
+	Operator To:Mat3<T>()
+		Return New Mat3<T>( Self )
+	End
+	
 	Method To:String()
 	Method To:String()
 		Return "Quat("+v+","+w+")"
 		Return "Quat("+v+","+w+")"
 	End
 	End
@@ -110,6 +146,9 @@ Class Quat<T>
 	End
 	End
 	
 	
 	Method Slerp:Quat( q:Quat,a:Double )
 	Method Slerp:Quat( q:Quat,a:Double )
+	
+		Const EPSILON:=0
+	
 		Local t:=q
 		Local t:=q
 		Local b:=1-a
 		Local b:=1-a
 		Local d:=Dot( q )
 		Local d:=Dot( q )

+ 24 - 27
modules/std/geom/vec2.monkey2

@@ -9,7 +9,12 @@ Alias Vec2i:Vec2<Int>
 #end
 #end
 Alias Vec2f:Vec2<Float>
 Alias Vec2f:Vec2<Float>
 
 
-#rem monkeydoc The Vec2 type provides support for 2 component vectors.
+#rem monkeydoc The generic Vec2 type provides support for 2 component vectors.
+
+Unless otherwise noted, methods and operators always return a new vec2 containing the result, without modifying any parameters or 'self'.
+
+This allows you to chain operators together easily just like 'real' expressions.
+
 #end
 #end
 Struct Vec2<T>
 Struct Vec2<T>
 
 
@@ -34,14 +39,12 @@ Struct Vec2<T>
 		Self.x=x;Self.y=y
 		Self.x=x;Self.y=y
 	End
 	End
 	
 	
-	#rem monkeydoc Converts the vector to a vector of a different type.
+	#rem monkeydoc Converts the vector to a vector of a different type or a printable string.
 	#end
 	#end
 	Operator To<C>:Vec2<C>()
 	Operator To<C>:Vec2<C>()
 		Return New Vec2<C>( x,y )
 		Return New Vec2<C>( x,y )
 	End
 	End
 
 
-	#rem monkeydoc Converts the vector to a printable string.
-	#end
 	Operator To:String()
 	Operator To:String()
 		Return "Vec2("+x+","+y+")"
 		Return "Vec2("+x+","+y+")"
 	End
 	End
@@ -62,55 +65,55 @@ Struct Vec2<T>
 		Self.y=y
 		Self.y=y
 	End
 	End
 	
 	
-	#rem monkeydoc Negates the vector components and returns the result.
+	#rem monkeydoc Negates the vector.
 	#end
 	#end
 	Operator-:Vec2()
 	Operator-:Vec2()
 		Return New Vec2( -x,-y )
 		Return New Vec2( -x,-y )
 	End
 	End
 	
 	
-	#rem monkeydoc Multiplies the vector by another vector and returns the result.
+	#rem monkeydoc Multiplies the vector by another vector.
 	#end
 	#end
 	Operator*:Vec2( v:Vec2 )
 	Operator*:Vec2( v:Vec2 )
 		Return New Vec2( x*v.x,y*v.y )
 		Return New Vec2( x*v.x,y*v.y )
 	End
 	End
 
 
-	#rem monkeydoc Divides the vector by another vector and returns the result.
+	#rem monkeydoc Divides the vector by another vector.
 	#end	
 	#end	
 	Operator/:Vec2( v:Vec2 )
 	Operator/:Vec2( v:Vec2 )
 		Return New Vec2( x/v.x,y/v.y )
 		Return New Vec2( x/v.x,y/v.y )
 	End
 	End
 
 
-	#rem monkeydoc Adds another vector to the vector and returns the result.
+	#rem monkeydoc Adds another vector to the vector.
 	#end	
 	#end	
 	Operator+:Vec2( v:Vec2 )
 	Operator+:Vec2( v:Vec2 )
 		Return New Vec2( x+v.x,y+v.y )
 		Return New Vec2( x+v.x,y+v.y )
 	End
 	End
 	
 	
-	#rem monkeydoc Subtracts another vector from the vector and returns the result.
+	#rem monkeydoc Subtracts another vector from the vector.
 	#end
 	#end
 	Operator-:Vec2( v:Vec2 )
 	Operator-:Vec2( v:Vec2 )
 		Return New Vec2( x-v.x,y-v.y )
 		Return New Vec2( x-v.x,y-v.y )
 	End
 	End
 	
 	
-	#rem monkeydoc Scales the vector by a value and returns the result.
+	#rem monkeydoc Multiplies the vector by a scalar.
 	#end
 	#end
 	Operator*:Vec2( s:Double )
 	Operator*:Vec2( s:Double )
 		Return New Vec2( x*s,y*s )
 		Return New Vec2( x*s,y*s )
 	End
 	End
 	
 	
-	#rem monkeydoc Inverse scales the vector by a value and returns the result.
+	#rem monkeydoc Divides the vector by a scalar.
 	#end
 	#end
 	Operator/:Vec2( s:Double )
 	Operator/:Vec2( s:Double )
 		Return New Vec2( x/s,y/s )
 		Return New Vec2( x/s,y/s )
 	End
 	End
 	
 	
-	#rem monkeydoc Adds a value to the vector components and returns the result.
+	#rem monkeydoc Adds a scalar to the vector.
 	#end
 	#end
 	Operator+:Vec2( s:T )
 	Operator+:Vec2( s:T )
 		Return New Vec2( x+s,y+s )
 		Return New Vec2( x+s,y+s )
 	End
 	End
 	
 	
-	#rem monkeydoc Subtracts a value from the vector components and returns the result.
+	#rem monkeydoc Subtracts a scalar from the vector.
 	#end
 	#end
 	Operator-:Vec2( s:T )
 	Operator-:Vec2( s:T )
 		Return New Vec2( x-s,y-s )
 		Return New Vec2( x-s,y-s )
@@ -122,42 +125,36 @@ Struct Vec2<T>
 		Return Sqrt( x*x+y*y )
 		Return Sqrt( x*x+y*y )
 	End
 	End
 
 
+	#rem monkeydoc The normal to the vector.
+	#end	
+	Property Normal:Vec2()
+		Return New Vec2( -y,x )
+	End
+
 	#rem monkeydoc Computes the distance from this vector to another.
 	#rem monkeydoc Computes the distance from this vector to another.
 	#end
 	#end
 	Method Distance:Double( v:Vec2 )
 	Method Distance:Double( v:Vec2 )
 		Return (v-Self).Length
 		Return (v-Self).Length
 	End
 	End
 	
 	
-	#rem monkeydoc Normalizes the vector and returns the result.
+	#rem monkeydoc Normalizes the vector.
 	#end
 	#end
 	Method Normalize:Vec2()
 	Method Normalize:Vec2()
 		Return Self/Length
 		Return Self/Length
 	End
 	End
 	
 	
-	#rem monkeydoc The normal to the vector.
-	#end	
-	Property Normal:Vec2()
-		Return New Vec2( -y,x )
-	End
-
 	#rem monkeydoc Computes the dot product of the vector with another vector.
 	#rem monkeydoc Computes the dot product of the vector with another vector.
 	#end
 	#end
 	Method Dot:T( v:Vec2 )
 	Method Dot:T( v:Vec2 )
 		Return x*v.x+y*v.y
 		Return x*v.x+y*v.y
 	End
 	End
 	
 	
-	#rem monkeydoc Blends the vector with another vector and returns the result.
+	#rem monkeydoc Blends the vector with another vector.
 	#end
 	#end
 	Method Blend:Vec2( v:Vec2,alpha:Double )
 	Method Blend:Vec2( v:Vec2,alpha:Double )
 		Return New Vec2( (v.x-x)*alpha+x,(v.y-y)*alpha+y )
 		Return New Vec2( (v.x-x)*alpha+x,(v.y-y)*alpha+y )
 	End
 	End
 	
 	
-	#rem monkeydoc Gets a string representation for the vector.
-	#end
-	Method ToString:String()
-		Return Self
-	End
-
 End
 End
 
 
 #rem monkeydoc Transforms a Vec2\<Int\> by an AffineMat3.
 #rem monkeydoc Transforms a Vec2\<Int\> by an AffineMat3.

+ 96 - 4
modules/std/geom/vec3.monkey2

@@ -1,18 +1,33 @@
 
 
 Namespace std.geom
 Namespace std.geom
 
 
-#rem monkeydoc @hidden
+#rem monkeydoc Convenience type alias for Vec3\<Float\>.
 #end
 #end
 Alias Vec3f:Vec3<Float>
 Alias Vec3f:Vec3<Float>
 
 
-#rem monkeydoc @hidden
+#rem monkeydoc The generic Vec3 type provides support for 3 component vectors.
+
+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 Vec3<T>
 Struct Vec3<T>
 
 
+	#rem monkeydoc The vector x coordinate.
+	#end
 	Field x:T
 	Field x:T
+
+	#rem monkeydoc The vector y coordinate.
+	#end
 	Field y:T
 	Field y:T
+
+	#rem monkeydoc The vector z coordinate.
+	#end
 	Field z:T
 	Field z:T
 	
 	
+	#rem Creates a new vec3.
+	#end
 	Method New()
 	Method New()
 	End
 	End
 	
 	
@@ -28,6 +43,12 @@ Struct Vec3<T>
 		Self.x=v.x;Self.y=v.y;Self.z=z
 		Self.x=v.x;Self.y=v.y;Self.z=z
 	End
 	End
 	
 	
+	Method New( x:T,v:Vec2<T> )
+		Self.x=z;Self.y=v.x;Self.z=v.y
+	End
+
+	#Rem monkeydoc Converts the vec3 to a vec3 of a different type or a printable string.
+	#end
 	Method To<C>:Vec3<C>()
 	Method To<C>:Vec3<C>()
 		Return New Vec3<C>( x,y,z )
 		Return New Vec3<C>( x,y,z )
 	End
 	End
@@ -36,94 +57,165 @@ Struct Vec3<T>
 		Return "Vec3("+x+","+y+","+z+")"
 		Return "Vec3("+x+","+y+","+z+")"
 	End
 	End
 	
 	
+	#rem monkeydoc The X coordinate of the vec3.
+	#end
 	Property X:T()
 	Property X:T()
 		Return x
 		Return x
 	Setter( x:T )
 	Setter( x:T )
 		Self.x=x
 		Self.x=x
 	End
 	End
 	
 	
+	#rem monkeydoc The Y coordinate of the vec3.
+	#end
 	Property Y:T()
 	Property Y:T()
 		Return y
 		Return y
 	Setter( y:T )
 	Setter( y:T )
 		Self.y=y
 		Self.y=y
 	End
 	End
 	
 	
+	#rem monkeydoc The X coordinate of the vec3.
+	#end
 	Property Z:T()
 	Property Z:T()
 		Return z
 		Return z
 	Setter( z:T )
 	Setter( z:T )
 		Self.z=z
 		Self.z=z
 	End
 	End
 	
 	
+	#rem monkeydoc The XY components of the vec3 as a vec2.
+	#end
 	Property XY:Vec2<T>()
 	Property XY:Vec2<T>()
 		Return New Vec2<T>( x,y )
 		Return New Vec2<T>( x,y )
 	Setter( xy:Vec2<T> )
 	Setter( xy:Vec2<T> )
 		x=xy.x;y=xy.y
 		x=xy.x;y=xy.y
 	End
 	End
 	
 	
+	#rem monkeydoc The YZ components of the vec3 as a vec2.
+	#end
+	Property YZ:Vec2<T>()
+		Return New Vec2<T>( y,z )
+	Setter( yz:Vec2<T> )
+		y=yz.x;z=yz.y
+	End
+
+	#rem monkeydoc The XZ components of the vec3 as a vec2.
+	#end
+	Property XZ:Vec2<T>()
+		Return New Vec2<T>( x,z )
+	Setter( xz:Vec2<T> )
+		x=xz.x;z=xz.y
+	End
+	
+	#rem monkeydoc Negates the vec3.
+	#end
 	Operator-:Vec3()
 	Operator-:Vec3()
 		Return New Vec3( -x,-y,-z )
 		Return New Vec3( -x,-y,-z )
 	End
 	End
 	
 	
+	#rem monkeydoc Multiplies the vec3 by another vec3.
+	#end
 	Operator*:Vec3( v:Vec3 )
 	Operator*:Vec3( v:Vec3 )
 		Return New Vec3( x*v.x,y*v.y,z*v.z )
 		Return New Vec3( x*v.x,y*v.y,z*v.z )
 	End
 	End
 	
 	
+	#rem monkeydoc Divides the vec3 by another vec3.
+	#end
 	Operator/:Vec3( v:Vec3 )
 	Operator/:Vec3( v:Vec3 )
 		Return New Vec3( x/v.x,y/v.y,z/v.z )
 		Return New Vec3( x/v.x,y/v.y,z/v.z )
 	End
 	End
 	
 	
+	#rem monkeydoc Adds the vec3 to another vec3.
+	#end
 	Operator+:Vec3( v:Vec3 )
 	Operator+:Vec3( v:Vec3 )
 		Return New Vec3( x+v.x,y+v.y,z+v.z )
 		Return New Vec3( x+v.x,y+v.y,z+v.z )
 	End
 	End
 	
 	
+	#rem monkeydoc Subtracts another vec3 from the vec3.
+	#end
 	Operator-:Vec3( v:Vec3 )
 	Operator-:Vec3( v:Vec3 )
 		Return New Vec3( x-v.x,y-v.y,z-v.z )
 		Return New Vec3( x-v.x,y-v.y,z-v.z )
 	End
 	End
 	
 	
+	#rem monkeydoc Multiplies the vec3 by a scalar.
+	#end
 	Operator*:Vec3( s:Double )
 	Operator*:Vec3( s:Double )
 		Return New Vec3( x*s,y*s,z*s )
 		Return New Vec3( x*s,y*s,z*s )
 	End
 	End
 	
 	
+	#rem monkeydoc Divides the vec3 by a scalar.
+	#end
 	Operator/:Vec3( s:Double )
 	Operator/:Vec3( s:Double )
 		Return New Vec3( x/s,y/s,z/s )
 		Return New Vec3( x/s,y/s,z/s )
 	End
 	End
 	
 	
+	#rem monkeydoc Adds a scalar to each component of the vec3.
+	#end
 	Operator+:Vec3( s:T )
 	Operator+:Vec3( s:T )
 		Return New Vec3( x+s,y+s,z+s )
 		Return New Vec3( x+s,y+s,z+s )
 	End
 	End
 	
 	
+	#rem monkeydoc Subtracts a scalar from each component of the vec3.
+	#end
 	Operator-:Vec3( s:T )
 	Operator-:Vec3( s:T )
 		Return New Vec3( x-s,y-s,z-s )
 		Return New Vec3( x-s,y-s,z-s )
 	End
 	End
 	
 	
+	#rem monkeydoc Returns the pitch of the vec3.
+	
+	Pitch is the angle of rotation, in radians, of the vec3 around the x axis.
+	
+	#end
 	Property Pitch:Double()
 	Property Pitch:Double()
 		return -ATan2( y,Sqrt( x*x+z*z ) )
 		return -ATan2( y,Sqrt( x*x+z*z ) )
 	End
 	End
 
 
+	#rem monkeydoc Returns the yaw of the vec3.
+	
+	Yaw is the angle of rotation, in radians, of the vec3 around the y axis.
+	
+	#end
 	Property Yaw:Double()
 	Property Yaw:Double()
 		return -ATan2( x,z )
 		return -ATan2( x,z )
 	End
 	End
-	
+
+	#rem monkeydoc Returns the length of the vec3.
+	#end
 	Property Length:Double()
 	Property Length:Double()
 		Return Sqrt( x*x+y*y+z*z )
 		Return Sqrt( x*x+y*y+z*z )
 	End
 	End
 
 
+	#rem monkeydoc Returns the distance of the vec to another vec3.
+	#end
 	Method Distance:Double( v:Vec3 )
 	Method Distance:Double( v:Vec3 )
 		Return (v-Self).Length
 		Return (v-Self).Length
 	End
 	End
-
+	
+	#rem monkeydoc Normalizes the vec3.
+	#end
 	Method Normalize:Vec3()
 	Method Normalize:Vec3()
 		Return Self/Length
 		Return Self/Length
 	End
 	End
 	
 	
+	#rem monkeydoc Returns the dot product of the vec3 with another vec3.
+	#end
 	Method Dot:T( v:Vec3 )
 	Method Dot:T( v:Vec3 )
 		Return x*v.x+y*v.y+z*v.z
 		Return x*v.x+y*v.y+z*v.z
 	End
 	End
 
 
+	#rem monkeydoc Returns the cross product of the vec3 with another vec3.
+	#end
 	Method Cross:Vec3( v:Vec3 )
 	Method Cross:Vec3( v:Vec3 )
 		Return New Vec3( y*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x )
 		Return New Vec3( y*v.z-z*v.y,z*v.x-x*v.z,x*v.y-y*v.x )
 	End
 	End
 	
 	
+	#rem monkeydoc Blends the vec3 with another vec3.
+	
+	Components are linearly blended using `alpha` as a weighting factor.
+
+	If alpha is 0, self is returned.
+	
+	If alpha is 1, `v` is returned.
+	
+	#end
 	Method Blend:Vec3( v:Vec3,alpha:Double )
 	Method Blend:Vec3( v:Vec3,alpha:Double )
 		Return New Vec3( (v.x-x)*alpha+x,(v.y-y)*alpha+y,(v.z-z)*alpha+z )
 		Return New Vec3( (v.x-x)*alpha+x,(v.y-y)*alpha+y,(v.z-z)*alpha+z )
 	End
 	End

+ 84 - 24
modules/std/geom/vec4.monkey2

@@ -1,19 +1,37 @@
 
 
 Namespace std.geom
 Namespace std.geom
 
 
-#rem monkeydoc @hidden
+#rem monkeydoc Convenience type alias for Vec4\<Float\>.
 #end
 #end
 Alias Vec4f:Vec4<Float>
 Alias Vec4f:Vec4<Float>
 
 
-#rem monkeydoc @hidden
+#rem monkeydoc The generic Vec4 type provides support for 4 component vectors.
+
+Unless otherwise noted, methods and operators always return a new vec4 containing the result, without modifying any parameters or 'self'.
+
+This allows you to chain operators together easily just like 'real' expressions.
+
 #end
 #end
 Struct Vec4<T>
 Struct Vec4<T>
 
 
+	#rem monkeydoc The vector x coordinate.
+	#end
 	Field x:T
 	Field x:T
+
+	#rem monkeydoc The vector y coordinate.
+	#end
 	Field y:T
 	Field y:T
+
+	#rem monkeydoc The vector z coordinate.
+	#end
 	Field z:T
 	Field z:T
+
+	#rem monkeydoc The vector w coordinate.
+	#end
 	Field w:T
 	Field w:T
 	
 	
+	#rem Creates a new vec4.
+	#end
 	Method New()
 	Method New()
 	End
 	End
 	
 	
@@ -25,114 +43,156 @@ Struct Vec4<T>
 		Self.x=x;Self.y=y;Self.z=z;Self.w=w
 		Self.x=x;Self.y=y;Self.z=z;Self.w=w
 	End
 	End
 	
 	
-	Method New( v:Vec3<T>,w:T )
-		x=v.x;y=v.y;z=v.z;Self.w=w
+	Method New( xy:Vec2<T>,z:T,w:T )
+		Self.x=xy.x;Self.y=xy.y;Self.z=z;Self.w=w
 	End
 	End
 	
 	
-	Method New( v:Vec2<T>,z:T,w:T )
-		x=v.x;y=v.y;Self.z=z;Self.w=w
+	Method New( x:T,yz:Vec2<T>,w:T )
+		Self.x=x;Self.y=yz.x;Self.z=yz.y;Self.w=w
 	End
 	End
-
-	Method To<C>:Vec4<C>()
+	
+	Method New( x:T,y:T,zw:Vec2<T> )
+		Self.x=x;Self.y=y;Self.z=zw.x;Self.w=zw.y
+	End
+	
+	Method New( xyz:Vec3<T>,w:T )
+		Self.x=xyz.x;Self.y=xyz.y;Self.z=xyz.z;Self.w=w
+	End
+	
+	Method new( x:T,yzw:Vec3<T> )
+		Self.x=x;Self.y=yzw.x;self.z=yzw.y;Self.w=yzw.z
+	End
+	
+	#Rem monkeydoc Converts the vec4 to a vec4 of a different type or a printable string.
+	#end
+	Operator To<C>:Vec4<C>()
 		Return New Vec4<C>( x,y,z )
 		Return New Vec4<C>( x,y,z )
 	End
 	End
-		
-	Method To:Vec3<T>()
-		Return New Vec3<T>( x,y,z )
+	
+	Operator To:String()
+		Return "Vec4("+x+","+y+","+z+","+w+")"
 	End
 	End
 	
 	
+	#rem monkeydoc The X coordinate of the vec4.
+	#end
 	Property X:T()
 	Property X:T()
 		Return x
 		Return x
 	Setter( x:T )
 	Setter( x:T )
 		Self.x=x
 		Self.x=x
 	End
 	End
 	
 	
+	#rem monkeydoc The Y coordinate of the vec4.
+	#end
 	Property Y:T()
 	Property Y:T()
 		Return y
 		Return y
 	Setter( y:T )
 	Setter( y:T )
 		Self.y=y
 		Self.y=y
 	End
 	End
 	
 	
+	#rem monkeydoc The Y coordinate of the vec4.
+	#end
 	Property Z:T()
 	Property Z:T()
 		Return z
 		Return z
 	Setter( z:T )
 	Setter( z:T )
 		Self.z=z
 		Self.z=z
 	End
 	End
 	
 	
+	#rem monkeydoc The Y coordinate of the vec4.
+	#end
 	Property W:T()
 	Property W:T()
 		Return w
 		Return w
 	Setter( w:T )
 	Setter( w:T )
 		Self.w=w
 		Self.w=w
 	End
 	End
 	
 	
+	#rem monkeydoc The XY components as a vec2.
+	#end
 	Property XY:Vec2<T>()
 	Property XY:Vec2<T>()
 		Return New Vec2<T>( x,y )
 		Return New Vec2<T>( x,y )
 	Setter( xy:Vec2<T> )
 	Setter( xy:Vec2<T> )
 		x=xy.x;y=xy.y
 		x=xy.x;y=xy.y
 	End
 	End
 	
 	
+	#rem monkeydoc The XYZ components as a vec3.
+	#end
 	Property XYZ:Vec3<T>()
 	Property XYZ:Vec3<T>()
 		Return New Vec3<T>( x,y,z )
 		Return New Vec3<T>( x,y,z )
 	Setter( xyz:Vec3<T> )
 	Setter( xyz:Vec3<T> )
 		x=xyz.x;y=xyz.y;z=xyz.z
 		x=xyz.x;y=xyz.y;z=xyz.z
 	End
 	End
-	
-	Operator To:String()
-		Return "Vec4("+x+","+y+","+z+","+w+")"
-	End
-	
-	Operator To<C>:Vec4<C>()
-		Return New Vec4<C>( x,y,z,w )
-	End
-	
+
+	#rem monkeydoc Negates the vec4.
+	#end
 	Operator-:Vec4()
 	Operator-:Vec4()
 		Return New Vec4( -x,-y,-z,-w )
 		Return New Vec4( -x,-y,-z,-w )
 	End
 	End
 	
 	
+	#rem monkeydoc Multiplies the vec4 by another vec4.
+	#end
 	Operator*:Vec4( v:Vec4 )
 	Operator*:Vec4( v:Vec4 )
 		Return New Vec4( x*v.x,y*v.y,z*v.z,w*v.w )
 		Return New Vec4( x*v.x,y*v.y,z*v.z,w*v.w )
 	End
 	End
 	
 	
+	#rem monkeydoc Divides the vec4 by another vec4.
+	#end
 	Operator/:Vec4( v:Vec4 )
 	Operator/:Vec4( v:Vec4 )
 		Return New Vec4( x/v.x,y/v.y,z/v.z,w/v.w )
 		Return New Vec4( x/v.x,y/v.y,z/v.z,w/v.w )
 	End
 	End
 	
 	
+	#rem monkeydoc Adds the vec4 to another vec4.
+	#end
 	Operator+:Vec4( v:Vec4 )
 	Operator+:Vec4( v:Vec4 )
 		Return New Vec4( x+v.x,y+v.y,z+v.z,w+v.w )
 		Return New Vec4( x+v.x,y+v.y,z+v.z,w+v.w )
 	End
 	End
 	
 	
+	#rem monkeydoc Subtracts another vec4 from the vec4.
+	#end
 	Operator-:Vec4( v:Vec4 )
 	Operator-:Vec4( v:Vec4 )
 		Return New Vec4( x-v.x,y-v.y,z-v.z,w-v.w )
 		Return New Vec4( x-v.x,y-v.y,z-v.z,w-v.w )
 	End
 	End
 	
 	
+	#rem monkeydoc Multiplies the vec4 by a scalar.
+	#end
 	Operator*:Vec4( s:Double )
 	Operator*:Vec4( s:Double )
 		Return New Vec4( x*s,y*s,z*s,w*s )
 		Return New Vec4( x*s,y*s,z*s,w*s )
 	End
 	End
 	
 	
+	#rem monkeydoc Divides the vec4 by a scalar.
+	#end
 	Operator/:Vec4( s:Double )
 	Operator/:Vec4( s:Double )
 		Return New Vec4( x/s,y/s,z/s,w/s )
 		Return New Vec4( x/s,y/s,z/s,w/s )
 	End
 	End
 	
 	
+	#rem monkeydoc Adds a scalar to each component of the vec4.
+	#end
 	Operator+:Vec4( s:T )
 	Operator+:Vec4( s:T )
 		Return New Vec4( x+s,y+s,z+s,w+s )
 		Return New Vec4( x+s,y+s,z+s,w+s )
 	End
 	End
 	
 	
+	#rem monkeydoc Subtracts a scalar from each component of the vec4.
+	#end
 	Operator-:Vec4( s:T )
 	Operator-:Vec4( s:T )
 		Return New Vec4( x-s,y-s,z-s,w-s )
 		Return New Vec4( x-s,y-s,z-s,w-s )
 	End
 	End
 	
 	
+	#rem monkeydoc Returns the length of the vec4.
+	#end
 	Property Length:Double()
 	Property Length:Double()
 		Return Sqrt( x*x+y*y+z*z )
 		Return Sqrt( x*x+y*y+z*z )
 	End
 	End
 
 
-	Method Dot:Double( v:Vec4 )
-		Return x*v.x+y*v.y+z*v.z+w*v.w
-	End
-	
+	#rem monkeydoc Normalizes the vec4.
+	#end
 	Method Normalize:Vec4()
 	Method Normalize:Vec4()
 		Return Self/Length
 		Return Self/Length
 	End
 	End
 	
 	
+	#rem monkeydoc Returns the dot product of the vec4 with another vec4.
+	#end
+	Method Dot:Double( v:Vec4 )
+		Return x*v.x+y*v.y+z*v.z+w*v.w
+	End
+	
 	Method Blend:Vec4( v:Vec4,alpha:Double )
 	Method Blend:Vec4( v:Vec4,alpha:Double )
 		Return New Vec4( (v.x-x)*alpha+x,(v.y-y)*alpha+y,(v.z-z)*alpha+z,(v.w-w)*alpha+w )
 		Return New Vec4( (v.x-x)*alpha+x,(v.y-y)*alpha+y,(v.z-z)*alpha+z,(v.w-w)*alpha+w )
 	End
 	End

+ 2 - 0
modules/std/std.monkey2

@@ -83,6 +83,8 @@ Namespace std
 
 
 #Import "requesters/requesters"
 #Import "requesters/requesters"
 
 
+#Import "permissions/permissions"
+
 Private
 Private
 
 
 Function Main()
 Function Main()