void ProjectLightForScissor( const float radius, VECTOR lpos, float *x, float *y, float *width, float *height )
{
GLint viewport[4];
GLdouble mvmatrix[16], projmatrix[16];
double px, py, pz;
vector_t r1, r2, r3, r4;
vector_t p1, p2, p3, p4;
vector_t up( 0, 1, 0 ), right( 1, 0, 0 );
vector_t tempResult, projPt;
projPt.z = 0.0f;
vector_t vec_zero_one( 0, 1 ), vec_negone_zero( -1, 0 ), vec_zero_negone( 0, -1 );
//p1 = lpos + ( radius * ( ( cos(0) * right ) + ( sin(0) * up ) ) );
//p1 = lpos + ( right * radius );
VectorMAD( &p1, right, radius, lpos );
//p2 = lpos + ( radius * ( ( cos(PI / 2) * right ) + ( sin(PI / 2) * up ) ) );
//p2 = lpos + ( up * radius );
VectorMAD( &p2, up, radius, lpos );
//p3 = lpos + ( radius * ( ( cos(PI) * right ) + ( sin(PI) * up ) ) );
//p3 = lpos + ( -right * radius );
VectorInvert( &tempResult, right );
VectorMAD( &p3, tempResult, radius, lpos );
//p4 = lpos + ( radius * ( ( cos(3 * PI / 2) * right ) + ( sin( 3 * PI / 2) * up ) ) );
//p4 = lpos + ( radius * -up ); // Not used
//
/// Get the matricies and viewport that gluProject needs to project to window space
//
glGetIntegerv( GL_VIEWPORT, viewport );
glGetDoublev( GL_MODELVIEW_MATRIX, mvmatrix );
glGetDoublev( GL_PROJECTION_MATRIX, projmatrix );
//
/// Project points to window space
//
gluProject( p1.x, p1.y, p1.z, mvmatrix, projmatrix, viewport, &px, &py, &pz );
//r1 = VECTOR( px, py ) + ( VectorMUL( VECTOR( 0, 1 ), radius ) );
projPt.x = (float)px; projPt.y = (float)py;
VectorMAD( &r1, vec_zero_one, radius, projPt );
gluProject( p2.x, p2.y, p2.z, mvmatrix, projmatrix, viewport, &px, &py, &pz );
//r2 = VECTOR( px, py ) + ( VectorMUL( VECTOR( -1, 0 ), radius ) );
projPt.x = (float)px; projPt.y = (float)py;
VectorMAD( &r2, vec_negone_zero, radius, projPt );
gluProject( p3.x, p3.y, p3.z, mvmatrix, projmatrix, viewport, &px, &py, &pz );
//r3 = VECTOR( px, py ) + ( VectorMUL( VECTOR( 0, -1 ), radius ) );
projPt.x = (float)px; projPt.y = (float)py;
VectorMAD( &r3, vec_zero_negone, radius, projPt );
// Not used
//gluProject( p4.x, p4.y, p4.z, mvmatrix, projmatrix, viewport, px, py, pz );
//r4 = vec2_t( px, py ) + ( radius * vec2_t( 1, 0 ) );
//
/// Setup the data for glScissor
//
*x = r3.x;
*y = r3.y;
*width = r1.x - r2.x;
*height = r2.y - r3.y;
}