public void RenderSphereSolidOnly( DeviceContext deviceContext, Vector3 p, float radius, Vector3 color, Camera camera )
{
var databox = deviceContext.MapSubresource( mPositionVertexBuffer,
0,
NUM_VERTICES *
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
MapMode.WriteDiscard,
SlimDX.Direct3D11.MapFlags.None );
var currentPoint = new Vector3();
var furtherSouthPoint = new Vector3();
var numVertices = 0;
// northSouthTheta traces from north pole to south pole
float northSouthTheta = (float)Math.PI / 2;
for ( int i = 0; i <= NUM_LATITUDE_LINES; i++ )
{
float currentLatitudeRadius = (float)Math.Cos( northSouthTheta ) * radius;
float nextLatitudeRadius = (float)Math.Cos( northSouthTheta + LATITUDE_STEP ) * radius;
// eastWestTheta traces around each latitude line
float eastWestTheta = 0;
for ( int j = 0; j <= NUM_LONGITUDE_LINES; j++ )
{
currentPoint.X = p.X + ( (float)Math.Cos( eastWestTheta ) * currentLatitudeRadius );
currentPoint.Y = p.Y + ( (float)Math.Sin( northSouthTheta ) * radius );
currentPoint.Z = p.Z + ( (float)Math.Sin( eastWestTheta ) * currentLatitudeRadius );
databox.Data.Write( currentPoint );
numVertices++;
furtherSouthPoint.X = p.X + ( (float)Math.Cos( eastWestTheta ) * nextLatitudeRadius );
furtherSouthPoint.Y = p.Y + ( (float)Math.Sin( northSouthTheta + LATITUDE_STEP ) * radius );
furtherSouthPoint.Z = p.Z + ( (float)Math.Sin( eastWestTheta ) * nextLatitudeRadius );
databox.Data.Write( furtherSouthPoint );
numVertices++;
eastWestTheta += LONGITUDE_STEP;
}
northSouthTheta += LATITUDE_STEP;
}
deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 );
deviceContext.InputAssembler.InputLayout = mRenderSolidInputLayout;
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT,
new VertexBufferBinding( mPositionVertexBuffer,
POSITION_NUM_COMPONENTS_PER_VERTEX *
POSITION_NUM_BYTES_PER_COMPONENT,
0 ) );
mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() );
mEffect.GetVariableByName( "gColor" ).AsVector().Set( color );
mRenderSolidPass.Apply( deviceContext );
deviceContext.Draw( numVertices, 0 );
}