add wires + bounding box drawing for 3D shapes/Models

This commit is contained in:
arthur.jamet
2021-06-14 10:07:08 +02:00
parent d05d6f317b
commit ae68d5ab68
11 changed files with 49 additions and 1 deletions
+5
View File
@@ -30,4 +30,9 @@ namespace RAY::Drawables::Drawables3D
{
DrawCubeV(this->_position, this->_dimensions, this->_color);
}
void Cube::drawWiresOn(RAY::Window &)
{
DrawCubeWiresV(this->_position, this->_dimensions, GREEN);
}
}
+3
View File
@@ -41,6 +41,9 @@ namespace RAY::Drawables::Drawables3D {
//! @brief Draw circle on window
void drawOn(RAY::Window &) override;
//! @brief Draw cube's wires on window
void drawWiresOn(RAY::Window &) override;
private:
//! @brief Dimensions of the cube
Vector3 _dimensions;
@@ -52,4 +52,9 @@ namespace RAY::Drawables::Drawables3D
{
DrawCylinder(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, this->_color);
}
void Cylinder::drawWiresOn(RAY::Window &)
{
DrawCylinderWires(this->_position, this->_topRadius, this->_bottomRadius, this->_height, 0, GREEN);
}
}
@@ -55,6 +55,8 @@ namespace RAY::Drawables::Drawables3D {
//! @brief Draw point on window
void drawOn(RAY::Window &) override;
//! @brief Draw cylinder's wires on window
void drawWiresOn(RAY::Window &) override;
private:
//! @brief Radius of the cylinder
float _topRadius;
+5
View File
@@ -30,4 +30,9 @@ namespace RAY::Drawables::Drawables3D
{
DrawSphere(this->_position, this->_radius, this->_color);
}
void Sphere::drawWiresOn(RAY::Window &)
{
DrawSphereWires(this->_position, this->_radius, 10, 10, GREEN);
}
}
+3
View File
@@ -40,6 +40,9 @@ namespace RAY::Drawables::Drawables3D {
//! @brief Draw point on window
void drawOn(RAY::Window &) override;
//! @brief Draw sphere's wires on window
void drawWiresOn(RAY::Window &) override;
private:
//! @brief Radius of the sphere
int _radius;
@@ -36,4 +36,7 @@ namespace RAY::Drawables
this->_position = position;
return *this;
}
void ADrawable3D::drawWiresOn(RAY::Window &)
{}
}
@@ -30,6 +30,9 @@ namespace RAY::Drawables {
//! @brief Draw drawble on window
void drawOn(RAY::Window &) override = 0;
//! @brief Draw drawble's wires on window
virtual void drawWiresOn(RAY::Window &);
//! @return the color of the ADrawable
const RAY::Color &getColor(void) const;
+14
View File
@@ -114,6 +114,20 @@ namespace RAY::Drawables::Drawables3D
this->_color);
}
void Model::drawWiresOn(RAY::Window &)
{
if (this->_model->meshCount) {
::BoundingBox box = GetMeshBoundingBox(*this->_model->meshes);
box.min.x += this->_position.x;
box.min.y += this->_position.y;
box.min.z += this->_position.z;
box.max.x += this->_position.x;
box.max.y += this->_position.y;
box.max.z += this->_position.z;
DrawBoundingBox(box, GREEN);
}
}
void Model::setShader(const RAY::Shader &shader)
{
this->_originalShader = this->_model->materials[0].shader;
+3
View File
@@ -87,6 +87,9 @@ namespace RAY::Drawables::Drawables3D {
void drawOn(RAY::Window &) override;
//! @brief Draw model's wires on window
void drawWiresOn(RAY::Window &) override;
private:
//! @brief Raw data from raylib
std::shared_ptr<::Model> _model;
+3 -1
View File
@@ -40,6 +40,8 @@ namespace BBM
modelShader->model->setShader(modelShader->getShader());
drawable.drawable->setPosition(pos.position);
drawable.drawable->drawOn(this->_window);
if (this->_debugMode)
drawable.drawable->drawWiresOn(this->_window);
if (modelShader)
modelShader->model->resetShader();
}
@@ -59,7 +61,7 @@ namespace BBM
}
}
if (this->_debugMode)
this->_window.drawFPS(Vector2f());
this->_window.drawFPS(Vector2f(10, 10));
this->_window.endDrawing();
}