Commit 46c4a166 authored by Anakin's avatar Anakin

code improvement

parent 1918d5c8
......@@ -66,6 +66,7 @@ private:
void analyseClthChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
void readVertex(Segment* dataDestination, std::streampos position);
void readUV(Segment* dataDestination, std::streampos position);
void quat2eul(float &quat0, float &quat1, float &quat2, float &quat3);
public:
......
......@@ -271,27 +271,16 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
fsMesh.seekg(it->position);
//TODO: use loop
fsMesh.read(reinterpret_cast<char*>(&tempScale[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempScale[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempScale[2]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempRotation[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempRotation[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempRotation[2]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempRotation[3]), sizeof(float));
//TODO: make a function for this
//calculate x,y,z rotation
tempRotation[0] = atan2(2 * (tempRotation[0] * tempRotation[1] + tempRotation[2] * tempRotation[3]),
1 - 2 * (pow(tempRotation[1], 2) + pow(tempRotation[2], 2)));
tempRotation[1] = asin(2 * (tempRotation[0] * tempRotation[2] - tempRotation[3] * tempRotation[1]));
tempRotation[2] = atan2(2 * (tempRotation[0] * tempRotation[3] + tempRotation[1] * tempRotation[2]),
1 - 2 * (pow(tempRotation[2], 2) + pow(tempRotation[3], 2))) - PI;
fsMesh.read(reinterpret_cast<char*>(&tempTrans[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempTrans[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempTrans[2]), sizeof(float));
for(int i = 0; i < 3; i++)
fsMesh.read(reinterpret_cast<char*>(&tempScale[i]), sizeof(float));
for (int i = 0; i < 4; i++)
fsMesh.read(reinterpret_cast<char*>(&tempRotation[i]), sizeof(float));
quat2eul(tempRotation[0], tempRotation[1], tempRotation[2], tempRotation[3]);
for (int i = 0; i < 3; i++)
fsMesh.read(reinterpret_cast<char*>(&tempTrans[i]), sizeof(float));
dataDestination->m4x4Translation = glm::scale(
dataDestination->m4x4Translation,
......@@ -583,6 +572,25 @@ void Object::readUV(Segment* dataDestination, std::streampos position)
fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i]), sizeof(float));
}
void Object::quat2eul(float &quat0, float &quat1, float & quat2, float &quat3)
{
float eulX = atan2(
2 * (quat0 * quat1 + quat2 * quat3),
1 - 2 * (pow(quat1, 2) + pow(quat2, 2))
);
float eulY = asin(2 * (quat0 * quat2 - quat3 * quat1));
float eulZ = atan2(
2 * (quat0 * quat3 + quat1 * quat2),
1 - 2 * (pow(quat2, 2) + pow(quat3, 2))
) - PI;
quat0 = eulX;
quat1 = eulY;
quat2 = eulZ;
}
/////////////////////////////////////////////////////////////////////////
// public getter
......
......@@ -109,34 +109,31 @@ void OpenGLController::processInit()
void OpenGLController::deleteVectors()
{
//TODO: does .clear() work, too??
if (vModels != NULL)
{
while (!vModels->empty())
{
Modl* cursor = vModels->back();
Modl* modelVectorElement = vModels->back();
vModels->pop_back();
while (!cursor->segmLst.empty())
while (!modelVectorElement->segmLst.empty())
{
Segment* segmCuror = cursor->segmLst.back();
cursor->segmLst.pop_back();
Segment* segmentVectorElement = modelVectorElement->segmLst.back();
modelVectorElement->segmLst.pop_back();
delete[] segmCuror->uv;
delete[] segmCuror->vertex;
delete[] segmentVectorElement->uv;
delete[] segmentVectorElement->vertex;
while (!segmCuror->meshIndices.empty())
while (!segmentVectorElement->meshIndices.empty())
{
while (!segmCuror->meshIndices.back().empty())
segmCuror->meshIndices.back().pop_back();
segmCuror->meshIndices.pop_back();
segmentVectorElement->meshIndices.back().clear();
segmentVectorElement->meshIndices.pop_back();
}
delete segmCuror;
delete segmentVectorElement;
}
delete cursor;
delete modelVectorElement;
}
delete vModels;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment