Compare commits
2 Commits
7f0d22e5dc
...
7972becddd
Author | SHA1 | Date | |
---|---|---|---|
7972becddd | |||
16c045ba97 |
@ -7,16 +7,46 @@ CSS: /style.css
|
|||||||
A similar in essence trick to [by pi rotation](/articles/vector-pi-rotation.html), but with delta calculated
|
A similar in essence trick to [by pi rotation](/articles/vector-pi-rotation.html), but with delta calculated
|
||||||
for some corner which is reused later with negation and coordinate swap.
|
for some corner which is reused later with negation and coordinate swap.
|
||||||
|
|
||||||
Scaling by `M_SQRT1_2` is there to retain the quad size (Pythagorean stuffs).
|
Additionally `cos(a) = sqrt(1 - sin(a) ^ 2)` is used to reuse the result of sin(a),
|
||||||
|
with `fast_sqrt()` for good measure.
|
||||||
|
|
||||||
### Code ###
|
### Code ###
|
||||||
```c
|
```c
|
||||||
const t_fvec2 c = frect_center(sprite.rect);
|
/* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* instead of calculating cosf again, - use sinf result */
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/* final vertex calculation */
|
||||||
|
const t_fvec2 t = fast_cossine(sprite.rotation + (float)M_PI_4);
|
||||||
|
|
||||||
|
/* scaling by `M_SQRT1_2` is there to retain the quad size (Pythagorean stuffs). */
|
||||||
const t_fvec2 d = {
|
const t_fvec2 d = {
|
||||||
.x = (cosf(sprite.rotation + (float)M_PI_4) * sprite.rect.w) * (float)M_SQRT1_2,
|
.x = t.x * sprite.rect.w * (float)M_SQRT1_2,
|
||||||
.y = (sinf(sprite.rotation + (float)M_PI_4) * sprite.rect.h) * (float)M_SQRT1_2,
|
.y = t.y * sprite.rect.h * (float)M_SQRT1_2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const t_fvec2 c = frect_center(sprite.rect);
|
||||||
|
|
||||||
/* upper-left */
|
/* upper-left */
|
||||||
const t_fvec2 v0 = { c.x - d.x, c.y - d.y };
|
const t_fvec2 v0 = { c.x - d.x, c.y - d.y };
|
||||||
|
|
||||||
|
@ -65,6 +65,9 @@ CSS: /style.css
|
|||||||
- [Capsule collision detection](https://wickedengine.net/2020/04/26/capsule-collision-detection/)
|
- [Capsule collision detection](https://wickedengine.net/2020/04/26/capsule-collision-detection/)
|
||||||
- [Forsyth vertex cache optimization](https://tomforsyth1000.github.io/papers/fast_vert_cache_opt.html)
|
- [Forsyth vertex cache optimization](https://tomforsyth1000.github.io/papers/fast_vert_cache_opt.html)
|
||||||
- [Depth buffer based lighting](https://www.researchgate.net/publication/320616607_Eye-Dome_Lighting_a_non-photorealistic_shading_technique)
|
- [Depth buffer based lighting](https://www.researchgate.net/publication/320616607_Eye-Dome_Lighting_a_non-photorealistic_shading_technique)
|
||||||
|
- [Computational Geometry in C (Second Edition)](http://www.science.smith.edu/~jorourke/books/compgeom.html)
|
||||||
|
- [OpenGL FAQ](https://www.opengl.org/archives/resources/faq/technical/)
|
||||||
|
- [SGI BSP FAQ](https://web.archive.org/web/20010614072959/http://reality.sgi.com/bspfaq/)
|
||||||
|
|
||||||
## generational stuff
|
## generational stuff
|
||||||
- [Domain warping](https://iquilezles.org/articles/warp/)
|
- [Domain warping](https://iquilezles.org/articles/warp/)
|
||||||
@ -79,7 +82,6 @@ CSS: /style.css
|
|||||||
## notable extensions
|
## notable extensions
|
||||||
- [Vertex array locking](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_compiled_vertex_array.txt)
|
- [Vertex array locking](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_compiled_vertex_array.txt)
|
||||||
- [Packed pixels](https://people.freedesktop.org/~marcheu/extensions/EXT/packed_pixels.html)
|
- [Packed pixels](https://people.freedesktop.org/~marcheu/extensions/EXT/packed_pixels.html)
|
||||||
- [Provoking vertex](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_provoking_vertex.txt)
|
|
||||||
- [Framebuffer fetch](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_shader_framebuffer_fetch.txt)
|
- [Framebuffer fetch](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_shader_framebuffer_fetch.txt)
|
||||||
- [Integer textures](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_integer.txt)
|
- [Integer textures](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_integer.txt)
|
||||||
- [Texture swizzle](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_swizzle.txt)
|
- [Texture swizzle](https://registry.khronos.org/OpenGL/extensions/EXT/EXT_texture_swizzle.txt)
|
||||||
@ -96,7 +98,7 @@ CSS: /style.css
|
|||||||
- [Shader inter group communication](https://registry.khronos.org/OpenGL/extensions/ARB/ARB_shader_ballot.txt)
|
- [Shader inter group communication](https://registry.khronos.org/OpenGL/extensions/ARB/ARB_shader_ballot.txt)
|
||||||
- [Granular buffer memory control](https://registry.khronos.org/OpenGL/extensions/ARB/ARB_sparse_buffer.txt)
|
- [Granular buffer memory control](https://registry.khronos.org/OpenGL/extensions/ARB/ARB_sparse_buffer.txt)
|
||||||
- [Window pos](https://people.freedesktop.org/~marcheu/extensions/ARB/window_pos.html)
|
- [Window pos](https://people.freedesktop.org/~marcheu/extensions/ARB/window_pos.html)
|
||||||
- [Optimized fixed function fog](https://people.freedesktop.org/~marcheu/extensions/doc/fog_coord.html)
|
- [No perspective interpolation for screen aligned geometry](https://registry.khronos.org/OpenGL/extensions/NV/NV_shader_noperspective_interpolation.txt)
|
||||||
|
|
||||||
## data representations
|
## data representations
|
||||||
- [Efficient varying-length integers](https://john-millikin.com/vu128-efficient-variable-length-integers)
|
- [Efficient varying-length integers](https://john-millikin.com/vu128-efficient-variable-length-integers)
|
||||||
|
Loading…
Reference in New Issue
Block a user