- rename standard integer types to a more familiar (u)int(8/16/32) - many function/struct renames. i don't _really_ know if what i've done for this is better, but it "feels" better to me. many draw/blit function names are shorter which is nice, at least. kinda important to me because i develop this on a real DOS machine in 80x50 text mode. - add 'extern "C"' blocks to headers for C++ compiler usage - draw/pixel color value arguments for functions should all have been changed to be uint8 instead of a full 32-bit int. feels right, but maybe should've left alone... - small fix to keyboard handler. noticed a problem on one thinkpad laptop. was a result of what i think was a typo in a constant value used during the part of the interrupt handler that tells the keyboard controller the key event was processed - fix uncommon potential crash function return in draw_filled_rect - renamed low-level "direct" assembly functions to "lowlevel_xxx" to be a little bit more explicit about what they are - add some convenience event helper functions for determining event types - add fixed point atan2 - fixed some tabs/spaces inconsistences (should all be spaces now?) - maybe some other minor things i've forgotten
35 lines
834 B
C
Executable file
35 lines
834 B
C
Executable file
#include "dglmath.h"
|
|
#include <math.h>
|
|
|
|
float angle_between_i(int x1, int y1, int x2, int y2) {
|
|
int delta_x = x2 - x1;
|
|
int delta_y = y2 - y1;
|
|
if (delta_x == 0 && delta_y == 0)
|
|
return 0.0f;
|
|
else
|
|
return atan2(delta_y, delta_x);
|
|
}
|
|
|
|
float angle_between_f(float x1, float y1, float x2, float y2) {
|
|
float delta_x = x2 - x1;
|
|
float delta_y = y2 - y1;
|
|
if (close_enough(delta_x, 0.0f, TOLERANCE) && close_enough(delta_y, 0.0f, TOLERANCE))
|
|
return 0.0f;
|
|
else
|
|
return atan2(delta_y, delta_x);
|
|
}
|
|
|
|
int next_power_of_2(int n) {
|
|
int i = n & (~n + 1);
|
|
while (i < n) {
|
|
i <<= 1;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
void point_on_circle(float radius, float radians, float *x, float *y) {
|
|
*x = radius * cos(radians);
|
|
*y = radius * sin(radians);
|
|
}
|
|
|