private void _generatePlaneVertexData( HardwareVertexBuffer vbuf, int ySegments, int xSegments, float xSpace, float halfWidth, float ySpace, float halfHeight, Matrix4 transform, bool firstTime, bool normals, Matrix4 rotation, int numTexCoordSets, float xTexCoord, float yTexCoord, SubMesh subMesh, ref Vector3 min, ref Vector3 max, ref float maxSquaredLength )
{
Vector3 vec;
unsafe
{
// lock the vertex buffer
IntPtr data = vbuf.Lock( BufferLocking.Discard );
float* pData = (float*)data.ToPointer();
for ( int y = 0; y <= ySegments; y++ )
{
for ( int x = 0; x <= xSegments; x++ )
{
// centered on origin
vec.x = ( x * xSpace ) - halfWidth;
vec.y = ( y * ySpace ) - halfHeight;
vec.z = 0.0f;
vec = transform.TransformAffine( vec );
*pData++ = vec.x;
*pData++ = vec.y;
*pData++ = vec.z;
// Build bounds as we go
if ( firstTime )
{
min = vec;
max = vec;
maxSquaredLength = vec.LengthSquared;
firstTime = false;
}
else
{
min.Floor( vec );
max.Ceil( vec );
maxSquaredLength = Utility.Max( maxSquaredLength, vec.LengthSquared );
}
if ( normals )
{
vec = Vector3.UnitZ;
vec = rotation.TransformAffine( vec );
*pData++ = vec.x;
*pData++ = vec.y;
*pData++ = vec.z;
}
for ( int i = 0; i < numTexCoordSets; i++ )
{
*pData++ = x * xTexCoord;
*pData++ = 1 - ( y * yTexCoord );
} // for texCoords
} // for x
} // for y
// unlock the buffer
vbuf.Unlock();
subMesh.useSharedVertices = true;
} // unsafe
}