diff --git a/Containers/public/Buffer.hpp b/Containers/public/Buffer.hpp index 13b04be..1e68d9e 100644 --- a/Containers/public/Buffer.hpp +++ b/Containers/public/Buffer.hpp @@ -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() { @@ -406,4 +407,4 @@ namespace tp { } } -} \ No newline at end of file +} diff --git a/Math/private/Topology.cpp b/Math/private/Topology.cpp index e8c4c53..d2ebb8a 100644 --- a/Math/private/Topology.cpp +++ b/Math/private/Topology.cpp @@ -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 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); } -} \ No newline at end of file +} diff --git a/RayTracer/applications/Rayt.cpp b/RayTracer/applications/Rayt.cpp index aa2fb68..56b4373 100644 --- a/RayTracer/applications/Rayt.cpp +++ b/RayTracer/applications/Rayt.cpp @@ -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(); } }