MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / octahedron_encode

Method octahedron_encode

core/math/vector3.cpp:112–126  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112Vector2 Vector3::octahedron_encode() const {
113 Vector3 n = *this;
114 n /= Math::abs(n.x) + Math::abs(n.y) + Math::abs(n.z);
115 Vector2 o;
116 if (n.z >= 0.0f) {
117 o.x = n.x;
118 o.y = n.y;
119 } else {
120 o.x = (1.0f - Math::abs(n.y)) * (n.x >= 0.0f ? 1.0f : -1.0f);
121 o.y = (1.0f - Math::abs(n.x)) * (n.y >= 0.0f ? 1.0f : -1.0f);
122 }
123 o.x = o.x * 0.5f + 0.5f;
124 o.y = o.y * 0.5f + 0.5f;
125 return o;
126}
127
128Vector3 Vector3::octahedron_decode(const Vector2 &p_oct) {
129 Vector2 f(p_oct.x * 2.0f - 1.0f, p_oct.y * 2.0f - 1.0f);

Callers 6

_fix_array_compatibilityFunction · 0.80
_compress_keyMethod · 0.80
surface_endMethod · 0.80
draw_texture_rectMethod · 0.80
set_normalMethod · 0.80
_surface_set_dataMethod · 0.80

Calls 1

absFunction · 0.70

Tested by

no test coverage detected