About Monkey 2 › Forums › Monkey 2 Programming Help › Adding vertices to Shadowcaster()
This topic contains 5 replies, has 2 voices, and was last updated by
Richard Betson
2 years, 6 months ago.
-
AuthorPosts
-
October 12, 2016 at 12:18 am #4407
How do I add vertices to a shadow caster?
Thanks
October 12, 2016 at 6:28 pm #4423ShadowCaster is currently just a simple container for vertices, it doesn’t really ‘manage’ them.
So you can add vertices by doing something like:
Monkey123456789Local verts:=new Stack<float>verts.Push(...)verts.Push(...)verts.Push(...)verts.Push(...)Local shadowCaster:=New ShadowCaster( verts.ToArray() )...if we need to change them later...shadowCaster.Vertices=verts.ToArray()I guess it could include a stack, but this would just be ‘deadweight’ once the app was running, unless apps have a need to add vertices in realtime?
October 18, 2016 at 6:33 am #4507I’ll give that a try. Thanks.
October 20, 2016 at 9:59 pm #4551Hi,
I am having a little difficulty getting the above to work. I’ve modified the simplelight demo to try and use the method (see method New() ) above but cant seem to figure it out. Below is what I’m up to.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105Namespace myapp#Import "<std>"#Import "<mojo>"#Import "Slate Tiles II_D.png"#Import "Slate Tiles II_N.png"#Import "Slate Tiles II_S.png"#Import "pointlight_light.png"#Import "Monkey2-logo-48.png"Using std..Using mojo..Class MyWindow Extends WindowField _floor:ImageField _light:ImageField _logo:ImageField _shadowcaster:ShadowCaster 'Added for this testMethod New()ClearColor=Color.Black_floor=Image.LoadBump( "asset::Slate Tiles II_D.png","asset::Slate Tiles II_N.png","asset::Slate Tiles II_S.png",.5,True )_light=Image.LoadLight( "asset::pointlight_light.png" )_light.Handle=New Vec2f( .5 )_light.Scale=New Vec2f( 3 )_logo=Image.Load( "asset::Monkey2-logo-48.png" )_logo.Handle=New Vec2f( .5 )'_logo.ShadowCaster=New ShadowCaster( _logo.Width/2,20 )'-------------------'Add vertices ??'-------------------Local verts:=New Stack<Float>verts.Push(0.0)verts.Push(0.0)verts.Push(32.0)verts.Push(0.0)verts.Push(32.0)verts.Push(32.0)verts.Push(0.0)verts.Push(32.0)_logo.ShadowCaster=New ShadowCaster( verts.ToArray() )Self._shadowcaster=New ShadowCaster(verts.ToArray() )'Self._shadowcaster.Vertices=New Vec2(verts.ToArray())'-------------------EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.AmbientLight=Color.DarkGreycanvas.BeginLighting()canvas.AddLight( _light,Mouse.X,Mouse.Y )For Local x:=0 Until Width Step _floor.WidthFor Local y:=0 Until Height Step _floor.Heightcanvas.DrawImage( _floor,x,y )NextNextFor Local an:=0.0 Until TwoPi Step TwoPi/8.0canvas.DrawImage( _logo,Width/2+Cos( an ) * Width/4,Height/2 + Sin( an ) * Height/4 )Nextcanvas.EndLighting()canvas.DrawText( App.FPS,Width/2,0,.5,0 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndOctober 21, 2016 at 12:50 am #4552Ok, my mistake, you need to use an array of Vec2f’s – see below.
There is ‘help’ in there you know – pretty crappy, but clicking ‘F1’ on ShadowCaster a few times should bring up the ShadowCaster class.
Monkey12345678Local verts:=New Stack<Vec2f>verts.Push( New Vec2f( 0,0 ) )verts.Push( New Vec2f( 32,0 ) )verts.Push( New Vec2f( 32,32 ) )verts.Push( New Vec2f( 0,32 ) )_logo.ShadowCaster=New ShadowCaster( verts.ToArray() )October 21, 2016 at 4:57 am #4554Thanks! That seems to work.
I had a look at the help (F1) but still was confused. I’ve been working with a lot of legacy code conversion and I’ve really not had the time to really get into some of Monkey 2’s new features and ways of doing things. Much of it is still newish to me, but these little snippets, like the above, really go along way to getting a handle on it.
-
AuthorPosts
You must be logged in to reply to this topic.