public class Cube
{
// the device to use when creating resources
static readonly GraphicsDevice resourceDevice
= GraphicsDeviceManager.Current.GraphicsDevice;
// resources
VertexShader vertexShader;
PixelShader pixelShader;
public Cube()
{
// Initialize resources required to draw the Cube
vertexBuffer = CreateCube();
Stream shaderStream = Application.GetResourceStream(
new Uri(@"CubeSample;component/Cube.vs", UriKind.Relative)).Stream;
vertexShader = VertexShader.FromStream(resourceDevice, shaderStream);
shaderStream = Application.GetResourceStream(...);
,,,
}
VertexBuffer CreateCube()
{
// cube vertices
var cube = new VertexPositionColor[36];
// face coordinates
Vector3 topLeftFront = new Vector3(-1.0f, 1.0f, 1.0f);
Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 1.0f);
...
return vb;
}
public void Draw(GraphicsDevice graphicsDevice, ...)
{
// update cube transform
Matrix position = Matrix.Identity; // origin
Matrix scale = Matrix.CreateScale(1.0f); // no scale modifier
...
// setup pixel pipeline
graphicsDevice.SetPixelShader(pixelShader);
// draw using the configured pipeline
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 12);
}
}