mouse z aid

BlitzMax Forums/BlitzMax Programming/mouse z aid

Cruis.In(Posted 2013) [#1]
Hey guys, got a little issue with mousez hurting my head.

I like to scale up and down in floats so that it's smooth, and not in whole number steps.

I don't want to scale past 1.0 or scale less than 0.05


I am flushing the mouse because I don't want the issue of over scroll. Once you've reached the max zoom or min zoom, if you keep scrolling, the value of mousez is still going up/or down depending on direction of scroll. Since the whole process is based on mousez, then if you are zooming in, the zoom maxes out, and you keep scrolling, the user would have to scroll back down through all that excess zoom before being able to zoom back out.

Above stops it from going below 0.05, the mouse stays flushed. But it doesn't stop it on the max side. Once it reached the max 1.0 it loops around and resets to 0.05 (the minimum)

Last edited 2013

Last edited 2013


col(Posted 2013) [#2]
Hiya,

You could use MouseZSpeed() as a delta and simply add it to the scale variable, then use the Min and Max functions to limit its value :-

Global MinZ# = 0.05
Global MaxZ# = 1.0

[main loop]
scale :+ Float(MouseZSpeed()) / 20.0 ' Faster mouse speed will give faster zoom speed	
scale = Min(Max(scale,MinZ),MaxZ) ' clamp scale between MinZ and MaxZ ( 0.05 :: 1.00 )
[/mainloop]



col(Posted 2013) [#3]
[EDIT]This is slightly off-topic[/EDIT]

This could be a bug with MouseZSpeed interferring with variables when losing focus.
In this little example if you uncomment the MouseZSpeed() line, use the mouse to adjust the value away from 0.05, move the focus away from the window and the scale value goes to haywire!! This doesnt happen when you use the keys to adjust the value ( comment out the MouseZSpeed() line and uncomment the KeyDown() line.

This is happening on Win8 and Win7.
Strict

Graphics 400,400

Global MinZ# = 0.05
Global MaxZ# = 1.0
Local Scale# = 0.5

Repeat
	Cls
	
	'scale :+ Float((KeyDown(KEY_RIGHT) - KeyDown(KEY_LEFT))/20.0) ' scale keeps its value when App loses focus
	scale :+ Float(MouseZSpeed()) / 20.0 ' scale loses its value after App loses focus !!!
	scale = Min(Max(scale,MinZ),MaxZ)
	
	DrawText scale,0,0
	
	Flip
Until AppTerminate()


Last edited 2013


col(Posted 2013) [#4]
Hmm,

It appears that the MouseZ*() commands reset to 0 by negating their values at the instant that the window loses focus.....

Last edited 2013


Cruis.In(Posted 2013) [#5]
yeah, is this why then it only quirks up when making the value bigger?


col(Posted 2013) [#6]
It only plays up for me if you click away from the window and move back to it. Other than that it works ok.

Just to reiterate that this works perfect ( including when losing focus ) :-


There may be something else in your code causing it to jump back to the minimum when trying to go over the maximum.

Last edited 2013


Cruis.In(Posted 2013) [#7]
thanks, works fine for me too when I do it that way. But that way is the perfect steps zoom. It doesn't keep zooming in or out.

If I did a full turn of the wheel and let go, I am looking for a zoom in, and stop at the end of the value you would have scrolled too.

think like homeworld kinda thing.


Cruis.In(Posted 2013) [#8]
lol duh.....friction.......

stupid me. :)


col(Posted 2013) [#9]
Or just a simple interpolation. No need to think the 'physics' route :P

You have a variable holding the current zoom value, and another for a target zoom value that you want. Take one from the other to get a 'distance', multiply that 'distance' by a dividing factor, say 0.125, or 0.25. The lower the factor then the slower the zoom change will be. This will also give you a nice and smooth 'fast to slow' zoom effect. That is, when the wanted zoom value is far from the current zoom then it will alter quickly, then as the value get closer the zoom effect will slow down.

Only a couple lines of code too :)

Strict

Graphics 400,200

Global MinZ# = 0.05
Global MaxZ# = 1.0
Global ZoomSpeed# = 0.125 ' change this for a different 'zoom speed'
Global TargetScale# = 0.5
Global CurrScale# = 0.5

Repeat
	Cls

	TargetScale :+ Float(MouseZ()) * 0.05 ' / 20.0 - cpus prefer multiple instead of divide
	TargetScale = Min(Max(TargetScale,MinZ),MaxZ) ' Limit to 0.05 : 1.0
	
	Local diff# = (TargetScale - CurrScale) * ZoomSpeed
	CurrScale :+ diff
	
	FlushMouse()	
	
	DrawText "Target: "+TargetScale,0,0
	DrawText "Current: "+CurrScale,0,20
	Flip
Until AppTerminate()



Cruis.In(Posted 2013) [#10]
thanks col, that's way smooth and immediately gets rid of the problem of min/max since I dont have to wait until it reaches the min or max to set it at that. So no looping effects.