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