Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float ComputeScreenSize( const Vector &vecOrigin, float flRadius, const ScreenSizeComputeInfo_t& info )
- {
- // This is sort of faked, but it's faster that way
- // FIXME: Also, there's a much faster way to do this with similar triangles
- // but I want to make sure it exactly matches the current matrices, so
- // for now, I do it this conservative way
- /*
- Vector4D testPoint1, testPoint2;
- VectorMA( vecOrigin, flRadius, info.m_vecViewUp, testPoint1.AsVector3D() );
- VectorMA( vecOrigin, -flRadius, info.m_vecViewUp, testPoint2.AsVector3D() );
- testPoint1.w = testPoint2.w = 1.0f;
- Vector4D clipPos1, clipPos2;
- Vector4DMultiply( info.m_matViewProj, testPoint1, clipPos1 );
- Vector4DMultiply( info.m_matViewProj, testPoint2, clipPos2 );
- if (clipPos1.w >= 0.001f)
- {
- clipPos1.y /= clipPos1.w;
- }
- else
- {
- clipPos1.y *= 1000;
- }
- if (clipPos2.w >= 0.001f)
- {
- clipPos2.y /= clipPos2.w;
- }
- else
- {
- clipPos2.y *= 1000;
- }
- // The divide-by-two here is because y goes from -1 to 1 in projection space
- return info.m_nViewportHeight * fabs( clipPos2.y - clipPos1.y ) * 0.5f;
- */
- // NOTE: Optimized version of the above algorithm, which only uses y and w components of clip
- // Can also optimize based on clipPos = a +/- b * r
- const float *pViewProjY = info.m_matViewProj[1];
- const float *pViewProjW = info.m_matViewProj[3];
- float flODotY = pViewProjY[0] * vecOrigin.x + pViewProjY[1] * vecOrigin.y + pViewProjY[2] * vecOrigin.z + pViewProjY[3];
- float flViewDotY = pViewProjY[0] * info.m_vecViewUp.x + pViewProjY[1] * info.m_vecViewUp.y + pViewProjY[2] * info.m_vecViewUp.z;
- flViewDotY *= flRadius;
- float flODotW = pViewProjW[0] * vecOrigin.x + pViewProjW[1] * vecOrigin.y + pViewProjW[2] * vecOrigin.z + pViewProjW[3];
- float flViewDotW = pViewProjW[0] * info.m_vecViewUp.x + pViewProjW[1] * info.m_vecViewUp.y + pViewProjW[2] * info.m_vecViewUp.z;
- flViewDotW *= flRadius;
- float y0 = flODotY + flViewDotY;
- float w0 = flODotW + flViewDotW;
- y0 *= ( w0 >= 0.001f ) ? ( 1.0f / w0 ) : 1000.0f;
- float y1 = flODotY - flViewDotY;
- float w1 = flODotW - flViewDotW;
- y1 *= ( w1 >= 0.001f ) ? ( 1.0f / w1 ) : 1000.0f;
- // The divide-by-two here is because y goes from -1 to 1 in projection space
- return info.m_nViewportHeight * fabs( y1 - y0 ) * 0.5f;
- }
Add Comment
Please, Sign In to add comment