From b7c4d607ce0d8254889a13ae991c24528649e648 Mon Sep 17 00:00:00 2001 From: Lynix Date: Tue, 25 Jun 2013 14:06:04 +0200 Subject: [PATCH] Improved interface of Primitive Former-commit-id: bcd4f2eb247c8f7fb59d864884e6ecda5f60afb1 --- include/Nazara/Core/Primitive.hpp | 30 ++++- include/Nazara/Core/Primitive.inl | 169 ++++++++++++++++++++++++++ include/Nazara/Core/PrimitiveList.hpp | 14 +-- src/Nazara/Core/PrimitiveList.cpp | 76 +++--------- 4 files changed, 222 insertions(+), 67 deletions(-) create mode 100644 include/Nazara/Core/Primitive.inl diff --git a/include/Nazara/Core/Primitive.hpp b/include/Nazara/Core/Primitive.hpp index 06a04e7d8..23029f31a 100644 --- a/include/Nazara/Core/Primitive.hpp +++ b/include/Nazara/Core/Primitive.hpp @@ -15,6 +15,30 @@ struct NzPrimitive { + void MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + void MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + void MakeCubicSphere(float size, unsigned int subdivision = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + void MakeCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + void MakeIcoSphere(float size, unsigned int recursionLevel = 3, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + void MakeIcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + void MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + void MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane); + void MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + void MakeUVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + void MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + + static NzPrimitive Box(const NzVector3f& lengths, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + static NzPrimitive Box(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + static NzPrimitive CubicSphere(float size, unsigned int subdivision = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + static NzPrimitive CubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + static NzPrimitive IcoSphere(float size, unsigned int recursionLevel = 3, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + static NzPrimitive IcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + static NzPrimitive Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + static NzPrimitive Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane); + static NzPrimitive Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + static NzPrimitive UVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + static NzPrimitive UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + NzMatrix4f matrix; nzPrimitiveType type; @@ -55,8 +79,8 @@ struct NzPrimitive struct { - unsigned int slices; - unsigned int stacks; + unsigned int sliceCount; + unsigned int stackCount; } uv; }; @@ -65,4 +89,6 @@ struct NzPrimitive }; }; +#include + #endif // NAZARA_PRIMITIVE_HPP diff --git a/include/Nazara/Core/Primitive.inl b/include/Nazara/Core/Primitive.inl new file mode 100644 index 000000000..1597e7143 --- /dev/null +++ b/include/Nazara/Core/Primitive.inl @@ -0,0 +1,169 @@ +// Copyright (C) 2013 Jérôme Leclercq +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include + +inline void NzPrimitive::MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& transformMatrix) +{ + matrix = transformMatrix; + type = nzPrimitiveType_Box; + box.lengths = lengths; + box.subdivision = subdivision; +} + +inline void NzPrimitive::MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) +{ + MakeBox(lengths, subdivision, NzMatrix4f::Transform(position, rotation)); +} + +inline void NzPrimitive::MakeCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& transformMatrix) +{ + matrix = transformMatrix; + type = nzPrimitiveType_Sphere; + sphere.size = size; + sphere.type = nzSphereType_Cubic; + sphere.cubic.subdivision = subdivision; +} + +inline void NzPrimitive::MakeCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation) +{ + MakeCubicSphere(size, subdivision, NzMatrix4f::Transform(position, rotation)); +} + +inline void NzPrimitive::MakeIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& transformMatrix) +{ + matrix = transformMatrix; + type = nzPrimitiveType_Sphere; + sphere.size = size; + sphere.type = nzSphereType_Ico; + sphere.ico.recursionLevel = recursionLevel; +} + +inline void NzPrimitive::MakeIcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation) +{ + MakeIcoSphere(size, recursionLevel, NzMatrix4f::Transform(position, rotation)); +} + +inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix) +{ + matrix = transformMatrix; + type = nzPrimitiveType_Plane; + plane.size = size; + plane.subdivision = subdivision; +} + +inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& planeInfo) +{ + MakePlane(size, subdivision, NzMatrix4f::Transform(planeInfo.distance * planeInfo.normal, NzQuaternionf::RotationBetween(NzVector3f::Up(), planeInfo.normal))); +} + +inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) +{ + MakePlane(size, subdivision, NzMatrix4f::Transform(position, rotation)); +} + +inline void NzPrimitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& transformMatrix) +{ + matrix = transformMatrix; + type = nzPrimitiveType_Sphere; + sphere.size = size; + sphere.type = nzSphereType_UV; + sphere.uv.sliceCount = sliceCount; + sphere.uv.stackCount = stackCount; +} + +inline void NzPrimitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation) +{ + MakeUVSphere(size, sliceCount, stackCount, NzMatrix4f::Transform(position, rotation)); +} + +inline NzPrimitive NzPrimitive::Box(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& transformMatrix) +{ + NzPrimitive primitive; + primitive.MakeBox(lengths, subdivision, transformMatrix); + + return primitive; +} + +inline NzPrimitive NzPrimitive::Box(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) +{ + NzPrimitive primitive; + primitive.MakeBox(lengths, subdivision, position, rotation); + + return primitive; +} + +inline NzPrimitive NzPrimitive::CubicSphere(float size, unsigned int subdivision, const NzMatrix4f& transformMatrix) +{ + NzPrimitive primitive; + primitive.MakeCubicSphere(size, subdivision, transformMatrix); + + return primitive; +} + +inline NzPrimitive NzPrimitive::CubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation) +{ + NzPrimitive primitive; + primitive.MakeCubicSphere(size, subdivision, position, rotation); + + return primitive; +} + +inline NzPrimitive NzPrimitive::IcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& transformMatrix) +{ + NzPrimitive primitive; + primitive.MakeIcoSphere(size, recursionLevel, transformMatrix); + + return primitive; +} + +inline NzPrimitive NzPrimitive::IcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation) +{ + NzPrimitive primitive; + primitive.MakeIcoSphere(size, recursionLevel, position, rotation); + + return primitive; +} + +inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix) +{ + NzPrimitive primitive; + primitive.MakePlane(size, subdivision, transformMatrix); + + return primitive; +} + +inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane) +{ + NzPrimitive primitive; + primitive.MakePlane(size, subdivision, plane); + + return primitive; +} + +inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) +{ + NzPrimitive primitive; + primitive.MakePlane(size, subdivision, position, rotation); + + return primitive; +} + +inline NzPrimitive NzPrimitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& transformMatrix) +{ + NzPrimitive primitive; + primitive.MakeUVSphere(size, sliceCount, stackCount, transformMatrix); + + return primitive; +} + +inline NzPrimitive NzPrimitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation) +{ + NzPrimitive primitive; + primitive.MakeUVSphere(size, sliceCount, stackCount, position, rotation); + + return primitive; +} + +#include diff --git a/include/Nazara/Core/PrimitiveList.hpp b/include/Nazara/Core/PrimitiveList.hpp index 3feeb1b51..1f24681fc 100644 --- a/include/Nazara/Core/PrimitiveList.hpp +++ b/include/Nazara/Core/PrimitiveList.hpp @@ -17,17 +17,17 @@ class NAZARA_API NzPrimitiveList NzPrimitiveList() = default; ~NzPrimitiveList() = default; - void AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& matrix = NzMatrix4f::Identity()); + void AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); void AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); - void AddCubicSphere(float size, unsigned int subdivision = 4, const NzMatrix4f& matrix = NzMatrix4f::Identity()); + void AddCubicSphere(float size, unsigned int subdivision = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); void AddCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); - void AddIcoSphere(float size, unsigned int recursionLevel = 3, const NzMatrix4f& matrix = NzMatrix4f::Identity()); + void AddIcoSphere(float size, unsigned int recursionLevel = 3, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); void AddIcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); - void AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& matrix = NzMatrix4f::Identity()); - void AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane); + void AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + void AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& planeInfo); void AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); - void AddUVSphere(float size, unsigned int slices = 4, unsigned int stacks = 4, const NzMatrix4f& matrix = NzMatrix4f::Identity()); - void AddUVSphere(float size, unsigned int slices, unsigned int stacks, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); + void AddUVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity()); + void AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity()); NzPrimitive& GetPrimitive(unsigned int i); const NzPrimitive& GetPrimitive(unsigned int i) const; diff --git a/src/Nazara/Core/PrimitiveList.cpp b/src/Nazara/Core/PrimitiveList.cpp index 446ed026c..1c1ba1743 100644 --- a/src/Nazara/Core/PrimitiveList.cpp +++ b/src/Nazara/Core/PrimitiveList.cpp @@ -6,99 +6,59 @@ #include #include -void NzPrimitiveList::AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix) +void NzPrimitiveList::AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& transformMatrix) { - NzPrimitive primitive; - primitive.matrix = matrix; - primitive.type = nzPrimitiveType_Box; - primitive.box.lengths = lengths; - primitive.box.subdivision = subdivision; - - m_primitives.push_back(primitive); + m_primitives.push_back(NzPrimitive::Box(lengths, subdivision, transformMatrix)); } void NzPrimitiveList::AddBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) { - AddBox(lengths, subdivision, NzMatrix4f::Transform(position, rotation)); + m_primitives.push_back(NzPrimitive::Box(lengths, subdivision, position, rotation)); } -void NzPrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix) +void NzPrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& transformMatrix) { - NzPrimitive primitive; - primitive.matrix = matrix; - primitive.type = nzPrimitiveType_Sphere; - primitive.sphere.size = size; - primitive.sphere.type = nzSphereType_Cubic; - primitive.sphere.cubic.subdivision = subdivision; - - m_primitives.push_back(primitive); + m_primitives.push_back(NzPrimitive::CubicSphere(size, subdivision, transformMatrix)); } void NzPrimitiveList::AddCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation) { - AddCubicSphere(size, subdivision, NzMatrix4f::Transform(position, rotation)); + m_primitives.push_back(NzPrimitive::CubicSphere(size, subdivision, position, rotation)); } -void NzPrimitiveList::AddIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix) +void NzPrimitiveList::AddIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& transformMatrix) { - NzPrimitive primitive; - primitive.matrix = matrix; - primitive.type = nzPrimitiveType_Sphere; - primitive.sphere.size = size; - primitive.sphere.type = nzSphereType_Ico; - primitive.sphere.ico.recursionLevel = recursionLevel; - - m_primitives.push_back(primitive); + m_primitives.push_back(NzPrimitive::IcoSphere(size, recursionLevel, transformMatrix)); } void NzPrimitiveList::AddIcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation) { - AddIcoSphere(size, recursionLevel, NzMatrix4f::Transform(position, rotation)); + m_primitives.push_back(NzPrimitive::IcoSphere(size, recursionLevel, position, rotation)); } -void NzPrimitiveList::AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& matrix) +void NzPrimitiveList::AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix) { - NzPrimitive primitive; - primitive.matrix = matrix; - primitive.type = nzPrimitiveType_Plane; - primitive.plane.size = size; - primitive.plane.subdivision = subdivision; - - m_primitives.push_back(primitive); + m_primitives.push_back(NzPrimitive::Plane(size, subdivision, transformMatrix)); } -void NzPrimitiveList::AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane) +void NzPrimitiveList::AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& planeInfo) { - NzPrimitive primitive; - primitive.matrix = NzMatrix4f::Transform(plane.distance * plane.normal, NzQuaternionf::RotationBetween(NzVector3f::Up(), plane.normal)); - primitive.type = nzPrimitiveType_Plane; - primitive.plane.size = size; - primitive.plane.subdivision = subdivision; - - m_primitives.push_back(primitive); + m_primitives.push_back(NzPrimitive::Plane(size, subdivision, planeInfo)); } void NzPrimitiveList::AddPlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation) { - AddPlane(size, subdivision, NzMatrix4f::Transform(position, rotation)); + m_primitives.push_back(NzPrimitive::Plane(size, subdivision, position, rotation)); } -void NzPrimitiveList::AddUVSphere(float size, unsigned int slices, unsigned int stacks, const NzMatrix4f& matrix) +void NzPrimitiveList::AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& transformMatrix) { - NzPrimitive primitive; - primitive.matrix = matrix; - primitive.type = nzPrimitiveType_Sphere; - primitive.sphere.size = size; - primitive.sphere.type = nzSphereType_UV; - primitive.sphere.uv.slices = slices; - primitive.sphere.uv.stacks = stacks; - - m_primitives.push_back(primitive); + m_primitives.push_back(NzPrimitive::UVSphere(size, sliceCount, stackCount, transformMatrix)); } -void NzPrimitiveList::AddUVSphere(float size, unsigned int slices, unsigned int stacks, const NzVector3f& position, const NzQuaternionf& rotation) +void NzPrimitiveList::AddUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation) { - AddUVSphere(size, slices, stacks, NzMatrix4f::Transform(position, rotation)); + m_primitives.push_back(NzPrimitive::UVSphere(size, sliceCount, stackCount, position, rotation)); } NzPrimitive& NzPrimitiveList::GetPrimitive(unsigned int i)