|
From: <pat...@us...> - 2013-07-05 21:12:00
|
Revision: 1284
http://sourceforge.net/p/ggt/code/1284
Author: patrickh
Date: 2013-07-05 21:11:58 +0000 (Fri, 05 Jul 2013)
Log Message:
-----------
Normalize the frustum normal.
>From the patch submission:
Regarding ggt-devel discussion thread "Should Frustum::mPlanes[].mNorm
be normalized?", the attached patch shows my proposed fix, should we
all decide that having normalized plane normals will not break any other
code.
Note that without normalized plane normals, the isInVolume(Frustum,...)
functions produce incorrect results. So, we either need to normalize
here (the logical, most efficient place), or in the isInVolume()
functions (much less efficient), or we need to keep a second
(normalized) copy of each plane's normal.
Submitted by: Paul Martz
Modified Paths:
--------------
trunk/gmtl/Frustum.h
Modified: trunk/gmtl/Frustum.h
===================================================================
--- trunk/gmtl/Frustum.h 2013-07-05 20:59:14 UTC (rev 1283)
+++ trunk/gmtl/Frustum.h 2013-07-05 21:11:58 UTC (rev 1284)
@@ -113,35 +113,48 @@
{
const gmtl::Matrix<DATA_TYPE, 4, 4>& m = projMatrix;
+ gmtl::Vec<DATA_TYPE, 3> n;
//left
- mPlanes[PLANE_LEFT].setNormal(gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[0][0],
- m[3][1] + m[0][1],
- m[3][2] + m[0][2]));
+ n = (gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[0][0],
+ m[3][1] + m[0][1],
+ m[3][2] + m[0][2]));
+ normalize( n );
+ mPlanes[PLANE_LEFT].setNormal( n );
mPlanes[PLANE_LEFT].setOffset(m[3][3] + m[0][3]);
//right
- mPlanes[PLANE_RIGHT].setNormal(gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[0][0],
- m[3][1] - m[0][1],
- m[3][2] - m[0][2]));
+ n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[0][0],
+ m[3][1] - m[0][1],
+ m[3][2] - m[0][2]);
+ normalize( n );
+ mPlanes[PLANE_RIGHT].setNormal( n );
mPlanes[PLANE_RIGHT].setOffset(m[3][3] - m[0][3]);
//bottom
- mPlanes[PLANE_BOTTOM].setNormal(gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[1][0],
- m[3][1] + m[1][1],
- m[3][2] + m[1][2]));
+ n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[1][0],
+ m[3][1] + m[1][1],
+ m[3][2] + m[1][2]);
+ normalize( n );
+ mPlanes[PLANE_BOTTOM].setNormal( n );
mPlanes[PLANE_BOTTOM].setOffset(m[3][3] + m[1][3]);
//top
- mPlanes[PLANE_TOP].setNormal(gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[1][0],
- m[3][1] - m[1][1],
- m[3][2] - m[1][2]));
+ n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[1][0],
+ m[3][1] - m[1][1],
+ m[3][2] - m[1][2]);
+ normalize( n );
+ mPlanes[PLANE_TOP].setNormal( n );
mPlanes[PLANE_TOP].setOffset(m[3][3] - m[1][3]);
//near
- mPlanes[PLANE_NEAR].setNormal(gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[2][0],
- m[3][1] + m[2][1],
- m[3][2] + m[2][2]));
+ n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[2][0],
+ m[3][1] + m[2][1],
+ m[3][2] + m[2][2]);
+ normalize( n );
+ mPlanes[PLANE_NEAR].setNormal( n );
mPlanes[PLANE_NEAR].setOffset(m[2][3] + m[3][3]);
//far
- mPlanes[PLANE_FAR].setNormal(gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[2][0],
- m[3][1] - m[2][1],
- m[3][2] - m[2][2]));
+ n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[2][0],
+ m[3][1] - m[2][1],
+ m[3][2] - m[2][2]);
+ normalize( n );
+ mPlanes[PLANE_FAR].setNormal( n );
mPlanes[PLANE_FAR].setOffset(m[3][3] - m[2][3]);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <pat...@us...> - 2013-08-17 12:58:29
|
Revision: 1286
http://sourceforge.net/p/ggt/code/1286
Author: patrickh
Date: 2013-08-17 12:58:27 +0000 (Sat, 17 Aug 2013)
Log Message:
-----------
Follow-up to r1284: include modifying the plane offsets by
the unnormalized lenghts.
Submitted by: Paul Martz
Revision Links:
--------------
http://sourceforge.net/p/ggt/code/1284
Modified Paths:
--------------
trunk/gmtl/Frustum.h
Modified: trunk/gmtl/Frustum.h
===================================================================
--- trunk/gmtl/Frustum.h 2013-07-29 20:26:20 UTC (rev 1285)
+++ trunk/gmtl/Frustum.h 2013-08-17 12:58:27 UTC (rev 1286)
@@ -114,48 +114,49 @@
const gmtl::Matrix<DATA_TYPE, 4, 4>& m = projMatrix;
gmtl::Vec<DATA_TYPE, 3> n;
+ DATA_TYPE len;
//left
n = (gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[0][0],
m[3][1] + m[0][1],
m[3][2] + m[0][2]));
- normalize( n );
+ len = normalize( n );
mPlanes[PLANE_LEFT].setNormal( n );
- mPlanes[PLANE_LEFT].setOffset(m[3][3] + m[0][3]);
+ mPlanes[PLANE_LEFT].setOffset( (m[3][3] + m[0][3]) / len );
//right
n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[0][0],
m[3][1] - m[0][1],
m[3][2] - m[0][2]);
- normalize( n );
+ len = normalize( n );
mPlanes[PLANE_RIGHT].setNormal( n );
- mPlanes[PLANE_RIGHT].setOffset(m[3][3] - m[0][3]);
+ mPlanes[PLANE_RIGHT].setOffset( (m[3][3] - m[0][3]) / len );
//bottom
n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[1][0],
m[3][1] + m[1][1],
m[3][2] + m[1][2]);
- normalize( n );
+ len = normalize( n );
mPlanes[PLANE_BOTTOM].setNormal( n );
- mPlanes[PLANE_BOTTOM].setOffset(m[3][3] + m[1][3]);
+ mPlanes[PLANE_BOTTOM].setOffset( (m[3][3] + m[1][3]) / len );
//top
n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[1][0],
m[3][1] - m[1][1],
m[3][2] - m[1][2]);
- normalize( n );
+ len = normalize( n );
mPlanes[PLANE_TOP].setNormal( n );
- mPlanes[PLANE_TOP].setOffset(m[3][3] - m[1][3]);
+ mPlanes[PLANE_TOP].setOffset( (m[3][3] - m[1][3]) / len );
//near
n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] + m[2][0],
m[3][1] + m[2][1],
m[3][2] + m[2][2]);
- normalize( n );
+ len = normalize( n );
mPlanes[PLANE_NEAR].setNormal( n );
- mPlanes[PLANE_NEAR].setOffset(m[2][3] + m[3][3]);
+ mPlanes[PLANE_NEAR].setOffset( (m[2][3] + m[3][3]) / len );
//far
n = gmtl::Vec<DATA_TYPE, 3>(m[3][0] - m[2][0],
m[3][1] - m[2][1],
m[3][2] - m[2][2]);
- normalize( n );
+ len = normalize( n );
mPlanes[PLANE_FAR].setNormal( n );
- mPlanes[PLANE_FAR].setOffset(m[3][3] - m[2][3]);
+ mPlanes[PLANE_FAR].setOffset( (m[3][3] - m[2][3]) / len );
}
gmtl::Plane<DATA_TYPE> mPlanes[6];
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|