165 const glm::mat4& proj,
166 const glm::vec3& axis,
168 std::int32_t& in_out_min_x,
169 std::int32_t& in_out_max_x)
171 auto view_x = float(in_out_min_x);
172 auto view_size_x = float(in_out_max_x - in_out_min_x);
176 if(discriminant >= 0)
178 float sqrt_discriminant = glm::sqrt(discriminant);
179 float inv_light_square = 1.0f / (
square(light_x) +
square(light_z));
181 float Nxa = (radius * light_x - sqrt_discriminant) * inv_light_square;
182 float Nxb = (radius * light_x + sqrt_discriminant) * inv_light_square;
183 float Nza = (radius - Nxa * light_x) / light_z;
184 float Nzb = (radius - Nxb * light_x) / light_z;
185 float Pza = light_z - radius * Nza;
186 float Pzb = light_z - radius * Nzb;
191 float Pxa = -Pza * Nza / Nxa;
192 glm::vec4 P = proj * glm::vec4(axis.x * Pxa, axis.y * Pxa, Pza, 1);
193 float X = (glm::dot(glm::vec3(P), axis) / P.w + 1.0f * axis_sign) / 2.0f * axis_sign;
196 in_out_max_x = std::min<std::int32_t>(std::int32_t(glm::ceil(view_size_x * X + view_x)), in_out_max_x);
200 in_out_min_x = std::max<std::int32_t>(std::int32_t(glm::floor(view_size_x * X + view_x)), in_out_min_x);
207 float Pxb = -Pzb * Nzb / Nxb;
208 glm::vec4 P = proj * glm::vec4(axis.x * Pxb, axis.y * Pxb, Pzb, 1);
209 float X = (glm::dot(glm::vec3(P), axis) / P.w + 1.0f * axis_sign) / 2.0f * axis_sign;
212 in_out_max_x = std::min<std::int32_t>(std::int32_t(glm::ceil(view_size_x * X + view_x)), in_out_max_x);
216 in_out_min_x = std::max<std::int32_t>(std::int32_t(glm::floor(view_size_x * X + view_x)), in_out_min_x);
221 return in_out_min_x <= in_out_max_x;
228 std::int32_t& bottom,
229 const glm::vec3& sphere_center,
231 const glm::vec3& view_origin,
232 const glm::mat4& view,
233 const glm::mat4& proj)
236 if(glm::length2(sphere_center - view_origin) >
square(radius))
238 glm::vec3 lv = glm::vec3(view * glm::vec4(sphere_center, 1.0f));
std::uint32_t compute_projected_sphere_rect(std::int32_t &left, std::int32_t &right, std::int32_t &top, std::int32_t &bottom, const glm::vec3 &sphere_center, float radius, const glm::vec3 &view_origin, const glm::mat4 &view, const glm::mat4 &proj)
bool compute_projected_sphere_shaft(float light_x, float light_z, float radius, const glm::mat4 &proj, const glm::vec3 &axis, float axis_sign, std::int32_t &in_out_min_x, std::int32_t &in_out_max_x)