+ | Cylinder intersectio and rotation but capped edge + need opti

This commit is contained in:
TheRedShip
2025-01-09 22:42:09 +01:00
parent 0ece075f1a
commit 9aa1de378f
10 changed files with 155 additions and 11 deletions

View File

@ -22,6 +22,7 @@
# include "glm/gtx/string_cast.hpp"
# include "glm/gtc/matrix_transform.hpp"
# include "glm/gtc/type_ptr.hpp"
# include "glm/gtx/euler_angles.hpp"
# include "glad/gl.h"
# include "GLFW/glfw3.h"
@ -46,6 +47,7 @@ struct Vertex {
# include "objects/Triangle.hpp"
# include "objects/Cube.hpp"
# include "objects/Portal.hpp"
# include "objects/Cylinder.hpp"
# include "Camera.hpp"
# include "Window.hpp"

View File

@ -43,7 +43,8 @@ class Object
QUAD,
TRIANGLE,
CUBE,
PORTAL
PORTAL,
CYLINDER
};
virtual Type getType() const = 0;

View File

@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Cylinder.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#ifndef RT_CYLINDER__HPP
# define RT_CYLINDER__HPP
# include "RT.hpp"
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;
int mat_index;
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 >> pitch >> yaw >> roll))
throw std::runtime_error("Missing rotation values");
if (!(line >> mat_index))
throw std::runtime_error("Missing material properties");
_position = glm::vec3(x, y, z);
_radius = radius / 2.0;
_height = height;
_rotation = glm::mat3(glm::eulerAngleXYZ(pitch, yaw, roll));
_mat_index = mat_index;
}
catch (const std::exception& e) { throw; }
}
Cylinder(const glm::vec3& position, float radius, const int mat_index)
: Object(position, mat_index), _radius(radius) {}
float getRadius() const { return (_radius); }
float getHeight() const { return (_height); }
glm::mat3 getRotation() const { return (_rotation); }
Type getType() const override { return Type::CYLINDER; }
private:
float _radius;
float _height;
glm::mat3 _rotation;
};
#endif

View File

@ -54,7 +54,7 @@ class Portal : public Object
up = normalize(glm::cross(forward, right));
_transform = glm::mat3(right, up, forward);
_rotation = glm::mat3(right, up, forward);
_normal = forward * (invert_normal ? -1.0f : 1.0f);
_linked_portal = -1;
@ -89,7 +89,7 @@ class Portal : public Object
glm::vec3 getRight() const { return (_right); }
glm::vec3 getNormal() const { return (_normal); }
glm::mat3 getTransform() const { return (_transform); }
glm::mat3 getRotation() const { return (_rotation); }
int getLinkedPortalIndex() const { return (_linked_portal); }
void setLinkedPortalIndex(int index) { _linked_portal = index; }
@ -101,7 +101,7 @@ class Portal : public Object
glm::vec3 _right;
glm::vec3 _normal;
glm::mat3 _transform;
glm::mat3 _rotation;
int _linked_portal;
};