Forum Replies Created
-
AuthorPosts
-
Also, how can I remove the old file attachment from my initial post?
Should be gone now?
Thanks for the update too!
I wanted it to be able to use any element that extends a view and then, instead of having to specifically know if the (or which) element being added can have a click being listened to, be able to register clicks based on cells rather than what specific element is added in.
I’m not 100% comfortable with this because it means the behaviour of the added view may not be consistent. Many views wont work properly if you’re stealing mouse events – in fact, only views that have (or could have) a simple Clicked:Void() signal will really work (as expected) with a view like your TGrid.
That said, have a play with View.AcceptsKeyEvents and View.AcceptsMouseEvents – just remembered these even existed! Set these to false and views will send key/mouse events to parent views.
As for ‘composable’ guis, the idea is nice in theory but in my experience they are kind of a PITA in practice. Having a button (and other view types) that can have both text and an icon is just incredibly convenient, esp. if your ‘hand coding’ GUIs. And beyond buttons, what else really needs to (or can) be composed (apart from layouts)? Fancier buttons I guess…
libsdl2-dev
This apt-get makes things so much easier, thanks SDL!
…add a method to your window class like this:
Monkey12345678Method OnMouseEvent( event:MouseEvent ) OverrideSelect event.TypeCase EventType.MouseMove'Mouse has moved!Print "MouseMove:"+event.LocationEndEnd…or, you can just ‘poll’ for mouse movement by reading Mouse.X and Mouse.Y and comparing them with older readings.
What are you trying to achieve here though?
If the user clicks on a button and *something else* happens, isn’t that confusing?
What is the ‘real world’ use for this? Not the hypothetical ‘I want to be able to intercept events’ use, but the practical “I want to create a widgets that does XYZ’?
[edit]One thing I was thinking of doing originally was to add a ‘top down’ event filter system.
So before a view gets sent an event, all its parent views get a chance to filter the event first, using something like, say, OnFilterMouseEvent( event:MouseEvent ) etc. If a parent eats the event, the event is never sent to the child view, ie: it’s default prevented in a sense (although I never really got my head around how preventDefault worked in JS, I just used it as and when instructed to by stack overflow – I found the JS event system confusing and I don’t want to emulate it).
Here, I was thinking mainly of a GUI editor app where you want to go into a ‘mode’ to drag GUI elements around. I sort of forgot it about it because auto-layout solves most layout problems (or should anyway) and writing a GUI editor would have been a waste of time.
Multi-dimensional arrays aren’t too well supported yet, in particular there’s no way to intiailize them with values at creation time yet.
Creating them is easy enough, eg: Local myArray:=New Int[10,20], but you’ll have to get a bit tricky to initialize them, maybe something like:
Monkey123456789101112131415161718Function CreatePiece:Int[,]( args:Int[] )Local w:=args[0],h:=args[1]Local piece:=New Int[w,h]For Local y:=0 Until hFor Local x:=0 Until wpiece[x,y]=args[y*w+x+2]NextNextReturn pieceEndFunciton Main()Local piece:=CreatePiece( New Int[]( 2,3, '2 x 3 'T style piece1,0,1,11,0 ) )End(totally untested). Of course, string are also a cool way to do this…
Peronsally, I’d recommend creating a ‘Piece’ class or similar just to make all the arrays easier to deal with (although you seem to be quite comfortable with arrays!) as you’re also gonna wanna ‘Rotate’ them etc. Then you can just have a 1d array of pieces for the game, and give each piece a rotate method, maybe a clone method too for creating new pieces from template pieces etc. Just off the top of my head – I’ve never actually written a tetris game!
ship.Mesh.FitVertices(New Boxf(1,1),False)
This looks wrong. New Boxf( 1,1 ) will create a 0 volume box as min and max are both 1. Try New Boxf( -1,1 ) instead.
It’s missing the #imports at the top! Please post again…
This is often a sign that your model isn’t loading properly.
What you can do is put ‘Assert( model )’ after the Model.Load call to verify it did in fact load correctly.
Can you post the entire sourcec code? It’s generally much easier for us to spot problems if we can see the entire progam.
Add a ‘_camera.Viewport=Rect’ just after you create camera.
Or better yet, use ‘_camera.View=Self’ instead as this will be able to handle resizable views too.
Cameras currently draw to the entire canvas viewport regardless of what camera viewport is set to (but DO use the camera viewport to calculate projection matrix based on FOV) – this may change when I start messing around with multiple cameras, child views etc.
For now, safest thing to do is to attach view to camera.
I had a quick look at bmx (welll, glanced at digesteroids src), and rotation seems to be the same there, ie: +rotation=ccw. And I think, in the context of a +y=down coord system this is actually correct, these are just numbers after all.
What people are possibly really after here is a way to change +y=down to +y=up? This is probably doable and I think would be quite cool – cooler than just fudging rotation or something.
If you extend the Resource class, you can implement an OnFinalize (and OnDiscard) method. OnFinalize will only be called if OnDiscard hasn’t.
BUT, it should not read/write any monkey2 objects or arrays – just native handles, pointers etc. It should not allocate any GC memory (GC is currently suspended while finalizers run, but future versions may just cause a runtime error if you try to allocate GC memory inside a finalizer).
Monkey2 does not as yet (and may never) attempt to ‘sort’ finalizers by dependancy (it’s impossible with cyclic dependancies anyway, which leads to zombie objects etc – ugly, ugly stuff that can cause incredibly intermitent and hard to find problems) so any object object/array fields may or may not be dead/deallocated etc. I actually attempted a system where it ‘nulled out’ any object/array fields before calling OnFinalize, but there were issues…
So it’s pretty primitive, but it’s enough for fclosing files, freeing malloced memory, deleting gl objects, free type fonts etc, stuff that can be very hard to ‘keep alive’ sanely via ref counting etc.
I think the problem here is that I use the ‘standard’ 2d rotation matrix…
https://en.wikipedia.org/wiki/Rotation_matrix
…but I guess this assumes +y is ‘up’ (and I never really thought about this before) so perhaps the cosines or something need to be negated or perhaps you need to use: scale( 1,-1 ) * rotate( r ) * scale( 1,-1 )?
If this is the case, it wouldn’t be hard to add a canvas ‘mode’ that addressed this if enough people wanted it.
Here’s a little demo…
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788Namespace myapp3d#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"Using std..Using mojo..Using mojo3d..Class MyWindow Extends WindowField _scene:SceneField _camera:CameraField _light:LightField _ground:ModelField _donut:ModelMethod New( title:String="Simple mojo3d app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )Super.New( title,width,height,flags )'create (current) scene'_scene=Scene.GetCurrent()'create camera'_camera=New Camera_camera.Viewport=Rect_camera.AddComponent<FlyBehaviour>()_camera.Move( 0,10,-5 )'create light'_light=New Light_light.CastsShadow=True_light.RotateX( 90 )'create ground'Local groundBox:=New Boxf( -50,-1,-50,50,0,50 )Local groundMaterial:=New PbrMaterial( Color.Green )_ground=Model.CreateBox( groundBox,1,1,1,groundMaterial )_ground.CastsShadow=False'create dount'Local donutMaterial:=New PbrMaterial( Color.Brown )_donut=Model.CreateTorus( 2,.5,48,24,donutMaterial )_donut.Move( 0,10,0 )'Add a child!Local child:=Model.CreateBox( New Boxf(-1,1),1,1,1,New PbrMaterial( Color.Red ) )child.Parent=_donutchild.LocalPosition=New Vec3f( 0,-2,0 )EndMethod OnRender( canvas:Canvas ) OverrideRequestRender()_camera.Viewport=Rect_donut.Rotate( .2,.4,.6 )_scene.Update()_scene.Render( canvas )canvas.DrawText( "FPS="+App.FPS,0,0 )EndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndYes, it’s very much like blitz3d (if you’ve ever used that)!
A child entity’s position, rotation and scale are all relative to the parent entity. So moving, rotating, scaling the parent will also move, rotate, scale the child.
-
AuthorPosts