mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ Parsing object system
This commit is contained in:
@ -17,15 +17,59 @@
|
||||
|
||||
class Sphere : public Object
|
||||
{
|
||||
|
||||
public:
|
||||
struct ParseError : public std::runtime_error
|
||||
{
|
||||
ParseError(const std::string& msg) : std::runtime_error("Sphere parse error: " + msg) {}
|
||||
};
|
||||
|
||||
Sphere(std::stringstream &line) : Object(glm::vec3(0.0f), nullptr)
|
||||
{
|
||||
_mat = new Material;
|
||||
|
||||
try {
|
||||
float x, y, z, radius;
|
||||
float r, g, b, rough, spec;
|
||||
|
||||
if (!(line >> x >> y >> z >> radius))
|
||||
throw std::invalid_argument("Missing position or radius values");
|
||||
|
||||
if (radius <= 0.0f)
|
||||
throw std::invalid_argument("Radius must be positive");
|
||||
|
||||
if (!(line >> r >> g >> b >> rough >> spec))
|
||||
throw std::invalid_argument("Missing material properties");
|
||||
|
||||
if (r < 0.0f || r > 255.0f || g < 0.0f || g > 255.0f || b < 0.0f || b > 255.0f)
|
||||
throw std::invalid_argument("Color values must be between 0 and 255");
|
||||
|
||||
if (rough < 0.0f || rough > 1.0f)
|
||||
throw std::invalid_argument("Roughness must be between 0 and 1");
|
||||
|
||||
if (spec < 0.0f || spec > 1.0f)
|
||||
throw std::invalid_argument("Specular must be between 0 and 1");
|
||||
|
||||
_position = glm::vec3(x, y, z);
|
||||
_radius = radius;
|
||||
|
||||
_mat->color = glm::vec3(r / 255.0f, g / 255.0f, b / 255.0f);
|
||||
_mat->roughness = rough;
|
||||
_mat->specular = spec;
|
||||
|
||||
_material = _mat;
|
||||
}
|
||||
catch (const std::exception& e) { throw; }
|
||||
}
|
||||
Sphere(const glm::vec3& position, float radius, const Material *material)
|
||||
: Object(position, material), _radius(radius) {}
|
||||
|
||||
float getRadius() const { return (_radius); }
|
||||
Type getType() const override { return Type::SPHERE; }
|
||||
float getRadius() const { return (_radius); }
|
||||
Type getType() const override { return Type::SPHERE; }
|
||||
|
||||
private:
|
||||
float _radius;
|
||||
Material *_mat;
|
||||
float _radius;
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user