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 ?
Posted on 2003-04-29 11:25:16 by Nguga
Circle centered at (Cx, Cy)
Mouse at (Mx, My)

angle in radians = arctan( (My-Cy) / (Mx-Cx) ) ; see FPATAN
Posted on 2003-04-29 11:52:28 by bitRAKE
bitRAKE thanks for the asm instruction FPATAN !

but i?m asking if my solution is ok or not .
Posted on 2003-04-29 14:41:49 by Nguga
Nah, that's not right. That would return -dp sin a. You have to use FPATAN like he said.
Posted on 2003-04-29 15:21:56 by Sephiroth3
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

:)
Posted on 2003-04-29 16:13:05 by Nguga
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?
Posted on 2003-04-29 16:25:05 by Nguga
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

    [*]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. :)
Posted on 2003-04-29 19:14:00 by bitRAKE
bitRAKE is back?

I thought you were gone?

:alright:
Posted on 2003-04-29 21:19:38 by IwasTitan

bitRAKE is back?

I thought you were gone?

:alright:
Sheeeh, I am gone. :)
Posted on 2003-04-29 22:43:04 by bitRAKE
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 ...
Posted on 2003-04-30 13:16:12 by Nguga
Use fldpi

Mirno
Posted on 2003-04-30 14:07:14 by 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.
Posted on 2003-04-30 23:08:32 by NaN
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 :)
Posted on 2003-05-01 02:35:07 by f0dder
Sorry it is for FASM, but I think its no trouble to understand main code here.
Posted on 2003-05-01 23:14:02 by comrade
comrade, very consise code, good example. :alright:
Posted on 2003-05-01 23:23:21 by bitRAKE
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.
Posted on 2003-05-05 06:40:35 by Nguga
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
Posted on 2003-05-05 06:56:48 by Thomas