Forum Replies Created
July 14, 2019 at 8:21 am in reply to: Maintaining the relative position of a variably scaled image #16261
I’m not sure I get what you want but here is some code where you can move arond the map and zoom/unzoom spain only.
It uses matrix transfrom which is something used a lot for zoom/rotate/translate. When you move around the map, you don’t move the map but the “camera”(ie the transform) instead. I’ve added a method to canvas to get the transfrom as a “center the camera on this point”.
You can zoom/unzoom spain with the I and O keys.Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126Namespace MainWindow'Library Imports#Import "<std>"#Import "<mojo>"#Import "<mojox>"'Images#Import "sample.png"Using std..Using mojo..Using mojox..Global windowWidth:Int = 1285Global windowHeight:Int = 587Class MainWindow Extends WindowField ImageSample:Image = Image.Load("asset::sample.png")Field xOffset:Int=windowWidth/2 'now this is the camera center pointField yOffset:Int=windowHeight/2 'now this is the camera center point'Field selX:Int'Field selY:IntField zoom:Float = 0.5Field spainImage:ImageField spainOffset:Vec2iField spainZoom:=0.6Field debugOverlay:Bool = TrueMethod New()Super.New("Image Scaling",windowWidth,windowHeight,WindowFlags.Center)'copy pasting the spain portion to a small image (37*37 so the real center exists, trickyer for even size images)Local tempWorldCanvas:=New Canvas(ImageSample)Local spainPixmap:=tempWorldCanvas.CopyPixmap(New Recti(New Vec2i(537,152),New Vec2i(537+37,152+37)))spainImage=New Image(spainPixmap)spainImage.Handle=New Vec2f(0.5,0.5)spainOffset=New Vec2i(537+18,152+18) '18 is 37/2.0 tounded downEndMethod OnRender(canvas:Canvas) OverrideApp.RequestRender()'selX = (Mouse.X - xOffset)'selY = (Mouse.Y - yOffset)If Keyboard.KeyDown(Key.Z) Thenzoom -= 0.01'Increase offsetsxOffset += 0yOffset += 0EndifIf Keyboard.KeyDown(Key.X) Thenzoom += 0.01'Decrease offsetsxOffset -= 0yOffset -= 0EndifIf Keyboard.KeyDown(Key.W) Then yOffset += 3*(1/zoom)If Keyboard.KeyDown(Key.S) Then yOffset -= 3*(1/zoom)If Keyboard.KeyDown(Key.A) Then xOffset += 3*(1/zoom)If Keyboard.KeyDown(Key.D) Then xOffset -= 3*(1/zoom)If Keyboard.KeyDown(Key.I) Then spainZoom += 0.01If Keyboard.KeyDown(Key.O) Then spainZoom -= 0.01canvas.PushMatrix()'remeber state of the matrixcanvas.SetCameraByCenter(New Vec2f(xOffset,yOffset),zoom)canvas.Alpha = 1Local mouseOnMap:=-canvas.Matrix*MouseLocation 'use inverted matrix to get mouse location on the mapcanvas.DrawImage(ImageSample,0,0,0,1,1)If Keyboard.KeyHit(Key.R) Then debugOverlay = Not debugOverlayIf debugOverlay = True Thencanvas.Alpha = 0.5'canvas.DrawImage(ImageSample,xOffset,yOffset,0,zoom+0.01,zoom+0.01)canvas.DrawImage(spainImage,spainOffset.x,spainOffset.y,0,spainZoom,spainZoom)canvas.Alpha = 1Endifcanvas.PopMatrix() 'recover state of the matrix'Debug stuffcanvas.DrawRect(windowWidth/2,windowHeight/2,2,2)canvas.DrawText(xOffset+","+yOffset,0,0)canvas.DrawText(mouseOnMap,0,16)canvas.DrawText(zoom,0,48)If Keyboard.KeyHit(Key.Escape) Then App.Terminate()EndEndClass Canvas ExtensionMethod SetCameraByCenter(point:Vec2f,zoom:Float=1.0,rotation:Float=0.0)Translate(Viewport.Width/2.0,Viewport.Height/2.0)Scale(zoom,zoom)Rotate(rotation)Translate(-point)EndEndFunction Main()New AppInstanceNew MainWindowApp.Run()EndJuly 13, 2019 at 6:53 am in reply to: Maintaining the relative position of a variably scaled image #16258
handle is supposed to be from 0 to 1 for it to be inside the image.. (0,0) being top left and (1,1) bottom right.
image size is 1285*587
spain is at (560,170)
so your handle should be (560/1285,170/587) i.e. (0.435,0.29)
EDIT: note that dividing an int by an int will give an int. So in your code you’ll have to cast one of them to float: (zoomSpot.x/float(myImage. Width), zoomSpot.y/float(myImage.Height))
I had a small look and GLWindow extends Window and only has a few addition to Window. And Window works (there is this vsync issue with previous systems). So it’s looks doable. May be posting an issue on github could be interresting if you really need it working.
There is this vsync issue with different Mac systems for now and I’d love to see it solved as well as those gl issue. But Apple is not helping here..
here’s the commit mark made for the blank screen on mojave. it’s a sdl2 hack. But I thought you had made your own hack for your monkey2 fork. https://github.com/blitz-research/monkey2/commit/ce3a9ebdd92aa861358210e24c94d3d8c6a5631e
Maybe your problem has nothing to do with this blank screen issue on mojave, I haven’t tested the banana, just guessing here.
Since Apple has deprecated opengl with Mojave there as been a lot of troubles. I think importing latest dev sdl2 would resolve the problem (and reverting back the displaylink commit for Mac vsync). I had a try but sdl2 is configured by default to dynamic linking and there is some hack to do to get it statically linked.
Import sdl2 then it’s sdl2.SDL_StartTextInput( ) (and sdl2.SDL_StopTextInput( ) )
Lokking forward to test it in english..March 15, 2019 at 11:28 am in reply to: How to use GIT for your own projects/modules within the monkey2 repo #16129
I’m using githubDesktop on both Mac and MSWin and it has been flawless for now. Just clone your repo to the module folder. Changing the folder name if needed, and everything runs fine. The only problem is Ted2Go intellisens behaving badly when you work on files from the modules folder.
I can see some cross platform serial libraries so it should be doable. But the bmx serial package could be event better!?
I suppose you have to read tru your arduino drivers? There is no specific serial port thing in monkey2 AFAIK. But everything that can be donne in C can be imported into Monkey2 (c++ might need some glue/wrapping).
If you want some help in calling arduino with monkey2. I’ll be glad to help as I always wanted to play with an arduino. I don’t own one though, but I want to own one anyway.
If you show some C code that works I probably can help.March 5, 2019 at 6:53 pm in reply to: Assets, paths… Need some help putting together examples #16110
Just use a relative path (to your monkey2 file) and “asset::blah.bla” as amon told
Note that you can use ‘../’ to go to relative parent directory. eg “../assets/mycsv.csv”
you can also use the @ symbol to create virtual asset dirs.
eg #Import “../assets/images/@/images/”
Note that you can assign a class instance’s method to a first class function too.
The fisrt class functions has never been a problem with callbacks, for me.
To get your ‘char_t Ptr Ptr’
you might want to use ‘VarPtr myChar_tArray.Data’ as ‘Array.Data’ is already a pointer to the first element of the array.Edit doesn’t work. I’ve put some working code on the codebox below.Monkey12345678910111213141516171819202122#Import "<libc>"Function Main()Local baseStr:="y"Local cstr:=New libc.char_t[baseStr.Length+1] '1 char larger to put the null termination charbaseStr.ToCString(cstr.Data,baseStr.Length+1) 'writes the baseStr to the cstrLocal csDat:=cstr.Data 'VarPtr cstr.Data is not accepted by compiler! & won't accept VarPtr twice neitherLocal chptrptr:=Varptr csDatPrintstuff(chptrptr)EndFunction Printstuff(csptrptr:libc.char_t Ptr Ptr)Print "mx2 callback"Print String.FromCString(csptrptr)End
I’ve joined a little zip/demo code using external function pointers with first class function in various ‘directions’.
Yes, the compiler should tell you that you are using a non accepted type.
If I remember well you can also use ‘implements’ and ‘extends’
Where <T> implements myInterface
Where <T> extends myBaseClass.February 24, 2019 at 8:29 am in reply to: Fist class function in collection with struct parameter #16084
A correcting commit has arrived! Thx Mark!