Improved interface of Primitive

Former-commit-id: bcd4f2eb247c8f7fb59d864884e6ecda5f60afb1
This commit is contained in:
Lynix 2013-06-25 14:06:04 +02:00
parent 0bd70f8df1
commit b7c4d607ce
4 changed files with 222 additions and 67 deletions

View File

@ -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 <Nazara/Core/Primitive.inl>
#endif // NAZARA_PRIMITIVE_HPP

View File

@ -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 <Nazara/Core/Debug.hpp>
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 <Nazara/Core/DebugOff.hpp>

View File

@ -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;

View File

@ -6,99 +6,59 @@
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Debug.hpp>
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)