well i ask your opinion on my solution to resolve the (x,y) position of the
knob indicator.
i know that the formula for a body moving around a circle is :
x = - radio * sin t
y = radio * cos t
my initial problem was how to know the angle ... :)
so i think i resolve this by knowing that a circle has 4 quadrantes each of them
90? .
here the image:
please let me know what you think ! is this idea crazy ?
knob indicator.
i know that the formula for a body moving around a circle is :
x = - radio * sin t
y = radio * cos t
my initial problem was how to know the angle ... :)
so i think i resolve this by knowing that a circle has 4 quadrantes each of them
90? .
here the image:

please let me know what you think ! is this idea crazy ?
Circle centered at (Cx, Cy)
Mouse at (Mx, My)
angle in radians = arctan( (My-Cy) / (Mx-Cx) ) ; see FPATAN
Mouse at (Mx, My)
angle in radians = arctan( (My-Cy) / (Mx-Cx) ) ; see FPATAN
bitRAKE thanks for the asm instruction FPATAN !
but i?m asking if my solution is ok or not .
but i?m asking if my solution is ok or not .
Nah, that's not right. That would return -dp sin a. You have to use FPATAN like he said.
i think is ok !
supose that the mouse is at 1 quandrante (that is easy to program)
and r = 10 ( radio )
and we know by mouse position that d= 5
then the angle is = d/r * 90?
5/10 * 90 ? = 0,5 * 90? = 45 ?
**********************************************
another example if d = 0
0/10*90? = 0 ?
another example if d = r = 10
10/10*90?= 90?
well for me it seems to work ok
:)
supose that the mouse is at 1 quandrante (that is easy to program)
and r = 10 ( radio )
and we know by mouse position that d= 5
then the angle is = d/r * 90?
5/10 * 90 ? = 0,5 * 90? = 45 ?
**********************************************
another example if d = 0
0/10*90? = 0 ?
another example if d = r = 10
10/10*90?= 90?
well for me it seems to work ok
:)
i code in form to know the quadrante were the mouse is rotating the knob
=====================================================
formula for quadrante 1
angle= d/r * 90?
formula for quadrante 2
angle=180? - d/r * 90
formula for quadrante 3
angle= d/r * 90? + 180?
formula for quadrante 4
angle= 360 - d/r * 90?
=====================================================
formula for quadrante 1
angle= d/r * 90?
formula for quadrante 2
angle=180? - d/r * 90
formula for quadrante 3
angle= d/r * 90? + 180?
formula for quadrante 4
angle= 360 - d/r * 90?
Nguga, let us talk about the control first. I think the user should be able to grab the knob from anywhere around and change value. This involves these steps:
A. get initial angle when mouse down in circle of knob
A. get initial angle when mouse down in circle of knob
[*]start angle in radians = arctan( (My-Cy) / (Mx-Cx) )
B. track change in angle from start until mouse up
[*]current angle in radians = arctan( (My-Cy) / (Mx-Cx) )
[*]change in value = [(current angle in radians) - (start angle in radians)] * (max value)/(2*pi)
This is all you need to get value of knob. Quadrante not important here.
I am sorry - I miss-understood the question!
The knob angle in radians is = [ 2*pi / (max value) ] * (current value)
; (current value) ranges from 0 to (max value) - 1
; or from 1 to (max value)
; both work
Then use SIN and COS with R to find X and Y -- you already know. :)
bitRAKE is back?
I thought you were gone?
:alright:
I thought you were gone?
:alright:
bitRAKE is back?
I thought you were gone?
:alright:
Thankyo Very Much !
:)
i will try to implement such aproach us well , know i?m learning how to use FPU in NASM
then i will use as base code my already done Owner Drawn Bitmap Slider .
if here any one knows NASM FPU please post some examples for calculating
SIN and COS .
i think is like this:
section data
pi equ 3,1416
max_value equ 100
R equ 50
current_value dd 0
x dd 0
section code
;; angle_radians = [ 2*pi / (max_value) ] * (current_value)
fild dword pi ; 3,1415 to st0
fmul 2 ; 2*pi
fdiv max_value ; 2*3,1415/max_value
fmul ; 2*3,1415/max_value*current_value
fistp dword ; place result on angle_radians var
;; x = R * sin (angle_radians)
fild dword ; var to st0
fsin ;sin
fmul R ;sin * R
fistp dword ; x is the result
i will try this ...
:)
i will try to implement such aproach us well , know i?m learning how to use FPU in NASM
then i will use as base code my already done Owner Drawn Bitmap Slider .
if here any one knows NASM FPU please post some examples for calculating
SIN and COS .
i think is like this:
section data
pi equ 3,1416
max_value equ 100
R equ 50
current_value dd 0
x dd 0
section code
;; angle_radians = [ 2*pi / (max_value) ] * (current_value)
fild dword pi ; 3,1415 to st0
fmul 2 ; 2*pi
fdiv max_value ; 2*3,1415/max_value
fmul ; 2*3,1415/max_value*current_value
fistp dword ; place result on angle_radians var
;; x = R * sin (angle_radians)
fild dword ; var to st0
fsin ;sin
fmul R ;sin * R
fistp dword ; x is the result
i will try this ...
Use fldpi
Mirno
Mirno
Nguga,
Your ratio to 90Deg is only an approximation, it is not the correct angle. Trig is non-linear and your trying to make it fit to linear by your approximation above.
To help you see, i have plotted the correct (blue) and your d/r*90 approximation (green)
If you can live with error that gets worse at +/- 90 degrees, then go for it, if not, then you should consider more exacting methods that bitRAKE has offered.
Your ratio to 90Deg is only an approximation, it is not the correct angle. Trig is non-linear and your trying to make it fit to linear by your approximation above.
To help you see, i have plotted the correct (blue) and your d/r*90 approximation (green)
If you can live with error that gets worse at +/- 90 degrees, then go for it, if not, then you should consider more exacting methods that bitRAKE has offered.
For something like this, is there any point in choosing the approximation? It shouldn't be a very CPU-intensive operation... there's a limit to how fast you can move your mouse :)
Sorry it is for FASM, but I think its no trouble to understand main code here.
comrade, very consise code, good example. :alright:
i must say that i never thought that this was so dificult
THANK all of YOU ! :)
Here is the bitmap owner drawn Knob Slider its almost working , but it has a bug , i think is when i use the FPU to calculate the radians .
the is -> the knob rotates ok but does circle with jumps in the path.
( fistp fstp .... )
Please , try to see the the knob-rotin.asm i think the bug is there.
THANK all of YOU ! :)
Here is the bitmap owner drawn Knob Slider its almost working , but it has a bug , i think is when i use the FPU to calculate the radians .
the is -> the knob rotates ok but does circle with jumps in the path.
( fistp fstp .... )
Please , try to see the the knob-rotin.asm i think the bug is there.
Here's a snippet I wrote once to determine the angle of two relative x and y deltas.
http://www.madwizard.org/snippets/viewSnippet.php?s_ID=20
It returns the angle in tenths of degrees (0 - 3599).
Thomas
http://www.madwizard.org/snippets/viewSnippet.php?s_ID=20
It returns the angle in tenths of degrees (0 - 3599).
Thomas