opengl moment #1
@ -5,6 +5,7 @@
|
||||
#include "../textures.h"
|
||||
#include "../rendering.h"
|
||||
#include "../context.h"
|
||||
#include "../util.h"
|
||||
#include "quad_element_buffer.h"
|
||||
|
||||
#include <stb_ds.h>
|
||||
@ -180,9 +181,10 @@ static void render_sprites(const struct primitive_2d primitives[],
|
||||
} else {
|
||||
/* rotated case */
|
||||
const t_fvec2 c = frect_center(sprite.rect);
|
||||
const t_fvec2 t = fast_cossine(sprite.rotation + (float)M_PI_4);
|
||||
const t_fvec2 d = {
|
||||
.x = (cosf(sprite.rotation + (float)M_PI_4) * sprite.rect.w) * (float)M_SQRT1_2,
|
||||
.y = (sinf(sprite.rotation + (float)M_PI_4) * sprite.rect.h) * (float)M_SQRT1_2,
|
||||
.x = t.x * sprite.rect.w * (float)M_SQRT1_2,
|
||||
.y = t.y * sprite.rect.h * (float)M_SQRT1_2,
|
||||
};
|
||||
|
||||
payload[i] = (struct sprite_primitive_payload) {
|
||||
|
23
src/util.h
23
src/util.h
@ -154,5 +154,28 @@ void tick_ftimer(float *value);
|
||||
/* returns true if value was cycled */
|
||||
bool repeat_ftimer(float *value, float at);
|
||||
|
||||
/* http://www.azillionmonkeys.com/qed/sqroot.html */
|
||||
static inline float fast_sqrt(float x)
|
||||
{
|
||||
union {
|
||||
float f;
|
||||
uint32_t u;
|
||||
} pun = {.f = x};
|
||||
|
||||
pun.u += 127 << 23;
|
||||
pun.u >>= 1;
|
||||
|
||||
return pun.f;
|
||||
}
|
||||
|
||||
|
||||
static inline t_fvec2 fast_cossine(float a) {
|
||||
const float s = sinf(a);
|
||||
return (t_fvec2){
|
||||
.x = fast_sqrt(1.0f - s * s) * (a >= (float)M_PI_2 && a < (float)(M_PI + M_PI_2) ? -1 : 1),
|
||||
.y = s
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user