Plane
Planes are underlying functionality of the Simple Shapes. However, planes can still be used for more complex 2D applictions.
All 2D functions and objects are accessed using the MachGL::Plane
namespace.
Planes are configred by creating a Plane::MACH_PLANE
object and calling one of the 3 constructors:
Plane::MACH_PLANE plane1 = Plane::createPlane(planeProperties);
Plane::MACH_PLANE plane2 = Plane::createPlane(vertices, indices, uvs, planeProperties);
Plane::MACH_PLANE plane3 = Plane::createPlane(position, size, textureID);
Both the first and second constructor take in a Plane Properties
object. This defines the position, size, color, shape, image and type. Eg:
Plane::PlaneProperties properties;
properties.position = float3(0, 0, 0);
properties.size = float2(100, 100);
properties.color = float4(1, 1, 1, 1);
properties.shape = Plane::PlaneShape::QUAD;
properties.image = nullptr; // nullptr can be defined when no texture is required. Otherwise set to a Graphics::MACH_IMAGE object
properties.type = Plane::PlaneType::STATIC;
When creating a PlaneProperties object, shape is set to PlaneShape::QUAD and type is set to PlaneType::STATIC by default.
The shape of a Plane can be set to PlaneShape::QUAD
, PlaneShape::TRIANGLE
or PlaneShape::CUSTOM
. QUAD and TRIANGLE have pre-set up vertices, indices and UVs. Please note that for rendering a circle, it is recommended to use shape QUAD and remove the unwanted pixels in the fragment shader. For an easier way to create a circle, please see Simple Shapes.
A Plane can have 2 types PlaneType::STATIC
and PlaneType::DYNAMIC
, these indicate if the texure is static or dynamic. In constructor 3 above, the type is set to dynamic since the texture in is just a GLuint texture ID - this can be changed in runtime.
As with other object types in this engine, the create()
function needs to be called to initilize the Plane.
Planes have a veriety of getters and setters:
getPosition() //float3
getSize() //float2
getTID() //TextureID - uint32_t
getColor() //float4
getType() //PlaneType
getShape() //PlaneShape
getVAO() //uint32_t
getVBO() //uint32_t
getIBO() //uint32_t
getVertices() //std::vector<float3>
getIndices() //std::vector<unsigned short>
getUVs() //std::vector<float2>
To render a plane, a Plane::MACH_PLANE can be submitted to a Graphics::MACH_RENDERER_2D object. This can be sent either one object at a time or in a std::vector of Plane::MACH_PLANE objects. See Renderer