mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Cylinder intersectio and rotation but capped edge + need opti
This commit is contained in:
@ -43,7 +43,8 @@ class Object
|
||||
QUAD,
|
||||
TRIANGLE,
|
||||
CUBE,
|
||||
PORTAL
|
||||
PORTAL,
|
||||
CYLINDER
|
||||
};
|
||||
|
||||
virtual Type getType() const = 0;
|
||||
|
69
includes/RT/objects/Cylinder.hpp
Normal file
69
includes/RT/objects/Cylinder.hpp
Normal 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
|
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user