Skip to content

Commit

Permalink
fix: conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Mar 7, 2024
2 parents a42d48f + 3017ed3 commit e5d8f8d
Show file tree
Hide file tree
Showing 22 changed files with 315 additions and 79 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ CMakeFiles/*
*.app

.vscode
build
build
.3d
12 changes: 7 additions & 5 deletions common/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ 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
std::vector<Point> parseFile(std::string filename);
void saveToFile(const std::vector<Point>& points, const char* filepath);

// Function to parse OBJ file
std::vector<Point> parseOBJfile(std::string filename, std::string type);

// Function to parse 3D file
std::vector<Point> parse3Dfile(std::string filename);

#endif // UTILS_HPP
13 changes: 13 additions & 0 deletions engine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Engine

This engines has a couple of actions that enable you to control the orbital camera.
Here you will find all the controls and a couple of guides.

For proper usage, run the program in the engine directory.

### Controlos

**A** - Enables/Disables the axis of the projection
**R** - Resets the camera to the default position
**O/I** - Zoom in/Zoom out
**UP DOWN LEFT RIGHT** - Controls the camera movement
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
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();
// }
14 changes: 0 additions & 14 deletions engine/src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "../../common/include/utils.hpp"
#include "draw.hpp"

#define MODELS "../models/"

void drawTriangles(const std::vector<Point>& points) {
glBegin(GL_TRIANGLES);
for (size_t i = 0; i < points.size(); i += 3) {
Expand All @@ -25,15 +23,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);
}
113 changes: 93 additions & 20 deletions engine/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
#include "draw.hpp"
#include "parse.hpp"

#define MODELS "../models/"

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

float zoom = 1.0f;
int axis = 1;

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

void reshape(int w, int h) {
float aspect_ratio = (float)w / (float)h;
Expand All @@ -32,20 +38,22 @@ void reshape(int w, int h) {
}

void drawAxis(void) {
glBegin(GL_LINES);
// x-axis (red)
glColor3f(50.0f, 0.0f, 0.0f);
glVertex3f(-500.0f, 0.0f, 0.0f);
glVertex3f(500.0f, 0.0f, 0.0f);
// y-axis (green)
glColor3f(0.0f, 50.0f, 0.0f);
glVertex3f(0.0f, -500.0f, 0.0f);
glVertex3f(0.0f, 500.0f, 0.0f);
// z-axis (blue)
glColor3f(0.0f, 0.0f, 50.0f);
glVertex3f(0.0f, 0.0f, -500.0f);
glVertex3f(0.0f, 0.0f, 500.0f);
glEnd();
if (axis) {
glBegin(GL_LINES);
// x-axis (red)
glColor3f(50.0f, 0.0f, 0.0f);
glVertex3f(-500.0f, 0.0f, 0.0f);
glVertex3f(500.0f, 0.0f, 0.0f);
// y-axis (green)
glColor3f(0.0f, 50.0f, 0.0f);
glVertex3f(0.0f, -500.0f, 0.0f);
glVertex3f(0.0f, 500.0f, 0.0f);
// z-axis (blue)
glColor3f(0.0f, 0.0f, 50.0f);
glVertex3f(0.0f, 0.0f, -500.0f);
glVertex3f(0.0f, 0.0f, 500.0f);
glEnd();
}
}

void renderScene(void) {
Expand All @@ -60,12 +68,14 @@ void renderScene(void) {

glRotatef(cameraAngleY, 0.0f, 1.0f, 0.0f);
glRotatef(cameraAngle, 1.0f, 0.0f, 0.0f);
glScalef(zoom, zoom, zoom);

// put drawing instructions here
drawAxis();

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

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

int main(int argc, char** argv) {
void processNormalKeys(unsigned char key, int x, int y) {
switch (key) {
case 'a':
if (axis) {
axis = 0;
} else {
axis = 1;
}
break;
case 'r':
cameraAngle = 0;
cameraAngleY = 0;
zoom = 1.0f;
break;
case 'o':
if (zoom > 0.1) {
zoom -= 0.1;
}
break;
case 'i':
zoom += 0.1;
break;
default:
break;
}
}

void setupConfig(char* arg) {
std::string filename;
filename.assign(argv[1]);
c = parseConfig(filename);
filename.assign(arg);

if (filename.substr(filename.size() - 4) == ".xml") {
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);
}
} else {
c = parseConfig("../scenes/default.xml");
std::vector<Point> points = parseFile(filename);
vectors.push_back(points);
}
}

int main(int argc, char** argv) {
if (argc == 1) {
std::cout << "Invalid Arguments\n";
std::cout << "Usage: ./engine <file_path>\n";
return 1;
}

std::string filepath = argv[1];
if (filepath.substr(filepath.size() - 4) == ".xml") {
setupConfig(argv[1]);
} else {
c = parseConfig("../scenes/default.xml");
std::vector<Point> points = parseFile(filepath);
vectors.push_back(points);
}

// put GLUT�s init here
glutInit(&argc, argv);
Expand All @@ -110,6 +182,7 @@ int main(int argc, char** argv) {
glutReshapeFunc(reshape);

glutSpecialFunc(processSpecialKeys);
glutKeyboardFunc(processNormalKeys);

// some OpenGL settings
glEnable(GL_DEPTH_TEST);
Expand Down
11 changes: 11 additions & 0 deletions generator/include/shapes/cylinder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef CYLINDER_HPP
#define CYLINDER_HPP

#include <string>

#include "cylinder.hpp"

bool generateCylinder(float radius, float height, int slices,
const char* filepath);

#endif // CYLINDER_HPP
1 change: 0 additions & 1 deletion generator/include/shapes/plane.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define SOLAR_SYSTEM_PLANE_HPP

#include <string>
#include <vector>

#include "../../common/include/utils.hpp"

Expand Down
Loading

0 comments on commit e5d8f8d

Please sign in to comment.