math - C# Convert mouse position to radians -
i have "small" problem code convert mouse position radiance.
i need mouse position determine head of robot must point to. code works , head turns ... but! reaches max of pitch quickly.
as not super sharp in radiance calculation or c#, have resort expert help. :)
my code:
maxcursory = screen.primaryscreen.bounds.height; cursory = cursor.position.y; pitch = (float) (((3 / maxcursory * cursory) - 1.5) * 1);
the min , max values need: -0.6720 0.5149
edit: fixed code display error. ;)
edit 2: added min , max values
so want pick value within min , max based on ratio of cursor y position max screen height?
the current calculation pitch gives range -1.5 1.5.
for range between -.6720 , .5149 use:
1.1869 * cursory / maxcursory -.672
or, generalized:
(rangeend-rangestart)*(cursory / maxcursory) + rangestart
edit: assumed knew in case, cursor.position.y
treats top of screen 0 , bottom same height. if wanted top of screen have value of .5149 , bottom -.672 range start , end .5149 , -.672 respectively.
-1.1869 * cursory / maxcursory + .5149
Comments
Post a Comment