From 1624b53baaa9148377fa7598640b18273bad0116 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Mon, 24 May 2021 11:45:17 +0200 Subject: [PATCH] 3D drawables all have a position. Non-positionable object will throw an error when a setter/getter is called --- lib/Ray/sources/Drawables/3D/Circle.cpp | 7 +++---- lib/Ray/sources/Drawables/3D/Circle.hpp | 3 --- lib/Ray/sources/Drawables/3D/Cube.cpp | 13 +------------ lib/Ray/sources/Drawables/3D/Cube.hpp | 7 ------- lib/Ray/sources/Drawables/3D/Cylinder.cpp | 17 +++-------------- lib/Ray/sources/Drawables/3D/Cylinder.hpp | 10 +--------- lib/Ray/sources/Drawables/3D/Grid.cpp | 15 +++++++++++++-- lib/Ray/sources/Drawables/3D/Grid.hpp | 10 +++++++++- lib/Ray/sources/Drawables/3D/Line.cpp | 8 ++++---- lib/Ray/sources/Drawables/3D/Line.hpp | 2 -- lib/Ray/sources/Drawables/3D/Plane.cpp | 13 +------------ lib/Ray/sources/Drawables/3D/Plane.hpp | 8 -------- lib/Ray/sources/Drawables/3D/Point.cpp | 13 +------------ lib/Ray/sources/Drawables/3D/Point.hpp | 10 ---------- lib/Ray/sources/Drawables/3D/Ray.cpp | 22 ++++++---------------- lib/Ray/sources/Drawables/3D/Ray.hpp | 9 ++------- lib/Ray/sources/Drawables/3D/Sphere.cpp | 15 ++------------- lib/Ray/sources/Drawables/3D/Sphere.hpp | 9 --------- lib/Ray/sources/Drawables/3D/Triangle.cpp | 8 ++++---- lib/Ray/sources/Drawables/3D/Triangle.hpp | 2 -- lib/Ray/sources/Drawables/ADrawable3D.cpp | 17 +++++++++++++++-- lib/Ray/sources/Drawables/ADrawable3D.hpp | 16 +++++++++++++--- 22 files changed, 78 insertions(+), 156 deletions(-) diff --git a/lib/Ray/sources/Drawables/3D/Circle.cpp b/lib/Ray/sources/Drawables/3D/Circle.cpp index c174a30e..326e5ee7 100644 --- a/lib/Ray/sources/Drawables/3D/Circle.cpp +++ b/lib/Ray/sources/Drawables/3D/Circle.cpp @@ -8,12 +8,11 @@ #include "Drawables/3D/Circle.hpp" RAY::Drawables::Drawables3D::Circle::Circle(const Vector3 ¢erPosition, int radius, const Color &color, const Vector3 &rotationAxis, float rotationAngle): - ADrawable3D(color), _radius(radius), _centerPos(centerPosition), _rotationAxis(rotationAxis), _rotationAngle(rotationAngle) + ADrawable3D(centerPosition, color), _radius(radius), _rotationAxis(rotationAxis), _rotationAngle(rotationAngle) { } - int RAY::Drawables::Drawables3D::Circle::getRadius(void) const { return this->_radius; @@ -27,11 +26,11 @@ RAY::Drawables::Drawables3D::Circle &RAY::Drawables::Drawables3D::Circle::setRad const RAY::Vector3 &RAY::Drawables::Drawables3D::Circle::getCenterPos(void) const { - return this->_centerPos; + return this->_position; } void RAY::Drawables::Drawables3D::Circle::drawOn(RAY::Window &) { - DrawCircle3D(this->_centerPos, this->_radius,this->_rotationAxis, + DrawCircle3D(this->_position, this->_radius,this->_rotationAxis, this->_rotationAngle, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Circle.hpp b/lib/Ray/sources/Drawables/3D/Circle.hpp index 6c014e9c..656492ff 100644 --- a/lib/Ray/sources/Drawables/3D/Circle.hpp +++ b/lib/Ray/sources/Drawables/3D/Circle.hpp @@ -51,9 +51,6 @@ namespace RAY::Drawables::Drawables3D { //! @brief Radius of the circle int _radius; - //! @brief position of the center - Vector3 _centerPos; - //! @brief rotation axis Vector3 _rotationAxis; diff --git a/lib/Ray/sources/Drawables/3D/Cube.cpp b/lib/Ray/sources/Drawables/3D/Cube.cpp index edbd9474..ca0ffcc3 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.cpp +++ b/lib/Ray/sources/Drawables/3D/Cube.cpp @@ -9,16 +9,11 @@ RAY::Drawables::Drawables3D::Cube::Cube(const RAY::Vector3 &position, const RAY::Vector3 &dimensions, const Color &color): - ADrawable3D(color), _position(position), _dimenstions(dimensions) + ADrawable3D(position, color), _dimenstions(dimensions) { } -const RAY::Vector3 &RAY::Drawables::Drawables3D::Cube::getPosition(void) const -{ - return this->_position; -} - const RAY::Vector3 &RAY::Drawables::Drawables3D::Cube::getDimensions(void) const { return this->_dimenstions; @@ -30,12 +25,6 @@ RAY::Drawables::Drawables3D::Cube &RAY::Drawables::Drawables3D::Cube::setDimensi return *this; } -RAY::Drawables::Drawables3D::Cube &RAY::Drawables::Drawables3D::Cube::setPosition(const RAY::Vector3 &position) -{ - this->_position = position; - return *this; -} - void RAY::Drawables::Drawables3D::Cube::drawOn(RAY::Window &) { DrawCubeV(this->_position, this->_dimenstions, this->_color); diff --git a/lib/Ray/sources/Drawables/3D/Cube.hpp b/lib/Ray/sources/Drawables/3D/Cube.hpp index c9972f04..4d98f951 100644 --- a/lib/Ray/sources/Drawables/3D/Cube.hpp +++ b/lib/Ray/sources/Drawables/3D/Cube.hpp @@ -32,23 +32,16 @@ namespace RAY::Drawables::Drawables3D { //! @brief A default destructor ~Cube() = default; - //! @return the position of the cube - const Vector3 &getPosition(void) const; //! @return the dimensions of the cube const Vector3 &getDimensions(void) const; //! @brief set the dimensions of the cube Cube &setDimensions(const Vector3 &dimensions); - - //! @brief set the dimensions of the cube - Cube &setPosition(const Vector3 &position); //! @brief Draw circle on window void drawOn(RAY::Window &) override; private: - //! @brief Positon in space of the cube - Vector3 _position; //! @brief Dimensions of the cube Vector3 _dimenstions; }; diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.cpp b/lib/Ray/sources/Drawables/3D/Cylinder.cpp index eab4e1da..d34f4e81 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.cpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.cpp @@ -9,7 +9,7 @@ RAY::Drawables::Drawables3D::Cylinder::Cylinder(const Vector3 &position, float radiusTop, float radiusBottom, float height, const Color &color): - ADrawable3D(color), _topRadius(radiusTop), _bottomRadius(radiusBottom), _height(height), _centerPos(position) + ADrawable3D(position, color), _topRadius(radiusTop), _bottomRadius(radiusBottom), _height(height) { @@ -32,23 +32,12 @@ int RAY::Drawables::Drawables3D::Cylinder::getBottomRadius(void) const return this->_bottomRadius; } -RAY::Drawables::Drawables3D::Cylinder &RAY::Drawables::Drawables3D::Cylinder::setBottopRadius(float radius) +RAY::Drawables::Drawables3D::Cylinder &RAY::Drawables::Drawables3D::Cylinder::setBottomRadius(float radius) { this->_bottomRadius = radius; return *this; } -const RAY::Vector3 &RAY::Drawables::Drawables3D::Cylinder::getPosition(void) const -{ - return this->_centerPos; -} - -RAY::Drawables::Drawables3D::Cylinder &RAY::Drawables::Drawables3D::Cylinder::setPosition(const Vector3 &position) -{ - this->_centerPos = position; - return *this; -} - float RAY::Drawables::Drawables3D::Cylinder::getHeight(void) const { return this->_height; @@ -62,5 +51,5 @@ RAY::Drawables::Drawables3D::Cylinder &RAY::Drawables::Drawables3D::Cylinder::se void RAY::Drawables::Drawables3D::Cylinder::drawOn(RAY::Window &) { - DrawCylinder(this->_centerPos, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_color); + DrawCylinder(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Cylinder.hpp b/lib/Ray/sources/Drawables/3D/Cylinder.hpp index 91ca8ed2..341f18f2 100644 --- a/lib/Ray/sources/Drawables/3D/Cylinder.hpp +++ b/lib/Ray/sources/Drawables/3D/Cylinder.hpp @@ -44,13 +44,7 @@ namespace RAY::Drawables::Drawables3D { int getBottomRadius(void) const; //! @brief set radius - Cylinder &setBottopRadius(float radius); - - //! @return the position of the center - const Vector3 &getPosition(void) const; - - //! @brief the position of the center - Cylinder &setPosition(const Vector3 &); + Cylinder &setBottomRadius(float radius); //! @return the Height float getHeight(void) const; @@ -71,8 +65,6 @@ namespace RAY::Drawables::Drawables3D { //! @brief height of the cylinder float _height; - //! @brief position of the center - Vector3 _centerPos; }; }; diff --git a/lib/Ray/sources/Drawables/3D/Grid.cpp b/lib/Ray/sources/Drawables/3D/Grid.cpp index b3cd3159..90aaf96d 100644 --- a/lib/Ray/sources/Drawables/3D/Grid.cpp +++ b/lib/Ray/sources/Drawables/3D/Grid.cpp @@ -6,9 +6,10 @@ */ #include "Drawables/3D/Grid.hpp" +#include "Exceptions/RayError.hpp" -RAY::Drawables::Drawables3D::Grid::Grid(int slices, float spacing): - ADrawable3D(LIGHTGRAY), _slices(slices), _spacing(spacing) +RAY::Drawables::Drawables3D::Grid::Grid(int slices, float spacing, const RAY::Color &color): + ADrawable3D(RAY::Vector3(0, 0, 0), color), _slices(slices), _spacing(spacing) { } @@ -23,6 +24,16 @@ float RAY::Drawables::Drawables3D::Grid::getSpacing(void) const return this->_spacing; } +const RAY::Vector3 &RAY::Drawables::Drawables3D::Grid::getPosition(void) const +{ + throw RAY::Exception::NotSupportedError("A Grid does not have a position"); +} + +RAY::Drawables::Drawables3D::Grid &RAY::Drawables::Drawables3D::Grid::setPosition(const RAY::Vector3 &) +{ + throw RAY::Exception::NotSupportedError("A Grid does not have a position"); +} + RAY::Drawables::Drawables3D::Grid &RAY::Drawables::Drawables3D::Grid::setSlices(int slices) { this->_slices = slices; diff --git a/lib/Ray/sources/Drawables/3D/Grid.hpp b/lib/Ray/sources/Drawables/3D/Grid.hpp index ecb209cd..633d9478 100644 --- a/lib/Ray/sources/Drawables/3D/Grid.hpp +++ b/lib/Ray/sources/Drawables/3D/Grid.hpp @@ -18,7 +18,7 @@ namespace RAY::Drawables::Drawables3D { //! @brief Grid constructor //! @param slices slices of the grid //! @param spacing spacing of slices - Grid(int slices, float spacing); + Grid(int slices, float spacing, const Color & = LIGHTGRAY); //! @brief A default copy constructor Grid(const Grid &) = default; @@ -41,6 +41,14 @@ namespace RAY::Drawables::Drawables3D { //! @brief Set spacing Grid &setSpacing(float spacing); + //! @throw NotSupportedError + //! @remark The grid does not have a position + const Vector3 &getPosition(void) const override; + + //! @throw NotSupportedError + //! @remark The grid does not have a position + virtual Grid &setPosition(const Vector3 &position) override; + //! @brief Draw point on window void drawOn(RAY::Window &) override; diff --git a/lib/Ray/sources/Drawables/3D/Line.cpp b/lib/Ray/sources/Drawables/3D/Line.cpp index 76022af1..afa72bd3 100644 --- a/lib/Ray/sources/Drawables/3D/Line.cpp +++ b/lib/Ray/sources/Drawables/3D/Line.cpp @@ -8,14 +8,14 @@ #include "Drawables/3D/Line.hpp" RAY::Drawables::Drawables3D::Line::Line(const Vector3 &startPosition, const Vector3 &endPosition, const Color &color): - ADrawable3D(color), _startPosition(startPosition), _endPosition(endPosition) + ADrawable3D(startPosition, color), _endPosition(endPosition) { } const RAY::Vector3 &RAY::Drawables::Drawables3D::Line::getStartPosition(void) const { - return this->_startPosition; + return this->_position; } const RAY::Vector3 &RAY::Drawables::Drawables3D::Line::getEndPosition(void) const @@ -25,7 +25,7 @@ const RAY::Vector3 &RAY::Drawables::Drawables3D::Line::getEndPosition(void) cons RAY::Drawables::Drawables3D::Line &RAY::Drawables::Drawables3D::Line::setStartPosition(const Vector3 &startPosition) { - this->_startPosition = startPosition; + this->_position = startPosition; return *this; } @@ -37,5 +37,5 @@ RAY::Drawables::Drawables3D::Line &RAY::Drawables::Drawables3D::Line::setEndPosi void RAY::Drawables::Drawables3D::Line::drawOn(RAY::Window &) { - DrawLine3D(this->_startPosition, this->_endPosition, this->_color); + DrawLine3D(this->_position, this->_endPosition, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Line.hpp b/lib/Ray/sources/Drawables/3D/Line.hpp index 03148618..1c1f6196 100644 --- a/lib/Ray/sources/Drawables/3D/Line.hpp +++ b/lib/Ray/sources/Drawables/3D/Line.hpp @@ -48,8 +48,6 @@ namespace RAY::Drawables::Drawables3D { void drawOn(RAY::Window &) override; private: - //! @brief start position - Vector3 _startPosition; //! @brief end position Vector3 _endPosition; }; diff --git a/lib/Ray/sources/Drawables/3D/Plane.cpp b/lib/Ray/sources/Drawables/3D/Plane.cpp index 1a874ba2..cffa19c7 100644 --- a/lib/Ray/sources/Drawables/3D/Plane.cpp +++ b/lib/Ray/sources/Drawables/3D/Plane.cpp @@ -8,22 +8,11 @@ #include "Drawables/3D/Plane.hpp" RAY::Drawables::Drawables3D::Plane::Plane(const Vector3 &position, const Vector2 &dimensions, const Color &color): - ADrawable3D(color), _position(position), _dimensions(dimensions) + ADrawable3D(position, color), _dimensions(dimensions) { } -const RAY::Vector3 &RAY::Drawables::Drawables3D::Plane::getPosition(void) const -{ - return this->_position; -} - -RAY::Drawables::Drawables3D::Plane &RAY::Drawables::Drawables3D::Plane::setPosition(const Vector3 &Position) -{ - this->_position = Position; - return *this; -} - const RAY::Vector2 &RAY::Drawables::Drawables3D::Plane::getDimensions(void) const { return this->_dimensions; diff --git a/lib/Ray/sources/Drawables/3D/Plane.hpp b/lib/Ray/sources/Drawables/3D/Plane.hpp index a4f6dc71..7ff53e65 100644 --- a/lib/Ray/sources/Drawables/3D/Plane.hpp +++ b/lib/Ray/sources/Drawables/3D/Plane.hpp @@ -31,12 +31,6 @@ namespace RAY::Drawables::Drawables3D { //! @brief A default destructor ~Plane() = default; - //! @return the position of the plane - const Vector3 &getPosition(void) const; - - //! @brief Set position - Plane &setPosition(const Vector3 &Position); - //! @return the dimensions of the plane const Vector2 &getDimensions(void) const; @@ -47,8 +41,6 @@ namespace RAY::Drawables::Drawables3D { void drawOn(RAY::Window &) override; private: - //! @brief plane position - Vector3 _position; //! @brief plane dimensions Vector2 _dimensions; diff --git a/lib/Ray/sources/Drawables/3D/Point.cpp b/lib/Ray/sources/Drawables/3D/Point.cpp index 21a9f933..f8845984 100644 --- a/lib/Ray/sources/Drawables/3D/Point.cpp +++ b/lib/Ray/sources/Drawables/3D/Point.cpp @@ -9,22 +9,11 @@ #include "Drawables/3D/Point.hpp" RAY::Drawables::Drawables3D::Point::Point(const Vector3 &position, const Color &color): - ADrawable3D(color), _position(position) + ADrawable3D(position, color) { } -const RAY::Vector3 &RAY::Drawables::Drawables3D::Point::getPosition(void) const -{ - return this->_position; -} - -RAY::Drawables::Drawables3D::Point &RAY::Drawables::Drawables3D::Point::setPosition(const Vector3 &Position) -{ - this->_position = Position; - return *this; -} - void RAY::Drawables::Drawables3D::Point::drawOn(RAY::Window &) { DrawPoint3D(this->_position, this->_color); diff --git a/lib/Ray/sources/Drawables/3D/Point.hpp b/lib/Ray/sources/Drawables/3D/Point.hpp index 03af0e98..2c4001a9 100644 --- a/lib/Ray/sources/Drawables/3D/Point.hpp +++ b/lib/Ray/sources/Drawables/3D/Point.hpp @@ -30,18 +30,8 @@ namespace RAY::Drawables::Drawables3D { //! @brief A default destructor ~Point() = default; - //! @return the position of the point - const Vector3 &getPosition(void) const; - - //! @brief Set position - Point &setPosition(const Vector3 &Position); - //! @brief Draw point on window void drawOn(RAY::Window &) override; - - private: - //! @brief point position - Vector3 _position; }; }; diff --git a/lib/Ray/sources/Drawables/3D/Ray.cpp b/lib/Ray/sources/Drawables/3D/Ray.cpp index b6d5bfa2..82cce12c 100644 --- a/lib/Ray/sources/Drawables/3D/Ray.cpp +++ b/lib/Ray/sources/Drawables/3D/Ray.cpp @@ -8,34 +8,24 @@ #include "Drawables/3D/Ray.hpp" RAY::Drawables::Drawables3D::Ray::Ray(const Vector3 &startPosition, const Vector3 &direction, const Color &color): - ADrawable3D(color), _ray({startPosition, direction}) + ADrawable3D(startPosition, color), _direction(direction) { } -const RAY::Vector3 RAY::Drawables::Drawables3D::Ray::getStartPosition(void) const +const RAY::Vector3 &RAY::Drawables::Drawables3D::Ray::getDirection(void) const { - return this->_ray.position; -} - -const RAY::Vector3 RAY::Drawables::Drawables3D::Ray::getDirection(void) const -{ - return this->_ray.direction; -} - -RAY::Drawables::Drawables3D::Ray &RAY::Drawables::Drawables3D::Ray::setStartPosition(const Vector3 &startPosition) -{ - this->_ray.position = startPosition; - return *this; + return this->_direction; } RAY::Drawables::Drawables3D::Ray &RAY::Drawables::Drawables3D::Ray::setDirection(const Vector3 &direction) { - this->_ray.direction = direction; + this->_direction = direction; return *this; } void RAY::Drawables::Drawables3D::Ray::drawOn(RAY::Window &) { - DrawRay(this->_ray, this->_color); + ::Ray ray = {this->_position, this->_direction}; + DrawRay(ray, this->_color); } \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/3D/Ray.hpp b/lib/Ray/sources/Drawables/3D/Ray.hpp index 8895c342..3c0c8e8c 100644 --- a/lib/Ray/sources/Drawables/3D/Ray.hpp +++ b/lib/Ray/sources/Drawables/3D/Ray.hpp @@ -32,14 +32,9 @@ namespace RAY::Drawables::Drawables3D { ~Ray() = default; - //! @return the start position of the line - const Vector3 getStartPosition(void) const; //! @return the end position of the line - const Vector3 getDirection(void) const; - - //! @brief Set start position - Ray &setStartPosition(const Vector3 &startPosition); + const Vector3 &getDirection(void) const; //! @brief Set end position Ray &setDirection(const Vector3 &direction); @@ -48,7 +43,7 @@ namespace RAY::Drawables::Drawables3D { void drawOn(RAY::Window &) override; private: - ::Ray _ray; + Vector3 _direction; }; }; diff --git a/lib/Ray/sources/Drawables/3D/Sphere.cpp b/lib/Ray/sources/Drawables/3D/Sphere.cpp index 10c9a576..38cdd64c 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.cpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.cpp @@ -8,7 +8,7 @@ #include "Drawables/3D/Sphere.hpp" RAY::Drawables::Drawables3D::Sphere::Sphere(const Vector3 ¢erPosition, int radius, const Color &color): - ADrawable3D(color), _radius(radius), _centerPos(centerPosition) + ADrawable3D(centerPosition, color), _radius(radius) { } @@ -24,18 +24,7 @@ RAY::Drawables::Drawables3D::Sphere &RAY::Drawables::Drawables3D::Sphere::setRad return *this; } -const RAY::Vector3 &RAY::Drawables::Drawables3D::Sphere::getCenterPos(void) const -{ - return this->_centerPos; -} - -RAY::Drawables::Drawables3D::Sphere &RAY::Drawables::Drawables3D::Sphere::setRadius(const Vector3 &pos) -{ - this->_centerPos = pos; - return *this; -} - void RAY::Drawables::Drawables3D::Sphere::drawOn(RAY::Window &) { - DrawSphere(this->_centerPos, this->_radius, this->_color); + DrawSphere(this->_position, this->_radius, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Sphere.hpp b/lib/Ray/sources/Drawables/3D/Sphere.hpp index 4e1095f6..64005557 100644 --- a/lib/Ray/sources/Drawables/3D/Sphere.hpp +++ b/lib/Ray/sources/Drawables/3D/Sphere.hpp @@ -38,21 +38,12 @@ namespace RAY::Drawables::Drawables3D { //! @brief set radius Sphere &setRadius(int radius); - //! @return the position of the center - const Vector3 &getCenterPos(void) const; - - //! @brief set pos of center - Sphere &setRadius(const Vector3 &pos); - //! @brief Draw point on window void drawOn(RAY::Window &) override; private: //! @brief Radius of the sphere int _radius; - - //! @brief position of the center - Vector3 _centerPos; }; }; diff --git a/lib/Ray/sources/Drawables/3D/Triangle.cpp b/lib/Ray/sources/Drawables/3D/Triangle.cpp index d3b4ea8b..2b58ac6d 100644 --- a/lib/Ray/sources/Drawables/3D/Triangle.cpp +++ b/lib/Ray/sources/Drawables/3D/Triangle.cpp @@ -9,14 +9,14 @@ #include RAY::Drawables::Drawables3D::Triangle::Triangle(const Vector3 &positionA, const Vector3 &positionB, const Vector3 &positionC, const Color &color): - ADrawable3D(color), _posA(positionA), _posB(positionB), _posC(positionC) + ADrawable3D(positionA, color), _posB(positionB), _posC(positionC) { } const RAY::Vector3 &RAY::Drawables::Drawables3D::Triangle::getPositionA(void) const { - return this->_posA; + return this->getPosition(); } const RAY::Vector3 &RAY::Drawables::Drawables3D::Triangle::getPositionB(void) const @@ -31,7 +31,7 @@ const RAY::Vector3 &RAY::Drawables::Drawables3D::Triangle::getPositionC(void) co RAY::Drawables::Drawables3D::Triangle &RAY::Drawables::Drawables3D::Triangle::setPositionA(const Vector3 &position) { - this->_posA = position; + this->setPosition(position); return *this; } @@ -49,7 +49,7 @@ RAY::Drawables::Drawables3D::Triangle &RAY::Drawables::Drawables3D::Triangle::se void RAY::Drawables::Drawables3D::Triangle::drawOn(RAY::Window &) { - DrawTriangle3D(this->_posA, this->_posB, this->_posC, this->_color); + DrawTriangle3D(this->_position, this->_posB, this->_posC, this->_color); } diff --git a/lib/Ray/sources/Drawables/3D/Triangle.hpp b/lib/Ray/sources/Drawables/3D/Triangle.hpp index bee8b049..16508cda 100644 --- a/lib/Ray/sources/Drawables/3D/Triangle.hpp +++ b/lib/Ray/sources/Drawables/3D/Triangle.hpp @@ -56,8 +56,6 @@ namespace RAY::Drawables::Drawables3D { void drawOn(RAY::Window &) override; private: - //! @brief Position of A - Vector3 _posA; //! @brief Position of B Vector3 _posB; //! @brief Position of C diff --git a/lib/Ray/sources/Drawables/ADrawable3D.cpp b/lib/Ray/sources/Drawables/ADrawable3D.cpp index a810f562..447ad250 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.cpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.cpp @@ -7,8 +7,8 @@ #include "Drawables/ADrawable3D.hpp" -RAY::Drawables::Drawables3D::ADrawable3D::ADrawable3D(const RAY::Color &color): - _color(color) +RAY::Drawables::Drawables3D::ADrawable3D::ADrawable3D(const RAY::Vector3 &position, const RAY::Color &color): + _position(position), _color(color) { } @@ -23,3 +23,16 @@ RAY::Drawables::Drawables3D::ADrawable3D &RAY::Drawables::Drawables3D::ADrawable this->_color = color; return *this; } + + +const RAY::Vector3 &RAY::Drawables::Drawables3D::ADrawable3D::getPosition(void) const +{ + return this->_position; +} + + +RAY::Drawables::Drawables3D::ADrawable3D &RAY::Drawables::Drawables3D::ADrawable3D::setPosition(const RAY::Vector3 &position) +{ + this->_position = position; + return *this; +} \ No newline at end of file diff --git a/lib/Ray/sources/Drawables/ADrawable3D.hpp b/lib/Ray/sources/Drawables/ADrawable3D.hpp index cb2c8fcf..b87d4a77 100644 --- a/lib/Ray/sources/Drawables/ADrawable3D.hpp +++ b/lib/Ray/sources/Drawables/ADrawable3D.hpp @@ -17,8 +17,9 @@ namespace RAY::Drawables::Drawables3D { class ADrawable3D: public IDrawable { public: - //! @param Color Color of the drawable - ADrawable3D(const RAY::Color &color); + //! @param Color Color of the drawable + //! @param Position Position of the drawable (wether its center or start position for lines) + ADrawable3D(const RAY::Vector3 &position, const RAY::Color &color); //! @brief A default copy constructor ADrawable3D(const ADrawable3D &) = default; @@ -30,12 +31,21 @@ namespace RAY::Drawables::Drawables3D { virtual void drawOn(RAY::Window &) = 0; //! @return the color of the ADrawable - const Color &getColor(void) const; + const RAY::Color &getColor(void) const; //! @brief set color ADrawable3D &setColor(const RAY::Color &color); + //! @return the position of the ADrawable + virtual const Vector3 &getPosition(void) const; + + //! @brief set position + virtual ADrawable3D &setPosition(const Vector3 &position); + protected: + //! @brief Position of the ADrawable + Vector3 _position; + //! @brief Color of the ADrawable Color _color;