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,7 +193,8 @@ namespace tp {
Buffer& operator=(const Buffer& in) { Buffer& operator=(const Buffer& in) {
if (this == &in) return *this; if (this == &in) return *this;
clear(); this->~Buffer();
new (this) Buffer(in);
return *this; return *this;
} }

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) { void Topology::addTrig(const Vec3F& v1, const Vec3F& v2, const Vec3F& v3) {
auto trigIdx = mPoints.size(); auto trigIdx = mPoints.size();
Buffer<Vec3F> newPoints(3); mPoints.append(v1);
newPoints[0] = v1; mPoints.append(v2);
newPoints[1] = v2; mPoints.append(v3);
newPoints[2] = v3;
mPoints.append(newPoints);
transformPoint(newPoints[0]);
transformPoint(newPoints[1]);
transformPoint(newPoints[2]);
mPointsTransformed.append(newPoints);
TrigCache newTrig(trigIdx, trigIdx + 1, trigIdx + 2); TrigCache newTrig(trigIdx, trigIdx + 1, trigIdx + 2);
newTrig.updateCache(mPointsTransformed);
mTrigCaches.append(newTrig); mTrigCaches.append(newTrig);
} }

View file

@ -22,21 +22,21 @@ void loadScene(Scene& scene, const String& scenePath) {
} }
for (auto& curMesh : Loader.LoadedMeshes) { for (auto& curMesh : Loader.LoadedMeshes) {
// Go through each vertex and print its number, scene.mObjects.append(Topology());
// position, normal, and texture coordinate auto object = &scene.mObjects.last();
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";
}
// 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) { 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();
} }
} }