About Monkey 2 › Forums › Monkey 2 Code Library › Vectors extensions
This topic contains 3 replies, has 2 voices, and was last updated by
nerobot 1 year, 5 months ago.
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
September 8, 2017 at 4:02 am #10330
Bring some const into our vectors to simplify code view.
Before:
Monkey123456position2d=New Vec2f( 0 )'orposition2d=New Vec2f'restore scalescale=New Vec3f( 1 )Now:
Monkey12position2d=Vec2f.Zeroscale=Vec3f.OneExtensions code
(updated with Mark’s advice):
Monkey123456789101112131415161718192021222324252627282930Struct Vec2i ExtensionConst Zero := New Vec2i( 0 )Const One := New Vec2i( 1 )EndStruct Vec2f ExtensionConst Zero := New Vec2f( 0 )Const Half := New Vec2f( .5 )Const One := New Vec2f( 1 )EndStruct Vec3f ExtensionConst Zero := New Vec3f( 0 )Const Half := New Vec3f( .5 )Const One := New Vec3f( 1 )EndStruct Vec4f ExtensionConst Zero := New Vec4f( 0 )Const Half := New Vec4f( .5 )Const One := New Vec4f( 1 )EndSeptember 16, 2017 at 12:14 am #10501Just a quick note that Vec2, Vec3 etc have single component ctors too, eg: New Vec3f( .8 ) is the same as New Vec3f( .8,.8,.8 ).
October 31, 2017 at 1:33 pm #11388A few helpers for vectors – I started to use them instead of New Vec2_x(...):
Monkey12345678910111213Function v2f:Vec2f( x:Float,y:Float )Return New Vec2f( x,y )EndFunction v2f:Vec2f( v:Float )Return New Vec2f( v,v )EndFunction v2i:Vec2i( x:Int,y:Int )Return New Vec2i( x,y )EndFunction v2i:Vec2i( v:Int )Return New Vec2i( v,v )EndNovember 4, 2017 at 7:45 am #11467Monkey1234567891011121314151617181920212223242526272829303132333435363738Struct Vec2<T> ExtensionOperator |:Vec2<T>( other:Vec2<T> )Return Self+otherEndEndClass Pivot FinalConst Top:=v2f( 0,0 )Const Left:=v2f( 0,0 )Const Right:=v2f( 1,0 )Const Bottom:=v2f( 0,1 )Const HCenter:=v2f( .5,0 )Const VCenter:=v2f( 0,.5 )Const Center:=HCenter|VCenterConst TopLeft:=Top|LeftConst TopCenter:=Top|HCenterConst TopRight:=Top|RightConst BottomLeft:=Bottom|LeftConst BottomCenter:=Bottom|HCenterConst BottomRight:=Bottom|RightConst LeftTop:=Left|TopConst LeftCenter:=Left|VCenterConst LeftBottom:=Left|BottomConst RightTop:=Right|TopConst RightCenter:=Right|VCenterConst RightBottom:=Right|BottomEnd -
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.