Archived

This topic is now archived and is closed to further replies.

Help with implimenting arvos algoithm for a cube and ellipsoid

This topic is 5621 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I am using an octree in my code and I need to detect if my camera, which is represented by an ellipsoid is overlapping nodes, hence I turned to arvo''s algorithm to detect this case. But Arvo''s uses a sphere. How do I modify arvo''s to work with an ellipsoid? My ellipsoid is reprsented by a position and radius vector that specificies the radius of the ellipsoid with respect to the x, y, and z axis. I have tried multiplying the radius vector by its reciprocal, then multiplying the node cube''s center point and its extents(used to get the max and min of the cube) by this reciprocal vector, but its not working. What have I missed? Thanks.
  bool COctree::CameraOverlappingNode()
{
	CVector3 reciprocal = g_Camera.GetCameraRadiusVector().Reciprocal();
	CVector3 center(m_vCenter.x * reciprocal.x, m_vCenter.y * reciprocal.y, m_vCenter.z * reciprocal.z);
	CVector3 extents(m_Width / 2 * reciprocal.x, m_Width / 2 * reciprocal.y, m_Width / 2 * reciprocal.z);
	CAabb nodeBox(center, extents);
	return AABBOverlapsSphere(nodeBox, 1.0f, g_Camera.GetCameraPosition());

}

bool AABBOverlapsSphere(CAabb& box, const scalar_t radius, CVector3& center)
 {
	scalar_t s, d = 0;

	// find the square of the distance from the sphere to the box

	for(int i = 0; i < 3; i++)
	{
		if(center(i) < box.Min(i))
		{
			s = center(i) - box.Min(i);
			d += s*s;
		}

		else if(center(i) > box.Max(i))
		{
			s = center(i) - box.Max(i);
			d += s*s;
		}
	}
	return d <= radius * radius;
}


class CAabb
{
	public:
	
	CVector3 position;
	CVector3 extents;

	CAabb(const CVector3& p, const CVector3& e): position(p), extents(e) {};

	const scalar_t Min(int i) const
	{
		return ((CAabb*)this)->position(i) - ((CAabb*)this)->extents(i);

	};

	const scalar_t Max(int i) const
	{
		return ((CAabb*)this)->position(i) + ((CAabb*)this)->extents(i);
	};

	const bool Overlaps(const CAabb& b) const
	{
		const CVector3 t = b.position - position;
		return fabsf(t.x) <= (extents.x + b.extents.x)
			&&
			fabsf(t.y) <= (extents.y + b.extents.y)
			&&
			fabsf(t.z) <= (extents.y + b.extents.y);
	};
};   

Share this post


Link to post
Share on other sites