~ | removing useless trycatch

This commit is contained in:
RedShip
2025-01-13 18:50:55 +01:00
parent 449f059a07
commit 819c07f90d
8 changed files with 136 additions and 191 deletions

View File

@ -20,26 +20,23 @@ class Cube : public Object
public:
Cube(std::stringstream &line) : Object(glm::vec3(0.0f), -1)
{
try {
float x, y, z;
float width, height, depth;
int mat_index;
float x, y, z;
float width, height, depth;
int mat_index;
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position values");
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position values");
if (!(line >> width >> height >> depth))
throw std::runtime_error("Missing width, height or depth values");
if (!(line >> width >> height >> depth))
throw std::runtime_error("Missing width, height or depth values");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_size = glm::vec3(width, height, depth);
_mat_index = mat_index;
}
catch (const std::exception& e) { throw; }
_position = glm::vec3(x, y, z);
_size = glm::vec3(width, height, depth);
_mat_index = mat_index;
}
Cube(const glm::vec3& position, const glm::vec3 &size, const int mat_index)
: Object(position, mat_index), _size(size) {}

View File

@ -20,35 +20,32 @@ class Cylinder : public Object
public:
Cylinder(std::stringstream &line) : Object(glm::vec3(0.0f), -1)
{
try {
float x, y, z;
float radius, height;
float pitch, yaw, roll;
float x, y, z;
float radius, height;
float pitch, yaw, roll;
int mat_index;
int mat_index;
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position");
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position");
if (!(line >> radius >> height))
throw std::runtime_error("Missing radius or height values");
if (!(line >> radius >> height))
throw std::runtime_error("Missing radius or height values");
if (!(line >> pitch >> yaw >> roll))
throw std::runtime_error("Missing rotation values");
if (!(line >> pitch >> yaw >> roll))
throw std::runtime_error("Missing rotation values");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_position = glm::vec3(x, y, z);
_radius = radius;
_height = height;
_rotation = glm::mat3(glm::eulerAngleXYZ(pitch, yaw, roll));
_radius = radius;
_height = height;
_rotation = glm::mat3(glm::eulerAngleXYZ(pitch, yaw, roll));
_mat_index = mat_index;
}
catch (const std::exception& e) { throw; }
_mat_index = mat_index;
}
Cylinder(const glm::vec3& position, float radius, const int mat_index)
: Object(position, mat_index), _radius(radius) {}

View File

@ -20,26 +20,23 @@ class Plane : public Object
public:
Plane(std::stringstream &line) : Object(glm::vec3(0.0f), -1)
{
try {
float x, y, z;
float nx, ny, nz;
int mat_index;
float x, y, z;
float nx, ny, nz;
int mat_index;
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position");
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position");
if (!(line >> nx >> ny >> nz))
throw std::runtime_error("Missing plane's normal");
if (!(line >> nx >> ny >> nz))
throw std::runtime_error("Missing plane's normal");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_normal = glm::vec3(nx, ny, nz);
_mat_index = mat_index;
}
catch (const std::exception &e) { throw; }
_position = glm::vec3(x, y, z);
_normal = glm::vec3(nx, ny, nz);
_mat_index = mat_index;
}
Plane(const glm::vec3 &position, const glm::vec3 &normal, const int mat_index)
: Object(position, mat_index), _normal(normal) {}

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 19:12:51 by ycontre #+# #+# */
/* Updated: 2024/12/23 19:47:09 by ycontre ### ########.fr */
/* Updated: 2025/01/13 18:44:40 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,48 +20,45 @@ class Portal : public Object
public:
Portal(std::stringstream &line) : Object(glm::vec3(0.0f), -1)
{
try {
float x, y, z;
float x1, y1, z1;
float x2, y2, z2;
bool invert_normal;
float x, y, z;
float x1, y1, z1;
float x2, y2, z2;
bool invert_normal;
int mat_index;
int mat_index;
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position");
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position");
if (!(line >> x1 >> y1 >> z1))
throw std::runtime_error("Missing Portal's first edge ");
if (!(line >> x1 >> y1 >> z1))
throw std::runtime_error("Missing Portal's first edge ");
if (!(line >> x2 >> y2 >> z2))
throw std::runtime_error("Missing Portal's second edge");
if (!(line >> invert_normal))
throw std::runtime_error("Missing invert_normal");
if (!(line >> x2 >> y2 >> z2))
throw std::runtime_error("Missing Portal's second edge");
if (!(line >> invert_normal))
throw std::runtime_error("Missing invert_normal");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_up = glm::vec3(x1, y1, z1);
_right = glm::vec3(x2, y2, z2);
_position = glm::vec3(x, y, z);
_up = glm::vec3(x1, y1, z1);
_right = glm::vec3(x2, y2, z2);
glm::vec3 up = glm::normalize(_up);
glm::vec3 right = glm::normalize(_right);
glm::vec3 forward = glm::normalize(glm::cross(right, up));
glm::vec3 up = glm::normalize(_up);
glm::vec3 right = glm::normalize(_right);
glm::vec3 forward = glm::normalize(glm::cross(right, up));
up = normalize(glm::cross(forward, right));
up = normalize(glm::cross(forward, right));
_rotation = glm::mat3(right, up, forward);
_normal = forward * (invert_normal ? -1.0f : 1.0f);
_rotation = glm::mat3(right, up, forward);
_normal = forward * (invert_normal ? -1.0f : 1.0f);
_linked_portal = -1;
_linked_portal = -1;
_mat_index = mat_index;
}
catch (const std::exception &e) { throw; }
_mat_index = mat_index;
}
Portal(const glm::vec3 &position, const glm::vec3 &edge1, const glm::vec3 &edge2, const int linked_portal, const int mat_index)
: Object(position, mat_index), _up(edge1), _right(edge2), _linked_portal(linked_portal) {}

View File

@ -20,31 +20,28 @@ class Quad : public Object
public:
Quad(std::stringstream &line) : Object(glm::vec3(0.0f), -1)
{
try {
float x, y, z;
float x1, y1, z1;
float x2, y2, z2;
int mat_index;
float x, y, z;
float x1, y1, z1;
float x2, y2, z2;
int mat_index;
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position");
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing position");
if (!(line >> x1 >> y1 >> z1))
throw std::runtime_error("Missing quad's first edge ");
if (!(line >> x1 >> y1 >> z1))
throw std::runtime_error("Missing quad's first edge ");
if (!(line >> x2 >> y2 >> z2))
throw std::runtime_error("Missing quad's second edge");
if (!(line >> x2 >> y2 >> z2))
throw std::runtime_error("Missing quad's second edge");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_up = glm::vec3(x1, y1, z1);
_right = glm::vec3(x2, y2, z2);
_position = glm::vec3(x, y, z);
_up = glm::vec3(x1, y1, z1);
_right = glm::vec3(x2, y2, z2);
_mat_index = mat_index;
}
catch (const std::exception &e) { throw; }
_mat_index = mat_index;
}
Quad(const glm::vec3 &position, const glm::vec3 &edge1, const glm::vec3 &edge2, const int mat_index)
: Object(position, mat_index), _up(edge1), _right(edge2) {}

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 19:12:51 by ycontre #+# #+# */
/* Updated: 2025/01/08 20:20:34 by ycontre ### ########.fr */
/* Updated: 2025/01/13 18:46:58 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,25 +20,22 @@ class Sphere : public Object
public:
Sphere(std::stringstream &line) : Object(glm::vec3(0.0f), -1)
{
try {
float x, y, z, radius;
int mat_index;
float x, y, z, radius;
int mat_index;
if (!(line >> x >> y >> z >> radius))
throw std::runtime_error("Missing position or radius values");
if (!(line >> x >> y >> z >> radius))
throw std::runtime_error("Missing position or radius values");
if (radius <= 0.0f)
throw std::runtime_error("Radius must be positive");
if (radius <= 0.0f)
throw std::runtime_error("Radius must be positive");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_radius = radius / 2.0;
_mat_index = mat_index;
}
catch (const std::exception& e) { throw; }
_position = glm::vec3(x, y, z);
_radius = radius / 2.0;
_mat_index = mat_index;
}
Sphere(const glm::vec3& position, float radius, const int mat_index)
: Object(position, mat_index), _radius(radius) {}

View File

@ -6,7 +6,7 @@
/* By: ycontre <ycontre@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/23 19:12:51 by ycontre #+# #+# */
/* Updated: 2025/01/13 17:59:21 by tomoron ### ########.fr */
/* Updated: 2025/01/13 18:43:18 by ycontre ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,37 +20,34 @@ class Triangle : public Object
public:
Triangle(std::stringstream &line) : Object(glm::vec3(0.0f), -1)
{
try {
float x, y, z;
float x2, y2, z2;
float x3, y3, z3;
float x, y, z;
float x2, y2, z2;
float x3, y3, z3;
int mat_index;
int mat_index;
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing first vertex position");
if (!(line >> x >> y >> z))
throw std::runtime_error("Missing first vertex position");
if (!(line >> x2 >> y2 >> z2))
throw std::runtime_error("Missing second vertex position");
if (!(line >> x3 >> y3 >> z3))
throw std::runtime_error("Missing third vertex position");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_vertex2 = glm::vec3(x2, y2, z2);
_vertex3 = glm::vec3(x3, y3, z3);
_vertex2 -= _position; //optimization
_vertex3 -= _position; //optimization
_normal = glm::normalize(glm::cross(_vertex2, _vertex3)); //optimization
if (!(line >> x2 >> y2 >> z2))
throw std::runtime_error("Missing second vertex position");
_mat_index = mat_index;
}
catch (const std::exception &e) { throw; }
if (!(line >> x3 >> y3 >> z3))
throw std::runtime_error("Missing third vertex position");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_vertex2 = glm::vec3(x2, y2, z2);
_vertex3 = glm::vec3(x3, y3, z3);
_vertex2 -= _position; //optimization
_vertex3 -= _position; //optimization
_normal = glm::normalize(glm::cross(_vertex2, _vertex3)); //optimization
_mat_index = mat_index;
}
Triangle(const glm::vec3& position, const glm::vec3& vertex2, const glm::vec3& vertex3, const int mat_index)
: Object(position, mat_index), _vertex2(vertex2), _vertex3(vertex3) {