MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / getFrustumClipProj

Method getFrustumClipProj

Engine/source/scene/reflector.cpp:824–875  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

822}
823
824MatrixF PlaneReflector::getFrustumClipProj( MatrixF &modelview )
825{
826 static MatrixF rotMat(EulerF( static_cast<F32>(M_PI / 2.f), 0.0, 0.0));
827 static MatrixF invRotMat(EulerF( -static_cast<F32>(M_PI / 2.f), 0.0, 0.0));
828
829
830 MatrixF revModelview = modelview;
831 revModelview = rotMat * revModelview; // add rotation to modelview because it needs to be removed from projection
832
833 // rotate clip plane into modelview space
834 Point4F clipPlane;
835 Point3F pnt = refplane * -(refplane.d + 0.0 );
836 Point3F norm = refplane;
837
838 revModelview.mulP( pnt );
839 revModelview.mulV( norm );
840 norm.normalize();
841
842 clipPlane.set( norm.x, norm.y, norm.z, -mDot( pnt, norm ) );
843
844
845 // Manipulate projection matrix
846 //------------------------------------------------------------------------
847 MatrixF proj = GFX->getProjectionMatrix();
848 proj.mul( invRotMat ); // reverse rotation imposed by Torque
849 proj.transpose(); // switch to row-major order
850
851 // Calculate the clip-space corner point opposite the clipping plane
852 // as (sgn(clipPlane.x), sgn(clipPlane.y), 1, 1) and
853 // transform it into camera space by multiplying it
854 // by the inverse of the projection matrix
855 Vector4F q;
856 q.x = sgn(clipPlane.x) / proj(0,0);
857 q.y = sgn(clipPlane.y) / proj(1,1);
858 q.z = -1.0F;
859 q.w = ( 1.0F - proj(2,2) ) / proj(3,2);
860
861 F32 a = 1.0 / (clipPlane.x * q.x + clipPlane.y * q.y + clipPlane.z * q.z + clipPlane.w * q.w);
862
863 Vector4F c = clipPlane * a;
864
865 // CodeReview [ags 1/23/08] Come up with a better way to deal with this.
866 if(GFX->getAdapterType() == OpenGL)
867 c.z += 1.0f;
868
869 // Replace the third column of the projection matrix
870 proj.setColumn( 2, c );
871 proj.transpose(); // convert back to column major order
872 proj.mul( rotMat ); // restore Torque rotation
873
874 return proj;
875}

Callers

nothing calls this directly

Calls 11

sgnFunction · 0.85
mulPMethod · 0.80
mulVMethod · 0.80
getProjectionMatrixMethod · 0.80
setColumnMethod · 0.80
mDotFunction · 0.50
normalizeMethod · 0.45
setMethod · 0.45
mulMethod · 0.45
transposeMethod · 0.45
getAdapterTypeMethod · 0.45

Tested by

no test coverage detected