Skip to content

Commit

Permalink
fix: save points to memory
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioJPinto committed Mar 5, 2024
1 parent 8d56986 commit 3ddc9c5
Show file tree
Hide file tree
Showing 11 changed files with 1,254 additions and 290 deletions.
2 changes: 1 addition & 1 deletion engine/include/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Camera {
Camera(Point position, Point lookAt, Point up, int fov, float near,
float far);

std::string toString();
// std::string toString();
};

#endif // CAMERA_HPP
2 changes: 1 addition & 1 deletion engine/include/Configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Configuration {
Configuration() = default;
Configuration(Window window, Camera camera, std::vector<std::string> models);

std::string toString();
// std::string toString();
};

#endif // CONFIGURATION_HPP
2 changes: 1 addition & 1 deletion engine/include/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Window {
Window();
Window(float width, float height);

std::string toString();
// std::string toString();
};

#endif // WINDOW_HPP
6 changes: 1 addition & 5 deletions engine/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ typedef struct Point {
Point(float x_val = 0.0f, float y_val = 0.0f, float z_val = 0.0f)
: x(x_val), y(y_val), z(z_val) {}

std::string toString() {
std::stringstream ss;
ss << "Point(" << x << ", " << y << ", " << z << ")";
return ss.str();
}
// std::string toString();
} Point;

// Function to convert Point to string
Expand Down
20 changes: 10 additions & 10 deletions engine/src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Camera::Camera(Point position, Point lookAt, Point up, int fov, float near,
this->far = far;
}

std::string Camera::toString() {
std::stringstream ss;
ss << "\tPosition: " << position.toString() << std::endl
<< "\tLookAt: " << lookAt.toString() << std::endl
<< "\tUp: " << up.toString() << std::endl
<< "\tFOV: " << std::to_string(fov).c_str() << std::endl
<< "\tNear: " << std::to_string(near).c_str() << std::endl
<< "\tFar: " << std::to_string(far).c_str() << std::endl;
return ss.str();
}
// std::string Camera::toString() {
// std::stringstream ss;
// ss << "\tPosition: " << position.toString() << std::endl
// << "\tLookAt: " << lookAt.toString() << std::endl
// << "\tUp: " << up.toString() << std::endl
// << "\tFOV: " << std::to_string(fov).c_str() << std::endl
// << "\tNear: " << std::to_string(near).c_str() << std::endl
// << "\tFar: " << std::to_string(far).c_str() << std::endl;
// return ss.str();
// }
18 changes: 9 additions & 9 deletions engine/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ std::string vectorToString(std::vector<std::string> v) {
return ss.str();
}

std::string Configuration::toString() {
std::stringstream ss;
ss << "Window:\n"
<< window.toString() << std::endl
<< "Camera:\n"
<< camera.toString() << std::endl
<< "Models: " << vectorToString(models) << std::endl;
return ss.str();
}
// std::string Configuration::toString() {
// std::stringstream ss;
// ss << "Window:\n"
// << window.toString() << std::endl
// << "Camera:\n"
// << camera.toString() << std::endl
// << "Models: " << vectorToString(models) << std::endl;
// return ss.str();
// }
12 changes: 6 additions & 6 deletions engine/src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Window::Window(float width, float height) {
this->height = height;
}

std::string Window::toString() {
std::stringstream ss;
ss << "\tWidth: " << width << std::endl
<< "\tHeight: " << height << std::endl;
return ss.str();
}
// std::string Window::toString() {
// std::stringstream ss;
// ss << "\tWidth: " << width << std::endl
// << "\tHeight: " << height << std::endl;
// return ss.str();
// }
12 changes: 0 additions & 12 deletions engine/src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "draw.hpp"
#include "utils.hpp"

#define MODELS "../models/"

void drawTriangles(const std::vector<Point>& points) {
glBegin(GL_TRIANGLES);
Expand All @@ -26,14 +25,3 @@ void drawTriangles(const std::vector<Point>& points) {
glEnd();
}

void drawFile(char* filename) {
std::string dir = MODELS;
dir.append(filename);

std::vector<Point> points = parseFile(dir);
if (points.empty()) {
// File not found or empty, handle this case
return;
}
drawTriangles(points);
}
28 changes: 24 additions & 4 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
#include "draw.hpp"
#include "parse.hpp"

#define MODELS "../models/"

float cameraAngle = 0.0f;
float cameraAngleY = 0.0f;

Configuration c;
std::vector<std::vector<Point>> vectors;

void reshape(int w, int h) {
float aspect_ratio = (float)w / (float)h;
Expand Down Expand Up @@ -64,8 +67,8 @@ void renderScene(void) {
drawAxis();

glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
for (std::string model : c.models) {
drawFile(model.data());
for (std::vector<Point> model : vectors) {
drawTriangles(model);
}

// End of frame
Expand All @@ -92,10 +95,27 @@ void processSpecialKeys(int key, int xx, int yy) {
glutPostRedisplay();
}

int main(int argc, char** argv) {
void setupConfig(char* arg) {

std::string filename;
filename.assign(argv[1]);
filename.assign(arg);
c = parseConfig(filename);
for(std::string file : c.models) {
std::string dir = MODELS;
dir.append(file);

std::vector<Point> points = parseFile(dir);
if (points.empty()) {
std::cerr << "File not found";
}

vectors.push_back(points);
}
}

int main(int argc, char** argv) {

setupConfig(argv[1]);

// put GLUT�s init here
glutInit(&argc, argv);
Expand Down
Loading

0 comments on commit 3ddc9c5

Please sign in to comment.