Add handling of zero length vector to normalization methods
- Avoids having division by zero
This commit is contained in:
parent
d71dfd170b
commit
d96780a88e
@ -739,19 +739,25 @@ namespace Game
|
|||||||
{
|
{
|
||||||
const float length = std::sqrt((vec[0] * vec[0]) + (vec[1] * vec[1]));
|
const float length = std::sqrt((vec[0] * vec[0]) + (vec[1] * vec[1]));
|
||||||
|
|
||||||
|
if(length > 0.0f)
|
||||||
|
{
|
||||||
vec[0] /= length;
|
vec[0] /= length;
|
||||||
vec[1] /= length;
|
vec[1] /= length;
|
||||||
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vec3Normalize(vec3_t& vec)
|
float Vec3Normalize(vec3_t& vec)
|
||||||
{
|
{
|
||||||
const float length = static_cast<float>(std::sqrt(std::pow(vec[0], 2) + std::pow(vec[1], 2) + std::pow(vec[2], 2)));
|
const float length = std::sqrt(std::pow(vec[0], 2.0f) + std::pow(vec[1], 2.0f) + std::pow(vec[2], 2.0f));
|
||||||
|
|
||||||
|
if(length > 0.0f)
|
||||||
|
{
|
||||||
vec[0] /= length;
|
vec[0] /= length;
|
||||||
vec[1] /= length;
|
vec[1] /= length;
|
||||||
vec[2] /= length;
|
vec[2] /= length;
|
||||||
|
}
|
||||||
|
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user