Author |
Angry Simians |
Tiffy Rando Grand Admiral
Joined: January 19, 2003 Posts: 354 From: Austin, Texas
| Posted: 2004-05-18 18:45  
Not too long ago Faustus posted a piece of the DS source code, and asked someone to fix it...
void Trail::renderTrail( RenderContext &context, const Matrix33 & frame,
const Vector3 & position, const Vector3 & vHead )
{
if (! m_TrailMaterial.valid() )
return;
// simple visiblity check
if (! context.sphereVisible( position, m_TrailRadius ) )
return;
int nTrailSize = m_Trail.size();
int nVerts = (nTrailSize + 1) * 2;
if ( nVerts < 4 )
return;
DisplayDevice * pDisplay = context.display();
ASSERT( pDisplay );
// create the triangle strip primitive
PrimitiveTriangleStripDL::Ref pStrip = PrimitiveTriangleStripDL::create( pDisplay, nVerts );
// lock the primitive
VertexL * pVert = pStrip->lock();
const Matrix33 mWorldFrame( context.frame() );
const Vector3 vNormal( 0, 0, 0 );
const Vector3 vY( 0, m_TrailMaterial->height(), 0 );
const Color cDiffuse( 255,255,255,s_BaseAlpha );
// get the head position in view space
Vector3 vHeadVS( mWorldFrame * (vHead - context.position()) );
pVert->position = vHeadVS + vY;
pVert->normal = vNormal;
pVert->diffuse = cDiffuse;
pVert->u = 0.0f;
pVert->v = 0.0f;
pVert++;
pVert->position = vHeadVS - vY;
pVert->normal = vNormal;
pVert->diffuse = cDiffuse;
pVert->u = 0.0f;
pVert->v = 1.0f;
pVert++;
// calculate the maximum life of a segment, this is used to calculate the UV coordinates for the segments
const float fMaxLife = Max( s_TrailScalar * m_TrailLife, 1.0f );
// start at the end, since thats actually the beginning of the trail
m_Trail.end();
while( m_Trail.valid() )
{
Segment & segment = *m_Trail;
m_Trail.prev();
// get the UV coordinates for this segment
const float fT = float( segment.life ) / fMaxLife;
const float fU = Clamp( 1.0f - fT, 0.05f, 0.95f );
const Color cDiffuse( 255, 255, 255, fT * s_BaseAlpha );
// get the viewspace position of this segment
const Vector3 vSegmentVS( mWorldFrame * (segment.position - context.position()) );
pVert->position = vSegmentVS + vY;
pVert->normal = vNormal;
pVert->diffuse = cDiffuse;
pVert->u = fU;
pVert->v = 0.0f;
pVert++;
pVert->position = vSegmentVS - vY;
pVert->normal = vNormal;
pVert->diffuse = cDiffuse;
pVert->u = fU;
pVert->v = 1.0f;
pVert++;
}
pStrip->unlock();
// set the material
Material::push( context, m_TrailMaterial );
// set the transform line strip from worldspace to viewspace
PrimitiveSetTransform::createPush( pDisplay, Matrix33( true ), Vector3( true ) );
// push the triangle strip
PrimitiveTriangleStripDL::push( pDisplay, pStrip );
}
Well I took the code, printed it, and handed it to my C++ professor, and told him to fix it.
He stared at the code for a minute, then proceeded to take out a lighter and burn it. After which, he stormed away muttering something about not letting an angry chimp on an acid trip write code.
PS True story...
_________________ Flagship: MCC-717: C.S.S Antaeus
|
-Baron Von Virtu Cadet
Joined: December 21, 2002 Posts: 411
| Posted: 2004-05-18 18:49  
*rolls around on the ground laughing*
A Classic!
_________________
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\r\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n Site Director - The Darkspace Connection - http://www.3dap.com/darkspace
|
Forseth (Ret) Fleet Admiral
Joined: June 01, 2003 Posts: 828 From: Forseth
| Posted: 2004-05-18 18:49  
wow you can have lighters in school!!!! pimp
_________________
|
Atom$k {PK} Fleet Admiral
Joined: July 04, 2003 Posts: 168 From: Virginia Beach, VA
| Posted: 2004-05-18 18:51  
Erm....o..k...
(This is the kind of posts we deal with in the $|P forums )
-Xin
_________________
Once a Pirate, always -$|P-
|
Dempster Grand Admiral
Joined: August 03, 2003 Posts: 668
| Posted: 2004-05-18 19:33  
rofl so now we all know why theres lag
_________________
|
Meko Grand Admiral
Joined: March 03, 2004 Posts: 1956 From: Vancouver
| Posted: 2004-05-18 20:52  
heh well tell you professor to give faust a call already
_________________
|