mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 02:56:43 +01:00
Add a few utils from Rumina
This commit is contained in:
parent
8d0df727cb
commit
e58fbdb560
2 changed files with 37 additions and 0 deletions
30
src/utils.c
30
src/utils.c
|
@ -117,6 +117,36 @@ SYMBOL_EXPORT int DrawWrappedTextWithShadow(ALLEGRO_FONT* font, ALLEGRO_COLOR co
|
|||
return DrawWrappedText(font, color, x, y, width, flags, text);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT void DrawCentered(ALLEGRO_BITMAP* bitmap, int x, int y, int flags) {
|
||||
al_draw_bitmap(bitmap, x - al_get_bitmap_width(bitmap) / 2.0, y - al_get_bitmap_height(bitmap) / 2.0, flags);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT double DotProduct(const double v[], const double u[], int n) {
|
||||
float result = 0.0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
result += v[i] * u[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT double VectorLength(double x, double y, double z) {
|
||||
return sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT double Clip(double left, double right, double val) {
|
||||
if (val > right) {
|
||||
return right;
|
||||
}
|
||||
if (val < left) {
|
||||
return left;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT double Lerp(double left, double right, double pos) {
|
||||
return left + (right - left) * pos;
|
||||
}
|
||||
|
||||
/* linear filtering code written by SiegeLord */
|
||||
SYMBOL_EXPORT ALLEGRO_COLOR InterpolateColor(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac) {
|
||||
return al_map_rgba_f(c1.r + frac * (c2.r - c1.r),
|
||||
|
|
|
@ -52,6 +52,13 @@ void DrawTextWithShadow(ALLEGRO_FONT* font, ALLEGRO_COLOR color, float x, float
|
|||
int DrawWrappedText(ALLEGRO_FONT* font, ALLEGRO_COLOR color, float x, float y, int width, int flags, char const* text);
|
||||
int DrawWrappedTextWithShadow(ALLEGRO_FONT* font, ALLEGRO_COLOR color, float x, float y, int width, int flags, char const* text);
|
||||
|
||||
void DrawCentered(ALLEGRO_BITMAP* bitmap, int x, int y, int flags);
|
||||
|
||||
double DotProduct(const double v[], const double u[], int n);
|
||||
double VectorLength(double x, double y, double z);
|
||||
double Clip(double left, double right, double val);
|
||||
double Lerp(double left, double right, double pos);
|
||||
|
||||
ALLEGRO_COLOR InterpolateColor(ALLEGRO_COLOR c1, ALLEGRO_COLOR c2, float frac);
|
||||
void ScaleBitmap(ALLEGRO_BITMAP* source, int width, int height);
|
||||
|
||||
|
|
Loading…
Reference in a new issue