How would I convert a "normal" rectangle into a set of OpenGL ES vertices. I'm not good at geometry so I have no idea how vertices work, and I want to be able to manipulate rectangles without having to work out the values for the vertices by trial and error.
I basically need to convert this structure:
typedef struct __nrect {
float width;
float height;
float depth;
/* center */
float x;
float y;
float z;
} simple3dRect;
To something like this:
const GLfloat cubeVertices[6][12] = {
{ 1,-1, 1, -1,-1, 1, 1, 1, 1, -1, 1, 1 },
{ 1, 1, 1, 1,-1, 1, 1, 1,-1, 1,-1,-1 },
{-1, 1,-1, -1,-1,-1, -1, 1, 1, -1,-1, 1 },
{ 1, 1, 1, -1, 1, 1, 1, 1,-1, -1, 1,-1 },
{ 1,-1,-1, -1,-1,-1, 1, 1,-1, -1, 1,-1 },
{ 1,-1, 1, -1,-1, 1, 1,-1,-1, -1,-1,-1 },
};
Is there an easy way to do this?
Assuming that the resulting cube is axis-aligned and that width corresponds to the x-axis, height to the y-axis and depth to the z-axis:
Clearly, this can be simplified/optimised by pre-computing the width/2, etc. values, longhand included here for clarity.