Bug fixes

This commit is contained in:
IlyaShurupov 2023-10-16 00:02:32 +03:00 committed by Ilya Shurupov
parent 15b56a876a
commit b2fa4c4266
3 changed files with 20 additions and 27 deletions

View file

@ -193,8 +193,9 @@ namespace tp {
Buffer& operator=(const Buffer& in) {
if (this == &in) return *this;
clear();
return *this;
this->~Buffer();
new (this) Buffer(in);
return *this;
}
~Buffer() {
@ -405,4 +406,4 @@ namespace tp {
}
}
}
}

View file

@ -73,19 +73,11 @@ const Vec3F& TrigCache::getNormal() const { return mNormal; }
void Topology::addTrig(const Vec3F& v1, const Vec3F& v2, const Vec3F& v3) {
auto trigIdx = mPoints.size();
Buffer<Vec3F> newPoints(3);
newPoints[0] = v1;
newPoints[1] = v2;
newPoints[2] = v3;
mPoints.append(newPoints);
transformPoint(newPoints[0]);
transformPoint(newPoints[1]);
transformPoint(newPoints[2]);
mPointsTransformed.append(newPoints);
mPoints.append(v1);
mPoints.append(v2);
mPoints.append(v3);
TrigCache newTrig(trigIdx, trigIdx + 1, trigIdx + 2);
newTrig.updateCache(mPointsTransformed);
mTrigCaches.append(newTrig);
}
@ -102,4 +94,4 @@ void Topology::updateTransformed() {
for (auto idx : Range(mTrigCaches.size())) {
mTrigCaches[idx].updateCache(mPointsTransformed);
}
}
}

View file

@ -22,21 +22,21 @@ void loadScene(Scene& scene, const String& scenePath) {
}
for (auto& curMesh : Loader.LoadedMeshes) {
// Go through each vertex and print its number,
// position, normal, and texture coordinate
for (int j = 0; j < curMesh.Vertices.size(); j++) {
// file << "V" << j << ": "
// << "P(" << curMesh.Vertices[j].Position.X << ", " << curMesh.Vertices[j].Position.Y << ", " << curMesh.Vertices[j].Position.Z << ") "
// << "N(" << curMesh.Vertices[j].Normal.X << ", " << curMesh.Vertices[j].Normal.Y << ", " << curMesh.Vertices[j].Normal.Z << ") "
// << "TC(" << curMesh.Vertices[j].TextureCoordinate.X << ", " << curMesh.Vertices[j].TextureCoordinate.Y << ")\n";
}
scene.mObjects.append(Topology());
auto object = &scene.mObjects.last();
// Print Indices
// Go through every 3rd index and print the
// triangle that these indices represent
for (int j = 0; j < curMesh.Indices.size(); j += 3) {
// file << "T" << j / 3 << ": " << curMesh.Indices[j] << ", " << curMesh.Indices[j + 1] << ", " << curMesh.Indices[j + 2] << "\n";
unsigned int idx1 = curMesh.Indices[j];
unsigned int idx2 = curMesh.Indices[j + 1];
unsigned int idx3 = curMesh.Indices[j + 2];
Vec3F v1 = {curMesh.Vertices[idx1].Position.X, curMesh.Vertices[idx1].Position.Y, curMesh.Vertices[idx1].Position.Z};
Vec3F v2 = {curMesh.Vertices[idx2].Position.X, curMesh.Vertices[idx2].Position.Y, curMesh.Vertices[idx2].Position.Z};
Vec3F v3 = {curMesh.Vertices[idx3].Position.X, curMesh.Vertices[idx3].Position.Y, curMesh.Vertices[idx3].Position.Z};
object->addTrig(v1, v2, v3);
}
object->updateTransformed();
}
}