简体   繁体   中英

C++ How can i find the vector between 2 points in a window?

Im working on a project right now and i need to make a function that finds the vector direction for a bullet. My current code is off and i cant seem to find the reason why.

float AngleX = pMouse->X() - This->DirectionX();
float AngleY = pMouse->Y() - This->DirectionY();

The best function for finding angles from (x, y) offsets is atan2(dy, dx) , where dy and dx are the delta components in each direction.

Note that the result will be in radians, and that on some graphics systems the y axis goes down instead of up!

The particularly nice feature of atan2 is that it'll always give you the result in the full range of -π .. π which you can't get with a single acos or asin operation. The resulting angle will be the angle of the given line relative to the positive X axis, in an anti-clockwise direction.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM