Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3315)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaderenv.h	(revision 3318)
@@ -8,6 +8,6 @@
 //#define NUM_SAMPLES 8
 //#define NUM_SAMPLES 16
-//#define NUM_SAMPLES 24
-#define NUM_SAMPLES 48
+#define NUM_SAMPLES 24
+//#define NUM_SAMPLES 48
 
 //#define MIN_SAMPLES 48
@@ -61,5 +61,5 @@
 #define NUM_DOF_TABS 16
 
-#define USE_GTX
+//#define USE_GTX
 
 #define SSAO_FILTER_RADIUS 5
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h	(revision 3243)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.h	(revision 3318)
@@ -25,5 +25,5 @@
 	SimpleRay(const Vector3 &o, const Vector3 &d): mOrigin(o), mDirection(d) {}
 
-	Vector3 Extrap(const float t) const 
+	Vector3 Extrap(float t) const 
 	{
 		return mOrigin + mDirection * t;
@@ -41,5 +41,5 @@
 /** Axis alignedd box class.
     This is a box in 3-space, defined by min and max
-	corner vectors.  Many useful operations are defined.
+	corner vectors. Many useful operations are defined.
 */
 class AxisAlignedBox3
@@ -70,14 +70,14 @@
 	/** Computes the mid point in the given axis.
 	*/
-	float Center(const int axis) const;
+	float Center(int axis) const;
 	/** The vertex of the box with the smallest values in all dimensions.
 	*/
-	float Min(const int axis) const;
+	float Min(int axis) const;
 	/** The vertex of the box with the largest values in all dimensions.
 	*/
-	float Max(const int axis) const;
+	float Max(int axis) const;
 	/** The extent of the box in the given axis.
 	*/
-	float Size(const int axis) const;
+	float Size(int axis) const;
 	/** Returns axis where box has largest extent.
 	*/
@@ -138,5 +138,5 @@
 	/** Expand the axis-aligned box to include given values in particular axis.
 	*/
-	void Include(const int &axis, const float &newBound);
+	void Include(int axis, float newBound);
 	/** Includes returns true if a includes b (completely)
 	*/
@@ -243,5 +243,5 @@
 	/** Returns the supporting plane of this face.
 	*/
-	Plane3 GetPlane(const int face) const;
+	Plane3 GetPlane(int face) const;
 	/** Returns 
 		0 if box intersects plane
@@ -358,6 +358,8 @@
 
 
-// --------------------------------------------------------------------------
-// Implementation of inline (member) functions
+
+/////////////////////////////////////////////////////////
+//-- Implementation of inline (member) functions
+
 
 inline float AxisAlignedBox3::Radius() const 
@@ -373,6 +375,6 @@
 
 
-inline bool
-Overlap(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y)
+inline bool Overlap(const AxisAlignedBox3 &x,
+					const AxisAlignedBox3 &y)
 {
 	if (x.mMax.x < y.mMin.x ||
@@ -381,12 +383,15 @@
 		x.mMin.y > y.mMax.y ||
 		x.mMax.z < y.mMin.z ||
-		x.mMin.z > y.mMax.z) {
+		x.mMin.z > y.mMax.z)
+	{
 			return false;
 	}
+
 	return true;
 }
 
-inline bool
-OverlapS(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y)
+
+inline bool OverlapS(const AxisAlignedBox3 &x, 
+					 const AxisAlignedBox3 &y)
 {
 	if (x.mMax.x <= y.mMin.x ||
@@ -395,58 +400,77 @@
 		x.mMin.y >= y.mMax.y ||
 		x.mMax.z <= y.mMin.z ||
-		x.mMin.z >= y.mMax.z) {
+		x.mMin.z >= y.mMax.z) 
+	{
 			return false;
 	}
+
 	return true;
 }
 
-inline bool
-Overlap(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y, float eps)
-{
-	if ( (x.mMax.x - eps) < y.mMin.x ||
+
+inline bool Overlap(const AxisAlignedBox3 &x,
+					const AxisAlignedBox3 &y,
+					float eps)
+{
+	if ((x.mMax.x - eps) < y.mMin.x ||
 		(x.mMin.x + eps) > y.mMax.x ||
 		(x.mMax.y - eps) < y.mMin.y ||
 		(x.mMin.y + eps) > y.mMax.y ||
 		(x.mMax.z - eps) < y.mMin.z ||
-		(x.mMin.z + eps) > y.mMax.z ) {
+		(x.mMin.z + eps) > y.mMax.z ) 
+	{
 			return false;
 	}
+
 	return true;
 }
 
-inline AxisAlignedBox3
-Intersect(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y)
-{
-	if (x.Unbounded())
+
+inline AxisAlignedBox3 Intersect(const AxisAlignedBox3 &x,
+								 const AxisAlignedBox3 &y)
+{
+	if (x.Unbounded()) 
+	{
 		return y;
+	}
 	else
-		if (y.Unbounded())
-			return x;
+	{
+		if (y.Unbounded()) return x;
+	}
+
 	AxisAlignedBox3 ret = x;
-	if (Overlap(ret, y)) {
+
+	if (Overlap(ret, y)) 
+	{
 		Maximize(ret.mMin, y.mMin);
 		Minimize(ret.mMax, y.mMax);
+
 		return ret;
 	}
-	else      // Null intersection.
+	else // Null intersection
+	{
 		return AxisAlignedBox3(Vector3(0), Vector3(0));
-	// return AxisAlignedBox3(Vector3(0), Vector3(-1));
-}
-
-inline AxisAlignedBox3
-Union(const AxisAlignedBox3 &x, const AxisAlignedBox3 &y)
+	}
+}
+
+
+inline AxisAlignedBox3 Union(const AxisAlignedBox3 &x, 
+							 const AxisAlignedBox3 &y)
 {
 	Vector3 min = x.mMin;
 	Vector3 max = x.mMax;
+
 	Minimize(min, y.mMin);
 	Maximize(max, y.mMax);
+
 	return AxisAlignedBox3(min, max);
 }
 
-inline AxisAlignedBox3
-Transform(const AxisAlignedBox3 &box, const Matrix4x4 &tform)
-{
-	Vector3 mmin(MAXFLOAT);
-	Vector3 mmax(-MAXFLOAT);
+
+inline AxisAlignedBox3 Transform(const AxisAlignedBox3 &box, 
+								 const Matrix4x4 &tform)
+{
+	const Vector3 mmin(MAXFLOAT);
+	const Vector3 mmax(-MAXFLOAT);
 	
 	AxisAlignedBox3 ret(mmin, mmax);
@@ -464,5 +488,7 @@
 }
 
-inline float RatioOfOverlap(const AxisAlignedBox3 &box1, const AxisAlignedBox3 &box2)
+
+inline float RatioOfOverlap(const AxisAlignedBox3 &box1,
+							const AxisAlignedBox3 &box2)
 {
 	// return ratio of intersection to union
@@ -473,5 +499,7 @@
 }
 
-inline int operator==(const AxisAlignedBox3 &A, const AxisAlignedBox3 &B)
+
+inline int operator==(const AxisAlignedBox3 &A, 
+					  const AxisAlignedBox3 &B)
 {
 	return (A.mMin == B.mMin) && (A.mMax == B.mMax);
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3305)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsao.cg	(revision 3318)
@@ -161,4 +161,5 @@
 	if (col.w < DEPTH_THRESHOLD)
 	{
+	{
 		OUT.illum_col.xyz = col.xyz * max(2e-2f, 1.0f - ao.x);
 		//OUT.illum_col.xyz = col.xyz * ao.x;
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3316)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/ssao.cg	(revision 3318)
@@ -43,4 +43,33 @@
 
 
+float ComputeConvergence(uniform sampler2D tex, float2 texCoord, float2 res)
+{
+	// get the minimum convergence by exactly sampling the 4 surrounding
+	// texels in the old texture, otherwise flickering because convergence
+	// will be interpolated when upsampling and filter size does not match!
+
+	float4 texelCenterConv;
+	const float2 offs(1.0f / res.x, 1.0f / res.y);
+
+	// get position exactly between texel centers
+	float2 center = (floor(texCoord * res) + float2(.5f)) * offs;
+	//center.x = (floor(texCoord.x * res.x - .5f) + 1.0f) / res.x;
+	//center.y = (floor(texCoord.y * res.y - .5f) + 1.0f) / res.y;
+	//center.y = (floor(texCoord.y * res.y) + .5f) * yOffs;
+
+	/*texelCenterConv.x = tex2Dlod(tex, float4(center + float2( xoffs,  yoffs), 0, 0)).y;
+	texelCenterConv.y = tex2Dlod(tex, float4(center + float2( xoffs, -yoffs), 0, 0)).y;
+	texelCenterConv.z = tex2Dlod(tex, float4(center + float2(-xoffs, -yoffs), 0, 0)).y;
+	texelCenterConv.w = tex2Dlod(tex, float4(center + float2(-xoffs,  yoffs), 0, 0)).y;
+
+	const float m1 = min(texelCenterConv.x, texelCenterConv.y);
+	const float m2 = min(texelCenterConv.z, texelCenterConv.w);
+
+	const float convergence = min(m1, m2);*/
+
+	const float convergence = tex2Dlod(tex, float4(center, 0, 0)).y;
+
+	return convergence;
+}
 
 /** This shader computes the reprojection and stores 
@@ -107,10 +136,12 @@
 	{
 		// pixel valid => retrieve the convergence weight
-		float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y;
+		/*float w1 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0.5f / 1024.0f, 0), .0f, .0f)).y;
 		float w2 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0.5f / 1024.0f, 0), .0f, .0f)).y;
 		float w3 = tex2Dlod(oldTex, float4(oldTexCoords + float2(0, 0.5f / 768.0f), .0f, .0f)).y;
 		float w4 = tex2Dlod(oldTex, float4(oldTexCoords - float2(0, 0.5f / 768.0f), .0f, .0f)).y;
 
-		w = min(min(w1, w2), min(w3, w4));
+		w = min(min(w1, w2), min(w3, w4));*/
+		
+		w = ComputeConvergence(oldTex, oldTexCoords, float2(1024.0f, 768.0f));
 		//w = oldPixel.y;
 	}
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3317)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/combineSsaoSep.cg	(revision 3318)
@@ -232,6 +232,6 @@
 	if (depth < DEPTH_THRESHOLD)
 	{
-		OUT.illum_col.xyz = col.xyz * max(1e-3f, 1.0f - ao.x);
-		//OUT.illum_col.xyz = max(1e-3f, 1.0f - ao.x);
+		//OUT.illum_col.xyz = col.xyz * max(1e-3f, 1.0f - ao.x);
+		OUT.illum_col.xyz = max(1e-3f, 1.0f - ao.x);
 	}
 	else
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3316)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/chcdemo.cpp	(revision 3318)
@@ -635,5 +635,6 @@
 #if 1
 
-#if 0
+#if 1
+	// vienna positions
 	VertexArray positions;
 	positions.push_back(Vector3(478.398f, 268.0f, 181.3));
@@ -644,4 +645,5 @@
 #else
 
+	// sibenik positions
 	VertexArray positions;
 	//positions.push_back(Vector3(6.07307, 8.20723, 6.7));
Index: /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp
===================================================================
--- /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp	(revision 3202)
+++ /GTP/trunk/App/Demos/Vis/FriendlyCulling/src/AxisAlignedBox3.cpp	(revision 3318)
@@ -29,5 +29,5 @@
 {
 	return s << '[' << A.mMin.x << ", " << A.mMin.y << ", " << A.mMin.z << "]["
-		<< A.mMax.x << ", " << A.mMax.y << ", " << A.mMax.z << ']';
+		     << A.mMax.x << ", " << A.mMax.y << ", " << A.mMax.z << ']';
 }
 
@@ -39,13 +39,14 @@
 	// read "[min.x, min.y, min.z][mMax.x, mMax.y, mMax.z]"
 	return s >> a >> A.mMin.x >> a >> A.mMin.y >> a >> A.mMin.z >> a >> a
-		>> A.mMax.x >> a >> A.mMax.y >> a >> A.mMax.z >> a;
+		     >> A.mMax.x >> a >> A.mMax.y >> a >> A.mMax.z >> a;
 }
 
 
 AxisAlignedBox3::AxisAlignedBox3() 
-{ }
-
-
-AxisAlignedBox3::AxisAlignedBox3(const Vector3 &nMin, const Vector3 &nMax)
+{}
+
+
+AxisAlignedBox3::AxisAlignedBox3(const Vector3 &nMin,
+								 const Vector3 &nMax)
 : mMin(nMin), mMax(nMax)
 {}
@@ -72,5 +73,7 @@
 
 	for (it = newpoly.mVertices.begin(); it != it_end; ++ it)
+	{
 		Include(*it);
+	}
 }
 
@@ -81,5 +84,7 @@
 
 	for (it = polys.begin(); it != it_end; ++ it)
+	{
 		Include(*(*it));
+	}
 }
 
@@ -94,64 +99,70 @@
 bool AxisAlignedBox3::IsCorrect()
 {
-	if ( (mMin.x > mMax.x) ||
+	if ((mMin.x > mMax.x) ||
 		(mMin.y > mMax.y) ||
 		(mMin.z > mMax.z) )
+	{
 		return false; // box is not formed
+	}
+
 	return true;
 }
 
 
-void AxisAlignedBox3::GetEdge(const int edge, Vector3 *a, Vector3 *b) const
-{
-	switch(edge) {
-  case 0:
-	  a->SetValue(mMin.x, mMin.y, mMin.z);
-	  b->SetValue(mMin.x, mMin.y, mMax.z);
-	  break;
-  case 1:
-	  a->SetValue(mMin.x, mMin.y, mMin.z);
-	  b->SetValue(mMin.x, mMax.y, mMin.z);
-	  break;
-  case 2:
-	  a->SetValue(mMin.x, mMin.y, mMin.z);
-	  b->SetValue(mMax.x, mMin.y, mMin.z);
-	  break;
-  case 3:
-	  a->SetValue(mMax.x, mMax.y, mMax.z);
-	  b->SetValue(mMax.x, mMax.y, mMin.z);
-	  break;
-  case 4:
-	  a->SetValue(mMax.x, mMax.y, mMax.z);
-	  b->SetValue(mMax.x, mMin.y, mMax.z);
-	  break;
-  case 5:
-	  a->SetValue(mMax.x, mMax.y, mMax.z);
-	  b->SetValue(mMin.x, mMax.y, mMax.z);
-	  break;
-
-  case 6:
-	  a->SetValue(mMin.x, mMin.y, mMax.z);
-	  b->SetValue(mMin.x, mMax.y, mMax.z);
-	  break;
-  case 7:
-	  a->SetValue(mMin.x, mMin.y, mMax.z);
-	  b->SetValue(mMax.x, mMin.y, mMax.z);
-	  break;
-  case 8:
-	  a->SetValue(mMin.x, mMax.y, mMin.z);
-	  b->SetValue(mMin.x, mMax.y, mMax.z);
-	  break;
-  case 9:
-	  a->SetValue(mMin.x, mMax.y, mMin.z);
-	  b->SetValue(mMax.x, mMax.y, mMin.z);
-	  break;
-  case 10:
-	  a->SetValue(mMax.x, mMin.y, mMin.z);
-	  b->SetValue(mMax.x, mMax.y, mMin.z);
-	  break;
-  case 11:
-	  a->SetValue(mMax.x, mMin.y, mMin.z);
-	  b->SetValue(mMax.x, mMin.y, mMax.z);
-	  break;
+void AxisAlignedBox3::GetEdge(int edge, 
+							  Vector3 *a, 
+							  Vector3 *b) const
+{
+	switch(edge) 
+	{
+	case 0:
+		a->SetValue(mMin.x, mMin.y, mMin.z);
+		b->SetValue(mMin.x, mMin.y, mMax.z);
+		break;
+	case 1:
+		a->SetValue(mMin.x, mMin.y, mMin.z);
+		b->SetValue(mMin.x, mMax.y, mMin.z);
+		break;
+	case 2:
+		a->SetValue(mMin.x, mMin.y, mMin.z);
+		b->SetValue(mMax.x, mMin.y, mMin.z);
+		break;
+	case 3:
+		a->SetValue(mMax.x, mMax.y, mMax.z);
+		b->SetValue(mMax.x, mMax.y, mMin.z);
+		break;
+	case 4:
+		a->SetValue(mMax.x, mMax.y, mMax.z);
+		b->SetValue(mMax.x, mMin.y, mMax.z);
+		break;
+	case 5:
+		a->SetValue(mMax.x, mMax.y, mMax.z);
+		b->SetValue(mMin.x, mMax.y, mMax.z);
+		break;
+
+	case 6:
+		a->SetValue(mMin.x, mMin.y, mMax.z);
+		b->SetValue(mMin.x, mMax.y, mMax.z);
+		break;
+	case 7:
+		a->SetValue(mMin.x, mMin.y, mMax.z);
+		b->SetValue(mMax.x, mMin.y, mMax.z);
+		break;
+	case 8:
+		a->SetValue(mMin.x, mMax.y, mMin.z);
+		b->SetValue(mMin.x, mMax.y, mMax.z);
+		break;
+	case 9:
+		a->SetValue(mMin.x, mMax.y, mMin.z);
+		b->SetValue(mMax.x, mMax.y, mMin.z);
+		break;
+	case 10:
+		a->SetValue(mMax.x, mMin.y, mMin.z);
+		b->SetValue(mMax.x, mMax.y, mMin.z);
+		break;
+	case 11:
+		a->SetValue(mMax.x, mMin.y, mMin.z);
+		b->SetValue(mMax.x, mMin.y, mMax.z);
+		break;
 	}
 }
@@ -159,48 +170,46 @@
 // returns the vertex indices in the range <0..7>, v = 4.x + 2.y + z, where
 // x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate)
-void
-AxisAlignedBox3::GetEdge(const int edge, int  &aIdx, int &bIdx) const
-{
-	switch(edge) {
-  case 0: aIdx = 0; bIdx = 1; break;
-  case 1: aIdx = 0; bIdx = 2; break;
-  case 2: aIdx = 0; bIdx = 4; break;
-  case 3: aIdx = 7; bIdx = 6; break;
-  case 4: aIdx = 7; bIdx = 5; break;
-  case 5: aIdx = 7; bIdx = 3; break;
-  case 6: aIdx = 1; bIdx = 3; break;
-  case 7: aIdx = 1; bIdx = 5; break;
-  case 8: aIdx = 2; bIdx = 3; break;
-  case 9: aIdx = 2; bIdx = 6; break;
-  case 10: aIdx = 4; bIdx = 6; break;
-  case 11: aIdx = 4; bIdx = 5; break;
-	}
-}
-
-void
-AxisAlignedBox3::Include(const int &axis, const float &newBound)
-{
-	switch (axis) {
-	case 0: { // x-axis
-		if (mMin.x > newBound)
-			mMin.x = newBound;
-		if (mMax.x < newBound)
-			mMax.x = newBound;
-		break;
-			}
-	case 1: { // y-axis
-		if (mMin.y > newBound)
-			mMin.y = newBound;
-		if (mMax.y < newBound)
-			mMax.y = newBound;
-		break;
-			}
-	case 2: { // z-axis
-		if (mMin.z > newBound)
-			mMin.z = newBound;
-		if (mMax.z < newBound)
-			mMax.z = newBound;
-		break;
-			}
+void AxisAlignedBox3::GetEdge(int edge, int  &aIdx, int &bIdx) const
+{
+	switch(edge) 
+	{
+	case 0: aIdx = 0; bIdx = 1; break;
+	case 1: aIdx = 0; bIdx = 2; break;
+	case 2: aIdx = 0; bIdx = 4; break;
+	case 3: aIdx = 7; bIdx = 6; break;
+	case 4: aIdx = 7; bIdx = 5; break;
+	case 5: aIdx = 7; bIdx = 3; break;
+	case 6: aIdx = 1; bIdx = 3; break;
+	case 7: aIdx = 1; bIdx = 5; break;
+	case 8: aIdx = 2; bIdx = 3; break;
+	case 9: aIdx = 2; bIdx = 6; break;
+	case 10: aIdx = 4; bIdx = 6; break;
+	case 11: aIdx = 4; bIdx = 5; break;
+	}
+}
+
+
+void AxisAlignedBox3::Include(int axis, float newBound)
+{
+	switch (axis) 
+	{
+	case 0: 
+		{ // x-axis
+			if (mMin.x > newBound) mMin.x = newBound;
+			if (mMax.x < newBound) mMax.x = newBound;
+			break;
+		}
+	case 1: 
+		{ // y-axis
+			if (mMin.y > newBound) mMin.y = newBound;
+			if (mMax.y < newBound) mMax.y = newBound;
+			break;
+		}
+	case 2: 
+		{ // z-axis
+			if (mMin.z > newBound) mMin.z = newBound;
+			if (mMax.z < newBound) mMax.z = newBound;
+			break;
+		}
 	}
 }
@@ -213,13 +222,13 @@
 }
 
-int
-AxisAlignedBox3::IsInside(const Vector3 &v) const
+
+int AxisAlignedBox3::IsInside(const Vector3 &v) const
 {
 	return !((v.x < mMin.x) ||
-		    (v.x > mMax.x) ||
-			(v.y < mMin.y) ||
-			(v.y > mMax.y) ||
-			(v.z < mMin.z) ||
-			(v.z > mMax.z));
+		     (v.x > mMax.x) ||
+			 (v.y < mMin.y) ||
+			 (v.y > mMax.y) ||
+			 (v.z < mMin.z) ||
+			 (v.z > mMax.z));
 }
 
@@ -228,30 +237,23 @@
 {
 	return (b.mMin.x >= mMin.x &&
-		b.mMin.y >= mMin.y &&
-		b.mMin.z >= mMin.z &&
-		b.mMax.x <= mMax.x &&
-		b.mMax.y <= mMax.y &&
-		b.mMax.z <= mMax.z);
+     		b.mMin.y >= mMin.y &&
+			b.mMin.z >= mMin.z &&
+			b.mMax.x <= mMax.x &&
+			b.mMax.y <= mMax.y &&
+			b.mMax.z <= mMax.z);
 }
 
 
 // compute the coordinates of one vertex of the box
-Vector3 AxisAlignedBox3::GetVertex(int xAxis, int yAxis, int zAxis) const
+Vector3 AxisAlignedBox3::GetVertex(int xAxis, 
+								   int yAxis, 
+								   int zAxis) const
 {
 	Vector3 p;
-	if (xAxis)
-		p.x = mMax.x;
-	else
-		p.x = mMin.x;
-
-	if (yAxis)
-		p.y = mMax.y;
-	else
-		p.y = mMin.y;
-
-	if (zAxis)
-		p.z = mMax.z;
-	else
-		p.z = mMin.z;
+
+	p.x = xAxis ? mMax.x : mMin.x;
+	p.y = yAxis ? mMax.y : mMin.y;
+	p.z = zAxis ? mMax.z : mMin.z;
+
 	return p;
 }
@@ -304,8 +306,5 @@
 {
 	Vector3 ext = mMax - mMin;
-
-	return 2.0f * (ext.x * ext.y +
-		ext.x * ext.z +
-		ext.y * ext.z);
+	return 2.0f * (ext.x * ext.y + ext.x * ext.z + ext.y * ext.z);
 }
 
@@ -318,5 +317,5 @@
 
 const int AxisAlignedBox3::bvertices[27][9] =
-{                   // region number.. position
+{                                // region number .. position
 	{5,1,3,2,6,4,-1,-1,-1},      // 0 .. x=0 y=0 z=0
 	{4,5,1,3,2,0,-1,-1,-1},      // 1 .. x=0 y=0 z=1
@@ -361,5 +360,5 @@
 // one to three triples: (axis, min_vertex, max_vertex), axis==-1(terminator)
 const int AxisAlignedBox3::bfaces[27][10] =
-{                              // region number .. position
+{                                // region number .. position
 	{0,0,3,1,0,5,2,0,6,-1},      // 0 .. x=0 y=0 z=0
 	{0,0,3,1,0,5,-1,-1,-1,-1},   // 1 .. x=0 y=0 z=1
@@ -473,7 +472,6 @@
 // The sequence is ended by 15, number -1 is used as the separator
 // between the vertices and coordinates.
-const int
-AxisAlignedBox3::cvertices[27][9] = 
-{                   // region number.. position
+const int AxisAlignedBox3::cvertices[27][9] = 
+{                                // region number.. position
 	{0,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D one vertex
 	{0,1,-1,0,0,0,1,15,15},      // 1 .. x=0 y=0 z=1 D two vertices foll. by 2
@@ -536,7 +534,6 @@
 //        the sequence start with 15 .. no further testing is necessary
 //        in this case
-const int
-AxisAlignedBox3::csvertices[27][6] = 
-{                   // region number.. position
+const int AxisAlignedBox3::csvertices[27][6] = 
+{                        // region number.. position
 	{0,15,15,15,15,15},  // 0 .. x=0 y=0 z=0 D vertex only
 	{8,0,0,0,1,15},      // 1 .. x=0 y=0 z=1 D two coords.
@@ -586,7 +583,6 @@
 // For testing, if the AABB is whole in the sphere, it is enough
 // to test only vertices, either 1,2,4, or 8.
-const int
-AxisAlignedBox3::fvertices[27][9] = 
-{                   // region number.. position
+const int AxisAlignedBox3::fvertices[27][9] = 
+{                                // region number.. position
 	{7,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D
 	{6,7,15,15,15,15,15,15,15},  // 1 .. x=0 y=0 z=1 D
@@ -635,7 +631,6 @@
 // The number of vertices is minimized using some assumptions
 // about the ortogonality of vertices and sphere properties.
-const int
-AxisAlignedBox3::fsvertices[27][9] = 
-{                   // region number.. position
+const int AxisAlignedBox3::fsvertices[27][9] = 
+{                                // region number.. position
 	{7,15,15,15,15,15,15,15,15}, // 0 .. x=0 y=0 z=0 D 1 vertex
 	{6,7,15,15,15,15,15,15,15},  // 1 .. x=0 y=0 z=1 D 2 vertices
@@ -686,5 +681,6 @@
 	const float c = (float)(M_PI * 0.25);
 
-	if (y < 0.0) {
+	if (y < 0.0)
+	{
 		if (y < -1.0)
 			return c * (-2.0f + x / y); // for angle in <-PI/2, -PI/4)
@@ -692,5 +688,6 @@
 			return c * (y / x); // for angle in <-PI/4 , 0>
 	}
-	else {
+	else 
+	{
 		if (y > 1.0)
 			return c * (2.0f - x / y); // for angle in <PI/4, PI/2>
@@ -702,16 +699,19 @@
 
 // This definition allows to be a point when answering true
-bool
-AxisAlignedBox3::IsCorrectAndNotPoint() const
-{
-	if ( (mMin.x > mMax.x) ||
+bool AxisAlignedBox3::IsCorrectAndNotPoint() const
+{
+	if ((mMin.x > mMax.x) ||
 		(mMin.y > mMax.y) ||
-		(mMin.z > mMax.z) )
+		(mMin.z > mMax.z))
+	{
 		return false; // box is not formed
-
-	if ( (mMin.x == mMax.x) &&
+	}
+
+	if ((mMin.x == mMax.x) &&
 		(mMin.y == mMax.y) &&
-		(mMin.z == mMax.z) )
+		(mMin.z == mMax.z))
+	{
 		return false; // degenerates to a point
+	}
 
 	return true;
@@ -721,8 +721,10 @@
 bool AxisAlignedBox3::IsPoint() const
 {
-	if ( (mMin.x == mMax.x) &&
+	if ((mMin.x == mMax.x) &&
 		(mMin.y == mMax.y) &&
-		(mMin.z == mMax.z) )
+		(mMin.z == mMax.z))
+	{
 		return true; // degenerates to a point
+	}
 
 	return false;
@@ -732,8 +734,10 @@
 bool AxisAlignedBox3::IsSingularOrIncorrect() const
 {
-	if ( (mMin.x >= mMax.x) ||
+	if ((mMin.x >= mMax.x) ||
 		(mMin.y >= mMax.y) ||
-		(mMin.z >= mMax.z) )
+		(mMin.z >= mMax.z))
+	{
 		return true; // box is not formed
+	}
 
 	return false; // has non-zero volume
@@ -757,12 +761,18 @@
 
 	// for x-axis
-	for (int i = 0; i < 3; i++, minp++, maxp++, pcenter++) {
+	for (int i = 0; i < 3; i ++, minp ++, maxp ++, pcenter ++)
+	{
 		float minsqr = sqr(*minp - *pcenter);
 		float maxsqr = sqr(*maxp - *pcenter);
+
 		if (*pcenter < *minp)
+		{		
 			sumMin += minsqr;
+		}
 		else
-			if (*pcenter > *maxp)
-				sumMin += maxsqr;
+		{
+			if (*pcenter > *maxp) sumMin += maxsqr;
+		}
+
 		sumMax += (minsqr > maxsqr) ? minsqr : maxsqr;
 	}
@@ -773,8 +783,9 @@
 
 
-void AxisAlignedBox3::Scale(const float scale) 
-{
-	Vector3 newSize = Size()*(scale*0.5f);
+void AxisAlignedBox3::Scale(float scale) 
+{
+	Vector3 newSize = Size() * (scale * 0.5f);
 	Vector3 center = Center();
+
 	mMin = center - newSize;
 	mMax = center + newSize;
@@ -784,6 +795,7 @@
 void AxisAlignedBox3::Scale(const Vector3 &scale) 
 {
-	Vector3 newSize = Size()*(scale*0.5f);
+	Vector3 newSize = Size() * (scale * 0.5f);
 	Vector3 center = Center();
+
 	mMin = center - newSize;
 	mMax = center + newSize;
@@ -817,5 +829,5 @@
 
 
-float AxisAlignedBox3::Center(const int axis) const 
+float AxisAlignedBox3::Center(int axis) const 
 {
 	return  0.5f * (mMin[axis] + mMax[axis]);
@@ -823,5 +835,5 @@
 
 
-float AxisAlignedBox3::Min(const int axis) const 
+float AxisAlignedBox3::Min(int axis) const 
 {
 	return mMin[axis];
@@ -829,5 +841,5 @@
 
 
-float AxisAlignedBox3::Max(const int axis) const 
+float AxisAlignedBox3::Max(int axis) const 
 {
 	return  mMax[axis];
@@ -835,5 +847,5 @@
 
 
-float AxisAlignedBox3::Size(const int axis) const 
+float AxisAlignedBox3::Size(int axis) const 
 {
 	return  Max(axis) - Min(axis);
@@ -937,5 +949,5 @@
 
 
-void AxisAlignedBox3::SetMin(int axis, const float value) 
+void AxisAlignedBox3::SetMin(int axis, float value) 
 {
 	mMin[axis] = value;
@@ -943,5 +955,5 @@
 
 
-void AxisAlignedBox3::SetMax(int axis, const float value) 
+void AxisAlignedBox3::SetMax(int axis, float value) 
 {
 	mMax[axis] = value;
@@ -952,5 +964,5 @@
 void AxisAlignedBox3::Reduce(int axis, int right, float value) 
 {
-	if ((value >=mMin[axis]) && (value <= mMax[axis]))
+	if ((value >= mMin[axis]) && (value <= mMax[axis]))
 	{
 		if (right)
@@ -991,6 +1003,5 @@
 		if (*si < *ei) 
 		{
-			if (*si > *bmax || *ei < *bmin)
-				return false;
+			if (*si > *bmax || *ei < *bmin) return false;
 
 			const float di = *ei - *si;
@@ -1001,6 +1012,5 @@
 		else 
 		{
-			if (*ei > *bmax || *si < *bmin)
-				return false;
+			if (*ei > *bmax || *si < *bmin)	return false;
 
 			const float di = *ei - *si;
@@ -1012,6 +1022,5 @@
 		if (st > fst) fst = st;
 		if (et < fet) fet = et;
-		if (fet < fst)
-			return false;
+		if (fet < fst) return false;
 
 		++ bmin; ++ bmax;
@@ -1019,5 +1028,4 @@
 	}
 
-	//*time = fst;
 	return true;
 }
@@ -1117,8 +1125,9 @@
 	//-- compute classification of vertices
 
-	for (int i = 0; i < 8; ++i)
+	for (int i = 0; i < 8; ++ i)
 	{
 		GetVertex(i, vtx);
 		side[i] = plane.Side(vtx);
+
 		if (side[i] > 0)
 			onFrontSide = true;
@@ -1135,4 +1144,5 @@
 	{
 		Vector3 ptA, ptB;
+
 		for (int i = 0; i < 12; ++ i)
 		{
@@ -1159,6 +1169,8 @@
 		// compute center of mass
 		for (i = 0; i < (int)planePoly->mVertices.size(); ++ i)
+		{
 			centerOfMass += planePoly->mVertices[i];
-		
+		}
+
 		centerOfMass /= (float)planePoly->mVertices.size();
 
@@ -1170,5 +1182,5 @@
 		{
 		    float angle = 
-		      Angle(refVec, centerOfMass - planePoly->mVertices[i], plane.mNormal);
+				Angle(refVec, centerOfMass - planePoly->mVertices[i], plane.mNormal);
 		    
 		    vertexData.push_back(VertexData(planePoly->mVertices[i], angle));
@@ -1179,5 +1191,7 @@
 		// update vertices
 		for (i = 1; i < (int)planePoly->mVertices.size(); ++ i)
+		{
 			planePoly->mVertices[i] = vertexData[i - 1].mVertex;
+		}
 	}
 	else if (planePoly->mVertices.size() == 3)
@@ -1219,22 +1233,4 @@
 
 
-/*int AxisAlignedBox3::Side(const Plane3 &plane) const
-{
-	Vector3 v;
-	int i, m=3, M=-3, s;
-
-	for (i=0;i<8;i++) 
-	{
-		GetVertex(i, v);
-	
-		if((s = plane.Side(v)) < m) m=s;
-		if(s > M) M=s;
-		if (m && m==-M)	return 0;
-	}
-
-	return (m == M) ? m : m + M;
-}
-*/
-
 int AxisAlignedBox3::Side(const Plane3 &plane) const
 {
@@ -1287,6 +1283,7 @@
 
 
-
-bool AxisAlignedBox3::Intersects(const SimpleRay &ray, float &tnear, float &tfar) const
+bool AxisAlignedBox3::Intersects(const SimpleRay &ray,
+								 float &tnear, 
+								 float &tfar) const
 {
 	tnear = -1e20f;
@@ -1302,5 +1299,7 @@
 	{
 		if ((origin.x < mMin.x) || (origin.x > mMax.x)) 
+		{
 			return false; // origin not between planes
+		}
 	}
 	else
@@ -1311,24 +1310,17 @@
 		t2 = (mMax.x - origin.x) / dir.x;
 		
-		if (t1 > t2)
-			swap(t1, t2);
-		
-		if (t1 > tnear)
-			tnear = t1;
-		
-		if (t2 < tfar)
-			tfar = t2;
-		
-		if (tnear > tfar)
-			return false;
-		
-		if (tfar < 0)
-			return false;
+		if (t1 > t2) swap(t1, t2);
+		if (t1 > tnear)	tnear = t1;
+		if (t2 < tfar) tfar = t2;
+		if (tnear > tfar) return false;
+		if (tfar < 0) return false;
 	}
 
 	if (dir.y == 0) // ray is parallel to the planes
 	{
-		if ((origin.y < mMin.y) || (origin.y > mMax.y)) 
+		if ((origin.y < mMin.y) || (origin.y > mMax.y))
+		{
 			return false; // origin not between planes)
+		}
 	}
 	else
@@ -1337,24 +1329,17 @@
 		t2 = (mMax.y - origin.y) / dir.y; 
 		
-		if (t1 > t2)
-			swap(t1, t2);
-		
-		if (t1 > tnear)
-			tnear = t1;
-		
-		if (t2 < tfar)
-			tfar = t2;
-		
-		if (tnear > tfar)
-			return false;
-		
-		if (tfar < 0)
-			return false;
+		if (t1 > t2) swap(t1, t2);
+		if (t1 > tnear) tnear = t1;
+		if (t2 < tfar) tfar = t2;
+		if (tnear > tfar) return false;
+		if (tfar < 0) return false;
 	}
 
 	if (dir.z == 0) // ray is parallel to the planes
 	{
-		if ((origin.z < mMin.z) || (origin.z > mMax.z)) 
+		if ((origin.z < mMin.z) || (origin.z > mMax.z))
+		{
 			return false; // origin not between planes)
+		}
 	}
 	else
@@ -1363,18 +1348,9 @@
 		t2 = (mMax.z - origin.z) / dir.z; 
 		
-		if (t1 > t2)
-			swap(t1, t2);
-		
-		if (t1 > tnear)
-			tnear = t1;
-		
-		if (t2 < tfar)
-			tfar = t2;
-		
-		if (tnear > tfar)
-			return false;
-		
-		if (tfar < 0)
-			return false;
+		if (t1 > t2) swap(t1, t2);
+		if (t1 > tnear) tnear = t1;
+		if (t2 < tfar) tfar = t2;
+		if (tnear > tfar) return false;
+		if (tfar < 0) return false;
 	}
 
