Confused about converting vertexes from world space to clipspace
bitxue opened this issue · 2 comments
Hi,
I was developing a graphics application using opengl. currently I met a problem on integrating your great MaskedOcclusionCulling lib. I was Confused about converting vertexes from world space to clipspace.
Now I have a vertex array like this:
float vertex[100]={x1,y1,z1,x2,y2,z2,...}
in the "Readme" page, i noticed that you have mentioned this:
// Example matrix swapping the x and y coordinates
float swapxyMatrix[4][4] = {
{0,1,0,0},
{1,0,0,0},
{0,0,1,0},
{0,0,0,1}};
// Render triangle with transform.
moc.RenderTriangles(triVerts, triIndices, nTris, swapxyMatrix);
I followed this and my program crashed.
Then I tried to use the TransformVertices() function, It is defined as:
/*!
* \brief Utility function for transforming vertices and outputting them to an (x,y,z,w)
* format suitable for the occluder rasterization and occludee testing functions.
*
* \param mtx Pointer to matrix data. The matrix should column major for post
* multiplication (OGL) and row major for pre-multiplication (DX). This is
* consistent with OpenGL / DirectX behavior.
* \param inVtx Pointer to an array of input vertices. The input vertices are given as
* (x,y,z) cooordinates. The memory layout can be changed using vtxLayout.
* \param xfVtx Pointer to an array to store transformed vertices. The transformed
* vertices are always stored as array of structs (AoS) (x,y,z,w) packed in memory.
* \param nVtx Number of vertices to transform.
* \param vtxLayout A struct specifying the vertex layout (see struct for detailed
* description). For best performance, it is advicable to store position data
* as compactly in memory as possible. Note that for this function, the
* w-component is assumed to be 1.0.
*/
static void TransformVertices(const float *mtx, const float *inVtx, float *xfVtx, unsigned int nVtx, const VertexLayout &vtxLayout = VertexLayout(12, 4, 8));
However, i've no idea about how to get 'mtx' and a correct VertexLayout. Can you kindly help? Thanks!
The param 'mtx' in TransformVertices() function refers to the projection matrix? Am i right?
@kirkpatrickc @geoffrey-jon
Finally I figured them out. In OpenGL, the 'mtx' here = ProjectionMatrix * ViewMatrix * ModelMatrix. Now the culling works like a charm ;) Thanks!