Forum Replies Created
-
AuthorPosts
-
Thanks for looking at this. Still the same issue here, I’m on Windows 10 so looks like there’s differences in behaviour as I don’t get the error on the filter (maybe I should?). Will post on GitHub as I think there’s something odd going on. This is the current test code with a separate function for a sanity check:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117#Import "<std>"#Import "<mojo>"#Import "<chipmunk>"#Import "chipmunkdebugger"Using std..Using mojo..Using chipmunk..Struct somedataField value:IntEndClass HelloChipmunk Extends WindowField space:cpSpaceField ground:cpShapeField ballBody:cpBodyField ballShape:cpShapeField ballBody2:cpBodyField ballShape2:cpShapeField polyBody:cpBodyField polyShape:cpShapeField something:String = "App String"Field debugger:=New ChipmunkDebuggerMethod New()ClearColor=Color.Black'Create a new space and set its gravity to 100'space=cpSpaceNew()space.Gravity=cpv( 0,1000 )Local data:=New MyClassLocal body:= cpBodyNewStatic()body.Position = cpv(100,100)space.AddBody(body)Local shape:= cpBoxShapeNew(body, 50, 50, 0.0)shape.Friction = 1shape.UserData = Varptr(data)space.AddShape(shape)TestCallBack(Varptr(data))EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()Const timeStep:=1.0/60.0space.StepTime( timeStep )' Local rot:=ballBody.Rotation' Local pos:=ballBody.Position' Local vel:=ballBody.Velocity' Print "ball rot="+ATan2( rot.y,rot.x )+", pos.x="+pos.x+", pos.y="+pos.y+", vel.x="+vel.x+", vel.y="+vel.yLocal spacefilter:=cpShapeFilterNew(ULong(0), UInt(1), UInt(1) )Local Test:=SelfcpSpaceBBQuery(space, cpBBNew(0,0,640,480), spacefilter, CallBack, Varptr Test)canvas.Translate( Width/2, Height/2 )debugger.DebugDraw( canvas,space )EndFunction TestCallBack(d:Void Ptr)DebugStop()Local data:=Cast<MyClass Ptr>(d)[0]Print data.TestEndFunction CallBack:Void(shape:cpShape, p:Void Ptr)Local whatsthis:=cpShapeGetUserData(shape)Local data:=Cast<MyClass Ptr>(whatsthis)[0]Local app:=Cast<HelloChipmunk Ptr>(p)[0]DebugStop()If dataPrint app.somethingPrint data.TestEndEndMethod Cleanup() 'Yeah, right!cpShapeFree( ballShape )cpBodyFree( ballBody )cpShapeFree( ground )cpSpaceFree( space )EndEndClass MyClassField Test:String = "Something in myclass"EndFunction Main()New AppInstanceNew HelloChipmunkApp.Run()EndNext problem is the UserData in cpShape, I’m having trouble casting it to anything. It does equal something but gives a memory access error if I try and access it. This feels like a bug in Monkey now but not sure:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107#Import "<std>"#Import "<mojo>"#Import "<chipmunk>"#Import "chipmunkdebugger"Using std..Using mojo..Using chipmunk..Struct somedataField value:IntEndClass HelloChipmunk Extends WindowField space:cpSpaceField ground:cpShapeField ballBody:cpBodyField ballShape:cpShapeField ballBody2:cpBodyField ballShape2:cpShapeField polyBody:cpBodyField polyShape:cpShapeField debugger:=New ChipmunkDebuggerMethod New()ClearColor=Color.Black'Create a new space and set its gravity to 100'space=cpSpaceNew()space.Gravity=cpv( 0,1000 )Local data:=New MyClassLocal body:= cpBodyNewStatic()body.Position = cpv(100,100)space.AddBody(body)Local shape:= cpBoxShapeNew(body, 50, 50, 0.0)shape.Friction = 1shape.UserData = Varptr(data)space.AddShape(shape)EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()Const timeStep:=1.0/60.0space.StepTime( timeStep )' Local rot:=ballBody.Rotation' Local pos:=ballBody.Position' Local vel:=ballBody.Velocity' Print "ball rot="+ATan2( rot.y,rot.x )+", pos.x="+pos.x+", pos.y="+pos.y+", vel.x="+vel.x+", vel.y="+vel.yLocal spacefilter:=cpShapeFilterNew(0, 1, 1 )Local Test:=SelfcpSpaceBBQuery(space, cpBBNew(0,0,640,480), spacefilter, CallBack, Varptr Test)canvas.Translate( Width/2, Height/2 )debugger.DebugDraw( canvas,space )EndFunction CallBack:Void(shape:cpShape, p:Void Ptr)Local data:=Cast<MyClass Ptr>(shape.UserData)[0]Local app:=Cast<HelloChipmunk Ptr>(p)[0]If dataPrint data.TestEndEndMethod Cleanup() 'Yeah, right!cpShapeFree( ballShape )cpBodyFree( ballBody )cpShapeFree( ground )cpSpaceFree( space )EndEndClass MyClassField Test:String = "Something"EndFunction Main()New AppInstanceNew HelloChipmunkApp.Run()EndThe App object that I’m passing in seems to cast fine though so that’s something.
Thanks. It was Ptr I was missing, this compiles ok now, will see how it goes with an actual sample and data going through it:
Monkey123cpSpaceBBQuery(space, cpBBNew(0,0,640,480), spacefilter, Lambda:Void(shape:cpShape, p:Void Ptr)End, Varptr Test)Works with the callback as well.
I tried that first, see the CallBack function in the class, but unfortunately same issue. The void pointers are confusing me, as far as I know they are function pointers but in the chipmunk docs it seems you can pass data. I’m don’t know much about c though!
Great news! I have a feeling that someone probably pledged a large amount to get the remaining amount over 1k which if that’s the case then it’s a little bit dependent one person who might change their mind, but who knows.
If Mark announces he will start on a 3D module then that will generate a lot of interest/enthusiasm that may add some more pledges to give some more buffer. To capitalise on that the Patreon page could do with a few more higher pledge incentives, like early alpha/beta access to developer builds. I’d also suggest a pledge that gives access to a private forum where Mark can give general dedicated support and expertise, $25-$50 for that wouldn’t be unreasonable.
I’d be happy to pledge a bit more for early access and start on TimelineFX 3D
I think that’s a bit beyond me! The smaa shader looks good, but it looks a bit advanced to implement, I’m pretty new to shaders.
Which brings me onto another question: If we wanted to apply a shader to the whole screen after it’s rendered everything else where would you look in mojo? I can see where it does the lighting and shadow rendor passes so I’m guessing after that somewhere.
Ahh sorry, it was bad timing as I was away for a day and a bit so didn’t get a chance till today, thanks for purchasing
I tried out uniform as Mark/Cocon suggested and it’s much easier. Had a little play and made it easier to add your own uniforms by adding a new command:
Monkey1AddUserUniform:UserUniform(names:String[], index:Int, callback:Void(useruniform:UserUniform, uniforms:UniformBlock) )Which lets you define your own uniform (this should match what you put in your shader), and lets you define a callback which will be called every time the canvas is rendered. For example the demo program now looks like:
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152Namespace myapp#Import "<std>"#Import "<mojo>"#Import "assets/"Using std..Using mojo..Class MyWindow Extends WindowField image:ImageField shader:ShaderField timeuniform:UserUniformMethod New( title:String="Simple mojo app",width:Int=800,height:Int=600,flags:WindowFlags=Null )Super.New( title,width,height,flags )'shader = New Shader("Red", LoadString("asset::wave.glsl"))shader = New Shader("Red", LoadString("asset::noise.glsl"))timeuniform = AddUserUniform(New String[]("mx2_Time2"), 0, UniformCallback)image = Image.Load("asset::clouds.png", shader)EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.Clear(New Color(0,0,0,1))canvas.DrawImage(image, 100, 50)EndFunction UniformCallback(useruniform:UserUniform, uniforms:UniformBlock)uniforms.SetScalar( "mx2_Time2", Float(Millisecs())/1000.0)EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndWhich is reasonably neat. You could extend “UserUniform” Class to put your own fields in there to help pass whichever specific variables you need to as the UserUniform instance is passed into the callback function as well. I’ve attached the modified files again, only Canvas and UniformBlock needed changing this time.
Attachments:
Actually I just realised I don’t have my heart yet
I would give a heart to everyone who’s donated anything, as the more hearts the better in terms of persuading more people to donate (social proof), and also make the heart a little bigger with a small caption like “Supported via Patreon/Payal”, and link it straight to the relevant donate page.
Great
I cannot see any reason why it wouldn’t work with pyro 2. I can look at some of the pyro 2 examples and implement some effects there.
I’ve just set up a discount for monkey2 users, use “MONKEY2” code at the checkout to get 25% off until the end of Jan!
Does it as well here. The “fix”, and I use that word loosely because there could be a reason why Mark did it like this, is to change the order the mouse.Update is called in the UpdateEvents() method of app.monkey2
The original version looks like this:
Monkey123456789101112131415161718192021Method UpdateEvents()Keyboard.Update()Mouse.Update()Touch.Update()Local event:SDL_EventWhile SDL_PollEvent( Varptr event )DispatchEvent( Varptr event )WendLocal idle:=IdleIdle=Nullidle()EndSo move the Mouse.Update() after SDL_PollEvent (I moved keyboard and touch after as well):
Monkey123456789101112131415161718192021Method UpdateEvents()Local event:SDL_EventWhile SDL_PollEvent( Varptr event )DispatchEvent( Varptr event )WendKeyboard.Update()Mouse.Update()Touch.Update()Local idle:=IdleIdle=Nullidle()EndIf that’s an ok fix then maybe Mark can update or I can do a pull request. I just tried it with the game I’ve been doing and everything still works fine.
I use ToString/ToNumber etc. Here’s a snippet from a json loader I’m using if it helps:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354json = json.Load(file)directory = ExtractDir(file)If Not json RuntimeError("Couldn't load config for " + file)If json["width"] width = json["width"].ToNumber()If json["height"] height = json["height"].ToNumber()If json["frames"] frames = json["frames"].ToNumber()If json["statictile"] statictile = json["statictile"].ToNumber()If json["collisions"] And json["collisions"].IsArraycollisionframe = New tlCollisionInfo[json["collisions"].ToArray().Length]Local index:Int = 0Local collisions:=json["collisions"].ToArray()collisionframe = New tlCollisionInfo[collisions.Length]For Local collisionobj:=Eachin collisionsLocal collision:=collisionobj.ToObject()If collision["type"]Select collision["type"].ToString()Case "poly"collisionframe[index] = New tlCollisionInfocollisionframe[index].collisiontype = tlPOLY_COLLISIONcollisionframe[index].x = collision["handlex"].ToNumber()collisionframe[index].y = collision["handley"].ToNumber()collisionframe[index].verts = JsonFloatArray(collision["verts"].ToArray())Case "box"collisionframe[index] = New tlCollisionInfocollisionframe[index].collisiontype = tlBOX_COLLISIONcollisionframe[index].x = collision["handlex"].ToNumber()collisionframe[index].y = collision["handley"].ToNumber()collisionframe[index].width = collision["width"].ToNumber()collisionframe[index].height = collision["height"].ToNumber()Case "circle"collisionframe[index] = New tlCollisionInfocollisionframe[index].collisiontype = tlCIRCLE_COLLISIONcollisionframe[index].x = collision["handlex"].ToNumber()collisionframe[index].y = collision["handley"].ToNumber()collisionframe[index].radius = collision["radius"].ToNumber()EndElseRuntimeError("Error loading resource config")End Ifindex+=1NextEnd IfIf json["files"] And json["files"].IsArrayfiles = New String[json["files"].ToArray().Length]Local tmpfiles:=json["files"].ToArray()Local i:Int = 0For Local file:=Eachin tmpfilesfiles[i] = file.ToString()i+=1NextEnd IfAnd the json file for reference:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384{"width":32,"height":32,"frames":16,"files":["solidblock_01.png","solidblock_02.png","solidblock_03.png","solidblock_04.png","solidblock_05.png","solidblock_06.png","solidblock_07.png","solidblock_08.png","solidblock_09.png","solidblock_10.png","solidblock_11.png","solidblock_12.png","solidblock_13.png","solidblock_14.png","solidblock_15.png","solidblock_16.png"],"statictile":1,"collisions":[{"type":"poly","handlex":10.5,"handley":10.5,"verts":[32,32,32,16,16,32]},{"type":"poly","handlex":-10.5,"handley":10.5,"verts":[16,32,0,16,0,32]},{"type":"poly","handlex":10.5,"handley":-10.5,"verts":[32,0,16,0,32,16]},{"type":"poly","handlex":-10.5,"handley":-10.5,"verts":[16,0,0,0,0,16]},{"type":"poly","handlex":0,"handley":0,"verts":[0,16,0,32,32,32,32,0,16,0]},{"type":"poly","handlex":0,"handley":0,"verts":[0,0,0,32,32,32,32,16,16,0]},{"type":"poly","handlex":0,"handley":0,"verts":[0,0,0,32,16,32,32,16,32,0]},{"type":"poly","handlex":0,"handley":0,"verts":[0,0,0,16,16,32,32,32,32,0]},{"type":"box","handlex":8,"handley":0,"width":16,"height":32},{"type":"box","handlex":0,"handley":-8,"width":32,"height":16},{"type":"box","handlex":-8,"handley":0,"width":16,"height":32},{"type":"box","handlex":0,"handley":8,"width":32,"height":16},{"type":"poly","handlex":0,"handley":0,"verts":[0,0,0,16,16,32,32,32,32,16,16,0]},{"type":"poly","handlex":0,"handley":0,"verts":[0,16,0,32,16,32,32,16,32,0,16,0]},{"type":"box","handlex":0,"handley":0,"width":32,"height":32},{"type":"box","handlex":0,"handley":0,"width":32,"height":32}]}Thanks Mark, I looked at uniformblock but was struggling to make sense of how it all fits together so went the easier (to me) route with the vertex buffer just to see if I can make it work, still not sure what I’m doing!
Will take a closer look at it now I’m a bit clearer
what I would like to see added – flexible access to shaders in 3d and 2d
I’d love to see this as well. I was just playing with shaders and creating a few basic ones but there doesn’t seem to be anyway to pass a custom variable to the shader – for example Time so that you can do some shader animations. The way three.js does it looks pretty good and flexible: http://stemkoski.blogspot.co.uk/2013/05/animated-shaders-in-threejs.html and result: http://stemkoski.github.io/Three.js/Shader-Animate.html
Shaders is something I’d like to try more with particle effects
-
AuthorPosts