|
From: <axl...@us...> - 2010-04-25 17:59:49
|
Revision: 695
http://hgengine.svn.sourceforge.net/hgengine/?rev=695&view=rev
Author: axlecrusher
Date: 2010-04-25 17:59:43 +0000 (Sun, 25 Apr 2010)
Log Message:
-----------
box intersection
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/BoundingBox.h
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2010-04-25 02:50:12 UTC (rev 694)
+++ Mercury2/src/BoundingBox.cpp 2010-04-25 17:59:43 UTC (rev 695)
@@ -109,12 +109,22 @@
*this = bb;
}
+float BoundingBox::ComputeRadius() const
+{
+/* MercuryVertex p(m_center+m_extend);
+ float r = (m_center-p).Length();
+ if (abs(m_extend.Length() - r) > .000001) printf("wrong %f %f\n",m_extend.Length(), r);
+ return (m_center-p).Length();
+ */
+ return m_extend.Length(); //this is actually correct, verified above
+}
+
bool BoundingBox::Clip( const MercuryPlane& p )
{
//do a quick spherical test using the signed distance
//from the center of the box
float d = p.GetNormal().DotProduct( m_center - p.GetCenter() );
- if (d < -m_extend.Length()) return true; //sphere is further than radius distance behind plane
+ if (d < -ComputeRadius()) return true; //sphere is further than radius distance behind plane
//all points must be behind a plane to be considered clipped
bool clip = true;
@@ -133,6 +143,15 @@
return clipped;
}
+bool BoundingBox::Intersect( const BoundingBox& b )
+{
+ MercuryVector d(m_center - b.m_center);
+ if ( d.Length() > (ComputeRadius()+b.ComputeRadius()) ) return false; //quick circle check
+
+ MercuryVector l(m_extend+b.GetExtend());
+ return l.GetX()<=abs(d.GetX()) && l.GetY()<=abs(d.GetY()) && l.GetZ()<=abs(d.GetZ());
+}
+
bool BoundingBox::DoFrustumTest( const MercuryMatrix& m )
{
BoundingBox bb(*this);
Modified: Mercury2/src/BoundingBox.h
===================================================================
--- Mercury2/src/BoundingBox.h 2010-04-25 02:50:12 UTC (rev 694)
+++ Mercury2/src/BoundingBox.h 2010-04-25 17:59:43 UTC (rev 695)
@@ -85,10 +85,13 @@
virtual bool Clip( const MercuryPlane& p );
virtual bool Clip( const Frustum& f );
+ virtual bool Intersect( const BoundingBox& b );
+
virtual bool DoFrustumTest( const MercuryMatrix& m );
virtual void DoOcclusionTest(OcclusionResult& result);
private:
+ float ComputeRadius() const;
void ComputeNormals();
static void PopulateVertices();
static void InitVBO();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|