Compare commits
No commits in common. "7972becddd4fc12a3102cc71b666b20ba00cd562" and "7f0d22e5dc640b4ba4b4845560c91bc0a5653e36" have entirely different histories.
7972becddd
...
7f0d22e5dc
@ -7,45 +7,15 @@ 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.
|
||||||
|
|
||||||
Additionally `cos(a) = sqrt(1 - sin(a) ^ 2)` is used to reuse the result of sin(a),
|
Scaling by `M_SQRT1_2` is there to retain the quad size (Pythagorean stuffs).
|
||||||
with `fast_sqrt()` for good measure.
|
|
||||||
|
|
||||||
### Code ###
|
### Code ###
|
||||||
```c
|
```c
|
||||||
/* 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 = {
|
|
||||||
.x = t.x * sprite.rect.w * (float)M_SQRT1_2,
|
|
||||||
.y = t.y * sprite.rect.h * (float)M_SQRT1_2,
|
|
||||||
};
|
|
||||||
|
|
||||||
const t_fvec2 c = frect_center(sprite.rect);
|
const t_fvec2 c = frect_center(sprite.rect);
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
/* 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,9 +65,6 @@ 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/)
|
||||||
@ -82,6 +79,7 @@ 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)
|
||||||
@ -98,7 +96,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)
|
||||||
- [No perspective interpolation for screen aligned geometry](https://registry.khronos.org/OpenGL/extensions/NV/NV_shader_noperspective_interpolation.txt)
|
- [Optimized fixed function fog](https://people.freedesktop.org/~marcheu/extensions/doc/fog_coord.html)
|
||||||
|
|
||||||
## 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