const Vector3* AxisAlignedBox::getAllCorners(void) const
	{
		PE_ASSERT((mExtent == EXTENT_FINITE) && "Can't get corners of a null or infinite AAB");

		// The order of these items is, using right-handed co-ordinates:
		// Minimum Z face, starting with Min(all), then anticlockwise
		//   around face (looking onto the face)
		// Maximum Z face, starting with Max(all), then anticlockwise
		//   around face (looking onto the face)
		// Only for optimization/compatibility.
		if (!mpCorners)
			mpCorners = new Vector3[8];

		mpCorners[0] = mMinimum;
		mpCorners[1].x = mMinimum.x; mpCorners[1].y = mMaximum.y; mpCorners[1].z = mMinimum.z;
		mpCorners[2].x = mMaximum.x; mpCorners[2].y = mMaximum.y; mpCorners[2].z = mMinimum.z;
		mpCorners[3].x = mMaximum.x; mpCorners[3].y = mMinimum.y; mpCorners[3].z = mMinimum.z;

		mpCorners[4] = mMaximum;
		mpCorners[5].x = mMinimum.x; mpCorners[5].y = mMaximum.y; mpCorners[5].z = mMaximum.z;
		mpCorners[6].x = mMinimum.x; mpCorners[6].y = mMinimum.y; mpCorners[6].z = mMaximum.z;
		mpCorners[7].x = mMaximum.x; mpCorners[7].y = mMinimum.y; mpCorners[7].z = mMaximum.z;

		return mpCorners;
	}
Example #2
0
wchar_t * _itow(int value,	wchar_t *str,	int radix)
{
	PE_ASSERT(radix == 10);
	// assume buffer is smaller than 100. This is not full port. 
	swprintf(str, 100, L"%d", value);
	return str;
}
	void AxisAlignedBox::setExtents(const Vector3& min, const Vector3& max)
	{
		PE_ASSERT((min.x <= max.x && min.y <= max.y && min.z <= max.z) &&
			"The minimum corner of the box must be less than or equal to maximum corner");

		mExtent = EXTENT_FINITE;
		mMinimum = min;
		mMaximum = max;
	}
	ParaEngine::Vector3 AxisAlignedBox::getCenter(void) const
	{
		PE_ASSERT((mExtent == EXTENT_FINITE) && "Can't get center of a null or infinite AAB");

		return Vector3(
			(mMaximum.x + mMinimum.x) * 0.5f,
			(mMaximum.y + mMinimum.y) * 0.5f,
			(mMaximum.z + mMinimum.z) * 0.5f);
	}
Example #5
0
	void BMaxObject::SetPhysicsGroup(int nGroup)
	{
		PE_ASSERT(0 <= nGroup && nGroup < 32);
		if (m_nPhysicsGroup != nGroup)
		{
			m_nPhysicsGroup = nGroup;
			UnloadPhysics();
		}
	}
	void AxisAlignedBox::setExtents(float mx, float my, float mz, float Mx, float My, float Mz)
	{
		PE_ASSERT((mx <= Mx && my <= My && mz <= Mz) &&
			"The minimum corner of the box must be less than or equal to maximum corner");

		mExtent = EXTENT_FINITE;

		mMinimum.x = mx;
		mMinimum.y = my;
		mMinimum.z = mz;

		mMaximum.x = Mx;
		mMaximum.y = My;
		mMaximum.z = Mz;
	}
Example #7
0
/**
* _findclose - equivalent
*/
int _findclose(long h)
{
	if (h==-1) return 0;

	if (h < 0 || h >= (long)fileInfo.size())
	{
		PE_ASSERT(false);
		return -1;
	}

	_findinfo_t* fi = fileInfo[h];
	closedir(fi->openedDir);
	fileInfo.clear();
	delete fi;
	return 0;   
}
Example #8
0
int _findnext(long h, _finddata_t *f)
{
	PE_ASSERT(h >= 0 && h < (long)fileInfo.size());
	if (h < 0 || h >= (long)fileInfo.size()) return -1;

	_findinfo_t* fi = fileInfo[h];

	while(true)
	{
		dirent* entry = readdir(fi->openedDir);
		if(entry == 0) return -1;

		// Only report stuff matching our filter
		if (fnmatch(fi->filter.c_str(), entry->d_name, FNM_PATHNAME) != 0) continue;

		// To reliably determine the entry's type, we must do
		// a stat...  don't rely on entry->d_type, as this
		// might be unavailable!
		struct stat filestat;
		std::string fullPath = fi->dirName + entry->d_name;             
		if (stat(fullPath.c_str(), &filestat) != 0)
		{
			OUTPUT_LOG("Cannot stat %s\n", fullPath.c_str());
			continue;
		}

		if (S_ISREG(filestat.st_mode))
		{
			f->attrib = _A_NORMAL;
		} else if (S_ISDIR(filestat.st_mode))
		{
			f->attrib = _A_SUBDIR;                    
		} else continue; // We are interested in files and
		// directories only. Links currently
		// are not supported.

		f->size = filestat.st_size;
		strncpy(f->name, entry->d_name, STRING_BUFFER_SIZE);

		return 0;
	}

	return -1;
}
	void AxisAlignedBox::merge(const Vector3& point)
	{
		switch (mExtent)
		{
		case EXTENT_NULL: // if null, use this point
			setExtents(point, point);
			return;

		case EXTENT_FINITE:
			mMaximum.makeCeil(point);
			mMinimum.makeFloor(point);
			return;

		case EXTENT_INFINITE: // if infinite, makes no difference
			return;
		}

		PE_ASSERT(false && "Never reached");
	}
Example #10
0
	void AxisAlignedBox::transformAffine(const Matrix4& m)
	{
		PE_ASSERT(m.isAffine());

		// Do nothing if current null or infinite
		if (mExtent != EXTENT_FINITE)
			return;

		Vector3 centre = getCenter();
		Vector3 halfSize = getHalfSize();

		Vector3 newCentre = m.transformAffine(centre);
		Vector3 newHalfSize(
			Math::Abs(m[0][0]) * halfSize.x + Math::Abs(m[0][1]) * halfSize.y + Math::Abs(m[0][2]) * halfSize.z,
			Math::Abs(m[1][0]) * halfSize.x + Math::Abs(m[1][1]) * halfSize.y + Math::Abs(m[1][2]) * halfSize.z,
			Math::Abs(m[2][0]) * halfSize.x + Math::Abs(m[2][1]) * halfSize.y + Math::Abs(m[2][2]) * halfSize.z);

		setExtents(newCentre - newHalfSize, newCentre + newHalfSize);
	}
Example #11
0
	bool AxisAlignedBox::intersects(const Vector3& v) const
	{
		switch (mExtent)
		{
		case EXTENT_NULL:
			return false;

		case EXTENT_FINITE:
			return(v.x >= mMinimum.x  &&  v.x <= mMaximum.x  &&
				v.y >= mMinimum.y  &&  v.y <= mMaximum.y  &&
				v.z >= mMinimum.z  &&  v.z <= mMaximum.z);

		case EXTENT_INFINITE:
			return true;

		default: // shut up compiler
			PE_ASSERT(false && "Never reached");
			return false;
		}
	}
Example #12
0
	ParaEngine::Vector3 AxisAlignedBox::getSize(void) const
	{
		switch (mExtent)
		{
		case EXTENT_NULL:
			return Vector3::ZERO;

		case EXTENT_FINITE:
			return mMaximum - mMinimum;

		case EXTENT_INFINITE:
			return Vector3(
				Math::POS_INFINITY,
				Math::POS_INFINITY,
				Math::POS_INFINITY);

		default: // shut up compiler
			PE_ASSERT(false && "Never reached");
			return Vector3::ZERO;
		}
	}
Example #13
0
	float AxisAlignedBox::volume(void) const
	{
		switch (mExtent)
		{
		case EXTENT_NULL:
			return 0.0f;

		case EXTENT_FINITE:
		{
							  Vector3 diff = mMaximum - mMinimum;
							  return diff.x * diff.y * diff.z;
		}

		case EXTENT_INFINITE:
			return Math::POS_INFINITY;

		default: // shut up compiler
			PE_ASSERT(false && "Never reached");
			return 0.0f;
		}
	}