Game Development Reference
In-Depth Information
_vbOffset += _vbBatchSize;
// don't offset into memory thats outside the vb's
// range. If we're at the end, start at the beginning.
if(_vbOffset >= _vbSize)
_vbOffset = 0;
_vb->Lock(
_vbOffset * sizeof( Particle ),
_vbBatchSize * sizeof( Particle ),
(void**)&v,
_vbOffset ? D3DLOCK_NOOVERWRITE :
D3DLOCK_DISCARD);
numParticlesInBatch = 0; // reset for new batch
}//end if
}//end if
}//end for
_vb->Unlock();
// it's possible that the LAST batch being filled never
// got rendered because the condition
// (numParticlesInBatch == _vbBatchSize) would not have
// been satisfied. We draw the last partially filled batch now.
if( numParticlesInBatch )
{
_device->DrawPrimitive(
D3DPT_POINTLIST,
_vbOffset,
numParticlesInBatch);
}
// next block
_vbOffset += _vbBatchSize;
postRender();
}//end if
}// end render()
14.2.2 Randomness
There is a sort of randomness to the particles of a system. For exam-
ple, if we are modeling snow, we do not want all the snowflakes to fall in
exactly the same way. We want them to fall in a similar way but not
exactly the same way. To facilitate the randomness functionality
required for particle systems, we add the following two functions to the
d3dUtility.h/cpp files.
This first function returns a random float in the interval [lowBound,
highBound]:
Search WWH ::




Custom Search