How does Scale() work?

Monkey Forums/Monkey Beginners/How does Scale() work?

Hezkore(Posted 2015) [#1]
I seem to be unable to reset my Scale X and Y values after usage?
I'm used to SetScale in BlitzMax...
Strict
Import mojo

Global Zoom:Float=0.5

Function Main:Int()
	New Game
	Return 0
End

Class Game Extends App
	Method OnRender:Int()
		Cls()
		DrawText("Hello!",0,0)
		Scale(Zoom,Zoom)
		DrawText("Hello!",0,32)
		Scale(1,1)
		DrawText("Hello!",0,64)
		Return 0
	End
End



ziggy(Posted 2015) [#2]
Scale is accumulative, as any other matrix-based transform
In monkey, you usually do PopMatrix and PushMatrix.

PushMatrix   '<-- This is like a "restore point"
Scale, rotate, draw, whatever..
PopMatrix   '<-- This brings back the latest "restore point"
Now everything is unscaled unrotated, etc.

The PushMatrix command will store current scale, rotation, etc, status into memory so it can be restored later on the PopMatrix command. Notice this commands work on a stack, so any object can modify its own matrix, do its rendering, and leave it back as it was. Or you can define objects that do scale next drawing operations, etc. All in all it is a very nice system, as it allows for tree based transforms quite easily.


golomp(Posted 2015) [#3]
Thanks Ziggy !

Now i understand PushMatrix and PopMatrix usage.


Hezkore(Posted 2015) [#4]
That's what I'm doing now Ziggy.
But I'd still like to know how to reset the scale.


Derron(Posted 2015) [#5]
I assume you could do it similar to

SetAlpha( GetAlpha() * 0.5 )
doBla()
SetAlpha( GetAlpha() * 2.0 )

or you use backupVariables
local oldVal = GetVal()
SetVal( oldVal * modFactor )
doBla()
SetVal( oldVal )

If things "stack" on each other you would remember the "factor":
SetScale( 0.5 )
doBla()
SetScale( GetScale() / 0.5 ) 'multiply again

With Push/Pop-Matrix you automate this: You shovel one new "settings stack" on the pile of settings and when finished, you take that load away again leaving the "pile of settings" in the state of before. Means: When using Push/PopMatrix you do not need to "reset scale" as it is done automatically when "undoing" all things done since the last "pushmatrix".


bye
Ron


Midimaster(Posted 2015) [#6]
In this context "SetMatrix" is important too! Often you need a fixed scaling inside functions. f.e. a text-function, which should display text in always the same size, no matter what the last scaling outside the function defined....

Method OnRender()
     Scale 1.3, 1.6    'first scaling for the screen
     DrawMyBox(200,300,"blabla")
End


Method DrawMyBox (X%,Y%,content$)
     PushMatrix
          Translate X,Y
          Scale 2, 2 ' second scaling for box-elements
          DrawRect ...
          DrawRect ...
          DrawRect ...
          DrawRect ...
          ...
          DrawMyText(content)
     PopMatrix
End

Method DrawMyText
     PushMatrix
          SetMatrix 1,0,0,1,0,0
          DrawText "blabla", 10,10 
     PopMatrix
End




Derron(Posted 2015) [#7]
Does this take care of "autofit"-setups?

I mean: if something is scaled down on your device (to fit on the screen) then I cannot imagine things to get "visually bigger" than other things. But yepp, SetMatrix might come in handy from time to time.


bye
Ron


Nobuyuki(Posted 2015) [#8]
@Derron
Pushing the matrix to the stack essentially saves the last copy of the global matrix. If you use SetMatrix to go back to the identity matrix, then yes, whatever draw routines you use between PushMatrix and PopMatrix will be unaffected by autoFit and will display at whatever resolution the original maps to on the target.


Derron(Posted 2015) [#9]
@Nobuyuki
My question was more a rhetorical one. I just wasn't sure if there are special quirks done in Monkey and I would fool myself with saying things which aren't truth.

I already assumed, that this setmatrix-thing is like a "global change" - which is not what most of us want (especially in mobile dev). For desktop and html5-builds (with fixed resolution) this might behave a bit differently (aka "could get ignored").


bye
Ron