Calculating the vertex normals of a quad

好久不见. 提交于 2019-12-13 13:38:31

问题


Lets say that i have the following array :

float QuadVertices[4 * 2];
float QuadNormals[4 * 2];

Which i fill this way :

//Fill vertices for a 2d quad
Renderer->FillVertices(QuadVertices,GL_QUADS,x,y,width,height);

Now at this point everything is ok i can render a quad , texture it , stretch it and all that.

But now i want to calculate the normals of the quad :

for (int i = 0; i < 8;i++)
{
    QuadNormals[i] = ??
}

BUT i can't figure out how on earth i am supposed to calculate the normals of a simple 2d vertice array that contains either 4vertices of GL_QUADS or 6vertices of GL_TRIANGLES....


回答1:


If you have this -

   v1        v2
    +---------+
    |         | 
    |         |
    +---------+
    v3        v4

Where v1..v4 are the vertices of your quad then to calculate the normal at v1 you should calculate the vectors along the two edges it is on, and then calculate the cross product of those vertices.

So, the normal at v1 is

CrossProduct((v2-v1), (v3-v1))

You can repeat this for each vertex, although they will all be the same if the quad is "flat"

If you have other quads connected to this one, you may want to calculate the normal for each quad, and then assign the average of all the connected quads to be the normal for that vertex



来源:https://stackoverflow.com/questions/9806630/calculating-the-vertex-normals-of-a-quad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!