generated from Kaweees/KiwiCPP
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "../include/vector3d.hpp" | ||
|
||
namespace graphics { | ||
|
||
class Mesh { | ||
public: | ||
// Constructor | ||
Mesh(); | ||
|
||
// Destructor | ||
~Mesh(); | ||
|
||
// Method to load mesh data from a file | ||
bool loadFromFile(const std::string& filename); | ||
|
||
// Method to get vertices | ||
const std::vector<Vector3D>& getVertices() const; | ||
|
||
// Method to add a vertex | ||
void addVertex(const Vector3D& vertex); | ||
|
||
private: | ||
std::vector<Vector3D> vertices; // Store vertices of the mesh | ||
}; | ||
|
||
} // namespace graphics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
class Triangle { | ||
public: | ||
Triangle(int v1, int v2, int v3) : vertexIndices{v1, v2, v3} {} | ||
int vertexIndices[3]; // Indices of the vertices that form the triangle | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
class Triangle { | ||
public: | ||
Triangle(int v1, int v2, int v3) : vertexIndices{v1, v2, v3} {} | ||
|
||
// Method to get vertex indices | ||
const int* getVertexIndices() const { return vertexIndices; } | ||
|
||
private: | ||
int vertexIndices[3]; // Indices of the vertices that form the triangle | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include "../include/mesh.hpp" | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
namespace graphics { | ||
|
||
Mesh::Mesh() {} | ||
|
||
Mesh::~Mesh() {} | ||
|
||
bool Mesh::loadFromFile(const std::string& filename) { | ||
std::ifstream file(filename); | ||
if (!file.is_open()) { | ||
std::cerr << "Failed to open mesh file: " << filename << std::endl; | ||
return false; | ||
} | ||
|
||
std::string line; | ||
while (std::getline(file, line)) { | ||
std::istringstream iss(line); | ||
double x, y, z; | ||
if (iss >> x >> y >> z) { | ||
addVertex(Vector3D(x, y, z)); | ||
} | ||
} | ||
|
||
file.close(); | ||
return true; | ||
} | ||
|
||
const std::vector<Vector3D>& Mesh::getVertices() const { return vertices; } | ||
|
||
void Mesh::addVertex(const Vector3D& vertex) { vertices.push_back(vertex); } | ||
|
||
} // namespace graphics |
Empty file.