code improvement
This commit is contained in:
parent
1918d5c844
commit
46c4a166c4
|
@ -66,6 +66,7 @@ private:
|
||||||
void analyseClthChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
void analyseClthChunks(Modl* dataDestination, std::list<ChunkHeader*> &chunkList);
|
||||||
void readVertex(Segment* dataDestination, std::streampos position);
|
void readVertex(Segment* dataDestination, std::streampos position);
|
||||||
void readUV(Segment* dataDestination, std::streampos position);
|
void readUV(Segment* dataDestination, std::streampos position);
|
||||||
|
void quat2eul(float &quat0, float &quat1, float &quat2, float &quat3);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -271,27 +271,16 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
|
||||||
|
|
||||||
fsMesh.seekg(it->position);
|
fsMesh.seekg(it->position);
|
||||||
|
|
||||||
//TODO: use loop
|
for(int i = 0; i < 3; i++)
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempScale[0]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&tempScale[i]), 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));
|
for (int i = 0; i < 4; i++)
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempRotation[1]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&tempRotation[i]), 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
|
quat2eul(tempRotation[0], tempRotation[1], tempRotation[2], tempRotation[3]);
|
||||||
//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));
|
for (int i = 0; i < 3; i++)
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempTrans[1]), sizeof(float));
|
fsMesh.read(reinterpret_cast<char*>(&tempTrans[i]), sizeof(float));
|
||||||
fsMesh.read(reinterpret_cast<char*>(&tempTrans[2]), sizeof(float));
|
|
||||||
|
|
||||||
dataDestination->m4x4Translation = glm::scale(
|
dataDestination->m4x4Translation = glm::scale(
|
||||||
dataDestination->m4x4Translation,
|
dataDestination->m4x4Translation,
|
||||||
|
@ -583,6 +572,25 @@ void Object::readUV(Segment* dataDestination, std::streampos position)
|
||||||
fsMesh.read(reinterpret_cast<char*>(&dataDestination->uv[i]), sizeof(float));
|
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
|
// public getter
|
||||||
|
|
|
@ -109,34 +109,31 @@ void OpenGLController::processInit()
|
||||||
|
|
||||||
void OpenGLController::deleteVectors()
|
void OpenGLController::deleteVectors()
|
||||||
{
|
{
|
||||||
//TODO: does .clear() work, too??
|
|
||||||
if (vModels != NULL)
|
if (vModels != NULL)
|
||||||
{
|
{
|
||||||
while (!vModels->empty())
|
while (!vModels->empty())
|
||||||
{
|
{
|
||||||
Modl* cursor = vModels->back();
|
Modl* modelVectorElement = vModels->back();
|
||||||
vModels->pop_back();
|
vModels->pop_back();
|
||||||
|
|
||||||
while (!cursor->segmLst.empty())
|
while (!modelVectorElement->segmLst.empty())
|
||||||
{
|
{
|
||||||
Segment* segmCuror = cursor->segmLst.back();
|
Segment* segmentVectorElement = modelVectorElement->segmLst.back();
|
||||||
cursor->segmLst.pop_back();
|
modelVectorElement->segmLst.pop_back();
|
||||||
|
|
||||||
delete[] segmCuror->uv;
|
delete[] segmentVectorElement->uv;
|
||||||
delete[] segmCuror->vertex;
|
delete[] segmentVectorElement->vertex;
|
||||||
|
|
||||||
while (!segmCuror->meshIndices.empty())
|
while (!segmentVectorElement->meshIndices.empty())
|
||||||
{
|
{
|
||||||
while (!segmCuror->meshIndices.back().empty())
|
segmentVectorElement->meshIndices.back().clear();
|
||||||
segmCuror->meshIndices.back().pop_back();
|
segmentVectorElement->meshIndices.pop_back();
|
||||||
|
|
||||||
segmCuror->meshIndices.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete segmCuror;
|
delete segmentVectorElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete cursor;
|
delete modelVectorElement;
|
||||||
}
|
}
|
||||||
delete vModels;
|
delete vModels;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue