Added texture rect parameter to primitive generator
Former-commit-id: 5efc0fd1bcc2aad9cd4b75ff9fb8b29d84bfd363
This commit is contained in:
parent
3167531b39
commit
2fd86dc406
|
|
@ -11,36 +11,38 @@
|
|||
#include <Nazara/Math/Box.hpp>
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Plane.hpp>
|
||||
#include <Nazara/Math/Rect.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
|
||||
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());
|
||||
void MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakeCubicSphere(float size, unsigned int subdivision = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakeCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakeIcoSphere(float size, unsigned int recursionLevel = 3, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakeIcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane, const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakeUVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
void MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
|
||||
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 = NzVector2ui(0U), 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());
|
||||
static NzPrimitive Box(const NzVector3f& lengths, const NzVector3ui& subdivision = NzVector3ui(0U), const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive Box(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive CubicSphere(float size, unsigned int subdivision = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive CubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive IcoSphere(float size, unsigned int recursionLevel = 3, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive IcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive Plane(const NzVector2f& size, const NzVector2ui& subdivision = NzVector2ui(0U), const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane, const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive UVSphere(float size, unsigned int sliceCount = 4, unsigned int stackCount = 4, const NzMatrix4f& transformMatrix = NzMatrix4f::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
static NzPrimitive UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation = NzQuaternionf::Identity(), const NzRectf& uvCoords = NzRectf(0.f, 0.f, 1.f, 1.f));
|
||||
|
||||
NzMatrix4f matrix;
|
||||
nzPrimitiveType type;
|
||||
NzRectf textureCoords;
|
||||
|
||||
union
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,68 +4,73 @@
|
|||
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
inline void NzPrimitive::MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& transformMatrix)
|
||||
inline void NzPrimitive::MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
textureCoords = uvCoords;
|
||||
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)
|
||||
inline void NzPrimitive::MakeBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
MakeBox(lengths, subdivision, NzMatrix4f::Transform(position, rotation));
|
||||
MakeBox(lengths, subdivision, NzMatrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
inline void NzPrimitive::MakeCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& transformMatrix)
|
||||
inline void NzPrimitive::MakeCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
textureCoords = uvCoords;
|
||||
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)
|
||||
inline void NzPrimitive::MakeCubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
MakeCubicSphere(size, subdivision, NzMatrix4f::Transform(position, rotation));
|
||||
MakeCubicSphere(size, subdivision, NzMatrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
inline void NzPrimitive::MakeIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& transformMatrix)
|
||||
inline void NzPrimitive::MakeIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
textureCoords = uvCoords;
|
||||
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)
|
||||
inline void NzPrimitive::MakeIcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
MakeIcoSphere(size, recursionLevel, NzMatrix4f::Transform(position, rotation));
|
||||
MakeIcoSphere(size, recursionLevel, NzMatrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix)
|
||||
inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
textureCoords = uvCoords;
|
||||
type = nzPrimitiveType_Plane;
|
||||
plane.size = size;
|
||||
plane.subdivision = subdivision;
|
||||
}
|
||||
|
||||
inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& planeInfo)
|
||||
inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& planeInfo, const NzRectf& uvCoords)
|
||||
{
|
||||
MakePlane(size, subdivision, NzMatrix4f::Transform(planeInfo.distance * planeInfo.normal, NzQuaternionf::RotationBetween(NzVector3f::Up(), planeInfo.normal)));
|
||||
MakePlane(size, subdivision, NzMatrix4f::Transform(planeInfo.distance * planeInfo.normal, NzQuaternionf::RotationBetween(NzVector3f::Up(), planeInfo.normal)), uvCoords);
|
||||
}
|
||||
|
||||
inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation)
|
||||
inline void NzPrimitive::MakePlane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
MakePlane(size, subdivision, NzMatrix4f::Transform(position, rotation));
|
||||
MakePlane(size, subdivision, NzMatrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
inline void NzPrimitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& transformMatrix)
|
||||
inline void NzPrimitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
matrix = transformMatrix;
|
||||
textureCoords = uvCoords;
|
||||
type = nzPrimitiveType_Sphere;
|
||||
sphere.size = size;
|
||||
sphere.type = nzSphereType_UV;
|
||||
|
|
@ -73,95 +78,95 @@ inline void NzPrimitive::MakeUVSphere(float size, unsigned int sliceCount, unsig
|
|||
sphere.uv.stackCount = stackCount;
|
||||
}
|
||||
|
||||
inline void NzPrimitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation)
|
||||
inline void NzPrimitive::MakeUVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
MakeUVSphere(size, sliceCount, stackCount, NzMatrix4f::Transform(position, rotation));
|
||||
MakeUVSphere(size, sliceCount, stackCount, NzMatrix4f::Transform(position, rotation), uvCoords);
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::Box(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& transformMatrix)
|
||||
inline NzPrimitive NzPrimitive::Box(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakeBox(lengths, subdivision, transformMatrix);
|
||||
primitive.MakeBox(lengths, subdivision, transformMatrix, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::Box(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation)
|
||||
inline NzPrimitive NzPrimitive::Box(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakeBox(lengths, subdivision, position, rotation);
|
||||
primitive.MakeBox(lengths, subdivision, position, rotation, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::CubicSphere(float size, unsigned int subdivision, const NzMatrix4f& transformMatrix)
|
||||
inline NzPrimitive NzPrimitive::CubicSphere(float size, unsigned int subdivision, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakeCubicSphere(size, subdivision, transformMatrix);
|
||||
primitive.MakeCubicSphere(size, subdivision, transformMatrix, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::CubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation)
|
||||
inline NzPrimitive NzPrimitive::CubicSphere(float size, unsigned int subdivision, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakeCubicSphere(size, subdivision, position, rotation);
|
||||
primitive.MakeCubicSphere(size, subdivision, position, rotation, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::IcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& transformMatrix)
|
||||
inline NzPrimitive NzPrimitive::IcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakeIcoSphere(size, recursionLevel, transformMatrix);
|
||||
primitive.MakeIcoSphere(size, recursionLevel, transformMatrix, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::IcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation)
|
||||
inline NzPrimitive NzPrimitive::IcoSphere(float size, unsigned int recursionLevel, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakeIcoSphere(size, recursionLevel, position, rotation);
|
||||
primitive.MakeIcoSphere(size, recursionLevel, position, rotation, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix)
|
||||
inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakePlane(size, subdivision, transformMatrix);
|
||||
primitive.MakePlane(size, subdivision, transformMatrix, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane)
|
||||
inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzPlanef& plane, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakePlane(size, subdivision, plane);
|
||||
primitive.MakePlane(size, subdivision, plane, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation)
|
||||
inline NzPrimitive NzPrimitive::Plane(const NzVector2f& size, const NzVector2ui& subdivision, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakePlane(size, subdivision, position, rotation);
|
||||
primitive.MakePlane(size, subdivision, position, rotation, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& transformMatrix)
|
||||
inline NzPrimitive NzPrimitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& transformMatrix, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakeUVSphere(size, sliceCount, stackCount, transformMatrix);
|
||||
primitive.MakeUVSphere(size, sliceCount, stackCount, transformMatrix, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
||||
inline NzPrimitive NzPrimitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation)
|
||||
inline NzPrimitive NzPrimitive::UVSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzVector3f& position, const NzQuaternionf& rotation, const NzRectf& uvCoords)
|
||||
{
|
||||
NzPrimitive primitive;
|
||||
primitive.MakeUVSphere(size, sliceCount, stackCount, position, rotation);
|
||||
primitive.MakeUVSphere(size, sliceCount, stackCount, position, rotation, uvCoords);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ NAZARA_API void NzComputePlaneIndexVertexCount(const NzVector2ui& subdivision, u
|
|||
NAZARA_API void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, unsigned int* indexCount, unsigned int* vertexCount);
|
||||
template<typename T> NzBoxf NzComputeVerticesAABB(const T* vertices, unsigned int vertexCount);
|
||||
|
||||
NAZARA_API void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector2f& size, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector2f& size, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
|
||||
NAZARA_API void NzOptimizeIndices(NzIndexIterator indices, unsigned int indexCount);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace
|
|||
{
|
||||
}
|
||||
|
||||
void Generate(float size, unsigned int recursionLevel, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
void Generate(float size, unsigned int recursionLevel, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
{
|
||||
// Grandement inspiré de http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html
|
||||
const float t = (1.f + 2.236067f)/2.f;
|
||||
|
|
@ -708,7 +708,7 @@ void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int sta
|
|||
|
||||
/**********************************NzGenerate*********************************/
|
||||
|
||||
void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
{
|
||||
unsigned int xIndexCount, yIndexCount, zIndexCount;
|
||||
unsigned int xVertexCount, yVertexCount, zVertexCount;
|
||||
|
|
@ -723,42 +723,42 @@ void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, co
|
|||
|
||||
// Face +X
|
||||
transform.MakeTransform(NzVector3f::UnitX() * halfLengths.x, NzEulerAnglesf(-90.f, 0.f, -90.f));
|
||||
NzGeneratePlane(NzVector2ui(subdivision.z, subdivision.y), NzVector2f(lengths.z, lengths.y), transform, vertices, indices, nullptr, indexOffset);
|
||||
NzGeneratePlane(NzVector2ui(subdivision.z, subdivision.y), NzVector2f(lengths.z, lengths.y), transform, textureCoords, vertices, indices, nullptr, indexOffset);
|
||||
indexOffset += xVertexCount;
|
||||
indices += xIndexCount;
|
||||
vertices += xVertexCount;
|
||||
|
||||
// Face +Y
|
||||
transform.MakeTransform(NzVector3f::UnitY() * halfLengths.y, NzEulerAnglesf(0.f, 0.f, 0.f));
|
||||
NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), NzVector2f(lengths.x, lengths.z), transform, vertices, indices, nullptr, indexOffset);
|
||||
NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), NzVector2f(lengths.x, lengths.z), transform, textureCoords, vertices, indices, nullptr, indexOffset);
|
||||
indexOffset += yVertexCount;
|
||||
indices += yIndexCount;
|
||||
vertices += yVertexCount;
|
||||
|
||||
// Face +Z
|
||||
transform.MakeTransform(NzVector3f::UnitZ() * halfLengths.z, NzEulerAnglesf(-90.f, 90.f, 90.f));
|
||||
NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), NzVector2f(lengths.x, lengths.y), transform, vertices, indices, nullptr, indexOffset);
|
||||
NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), NzVector2f(lengths.x, lengths.y), transform, textureCoords, vertices, indices, nullptr, indexOffset);
|
||||
indexOffset += zVertexCount;
|
||||
indices += zIndexCount;
|
||||
vertices += zVertexCount;
|
||||
|
||||
// Face -X
|
||||
transform.MakeTransform(-NzVector3f::UnitX() * halfLengths.x, NzEulerAnglesf(-90.f, 0.f, 90.f));
|
||||
NzGeneratePlane(NzVector2ui(subdivision.z, subdivision.y), NzVector2f(lengths.z, lengths.y), transform, vertices, indices, nullptr, indexOffset);
|
||||
NzGeneratePlane(NzVector2ui(subdivision.z, subdivision.y), NzVector2f(lengths.z, lengths.y), transform, textureCoords, vertices, indices, nullptr, indexOffset);
|
||||
indexOffset += xVertexCount;
|
||||
indices += xIndexCount;
|
||||
vertices += xVertexCount;
|
||||
|
||||
// Face -Y
|
||||
transform.MakeTransform(-NzVector3f::UnitY() * halfLengths.y, NzEulerAnglesf(0.f, 0.f, 180.f));
|
||||
NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), NzVector2f(lengths.x, lengths.z), transform, vertices, indices, nullptr, indexOffset);
|
||||
NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.z), NzVector2f(lengths.x, lengths.z), transform, textureCoords, vertices, indices, nullptr, indexOffset);
|
||||
indexOffset += yVertexCount;
|
||||
indices += yIndexCount;
|
||||
vertices += yVertexCount;
|
||||
|
||||
// Face -Z
|
||||
transform.MakeTransform(-NzVector3f::UnitZ() * halfLengths.z, NzEulerAnglesf(-90.f, -90.f, 90.f));
|
||||
NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), NzVector2f(lengths.x, lengths.y), transform, vertices, indices, nullptr, indexOffset);
|
||||
NzGeneratePlane(NzVector2ui(subdivision.x, subdivision.y), NzVector2f(lengths.x, lengths.y), transform, textureCoords, vertices, indices, nullptr, indexOffset);
|
||||
indexOffset += zVertexCount;
|
||||
indices += zIndexCount;
|
||||
vertices += zVertexCount;
|
||||
|
|
@ -772,13 +772,13 @@ void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, co
|
|||
}
|
||||
}
|
||||
|
||||
void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
{
|
||||
unsigned int vertexCount;
|
||||
NzComputeBoxIndexVertexCount(NzVector3ui(subdivision), nullptr, &vertexCount);
|
||||
|
||||
// On envoie une matrice identité de sorte à ce que la boîte ne subisse aucune transformation (rendant plus facile l'étape suivante)
|
||||
NzGenerateBox(NzVector3f(size, size, size), NzVector3ui(subdivision), NzMatrix4f::Identity(), vertices, indices, nullptr, indexOffset);
|
||||
NzGenerateBox(NzVector3f(size, size, size), NzVector3ui(subdivision), NzMatrix4f::Identity(), textureCoords, vertices, indices, nullptr, indexOffset);
|
||||
|
||||
if (aabb)
|
||||
{
|
||||
|
|
@ -795,13 +795,13 @@ void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4
|
|||
}
|
||||
}
|
||||
|
||||
void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
{
|
||||
IcoSphereBuilder builder(matrix);
|
||||
builder.Generate(size, recursionLevel, vertices, indices, aabb, indexOffset);
|
||||
builder.Generate(size, recursionLevel, textureCoords, vertices, indices, aabb, indexOffset);
|
||||
}
|
||||
|
||||
void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector2f& size, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector2f& size, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
{
|
||||
// Pour plus de facilité, on va construire notre plan en considérant que la normale est de 0,1,0
|
||||
// Et appliquer ensuite une matrice "finissant le travail"
|
||||
|
|
@ -833,7 +833,7 @@ void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector2f& size, con
|
|||
{
|
||||
NzVector3f localPos((2.f*x*invHorizontalVertexCount - 1.f) * halfSizeX, 0.f, (2.f*y*invVerticalVertexCount - 1.f) * halfSizeY);
|
||||
vertices->position = matrix * localPos;
|
||||
vertices->uv.Set(x*invHorizontalVertexCount, y*invVerticalVertexCount);
|
||||
vertices->uv.Set(textureCoords.x + x*invHorizontalVertexCount*textureCoords.width, textureCoords.y + y*invVerticalVertexCount*textureCoords.height);
|
||||
vertices->normal = normal;
|
||||
vertices->tangent = tangent;
|
||||
vertices++;
|
||||
|
|
@ -855,13 +855,13 @@ void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector2f& size, con
|
|||
aabb->Set(matrix.Transform(NzVector3f(-halfSizeX, 0.f, -halfSizeY), 0.f), matrix.Transform(NzVector3f(halfSizeX, 0.f, halfSizeY), 0.f));
|
||||
}
|
||||
|
||||
void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackCount, const NzMatrix4f& matrix, const NzRectf& textureCoords, NzMeshVertex* vertices, NzIndexIterator indices, NzBoxf* aabb, unsigned int indexOffset)
|
||||
{
|
||||
// http://stackoverflow.com/questions/14080932/implementing-opengl-sphere-example-code
|
||||
float invSliceCount = 1.f / (sliceCount-1);
|
||||
float invStackCount = 1.f / (stackCount-1);
|
||||
|
||||
const float pi = M_PI; // Pour éviter toute promotion en double
|
||||
const float pi = static_cast<float>(M_PI); // Pour éviter toute promotion en double
|
||||
const float pi2 = pi * 2.f;
|
||||
const float pi_2 = pi / 2.f;
|
||||
|
||||
|
|
@ -883,7 +883,7 @@ void NzGenerateUvSphere(float size, unsigned int sliceCount, unsigned int stackC
|
|||
|
||||
vertices->position = matrix.Transform(size * normal);
|
||||
vertices->normal = matrix.Transform(normal, 0.f);
|
||||
vertices->uv.Set(1.f - sliceVal, stackVal);
|
||||
vertices->uv.Set(textureCoords.x + textureCoords.width*(1.f - sliceVal), textureCoords.y + textureCoords.height*stackVal);
|
||||
vertices++;
|
||||
|
||||
if (stack != stackCount-1 && slice != sliceCount-1)
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
|
|||
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
|
||||
NzGenerateBox(primitive.box.lengths, primitive.box.subdivision, matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
NzGenerateBox(primitive.box.lengths, primitive.box.subdivision, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +210,7 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
|
|||
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
|
||||
NzGeneratePlane(primitive.plane.subdivision, primitive.plane.size, matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
NzGeneratePlane(primitive.plane.subdivision, primitive.plane.size, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +233,7 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
|
|||
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
|
||||
NzGenerateCubicSphere(primitive.sphere.size, primitive.sphere.cubic.subdivision, matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
NzGenerateCubicSphere(primitive.sphere.size, primitive.sphere.cubic.subdivision, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +252,7 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
|
|||
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
|
||||
NzGenerateIcoSphere(primitive.sphere.size, primitive.sphere.ico.recursionLevel, matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
NzGenerateIcoSphere(primitive.sphere.size, primitive.sphere.ico.recursionLevel, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +271,7 @@ NzSubMesh* NzMesh::BuildSubMesh(const NzPrimitive& primitive, const NzMeshParams
|
|||
NzBufferMapper<NzVertexBuffer> vertexMapper(vertexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
NzIndexMapper indexMapper(indexBuffer.get(), nzBufferAccess_WriteOnly);
|
||||
|
||||
NzGenerateUvSphere(primitive.sphere.size, primitive.sphere.uv.sliceCount, primitive.sphere.uv.stackCount, matrix, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
NzGenerateUvSphere(primitive.sphere.size, primitive.sphere.uv.sliceCount, primitive.sphere.uv.stackCount, matrix, primitive.textureCoords, static_cast<NzMeshVertex*>(vertexMapper.GetPointer()), indexMapper.begin(), &aabb);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue