fixed gridMesh behavior
This commit is contained in:
parent
02e3fd7cb0
commit
96619f4f0f
21
gridmesh.cpp
21
gridmesh.cpp
@ -1,35 +1,36 @@
|
||||
#include "gridmesh.h"
|
||||
|
||||
GridMesh::GridMesh(int width, int height, bool alternate)
|
||||
GridMesh::GridMesh(Material* mat, int width, int height, bool alternate)
|
||||
{
|
||||
addGroup(mat);
|
||||
for(int i=0; i<=width; ++i)
|
||||
{
|
||||
for(int j=0; j<=height; ++j)
|
||||
{
|
||||
float x = (float)i/(float)width;
|
||||
float y = (float)j/(float)height;
|
||||
addPosition(x, y, 0);
|
||||
addNormal(0, 0, 1);
|
||||
addPosition(x-0.5f, 0, y-0.5f);
|
||||
addNormal(0, 1, 0);
|
||||
addTexCoord(x, y);
|
||||
if(i > 0 && j > 0)
|
||||
{
|
||||
if(alternate && (i+j)%2)
|
||||
{
|
||||
addTriangle(getVertexId(i, j, height),
|
||||
getVertexId(i-1, j, height),
|
||||
getVertexId(i, j-1, height));
|
||||
addTriangle(getVertexId(i-1, j-1, height),
|
||||
getVertexId(i, j-1, height),
|
||||
getVertexId(i-1, j, height));
|
||||
addTriangle(getVertexId(i-1, j-1, height),
|
||||
getVertexId(i-1, j, height),
|
||||
getVertexId(i, j-1, height));
|
||||
}
|
||||
else
|
||||
{
|
||||
addTriangle(getVertexId(i, j, height),
|
||||
getVertexId(i-1, j, height),
|
||||
getVertexId(i-1, j-1, height));
|
||||
addTriangle(getVertexId(i, j, height),
|
||||
getVertexId(i-1, j-1, height),
|
||||
getVertexId(i, j-1, height));
|
||||
getVertexId(i-1, j, height));
|
||||
addTriangle(getVertexId(i, j, height),
|
||||
getVertexId(i, j-1, height),
|
||||
getVertexId(i-1, j-1, height));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
class GridMesh : public MeshBuilder
|
||||
{
|
||||
public:
|
||||
GridMesh(int width, int height, bool alternate = true);
|
||||
GridMesh(Material* mat, int width, int height, bool alternate = true);
|
||||
private:
|
||||
int getVertexId(int i, int j, int height);
|
||||
};
|
||||
|
@ -70,6 +70,11 @@ void MeshBuilder::setCurrentGroup(int groupId)
|
||||
currentGroup = groupId;
|
||||
}
|
||||
|
||||
void MeshBuilder::setCurrentGroupMaterial(Material* myMaterial)
|
||||
{
|
||||
indiceGroups[currentGroup].material = myMaterial;
|
||||
}
|
||||
|
||||
int MeshBuilder::getNbGroups()
|
||||
{
|
||||
return indiceGroups.size();
|
||||
@ -81,7 +86,6 @@ void MeshBuilder::computeTangents()
|
||||
return;
|
||||
tangents = std::vector<Tangents>(positions.size());
|
||||
|
||||
|
||||
for(const Group &g : indiceGroups)
|
||||
for (int j=0; j < g.indices.size(); j += 3)
|
||||
{
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
|
||||
void addGroup(Material* myMaterial);
|
||||
void setCurrentGroup(int groupId);
|
||||
void setCurrentGroupMaterial(Material* myMaterial);
|
||||
int getNbGroups();
|
||||
|
||||
// require normals and texCoord
|
||||
|
Loading…
x
Reference in New Issue
Block a user