From 1eebeceeea640e46c1def0df6659ca1d8137c07d Mon Sep 17 00:00:00 2001 From: Gawaboumga Date: Sun, 21 Feb 2016 14:24:37 +0100 Subject: [PATCH] Documentation for Primitive Former-commit-id: 8f4e15d4e9131836545f8b112049a001638f411c --- include/Nazara/Core/Primitive.inl | 272 ++++++++++++++++++++++++++++ src/Nazara/Core/PrimitiveList.cpp | 160 ++++++++++++++++ tests/Engine/Core/PrimitiveList.cpp | 31 ++++ 3 files changed, 463 insertions(+) create mode 100644 tests/Engine/Core/PrimitiveList.cpp diff --git a/include/Nazara/Core/Primitive.inl b/include/Nazara/Core/Primitive.inl index ce458739d..8aeecc5b6 100644 --- a/include/Nazara/Core/Primitive.inl +++ b/include/Nazara/Core/Primitive.inl @@ -6,6 +6,20 @@ namespace Nz { + /*! + * \class Nz::PrimitiveList + * \brief Core class that represents a geometric primitive + */ + + /*! + * \brief Makes a box centered + * + * \param lengths (Width, Height, Depht) + * \param subdivision Number of subdivision for the axis + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeBox(const Vector3f& lengths, const Vector3ui& subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords) { matrix = transformMatrix; @@ -15,11 +29,31 @@ namespace Nz box.subdivision = subdivision; } + /*! + * \brief Makes a box centered + * + * \param lengths (Width, Height, Depht) + * \param subdivision Number of subdivision for the axis + * \param position Position of the box + * \param rotation Rotation of the box + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeBox(const Vector3f& lengths, const Vector3ui& subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { MakeBox(lengths, subdivision, Matrix4f::Transform(position, rotation), uvCoords); } + /*! + * \brief Makes a cone, centered in (0, 0, 0) and circle in (0, -length, 0) + * + * \param length Height of the cone + * \param radius Width of the radius + * \param subdivision Number of sides for the circle + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeCone(float length, float radius, unsigned int subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords) { matrix = transformMatrix; @@ -30,11 +64,31 @@ namespace Nz cone.subdivision = subdivision; } + /*! + * \brief Makes a cone, centered in (0, 0, 0) and circle in (0, -length, 0) + * + * \param length Height of the cone + * \param radius Width of the radius + * \param subdivision Number of sides for the circle + * \param position Position of the cone + * \param rotation Rotation of the cone + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeCone(float length, float radius, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { MakeCone(length, radius, subdivision, Matrix4f::Transform(position, rotation), uvCoords); } + /*! + * \brief Makes a cubic sphere, centered in (0, 0, 0) + * + * \param size Radius of the cubic sphere + * \param subdivision Number of subdivision for the box + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeCubicSphere(float size, unsigned int subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords) { matrix = transformMatrix; @@ -45,11 +99,30 @@ namespace Nz sphere.cubic.subdivision = subdivision; } + /*! + * \brief Adds a cubic sphere, centered in (0, 0, 0) + * + * \param size Radius of the cubic sphere + * \param subdivision Number of subdivision for the box + * \param position Position of the cubic sphere + * \param rotation Rotation of the cubic sphere + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeCubicSphere(float size, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { MakeCubicSphere(size, subdivision, Matrix4f::Transform(position, rotation), uvCoords); } + /*! + * \brief Makes a icosphere, centered in (0, 0, 0) + * + * \param size Radius of the icosphere + * \param recursionLevel Number of recursion for the icosphere + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeIcoSphere(float size, unsigned int recursionLevel, const Matrix4f& transformMatrix, const Rectf& uvCoords) { matrix = transformMatrix; @@ -60,11 +133,30 @@ namespace Nz sphere.ico.recursionLevel = recursionLevel; } + /*! + * \brief Makes a icosphere, centered in (0, 0, 0) + * + * \param size Radius of the sphere + * \param recursionLevel Number of recursion for the icosphere + * \param position Position of the icosphere + * \param rotation Rotation of the icosphere + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeIcoSphere(float size, unsigned int recursionLevel, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { MakeIcoSphere(size, recursionLevel, Matrix4f::Transform(position, rotation), uvCoords); } + /*! + * \brief Makes a plane, centered in (0, 0, 0) + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakePlane(const Vector2f& size, const Vector2ui& subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords) { matrix = transformMatrix; @@ -74,16 +166,45 @@ namespace Nz plane.subdivision = subdivision; } + /*! + * \brief Makes a plane, centered in (0, 0, 0) + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param planeInfo Information for the plane + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakePlane(const Vector2f& size, const Vector2ui& subdivision, const Planef& planeInfo, const Rectf& uvCoords) { MakePlane(size, subdivision, Matrix4f::Transform(planeInfo.distance * planeInfo.normal, Quaternionf::RotationBetween(Vector3f::Up(), planeInfo.normal)), uvCoords); } + /*! + * \brief Makes a plane, centered in (0, 0, 0) + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param position Position of the plane + * \param rotation Rotation of the plane + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakePlane(const Vector2f& size, const Vector2ui& subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { MakePlane(size, subdivision, Matrix4f::Transform(position, rotation), uvCoords); } + /*! + * \brief Makes a UV sphere, centered in (0, 0, 0) + * + * \param size Radius of the sphere + * \param sliceCount Number of slices + * \param stackCount Number of stacks + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& transformMatrix, const Rectf& uvCoords) { matrix = transformMatrix; @@ -95,11 +216,32 @@ namespace Nz sphere.uv.stackCount = stackCount; } + /*! + * \brief Makes a UV sphere, centered in (0, 0, 0) + * + * \param size Radius of the sphere + * \param sliceCount Number of slices + * \param stackCount Number of stacks + * \param position Position of the box + * \param rotation Rotation of the box + * \param uvCoords Coordinates for texture + */ + inline void Primitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { MakeUVSphere(size, sliceCount, stackCount, Matrix4f::Transform(position, rotation), uvCoords); } + /*! + * \brief Creates a box centered + * \return Primitive which is a box + * + * \param lengths (Width, Height, Depht) + * \param subdivision Number of subdivision for the axis + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::Box(const Vector3f& lengths, const Vector3ui& subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords) { Primitive primitive; @@ -108,6 +250,17 @@ namespace Nz return primitive; } + /*! + * \brief Creates a box centered + * \return Primitive which is a box + * + * \param lengths (Width, Height, Depht) + * \param subdivision Number of subdivision for the axis + * \param position Position of the box + * \param rotation Rotation of the box + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::Box(const Vector3f& lengths, const Vector3ui& subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { Primitive primitive; @@ -116,6 +269,17 @@ namespace Nz return primitive; } + /*! + * \brief Creates a cone, centered in (0, 0, 0) and circle in (0, -length, 0) + * \return Primitive which is a cone + * + * \param length Height of the cone + * \param radius Width of the radius + * \param subdivision Number of sides for the circle + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::Cone(float length, float radius, unsigned int subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords) { Primitive primitive; @@ -124,6 +288,18 @@ namespace Nz return primitive; } + /*! + * \brief Creates a cone, centered in (0, 0, 0) and circle in (0, -length, 0) + * \return Primitive which is a cone + * + * \param length Height of the cone + * \param radius Width of the radius + * \param subdivision Number of sides for the circle + * \param position Position of the cone + * \param rotation Rotation of the cone + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::Cone(float length, float radius, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { Primitive primitive; @@ -132,6 +308,16 @@ namespace Nz return primitive; } + /*! + * \brief Creates a cubic sphere, centered in (0, 0, 0) + * \return Primitive which is a cubic sphere + * + * \param size Radius of the cubic sphere + * \param subdivision Number of subdivision for the box + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::CubicSphere(float size, unsigned int subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords) { Primitive primitive; @@ -140,6 +326,17 @@ namespace Nz return primitive; } + /*! + * \brief Creates a cubic sphere, centered in (0, 0, 0) + * \return Primitive which is a cubic sphere + * + * \param size Radius of the cubic sphere + * \param subdivision Number of subdivision for the box + * \param position Position of the cubic sphere + * \param rotation Rotation of the cubic sphere + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::CubicSphere(float size, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { Primitive primitive; @@ -148,6 +345,16 @@ namespace Nz return primitive; } + /*! + * \brief Creates a icosphere, centered in (0, 0, 0) + * \return Primitive which is a icosphere + * + * \param size Radius of the icosphere + * \param recursionLevel Number of recursion for the icosphere + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::IcoSphere(float size, unsigned int recursionLevel, const Matrix4f& transformMatrix, const Rectf& uvCoords) { Primitive primitive; @@ -156,6 +363,17 @@ namespace Nz return primitive; } + /*! + * \brief Creates a icosphere, centered in (0, 0, 0) + * \return Primitive which is a icosphere + * + * \param size Radius of the sphere + * \param recursionLevel Number of recursion for the icosphere + * \param position Position of the icosphere + * \param rotation Rotation of the icosphere + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::IcoSphere(float size, unsigned int recursionLevel, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { Primitive primitive; @@ -164,6 +382,16 @@ namespace Nz return primitive; } + /*! + * \brief Creates a plane, centered in (0, 0, 0) + * \return Primitive which is a plane + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::Plane(const Vector2f& size, const Vector2ui& subdivision, const Matrix4f& transformMatrix, const Rectf& uvCoords) { Primitive primitive; @@ -172,6 +400,16 @@ namespace Nz return primitive; } + /*! + * \brief Creates a plane, centered in (0, 0, 0) + * \return Primitive which is a plane + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param planeInfo Information for the plane + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::Plane(const Vector2f& size, const Vector2ui& subdivision, const Planef& plane, const Rectf& uvCoords) { Primitive primitive; @@ -180,6 +418,17 @@ namespace Nz return primitive; } + /*! + * \brief Creates a plane, centered in (0, 0, 0) + * \return Primitive which is a plane + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param position Position of the plane + * \param rotation Rotation of the plane + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::Plane(const Vector2f& size, const Vector2ui& subdivision, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { Primitive primitive; @@ -188,6 +437,17 @@ namespace Nz return primitive; } + /*! + * \brief Creates a UV sphere, centered in (0, 0, 0) + * \return Primitive which is a uv sphere + * + * \param size Radius of the sphere + * \param sliceCount Number of slices + * \param stackCount Number of stacks + * \param transformMatrix Matrix to apply + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& transformMatrix, const Rectf& uvCoords) { Primitive primitive; @@ -196,6 +456,18 @@ namespace Nz return primitive; } + /*! + * \brief Creates a UV sphere, centered in (0, 0, 0) + * \return Primitive which is a uv sphere + * + * \param size Radius of the sphere + * \param sliceCount Number of slices + * \param stackCount Number of stacks + * \param position Position of the box + * \param rotation Rotation of the box + * \param uvCoords Coordinates for texture + */ + inline Primitive Primitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation, const Rectf& uvCoords) { Primitive primitive; diff --git a/src/Nazara/Core/PrimitiveList.cpp b/src/Nazara/Core/PrimitiveList.cpp index a9d2fc6ee..644f46e66 100644 --- a/src/Nazara/Core/PrimitiveList.cpp +++ b/src/Nazara/Core/PrimitiveList.cpp @@ -8,71 +8,199 @@ namespace Nz { + /*! + * \class Nz::PrimitiveList + * \brief Core class that represents a list of geometric primitives + */ + + /*! + * \brief Adds a box centered + * + * \param lengths (Width, Height, Depht) + * \param subdivision Number of subdivision for the axis + * \param transformMatrix Matrix to apply + */ + void PrimitiveList::AddBox(const Vector3f& lengths, const Vector3ui& subdivision, const Matrix4f& transformMatrix) { m_primitives.push_back(Primitive::Box(lengths, subdivision, transformMatrix)); } + /*! + * \brief Adds a box centered + * + * \param lengths (Width, Height, Depht) + * \param subdivision Number of subdivision for the axis + * \param position Position of the box + * \param rotation Rotation of the box + */ + void PrimitiveList::AddBox(const Vector3f& lengths, const Vector3ui& subdivision, const Vector3f& position, const Quaternionf& rotation) { m_primitives.push_back(Primitive::Box(lengths, subdivision, position, rotation)); } + /*! + * \brief Adds a cone, centered in (0, 0, 0) and circle in (0, -length, 0) + * + * \param length Height of the cone + * \param radius Width of the radius + * \param subdivision Number of sides for the circle + * \param transformMatrix Matrix to apply + */ + void PrimitiveList::AddCone(float length, float radius, unsigned int subdivision, const Matrix4f& transformMatrix) { m_primitives.push_back(Primitive::Cone(length, radius, subdivision, transformMatrix)); } + /*! + * \brief Adds a cone, centered in (0, 0, 0) and circle in (0, -length, 0) + * + * \param length Height of the cone + * \param radius Width of the radius + * \param subdivision Number of sides for the circle + * \param position Position of the cone + * \param rotation Rotation of the cone + */ + void PrimitiveList::AddCone(float length, float radius, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation) { m_primitives.push_back(Primitive::Cone(length, radius, subdivision, position, rotation)); } + /*! + * \brief Adds a cubic sphere, centered in (0, 0, 0) + * + * \param size Radius of the cubic sphere + * \param subdivision Number of subdivision for the box + * \param transformMatrix Matrix to apply + */ + void PrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const Matrix4f& transformMatrix) { m_primitives.push_back(Primitive::CubicSphere(size, subdivision, transformMatrix)); } + /*! + * \brief Adds a cubic sphere, centered in (0, 0, 0) + * + * \param size Radius of the cubic sphere + * \param subdivision Number of subdivision for the box + * \param position Position of the cubic sphere + * \param rotation Rotation of the cubic sphere + */ + void PrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation) { m_primitives.push_back(Primitive::CubicSphere(size, subdivision, position, rotation)); } + /*! + * \brief Adds a icosphere, centered in (0, 0, 0) + * + * \param size Radius of the icosphere + * \param recursionLevel Number of recursion for the icosphere + * \param transformMatrix Matrix to apply + */ + void PrimitiveList::AddIcoSphere(float size, unsigned int recursionLevel, const Matrix4f& transformMatrix) { m_primitives.push_back(Primitive::IcoSphere(size, recursionLevel, transformMatrix)); } + /*! + * \brief Adds a icosphere, centered in (0, 0, 0) + * + * \param size Radius of the sphere + * \param recursionLevel Number of recursion for the icosphere + * \param position Position of the icosphere + * \param rotation Rotation of the icosphere + */ + void PrimitiveList::AddIcoSphere(float size, unsigned int recursionLevel, const Vector3f& position, const Quaternionf& rotation) { m_primitives.push_back(Primitive::IcoSphere(size, recursionLevel, position, rotation)); } + /*! + * \brief Adds a plane, centered in (0, 0, 0) + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param transformMatrix Matrix to apply + */ + void PrimitiveList::AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Matrix4f& transformMatrix) { m_primitives.push_back(Primitive::Plane(size, subdivision, transformMatrix)); } + /*! + * \brief Adds a plane, centered in (0, 0, 0) + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param planeInfo Information for the plane + */ + void PrimitiveList::AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Planef& planeInfo) { m_primitives.push_back(Primitive::Plane(size, subdivision, planeInfo)); } + /*! + * \brief Adds a plane, centered in (0, 0, 0) + * + * \param size (Width, Depth) + * \param subdivision Number of subdivision for the axis + * \param position Position of the plane + * \param rotation Rotation of the plane + */ + void PrimitiveList::AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Vector3f& position, const Quaternionf& rotation) { m_primitives.push_back(Primitive::Plane(size, subdivision, position, rotation)); } + /*! + * \brief Adds a UV sphere, centered in (0, 0, 0) + * + * \param size Radius of the sphere + * \param sliceCount Number of slices + * \param stackCount Number of stacks + * \param transformMatrix Matrix to apply + */ + void PrimitiveList::AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& transformMatrix) { m_primitives.push_back(Primitive::UVSphere(size, sliceCount, stackCount, transformMatrix)); } + /*! + * \brief Adds a UV sphere, centered in (0, 0, 0) + * + * \param size Radius of the sphere + * \param sliceCount Number of slices + * \param stackCount Number of stacks + * \param position Position of the box + * \param rotation Rotation of the box + */ + void PrimitiveList::AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation) { m_primitives.push_back(Primitive::UVSphere(size, sliceCount, stackCount, position, rotation)); } + /*! + * \brief Gets the ith primitive + * \return A reference to the ith primitive + * + * \param i Index of the primitive + * + * \remark Produces a NazaraAssert if index is greather than the size + */ + Primitive& PrimitiveList::GetPrimitive(std::size_t i) { NazaraAssert(i < m_primitives.size(), "Primitive index out of range"); @@ -80,6 +208,15 @@ namespace Nz return m_primitives[i]; } + /*! + * \brief Gets the ith primitive + * \return A constant reference to the ith primitive + * + * \param i Index of the primitive + * + * \remark Produces a NazaraAssert if index is greather than the size + */ + const Primitive& PrimitiveList::GetPrimitive(std::size_t i) const { NazaraAssert(i < m_primitives.size(), "Primitive index out of range"); @@ -87,16 +224,39 @@ namespace Nz return m_primitives[i]; } + /*! + * \brief Gets the number of primitives + * \return Number of primitives + */ + std::size_t PrimitiveList::GetSize() const { return m_primitives.size(); } + /*! + * \brief Gets the ith primitive + * \return A reference to the ith primitive + * + * \param i Index of the primitive + * + * \remark Produces a NazaraAssert if index is greather than the size + */ + Primitive& PrimitiveList::operator()(unsigned int i) { return GetPrimitive(i); } + /*! + * \brief Gets the ith primitive + * \return A constant reference to the ith primitive + * + * \param i Index of the primitive + * + * \remark Produces a NazaraAssert if index is greather than the size + */ + const Primitive& PrimitiveList::operator()(unsigned int i) const { return GetPrimitive(i); diff --git a/tests/Engine/Core/PrimitiveList.cpp b/tests/Engine/Core/PrimitiveList.cpp new file mode 100644 index 000000000..84a39cac2 --- /dev/null +++ b/tests/Engine/Core/PrimitiveList.cpp @@ -0,0 +1,31 @@ +#include +#include + +SCENARIO("PrimitiveList", "[CORE][PRIMITIVELIST]") +{ + GIVEN("An empty PrimitiveList") + { + Nz::PrimitiveList primitiveList; + + WHEN("We add two primitives") + { + float size = 1.f; + unsigned int subdivision = 1; + unsigned int recursionLevel = 1; + Nz::Matrix4f identity = Nz::Matrix4f::Identity(); + + primitiveList.AddCubicSphere(size, subdivision, identity); + primitiveList.AddIcoSphere(size, subdivision, identity); + + THEN("There must be two items") + { + REQUIRE(primitiveList.GetSize() == 2); + } + + THEN("The first one is the cubic sphere") + { + REQUIRE(primitiveList(0).sphere.type == Nz::SphereType_Cubic); + } + } + } +}