Here is my code. Any idea's?
As you can guess from the code the cordinates & UV's are floating point but the color is 32bit 8888 RGBA.
Code: Select all
int ClipLineToPlane( Quake3BspPlane* pPlane, BspClipVertex* vStart, BspClipVertex* vEnd )
{
//* Clip Return Status
//* 00 = Point Not Visable (save neither point)
//* 01 = Save Start Point
//* 10 = Save End Point
//* 11 = Save Both Points
float fStartDistance = IsPointVisableFloat( pPlane, vStart->x, vStart->y, vStart->z );
float fEndDistance = IsPointVisableFloat( pPlane, vEnd->x, vEnd->y, vEnd->z );
float fInverDistance = 1.0f;
float fFraction = 0.0f;
float uColor1[4];
float uColor2[4];
float uColor3[4];
BspClipVertex vNewPoint;
//* Both Points Visable
if( ( fStartDistance >= 0 ) && ( fEndDistance >= 0 ) )
return 1;
//* Both Points Not Visable
if( ( fStartDistance < 0 ) && ( fEndDistance < 0 ) )
return 0;
//* Calculate Inverse
if( ( fStartDistance - fEndDistance ) != 0 )
fInverDistance = 1.0f / ( fStartDistance - fEndDistance );
//* Get Fractional Value
fFraction = ( fStartDistance ) * fInverDistance;
//* Let it go outside the bounds a bit so we dont clip too early
if( fStartDistance > fEndDistance )
fFraction += EPSILON2;
else
fFraction -= EPSILON2;
//* Verify it's valid
if( fFraction < 0.0f )
fFraction = 0.0f;
else if( fFraction > 1.0f )
fFraction = 1.0f;
//* Generate Point of Intersection
vNewPoint.x = vStart->x + ( fFraction * ( vEnd->x - vStart->x ) );
vNewPoint.y = vStart->y + ( fFraction * ( vEnd->y - vStart->y ) );
vNewPoint.z = vStart->z + ( fFraction * ( vEnd->z - vStart->z ) );
//* Generate UVs
vNewPoint.u = vStart->u + ( fFraction * ( vEnd->u - vStart->u ) );
vNewPoint.v = vStart->v + ( fFraction * ( vEnd->v - vStart->v ) );
//* Generate Color
uColor2[0] = (float)vStart->color[0] / 255.0f;
uColor2[1] = (float)vStart->color[1] / 255.0f;
uColor2[2] = (float)vStart->color[2] / 255.0f;
uColor2[3] = (float)vStart->color[3] / 255.0f;
uColor3[0] = (float)vEnd->color[0] / 255.0f;
uColor3[1] = (float)vEnd->color[1] / 255.0f;
uColor3[2] = (float)vEnd->color[2] / 255.0f;
uColor3[3] = (float)vEnd->color[3] / 255.0f;
uColor1[0] = uColor2[0] + ( fFraction * (uColor3[0] - uColor2[0]) );
uColor1[1] = uColor2[1] + ( fFraction * (uColor3[1] - uColor2[1]) );
uColor1[2] = uColor2[2] + ( fFraction * (uColor3[2] - uColor2[2]) );
uColor1[3] = uColor2[3] + ( fFraction * (uColor3[3] - uColor2[3]) );
//* Store Point
if( fStartDistance > fEndDistance )
{
vEnd->x = vNewPoint.x;
vEnd->y = vNewPoint.y;
vEnd->z = vNewPoint.z;
vEnd->u = vNewPoint.u;
vEnd->v = vNewPoint.v;
//vEnd->color = uColor1[0] + ( uColor1[1] << 8) + ( uColor1[2] << 16) + ( uColor1[3] << 24);
vEnd->color[0] = (unsigned char)( uColor1[0] * 255.0f );
vEnd->color[1] = (unsigned char)( uColor1[1] * 255.0f );
vEnd->color[2] = (unsigned char)( uColor1[2] * 255.0f );
vEnd->color[3] = (unsigned char)( uColor1[3] * 255.0f );
//* Line Clipped (Save both Points)
return 3;
}
else
{
vStart->x = vNewPoint.x;
vStart->y = vNewPoint.y;
vStart->z = vNewPoint.z;
vStart->u = vNewPoint.u;
vStart->v = vNewPoint.v;
//vStart->color = uColor1[0] + ( uColor1[1] << 8) + ( uColor1[2] << 16) + ( uColor1[3] << 24);
vStart->color[0] = (unsigned char)( uColor1[0] * 255.0f );
vStart->color[1] = (unsigned char)( uColor1[1] * 255.0f );
vStart->color[2] = (unsigned char)( uColor1[2] * 255.0f );
vStart->color[3] = (unsigned char)( uColor1[3] * 255.0f );
}
//* Line Clipped
return 1;
}
I have another question. I have also been working on a n64 emulator called monkey64. Some of the n64 floating point unit seems to control how it wants values rounded. Is there a way I can set and controll this on the psp?