Constructed a simple quad for debugging terrain generation.
This commit is contained in:
parent
213a936fbb
commit
5ca77ae3cc
7
level.cc
7
level.cc
@ -34,12 +34,13 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) {
|
|||||||
|
|
||||||
// load terrain
|
// load terrain
|
||||||
this->terrain.load();
|
this->terrain.load();
|
||||||
Model terrainModel = this->terrain.getModel();
|
Model terrainModel = Model(this->terrain.getModel());
|
||||||
// load a texture:
|
// load a texture:
|
||||||
Material terrainMaterial = Material("clownfishBunny.png", 0.1f, 0.7f, 0.3f, 1.0f);
|
Material terrainMaterial = Material("clownfishBunny.png", 1.0f, 0.0f, 0.0f, 3.0f);
|
||||||
//Create object
|
//Create object
|
||||||
Object terrainObject = Object(terrainModel, terrainMaterial,
|
Object terrainObject = Object(terrainModel, terrainMaterial,
|
||||||
glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), 0.0f, -0.5f*(float)this->terrain.getHeightmapWidth()),
|
//glm::vec3(-0.5f*(float)this->terrain.getHeightmapHeight(), -0.5f, -0.5f*(float)this->terrain.getHeightmapWidth()),
|
||||||
|
glm::vec3(-1.0f, 0.0f, -1.0f),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
||||||
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
objects.push_back(object);
|
objects.push_back(object);
|
||||||
|
64
terrain.cc
64
terrain.cc
@ -42,11 +42,12 @@ void Terrain::load() {
|
|||||||
void Terrain::makeTriangleMesh(){
|
void Terrain::makeTriangleMesh(){
|
||||||
|
|
||||||
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
||||||
ab->defineAttribute("aPosition", GL_FLOAT, 3); //TODO: ArrayBuffer for the texture coordinates
|
// Do NOT change the order of this!
|
||||||
ab->defineAttribute("aNormal", GL_FLOAT, 3);
|
ab->defineAttribute("aPosition", GL_FLOAT, 3);
|
||||||
ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
|
ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
|
||||||
|
ab->defineAttribute("aNormal", GL_FLOAT, 3);
|
||||||
|
|
||||||
unsigned int rowNum=0, columnNum=0, dataCount=0, abNumFloats=8; //initializing:
|
/* unsigned int rowNum=0, columnNum=0, dataCount=0, abNumFloats=8; //initializing:
|
||||||
bool movingRight = true, isUp = true;
|
bool movingRight = true, isUp = true;
|
||||||
int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1;
|
int numVertices = (this->heightmapHeight - 1) * (this->heightmapWidth * 2 + 1) + 1;
|
||||||
float* abData = new float[numVertices * abNumFloats];
|
float* abData = new float[numVertices * abNumFloats];
|
||||||
@ -57,20 +58,23 @@ void Terrain::makeTriangleMesh(){
|
|||||||
if (isUp){
|
if (isUp){
|
||||||
rowNum = rowNum + 1;
|
rowNum = rowNum + 1;
|
||||||
isUp = false;
|
isUp = false;
|
||||||
}else if (movingRight){
|
}
|
||||||
if (columnNum == this->heightmapWidth - 1){
|
else if (movingRight) {
|
||||||
|
if (columnNum == this->heightmapWidth - 1) {
|
||||||
set_abData(abData, dataCount, rowNum, columnNum);
|
set_abData(abData, dataCount, rowNum, columnNum);
|
||||||
dataCount += abNumFloats;
|
dataCount += abNumFloats;
|
||||||
set_abData(abData, dataCount, rowNum, columnNum);
|
set_abData(abData, dataCount, rowNum, columnNum);
|
||||||
dataCount += abNumFloats;
|
dataCount += abNumFloats;
|
||||||
movingRight = false;
|
movingRight = false;
|
||||||
rowNum = rowNum + 1;
|
rowNum = rowNum + 1;
|
||||||
} else{
|
}
|
||||||
|
else {
|
||||||
rowNum = rowNum - 1;
|
rowNum = rowNum - 1;
|
||||||
columnNum = columnNum + 1;
|
columnNum = columnNum + 1;
|
||||||
isUp = true;
|
isUp = true;
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
if (columnNum == 0){
|
if (columnNum == 0){
|
||||||
set_abData(abData, dataCount, rowNum, columnNum);
|
set_abData(abData, dataCount, rowNum, columnNum);
|
||||||
dataCount += abNumFloats;
|
dataCount += abNumFloats;
|
||||||
@ -78,7 +82,8 @@ void Terrain::makeTriangleMesh(){
|
|||||||
dataCount += abNumFloats;
|
dataCount += abNumFloats;
|
||||||
movingRight = true;
|
movingRight = true;
|
||||||
rowNum = rowNum + 1;
|
rowNum = rowNum + 1;
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
rowNum = rowNum - 1;
|
rowNum = rowNum - 1;
|
||||||
columnNum = columnNum - 1;
|
columnNum = columnNum - 1;
|
||||||
isUp = true;
|
isUp = true;
|
||||||
@ -86,7 +91,23 @@ void Terrain::makeTriangleMesh(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ab->setDataElements(numVertices, abData);
|
ab->setDataElements(numVertices, abData);*/
|
||||||
|
float abData[32] = {0.0f, 0.0f, 0.0f,
|
||||||
|
1.0f, 0.0f,
|
||||||
|
0.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
|
1.0f, 0.0f, 0.0f,
|
||||||
|
1.0f, 1.0f,
|
||||||
|
0.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
|
0.0f, 0.0f, 1.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
0.0f, 1.0f, 0.0f,
|
||||||
|
|
||||||
|
1.0f, 0.0f, 1.0f,
|
||||||
|
0.0f, 1.0f,
|
||||||
|
0.0f, 1.0f, 0.0f};
|
||||||
|
ab->setDataElements(4, abData);
|
||||||
this->triangleMesh = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
this->triangleMesh = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
||||||
this->triangleMesh->bind();
|
this->triangleMesh->bind();
|
||||||
this->triangleMesh->setMode(GL_TRIANGLE_STRIP);
|
this->triangleMesh->setMode(GL_TRIANGLE_STRIP);
|
||||||
@ -101,15 +122,20 @@ void Terrain::set_abData(float* abData, unsigned int dataCount, unsigned int row
|
|||||||
abData[dataCount+1] = heightmap[rowNum][columnNum];
|
abData[dataCount+1] = heightmap[rowNum][columnNum];
|
||||||
abData[dataCount+2] = (float)columnNum;
|
abData[dataCount+2] = (float)columnNum;
|
||||||
|
|
||||||
|
//set Texture Coordinate
|
||||||
|
abData[dataCount+3] = (float)(rowNum % 2);
|
||||||
|
abData[dataCount+4] = (float)(columnNum % 2);
|
||||||
|
|
||||||
//setNormal
|
//setNormal
|
||||||
if (rowNum==0 || rowNum==(this->heightmapHeight-1) || columnNum==0 || columnNum==(this->heightmapWidth-1)){
|
if (rowNum==0 || rowNum==(this->heightmapHeight-1) || columnNum==0 || columnNum==(this->heightmapWidth-1)){
|
||||||
abData[dataCount+3] = 0.0;
|
|
||||||
abData[dataCount+4] = 1.0;
|
|
||||||
abData[dataCount+5] = 0.0;
|
abData[dataCount+5] = 0.0;
|
||||||
}else{
|
abData[dataCount+6] = 1.0;
|
||||||
|
abData[dataCount+7] = 0.0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
glm::vec3 sumNormals;
|
glm::vec3 sumNormals;
|
||||||
for (int i=-1; i<2; i+=1){
|
for (int i=-1; i<2; i+=1) {
|
||||||
for (int j=-1; j<2; j+=1){
|
for (int j=-1; j<2; j+=1) {
|
||||||
glm::vec3 vecA, vecB, normal;
|
glm::vec3 vecA, vecB, normal;
|
||||||
vecA = glm::vec3((float)i, (heightmap[rowNum+i][columnNum] - heightmap[rowNum][columnNum]), 0.0f);
|
vecA = glm::vec3((float)i, (heightmap[rowNum+i][columnNum] - heightmap[rowNum][columnNum]), 0.0f);
|
||||||
vecB = glm::vec3(0.0f, (heightmap[rowNum][columnNum+j] - heightmap[rowNum][columnNum]), (float)j);
|
vecB = glm::vec3(0.0f, (heightmap[rowNum][columnNum+j] - heightmap[rowNum][columnNum]), (float)j);
|
||||||
@ -120,14 +146,10 @@ void Terrain::set_abData(float* abData, unsigned int dataCount, unsigned int row
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sumNormals = sumNormals*0.111f;
|
sumNormals = sumNormals*0.111f;
|
||||||
abData[dataCount+3] = sumNormals[0];
|
abData[dataCount+5] = sumNormals[0];
|
||||||
abData[dataCount+4] = sumNormals[1];
|
abData[dataCount+6] = sumNormals[1];
|
||||||
abData[dataCount+5] = sumNormals[2];
|
abData[dataCount+7] = sumNormals[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
//set Texture Coordinate
|
|
||||||
abData[dataCount+6] = (float)(rowNum % 2);
|
|
||||||
abData[dataCount+7] = (float)(columnNum % 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Model Terrain::getModel(){
|
Model Terrain::getModel(){
|
||||||
|
Loading…
Reference in New Issue
Block a user