| 933 | } |
| 934 | |
| 935 | void GeneratePlane(const Vector2ui& subdivision, const Vector2f& size, const Matrix4f& matrix, const Rectf& textureCoords, VertexPointers vertexPointers, IndexIterator indices, Boxf* aabb, unsigned int indexOffset) |
| 936 | { |
| 937 | // Pour plus de facilité, on va construire notre plan en considérant que la normale est de 0,1,0 |
| 938 | // Et appliquer ensuite une matrice "finissant le travail" |
| 939 | |
| 940 | // Le nombre de faces appartenant à un axe est équivalent à 2 exposant la subdivision (1,2,4,8,16,32,...) |
| 941 | unsigned int horizontalFaceCount = (1 << subdivision.x); |
| 942 | unsigned int verticalFaceCount = (1 << subdivision.y); |
| 943 | |
| 944 | // Et le nombre de sommets est ce nombre ajouté de 1 (2,3,5,9,17,33,...) |
| 945 | unsigned int horizontalVertexCount = horizontalFaceCount + 1; |
| 946 | unsigned int verticalVertexCount = verticalFaceCount + 1; |
| 947 | |
| 948 | Vector3f normal(Vector3f::UnitY()); |
| 949 | normal = matrix.Transform(normal, 0.f); |
| 950 | normal.Normalize(); |
| 951 | |
| 952 | Vector3f tangent(1.f, 1.f, 0.f); |
| 953 | tangent = matrix.Transform(tangent, 0.f); |
| 954 | tangent.Normalize(); |
| 955 | |
| 956 | float halfSizeX = size.x / 2.f; |
| 957 | float halfSizeY = size.y / 2.f; |
| 958 | |
| 959 | float invHorizontalVertexCount = 1.f/(horizontalVertexCount-1); |
| 960 | float invVerticalVertexCount = 1.f/(verticalVertexCount-1); |
| 961 | for (unsigned int x = 0; x < horizontalVertexCount; ++x) |
| 962 | { |
| 963 | for (unsigned int y = 0; y < verticalVertexCount; ++y) |
| 964 | { |
| 965 | Vector3f localPos((2.f*x*invHorizontalVertexCount - 1.f) * halfSizeX, 0.f, (2.f*y*invVerticalVertexCount - 1.f) * halfSizeY); |
| 966 | *vertexPointers.positionPtr++ = matrix * localPos; |
| 967 | |
| 968 | if (vertexPointers.normalPtr) |
| 969 | *vertexPointers.normalPtr++ = normal; |
| 970 | |
| 971 | if (vertexPointers.tangentPtr) |
| 972 | *vertexPointers.tangentPtr++ = tangent; |
| 973 | |
| 974 | if (vertexPointers.uvPtr) |
| 975 | *vertexPointers.uvPtr++ = Vector2f(textureCoords.x + x*invHorizontalVertexCount*textureCoords.width, textureCoords.y + y*invVerticalVertexCount*textureCoords.height); |
| 976 | |
| 977 | if (x != horizontalVertexCount-1 && y != verticalVertexCount-1) |
| 978 | { |
| 979 | *indices++ = (x+0)*verticalVertexCount + y + 0 + indexOffset; |
| 980 | *indices++ = (x+0)*verticalVertexCount + y + 1 + indexOffset; |
| 981 | *indices++ = (x+1)*verticalVertexCount + y + 0 + indexOffset; |
| 982 | |
| 983 | *indices++ = (x+1)*verticalVertexCount + y + 0 + indexOffset; |
| 984 | *indices++ = (x+0)*verticalVertexCount + y + 1 + indexOffset; |
| 985 | *indices++ = (x+1)*verticalVertexCount + y + 1 + indexOffset; |
| 986 | } |
| 987 | } |
| 988 | } |
| 989 | |
| 990 | if (aabb) |
| 991 | aabb->Set(matrix.Transform(Vector3f(-halfSizeX, 0.f, -halfSizeY), 0.f), matrix.Transform(Vector3f(halfSizeX, 0.f, halfSizeY), 0.f)); |
| 992 | } |
no test coverage detected