Check for zero length vector in Trace
Added hasNonZeroLength member function to Vector3
This commit is contained in:
parent
4e8b4981d8
commit
797e3130d2
@ -56,6 +56,9 @@ float cTracer::SigNum(float a_Num)
|
|||||||
|
|
||||||
void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction)
|
void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction)
|
||||||
{
|
{
|
||||||
|
// Since this method should only be called by Trace, zero length vectors should already have been taken care of
|
||||||
|
ASSERT(a_Direction.hasNonZeroLength());
|
||||||
|
|
||||||
// calculate the direction of the ray (linear algebra)
|
// calculate the direction of the ray (linear algebra)
|
||||||
dir = a_Direction;
|
dir = a_Direction;
|
||||||
|
|
||||||
@ -65,10 +68,8 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction)
|
|||||||
step.z = (int) SigNum(dir.z);
|
step.z = (int) SigNum(dir.z);
|
||||||
|
|
||||||
// normalize the direction vector
|
// normalize the direction vector
|
||||||
if (dir.SqrLength() > 0.f)
|
dir.Normalize();
|
||||||
{
|
|
||||||
dir.Normalize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// how far we must move in the ray direction before
|
// how far we must move in the ray direction before
|
||||||
// we encounter a new voxel in x-direction
|
// we encounter a new voxel in x-direction
|
||||||
@ -139,6 +140,11 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction)
|
|||||||
|
|
||||||
bool cTracer::Trace(const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight)
|
bool cTracer::Trace(const Vector3f & a_Start, const Vector3f & a_Direction, int a_Distance, bool a_LineOfSight)
|
||||||
{
|
{
|
||||||
|
if(!a_Direction.hasNonZeroLength())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if ((a_Start.y < 0) || (a_Start.y >= cChunkDef::Height))
|
if ((a_Start.y < 0) || (a_Start.y >= cChunkDef::Height))
|
||||||
{
|
{
|
||||||
LOGD("%s: Start Y is outside the world (%.2f), not tracing.", __FUNCTION__, a_Start.y);
|
LOGD("%s: Start Y is outside the world (%.2f), not tracing.", __FUNCTION__, a_Start.y);
|
||||||
|
@ -78,6 +78,11 @@ public:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool hasNonZeroLength(void) const
|
||||||
|
{
|
||||||
|
return ((x != 0) || (y != 0) || (z != 0));
|
||||||
|
}
|
||||||
|
|
||||||
inline double Length(void) const
|
inline double Length(void) const
|
||||||
{
|
{
|
||||||
return sqrt(static_cast<double>(x * x + y * y + z * z));
|
return sqrt(static_cast<double>(x * x + y * y + z * z));
|
||||||
|
Loading…
Reference in New Issue
Block a user