trying to create a knob control in Blitz3d

Blitz3D Forums/Blitz3D Programming/trying to create a knob control in Blitz3d

dman(Posted 2010) [#1]
Can anyone help in creating a knob and slider control?

heres the program that needs it.

CLICK HERE : http://www.mediaandgames.com/media.html

Last edited 2010

Last edited 2010

Last edited 2010


Ross C(Posted 2010) [#2]
I'd imagine a knob control would need to firstly trap a mousedown event, then take the mouses X/Y co-ords, and find the angle from that point, to the centre of the knob. Have a look at the Atan2 command for that. Using the angle, you can determine have much the angle has changed from frame to frame, and rotate the knob accordingly.


PowerPC603(Posted 2010) [#3]
For a knob (button), it's easy.
Just draw your button on the screen and check with MouseX() and MouseY() if your mouse is positioned over the button (a rectangular box which starts from the top-left corner of your button to the bottom-right corner). If the mouse is positioned over the button, check for a mouseclick.
Then the user clicked the button.

For a slider, that's a bit more difficult. I can't help you with those as I haven't created sliders before.


dman(Posted 2010) [#4]
I 'm using this piece of code to simulate a knob control, but I can not get it working properly. I store the last mouse value and used it to calculate.



If MouseX() > 85 And MouseX() < 120 And MouseY() > 290 And MouseY() < 310 And MouseDown(1)
	
				
	    rot#=store_MouseY#+Float(MouseYSpeed())/0.2
	    If rot<-90 rot=-90
	    If rot>90 rot=90
	
	    RotateImage3D sprite3d,rot
	 	
	EndIf
store_MouseY# = rot#



jfk EO-11110(Posted 2010) [#5]
Maybe this one is useful for you:
Graphics 640,480,32,2
SetBuffer BackBuffer()

x=100
y=100
w=48
h=48
wd2=w/2
hd2=h/2
mx=x+wd2
my=y+hd2

rot#=135

While KeyHit(1)=0
 If MouseX() > x And MouseX() < x+w And MouseY() > y And MouseY() < y+h And MouseDown(1)
  flipflop=1
 EndIf
 If flipflop=1 
  rot2#=ATan2( (mx-MouseX()),(my-MouseY()) )
  rot#=rot#+(rot2#-rot#)/4.0
  If rot#<-135 Then rot#=-135
  If rot#> 135 Then rot#= 135
  If MouseDown(1)=0
   flipflop=0
  EndIf
 EndIf
 Cls
 Oval x,y,w,h,0
 Line mx,my,mx-(Sin(rot)*Float(w/2.0)),my-(Cos(rot)*Float(h/2.0))
 parameter#= (((-rot)+135)/2.7)
 Text x+10,y-20, parameter# +" %"
 VWait()
 Flip
Wend
End

you may calculate rot to a range from -90 to 90 if you need that for the RotateImage3D thing, eg:
rot_img#=((rot#)/270.0)*180.0