Core/PrimitiveList: Rework and inline the class
This commit is contained in:
parent
e8eebc1dfc
commit
72182327dd
|
|
@ -13,42 +13,40 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
///TODO: Inline this
|
||||
class NAZARA_CORE_API PrimitiveList
|
||||
class PrimitiveList
|
||||
{
|
||||
public:
|
||||
PrimitiveList() = default;
|
||||
PrimitiveList(const PrimitiveList&) = default;
|
||||
PrimitiveList(PrimitiveList&&) noexcept = default;
|
||||
~PrimitiveList() = default;
|
||||
inline PrimitiveList(const Primitive& primitive);
|
||||
inline PrimitiveList(std::initializer_list<Primitive> primitives);
|
||||
|
||||
void AddBox(const Vector3f& lengths, const Vector3ui& subdivision = Vector3ui(0U), const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
void AddBox(const Vector3f& lengths, const Vector3ui& subdivision, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
void AddCone(float length, float radius, unsigned int subdivision = 4, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
void AddCone(float length, float radius, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
void AddCubicSphere(float size, unsigned int subdivision = 4, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
void AddCubicSphere(float size, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
void AddIcoSphere(float size, unsigned int recursionLevel = 3, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
void AddIcoSphere(float size, unsigned int recursionLevel, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
void AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
void AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Planef& planeInfo);
|
||||
void AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
void AddUVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
void AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
inline void Add(const Primitive& primitive);
|
||||
inline void AddBox(const Vector3f& lengths, const Vector3ui& subdivision = Vector3ui(0U), const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
inline void AddBox(const Vector3f& lengths, const Vector3ui& subdivision, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
inline void AddCone(float length, float radius, unsigned int subdivision = 4, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
inline void AddCone(float length, float radius, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
inline void AddCubicSphere(float size, unsigned int subdivision = 4, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
inline void AddCubicSphere(float size, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
inline void AddIcoSphere(float size, unsigned int recursionLevel = 3, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
inline void AddIcoSphere(float size, unsigned int recursionLevel, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
inline void AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
inline void AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Planef& planeInfo);
|
||||
inline void AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
inline void AddUVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const Matrix4f& transformMatrix = Matrix4f::Identity());
|
||||
inline void AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Vector3f& position, const Quaternionf& rotation = Quaternionf::Identity());
|
||||
|
||||
Primitive& GetPrimitive(std::size_t i);
|
||||
const Primitive& GetPrimitive(std::size_t i) const;
|
||||
std::size_t GetSize() const;
|
||||
inline Primitive& GetPrimitive(std::size_t i);
|
||||
inline const Primitive& GetPrimitive(std::size_t i) const;
|
||||
inline std::size_t GetSize() const;
|
||||
|
||||
PrimitiveList& operator=(const PrimitiveList&) = default;
|
||||
PrimitiveList& operator=(PrimitiveList&&) noexcept = default;
|
||||
|
||||
Primitive& operator()(unsigned int i);
|
||||
const Primitive& operator()(unsigned int i) const;
|
||||
inline Primitive& operator[](std::size_t i);
|
||||
inline const Primitive& operator[](std::size_t i) const;
|
||||
|
||||
private:
|
||||
std::vector<Primitive> m_primitives;
|
||||
};
|
||||
}
|
||||
|
||||
#include <Nazara/Core/PrimitiveList.inl>
|
||||
|
||||
#endif // NAZARA_CORE_PRIMITIVELIST_HPP
|
||||
|
|
|
|||
|
|
@ -14,6 +14,21 @@ namespace Nz
|
|||
* \brief Core class that represents a list of geometric primitives
|
||||
*/
|
||||
|
||||
inline PrimitiveList::PrimitiveList(const Primitive& primitive)
|
||||
{
|
||||
Add(primitive);
|
||||
}
|
||||
|
||||
inline PrimitiveList::PrimitiveList(std::initializer_list<Primitive> primitives)
|
||||
{
|
||||
m_primitives.assign(primitives);
|
||||
}
|
||||
|
||||
inline void PrimitiveList::Add(const Primitive& primitive)
|
||||
{
|
||||
m_primitives.push_back(primitive);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds a box centered
|
||||
*
|
||||
|
|
@ -21,8 +36,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline void PrimitiveList::AddBox(const Vector3f& lengths, const Vector3ui& subdivision, const Matrix4f& transformMatrix)
|
||||
{
|
||||
m_primitives.push_back(Primitive::Box(lengths, subdivision, transformMatrix));
|
||||
}
|
||||
|
|
@ -35,8 +49,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline 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));
|
||||
}
|
||||
|
|
@ -49,8 +62,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline void PrimitiveList::AddCone(float length, float radius, unsigned int subdivision, const Matrix4f& transformMatrix)
|
||||
{
|
||||
m_primitives.push_back(Primitive::Cone(length, radius, subdivision, transformMatrix));
|
||||
}
|
||||
|
|
@ -64,8 +76,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline 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));
|
||||
}
|
||||
|
|
@ -77,8 +88,7 @@ namespace Nz
|
|||
* \param subdivision Number of subdivision for the box
|
||||
* \param transformMatrix Matrix to apply
|
||||
*/
|
||||
|
||||
void PrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const Matrix4f& transformMatrix)
|
||||
inline void PrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const Matrix4f& transformMatrix)
|
||||
{
|
||||
m_primitives.push_back(Primitive::CubicSphere(size, subdivision, transformMatrix));
|
||||
}
|
||||
|
|
@ -91,8 +101,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline void PrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const Vector3f& position, const Quaternionf& rotation)
|
||||
{
|
||||
m_primitives.push_back(Primitive::CubicSphere(size, subdivision, position, rotation));
|
||||
}
|
||||
|
|
@ -104,8 +113,7 @@ namespace Nz
|
|||
* \param recursionLevel Number of recursion for the icosphere
|
||||
* \param transformMatrix Matrix to apply
|
||||
*/
|
||||
|
||||
void PrimitiveList::AddIcoSphere(float size, unsigned int recursionLevel, const Matrix4f& transformMatrix)
|
||||
inline void PrimitiveList::AddIcoSphere(float size, unsigned int recursionLevel, const Matrix4f& transformMatrix)
|
||||
{
|
||||
m_primitives.push_back(Primitive::IcoSphere(size, recursionLevel, transformMatrix));
|
||||
}
|
||||
|
|
@ -118,8 +126,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline void PrimitiveList::AddIcoSphere(float size, unsigned int recursionLevel, const Vector3f& position, const Quaternionf& rotation)
|
||||
{
|
||||
m_primitives.push_back(Primitive::IcoSphere(size, recursionLevel, position, rotation));
|
||||
}
|
||||
|
|
@ -131,8 +138,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline void PrimitiveList::AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Matrix4f& transformMatrix)
|
||||
{
|
||||
m_primitives.push_back(Primitive::Plane(size, subdivision, transformMatrix));
|
||||
}
|
||||
|
|
@ -144,8 +150,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline void PrimitiveList::AddPlane(const Vector2f& size, const Vector2ui& subdivision, const Planef& planeInfo)
|
||||
{
|
||||
m_primitives.push_back(Primitive::Plane(size, subdivision, planeInfo));
|
||||
}
|
||||
|
|
@ -158,8 +163,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline 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));
|
||||
}
|
||||
|
|
@ -172,8 +176,7 @@ namespace Nz
|
|||
* \param stackCount Number of stacks
|
||||
* \param transformMatrix Matrix to apply
|
||||
*/
|
||||
|
||||
void PrimitiveList::AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& transformMatrix)
|
||||
inline void PrimitiveList::AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const Matrix4f& transformMatrix)
|
||||
{
|
||||
m_primitives.push_back(Primitive::UVSphere(size, sliceCount, stackCount, transformMatrix));
|
||||
}
|
||||
|
|
@ -187,8 +190,7 @@ namespace Nz
|
|||
* \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)
|
||||
inline 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));
|
||||
}
|
||||
|
|
@ -201,8 +203,7 @@ namespace Nz
|
|||
*
|
||||
* \remark Produces a NazaraAssert if index is greather than the size
|
||||
*/
|
||||
|
||||
Primitive& PrimitiveList::GetPrimitive(std::size_t i)
|
||||
inline Primitive& PrimitiveList::GetPrimitive(std::size_t i)
|
||||
{
|
||||
NazaraAssert(i < m_primitives.size(), "Primitive index out of range");
|
||||
|
||||
|
|
@ -217,8 +218,7 @@ namespace Nz
|
|||
*
|
||||
* \remark Produces a NazaraAssert if index is greather than the size
|
||||
*/
|
||||
|
||||
const Primitive& PrimitiveList::GetPrimitive(std::size_t i) const
|
||||
inline const Primitive& PrimitiveList::GetPrimitive(std::size_t i) const
|
||||
{
|
||||
NazaraAssert(i < m_primitives.size(), "Primitive index out of range");
|
||||
|
||||
|
|
@ -229,8 +229,7 @@ namespace Nz
|
|||
* \brief Gets the number of primitives
|
||||
* \return Number of primitives
|
||||
*/
|
||||
|
||||
std::size_t PrimitiveList::GetSize() const
|
||||
inline std::size_t PrimitiveList::GetSize() const
|
||||
{
|
||||
return m_primitives.size();
|
||||
}
|
||||
|
|
@ -243,8 +242,7 @@ namespace Nz
|
|||
*
|
||||
* \remark Produces a NazaraAssert if index is greather than the size
|
||||
*/
|
||||
|
||||
Primitive& PrimitiveList::operator()(unsigned int i)
|
||||
inline Primitive& PrimitiveList::operator[](std::size_t i)
|
||||
{
|
||||
return GetPrimitive(i);
|
||||
}
|
||||
|
|
@ -257,8 +255,7 @@ namespace Nz
|
|||
*
|
||||
* \remark Produces a NazaraAssert if index is greather than the size
|
||||
*/
|
||||
|
||||
const Primitive& PrimitiveList::operator()(unsigned int i) const
|
||||
inline const Primitive& PrimitiveList::operator[](std::size_t i) const
|
||||
{
|
||||
return GetPrimitive(i);
|
||||
}
|
||||
|
|
@ -25,19 +25,19 @@ SCENARIO("PrimitiveList", "[CORE][PRIMITIVELIST]")
|
|||
|
||||
THEN("The first one is the cubic sphere")
|
||||
{
|
||||
REQUIRE(primitiveList(0).type == Nz::PrimitiveType::Sphere);
|
||||
REQUIRE(primitiveList(0).sphere.type == Nz::SphereType::Cubic);
|
||||
REQUIRE(primitiveList[0].type == Nz::PrimitiveType::Sphere);
|
||||
REQUIRE(primitiveList[0].sphere.type == Nz::SphereType::Cubic);
|
||||
}
|
||||
|
||||
THEN("The second one is the box")
|
||||
{
|
||||
REQUIRE(primitiveList(1).type == Nz::PrimitiveType::Box);
|
||||
REQUIRE(primitiveList[1].type == Nz::PrimitiveType::Box);
|
||||
}
|
||||
|
||||
THEN("The third one is the ico sphere")
|
||||
{
|
||||
REQUIRE(primitiveList(2).type == Nz::PrimitiveType::Sphere);
|
||||
REQUIRE(primitiveList(2).sphere.type == Nz::SphereType::Ico);
|
||||
REQUIRE(primitiveList[2].type == Nz::PrimitiveType::Sphere);
|
||||
REQUIRE(primitiveList[2].sphere.type == Nz::SphereType::Ico);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue