This is a helper for drawing simple geometric shapes including texture coordinates and surface normals.
For exception safety, it is recommended you make use of the C++ RAII pattern and use a std::unique_ptr or std::shared_ptr
The draw method accepts an optional texture parameter, wireframe flag, and a callback function which can be used to override the default rendering state:
http://msdn.microsoft.com/en-us/library/windows/desktop/ff476892.aspx
- Cube
- Sphere
- GeoSphere
- Cylinder
- Torus
- Teapot
Initialization
The GeometryPrimitive class must be created from a factory method which takes the Direct3D 11 device context.std::unique_ptr<GeometricPrimitive> shape( GeometricPrimitive::CreateTeapot(deviceContext) );
- CreateCube( deviceContext, float size = 1)
- CreateSphere( deviceContext, float diameter = 1, size_t tessellation = 16)
- CreateGeoSphere( deviceContext, float diameter = 1, size_t tessellation = 3)
- CreateCylinder( deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32)
- CreateTorus( deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32)
- CreateTeapot( deviceContext, float size = 1, size_t tessellation = 8)
Simple drawing
shape->Draw(world, view, projection, Colors::CornflowerBlue);
shape->Draw(world, view, projection, Colors::White, catTexture, false, [=]
{
deviceContext->OMSetBlendState(...);
});
Coordinate Systems
The geometric primitives created by default are set up for 'counter-clockwise' winding for rendering with right-handed projection matrices. There is an optional parameter that can be passed to make the rendering use 'clockwise' backface culling for use with left-handed projection matrices.
std::unique_ptr<GeometricPrimitive> shape(
GeometricPrimitive::CreateTeapot( deviceContext, 1.f, 8, false ) );
Threading model
Each GeometricPrimitive instance only supports drawing from one thread at a time, but you can simultaneously submit primitives on multiple threads if you create a separate GeometricPrimitive instance per Direct3D 11 deferred context.http://msdn.microsoft.com/en-us/library/windows/desktop/ff476892.aspx