Added index iterators
Former-commit-id: de3ed77ba9e3c48aa68020e23ded679066b9878f
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <Nazara/Math/Matrix4.hpp>
|
||||
#include <Nazara/Math/Vector2.hpp>
|
||||
#include <Nazara/Math/Vector3.hpp>
|
||||
#include <Nazara/Utility/IndexIterator.hpp>
|
||||
#include <Nazara/Utility/Mesh.hpp>
|
||||
|
||||
NAZARA_API void NzComputeBoxIndexVertexCount(const NzVector3ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount);
|
||||
@@ -20,12 +21,11 @@ NAZARA_API void NzComputeIcoSphereIndexVertexCount(unsigned int recursionLevel,
|
||||
NAZARA_API void NzComputePlaneIndexVertexCount(const NzVector2ui& subdivision, unsigned int* indexCount, unsigned int* vertexCount);
|
||||
NAZARA_API void NzComputeUvSphereIndexVertexCount(unsigned int sliceCount, unsigned int stackCount, unsigned int* indexCount, unsigned int* vertexCount);
|
||||
|
||||
///TODO: Itérateur sur les indices
|
||||
NAZARA_API void NzGenerateBox(const NzVector3f& lengths, const NzVector3ui& subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateCubicSphere(float size, unsigned int subdivision, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGenerateIcoSphere(float size, unsigned int recursionLevel, const NzMatrix4f& matrix, NzMeshVertex* vertices, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
NAZARA_API void NzGeneratePlane(const NzVector2ui& subdivision, const NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, NzMeshVertex* vertices, nzUInt32* 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, nzUInt32* indices, NzBoxf* aabb = nullptr, unsigned int indexOffset = 0);
|
||||
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 NzVector3f& position, const NzVector3f& normal, const NzVector2f& size, 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);
|
||||
|
||||
inline void NzTransformVertex(NzMeshVertex* vertex, const NzMatrix4f& matrix);
|
||||
inline void NzTransformVertices(NzMeshVertex* vertices, unsigned int vertexCount, const NzMatrix4f& matrix);
|
||||
|
||||
79
include/Nazara/Utility/IndexIterator.hpp
Normal file
79
include/Nazara/Utility/IndexIterator.hpp
Normal file
@@ -0,0 +1,79 @@
|
||||
// Copyright (C) 2013 Jérôme Leclercq
|
||||
// This file is part of the "Nazara Engine - Utility module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_INDEXITERATOR_HPP
|
||||
#define NAZARA_INDEXITERATOR_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
|
||||
class NzIndexMapper;
|
||||
|
||||
class NzIndexIterator
|
||||
{
|
||||
friend NzIndexMapper;
|
||||
|
||||
public:
|
||||
class Reference;
|
||||
|
||||
NzIndexIterator();
|
||||
NzIndexIterator(const NzIndexIterator& iterator);
|
||||
~NzIndexIterator() = default;
|
||||
|
||||
Reference operator*() const;
|
||||
|
||||
Reference operator[](unsigned int index) const;
|
||||
|
||||
NzIndexIterator& operator=(const NzIndexIterator& iterator);
|
||||
|
||||
NzIndexIterator operator+(unsigned int indexCount);
|
||||
NzIndexIterator operator-(unsigned int indexCount);
|
||||
|
||||
NzIndexIterator& operator+=(unsigned int indexCount);
|
||||
NzIndexIterator& operator-=(unsigned int indexCount);
|
||||
|
||||
NzIndexIterator& operator++();
|
||||
NzIndexIterator operator++(int);
|
||||
|
||||
NzIndexIterator& operator--();
|
||||
NzIndexIterator operator--(int);
|
||||
|
||||
friend bool operator==(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
|
||||
friend bool operator!=(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
|
||||
friend bool operator<(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
|
||||
friend bool operator<=(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
|
||||
friend bool operator>(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
|
||||
friend bool operator>=(const NzIndexIterator& lhs, const NzIndexIterator& rhs);
|
||||
|
||||
private:
|
||||
NzIndexIterator(NzIndexMapper* mapper, unsigned int index);
|
||||
|
||||
NzIndexMapper* m_mapper;
|
||||
unsigned int m_index;
|
||||
};
|
||||
|
||||
class NzIndexIterator::Reference
|
||||
{
|
||||
friend NzIndexIterator;
|
||||
|
||||
public:
|
||||
Reference(const Reference& reference) = default;
|
||||
~Reference() = default;
|
||||
|
||||
Reference& operator=(nzUInt32 value);
|
||||
Reference& operator=(const Reference& reference);
|
||||
|
||||
operator nzUInt32() const;
|
||||
|
||||
private:
|
||||
Reference(NzIndexMapper* mapper, unsigned int index);
|
||||
|
||||
NzIndexMapper* m_mapper;
|
||||
unsigned int m_index;
|
||||
};
|
||||
|
||||
#include <Nazara/Utility/IndexIterator.inl>
|
||||
|
||||
#endif // NAZARA_INDEXITERATOR_HPP
|
||||
158
include/Nazara/Utility/IndexIterator.inl
Normal file
158
include/Nazara/Utility/IndexIterator.inl
Normal file
@@ -0,0 +1,158 @@
|
||||
// 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/Utility/IndexMapper.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
inline NzIndexIterator::NzIndexIterator() :
|
||||
m_mapper(nullptr),
|
||||
m_index(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzIndexIterator::NzIndexIterator(const NzIndexIterator& iterator) :
|
||||
m_mapper(iterator.m_mapper),
|
||||
m_index(iterator.m_index)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzIndexIterator::NzIndexIterator(NzIndexMapper* mapper, unsigned int index) :
|
||||
m_mapper(mapper),
|
||||
m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzIndexIterator::Reference NzIndexIterator::operator*() const
|
||||
{
|
||||
return Reference(m_mapper, m_index);
|
||||
}
|
||||
|
||||
inline NzIndexIterator::Reference NzIndexIterator::operator[](unsigned int index) const
|
||||
{
|
||||
return Reference(m_mapper, m_index+index);
|
||||
}
|
||||
|
||||
inline NzIndexIterator& NzIndexIterator::operator=(const NzIndexIterator& iterator)
|
||||
{
|
||||
m_mapper = iterator.m_mapper;
|
||||
m_index = iterator.m_index;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NzIndexIterator NzIndexIterator::operator+(unsigned int indexCount)
|
||||
{
|
||||
return NzIndexIterator(m_mapper, m_index + indexCount);
|
||||
}
|
||||
|
||||
inline NzIndexIterator NzIndexIterator::operator-(unsigned int indexCount)
|
||||
{
|
||||
return NzIndexIterator(m_mapper, m_index - indexCount);
|
||||
}
|
||||
|
||||
inline NzIndexIterator& NzIndexIterator::operator+=(unsigned int indexCount)
|
||||
{
|
||||
m_index += indexCount;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NzIndexIterator& NzIndexIterator::operator-=(unsigned int indexCount)
|
||||
{
|
||||
m_index += indexCount;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NzIndexIterator& NzIndexIterator::operator++()
|
||||
{
|
||||
m_index++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NzIndexIterator NzIndexIterator::operator++(int)
|
||||
{
|
||||
NzIndexIterator iterator(*this);
|
||||
operator++();
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
||||
inline NzIndexIterator& NzIndexIterator::operator--()
|
||||
{
|
||||
m_index--;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NzIndexIterator NzIndexIterator::operator--(int)
|
||||
{
|
||||
NzIndexIterator iterator(*this);
|
||||
operator--();
|
||||
|
||||
return iterator;
|
||||
}
|
||||
|
||||
inline bool operator==(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
|
||||
{
|
||||
return lhs.m_mapper == rhs.m_mapper && lhs.m_index == rhs.m_index;
|
||||
}
|
||||
|
||||
inline bool operator!=(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
|
||||
{
|
||||
return !operator==(lhs, rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
|
||||
{
|
||||
if (lhs.m_mapper == rhs.m_mapper)
|
||||
return lhs.m_index < rhs.m_index;
|
||||
else
|
||||
return lhs.m_mapper < rhs.m_mapper;
|
||||
}
|
||||
|
||||
inline bool operator<=(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
|
||||
{
|
||||
return !operator<(rhs, lhs);
|
||||
}
|
||||
|
||||
inline bool operator>(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
|
||||
{
|
||||
return operator<(rhs, lhs);
|
||||
}
|
||||
|
||||
inline bool operator>=(const NzIndexIterator& lhs, const NzIndexIterator& rhs)
|
||||
{
|
||||
return !operator<(lhs, rhs);
|
||||
}
|
||||
|
||||
/**************************NzIndexIterator::Reference*************************/
|
||||
|
||||
inline NzIndexIterator::Reference::Reference(NzIndexMapper* mapper, unsigned int index) :
|
||||
m_mapper(mapper),
|
||||
m_index(index)
|
||||
{
|
||||
}
|
||||
|
||||
inline NzIndexIterator::Reference& NzIndexIterator::Reference::operator=(nzUInt32 value)
|
||||
{
|
||||
m_mapper->Set(m_index, value);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NzIndexIterator::Reference& NzIndexIterator::Reference::operator=(const NzIndexIterator::Reference& reference)
|
||||
{
|
||||
m_mapper->Set(m_index, reference); // Conversion implicite en UInt32
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline NzIndexIterator::Reference::operator nzUInt32() const
|
||||
{
|
||||
return m_mapper->Get(m_index);
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <Nazara/Utility/BufferMapper.hpp>
|
||||
|
||||
class NzIndexBuffer;
|
||||
class NzIndexIterator;
|
||||
class NzSubMesh;
|
||||
|
||||
using NzIndexMapperGetter = nzUInt32 (*)(const void* buffer, unsigned int i);
|
||||
@@ -26,15 +27,24 @@ class NAZARA_API NzIndexMapper
|
||||
|
||||
nzUInt32 Get(unsigned int i) const;
|
||||
const NzIndexBuffer* GetBuffer() const;
|
||||
unsigned int GetIndexCount() const;
|
||||
|
||||
void Set(unsigned int i, nzUInt32 value);
|
||||
|
||||
void Unmap();
|
||||
|
||||
// Méthodes STD
|
||||
NzIndexIterator begin();
|
||||
//NzIndexConstIterator begin() const;
|
||||
NzIndexIterator end();
|
||||
//NzIndexIterator end() const;
|
||||
// Méthodes STD
|
||||
|
||||
private:
|
||||
NzBufferMapper<NzIndexBuffer> m_mapper;
|
||||
NzIndexMapperGetter m_getter;
|
||||
NzIndexMapperSetter m_setter;
|
||||
unsigned int m_indexCount;
|
||||
};
|
||||
|
||||
#endif // NAZARA_INDEXMAPPER_HPP
|
||||
|
||||
Reference in New Issue
Block a user