move the model to the center,

clean up variables,
use delete[]
This commit is contained in:
Anakin 2016-12-01 19:51:11 +01:00
parent 1c0ed61b34
commit a47eefe92e
4 changed files with 24 additions and 9 deletions

View File

@ -71,5 +71,5 @@ private:
public:
std::vector<Modl*>* getModels() const;
std::vector<std::string> getTextureList() const;
Bbox getBoundgBox() const;
};

View File

@ -72,6 +72,7 @@ private:
// data
std::vector<Modl*>* vModels = NULL;
std::vector<textureData*> vTextures;
Bbox sceneBoundingBox;
// transformation =========================
//values

View File

@ -134,6 +134,9 @@ void Object::analyseMsh2Chunks(std::list<ChunkHeader*>& chunkList)
fsMesh.read(reinterpret_cast<char*>(&boundingBox.extents[i]), sizeof(float));
}
}
for (ChunkHeader* it : tempSinfChunks)
delete it;
}
else if (!strcmp("MATL", it->name))
@ -217,7 +220,7 @@ void Object::analyseMatdChunks(std::list<ChunkHeader*>& chunkList)
*buffer = { 0 };
fsMesh.read(buffer, it->size);
vTextures.back() = buffer;
delete buffer;
delete[] buffer;
}
}
}
@ -241,7 +244,7 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
*buffer = { 0 };
fsMesh.read(buffer, it->size);
dataDestination->parent = buffer;
delete buffer;
delete[] buffer;
}
else if (!strcmp("NAME", it->name))
@ -251,7 +254,7 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
*buffer = { 0 };
fsMesh.read(buffer, it->size);
dataDestination->name = buffer;
delete buffer;
delete[] buffer;
}
else if (!strcmp("FLGS", it->name))
@ -515,7 +518,7 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
tempData->textureIndex = vTextures.size() - 1;
}
delete buffer;
delete[] buffer;
}
else if (!strcmp("CPOS", it->name))
@ -594,6 +597,11 @@ std::vector<std::string> Object::getTextureList() const
return vTextures;
}
Bbox Object::getBoundgBox() const
{
return boundingBox;
}
/////////////////////////////////////////////////////////////////////////
// public functions

View File

@ -122,8 +122,8 @@ void OpenGLController::deleteVectors()
Segment* segmCuror = cursor->segmLst.back();
cursor->segmLst.pop_back();
delete segmCuror->uv;
delete segmCuror->vertex;
delete[] segmCuror->uv;
delete[] segmCuror->vertex;
while (!segmCuror->meshIndices.empty())
{
@ -243,8 +243,13 @@ glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationY, glm::vec3(0, 1, 0));
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationZ, glm::vec3(0, 0, 1));
glm::mat4 m4x4ModelCenter = glm::translate(
glm::mat4(1.0f),
glm::vec3(-sceneBoundingBox.center[0], -sceneBoundingBox.center[1], -sceneBoundingBox.center[2])
);
// Return MVP
return m4x4Projection * m4x4View * m4x4ModelRot * getModelMatrix(index);
return m4x4Projection * m4x4View * m4x4ModelRot * m4x4ModelCenter * getModelMatrix(index);
}
@ -378,11 +383,12 @@ void OpenGLController::loadMsh(const char * path)
Object obj(path);
vModels = obj.getModels();
tempTexList = obj.getTextureList();
sceneBoundingBox = obj.getBoundgBox();
}
catch (std::invalid_argument e)
{
MessageBox(NULL, e.what(), "MeshViewer 2.0 Error", MB_OK | MB_ICONERROR);
return; exit(1);
return;
}
// collect vertex data of all models