سؤال

I have a "small" problem with my code that convert the mouse position to radiance.

I need the mouse position to determine where the head of my robot must point to. The code works and head turns ... but! It reaches max of pitch too quickly.

As I am not exactly super sharp in radiance calculation or C#, I have to resort to expert help. :)

My code:

maxcursory = Screen.PrimaryScreen.Bounds.Height;

cursory = Cursor.Position.Y;

pitch = (float) (((3 / maxcursory * cursory) - 1.5) * 1);

The min and max values I need: -0.6720 to 0.5149

Edit: Fixed code display error. ;)

Edit 2: Added min and max values

هل كانت مفيدة؟

المحلول

So you want to pick a value within your min and max based on the ratio of cursor y position to max screen height?

The current calculation for pitch gives the range from -1.5 to 1.5.

For a range between -.6720 and .5149 use:

1.1869 * cursory / maxcursory -.672

Or, generalized:

(rangeEnd-rangeStart)*(cursory / maxcursory) + rangeStart

Edit: I assumed you knew this but just in case, Cursor.Position.Y treats the top of the screen as 0 and the bottom as the same as the height. So if you wanted the top of the screen to have the value of .5149 and the bottom to be -.672 your range start and end would be .5149 and -.672 respectively.

-1.1869 * cursory / maxcursory + .5149

نصائح أخرى

It seems you have your * sign in the wrong position

pitch = (float) (((3 / maxcursory cursory *) - 1.5) * 1);

try:

pitch = (float) (((3 / maxcursory * cursory ) - 1.5) * 1);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top