Merge branch 'master' of git://github.com/DigitalPulseSoftware/NazaraEngine
Former-commit-id: 4d6ef07eaae20b252db101910a9528a9aad606da
This commit is contained in:
@@ -515,7 +515,7 @@ NzString NzFile::AbsolutePath(const NzString& filePath)
|
||||
NazaraError("Path unrecognized");
|
||||
return path;
|
||||
}
|
||||
#elif defined(NAZARA_PLATEFORM_LINUX)
|
||||
#elif defined(NAZARA_PLATFORM_POSIX)
|
||||
base = '/';
|
||||
start = 0;
|
||||
#else
|
||||
@@ -664,7 +664,7 @@ bool NzFile::IsAbsolute(const NzString& filePath)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
#elif defined(NAZARA_PLATEFORM_LINUX)
|
||||
#elif defined(NAZARA_PLATFORM_POSIX)
|
||||
return path.StartsWith('/');
|
||||
#else
|
||||
#error OS case not implemented
|
||||
|
||||
171
src/Nazara/Utility/TriangleIterator.cpp
Normal file
171
src/Nazara/Utility/TriangleIterator.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
// Copyright (C) 2012 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
|
||||
|
||||
#include <Nazara/Utility/TriangleIterator.hpp>
|
||||
#include <Nazara/Utility/SubMesh.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzTriangleIterator::NzTriangleIterator(NzSubMesh* subMesh, nzBufferAccess access) :
|
||||
m_primitiveType(subMesh->GetPrimitiveType()),
|
||||
m_indexMapper(subMesh->GetIndexBuffer(), nzBufferAccess_ReadOnly),
|
||||
m_vertexMapper(subMesh)
|
||||
{
|
||||
NazaraUnused(access);
|
||||
|
||||
m_currentIndex = 3;
|
||||
m_triangleIndices[0] = m_indexMapper.Get(0);
|
||||
m_triangleIndices[1] = m_indexMapper.Get(1);
|
||||
m_triangleIndices[2] = m_indexMapper.Get(2);
|
||||
|
||||
const NzIndexBuffer* indexBuffer = m_indexMapper.GetBuffer();
|
||||
if (indexBuffer)
|
||||
m_indexCount = indexBuffer->GetIndexCount();
|
||||
else
|
||||
m_indexCount = subMesh->GetVertexBuffer()->GetVertexCount();
|
||||
}
|
||||
|
||||
bool NzTriangleIterator::Advance()
|
||||
{
|
||||
if (m_currentIndex >= m_indexCount)
|
||||
{
|
||||
Unmap();
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (m_primitiveType)
|
||||
{
|
||||
case nzPrimitiveType_TriangleFan:
|
||||
m_triangleIndices[1] = m_indexMapper.Get(m_currentIndex++);
|
||||
m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++);
|
||||
break;
|
||||
|
||||
case nzPrimitiveType_TriangleList:
|
||||
m_triangleIndices[0] = m_indexMapper.Get(m_currentIndex++);
|
||||
m_triangleIndices[1] = m_indexMapper.Get(m_currentIndex++);
|
||||
m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++);
|
||||
break;
|
||||
|
||||
case nzPrimitiveType_TriangleStrip:
|
||||
m_triangleIndices[2] = m_indexMapper.Get(m_currentIndex++);
|
||||
m_triangleIndices[1] = m_triangleIndices[2];
|
||||
m_triangleIndices[0] = m_triangleIndices[1];
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
NzVector3f NzTriangleIterator::GetNormal(unsigned int i) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (i > 2)
|
||||
{
|
||||
NazaraError("Index out of range: (" + NzString::Number(i) + " > 2)");
|
||||
return NzVector3f();
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_vertexMapper.GetNormal(m_triangleIndices[i]);
|
||||
}
|
||||
|
||||
NzVector3f NzTriangleIterator::GetPosition(unsigned int i) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (i > 2)
|
||||
{
|
||||
NazaraError("Index out of range: (" + NzString::Number(i) + " > 2)");
|
||||
return NzVector3f();
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_vertexMapper.GetPosition(m_triangleIndices[i]);
|
||||
}
|
||||
|
||||
NzVector3f NzTriangleIterator::GetTangent(unsigned int i) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (i > 2)
|
||||
{
|
||||
NazaraError("Index out of range: (" + NzString::Number(i) + " > 2)");
|
||||
return NzVector3f();
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_vertexMapper.GetTangent(m_triangleIndices[i]);
|
||||
}
|
||||
|
||||
NzVector2f NzTriangleIterator::GetTexCoords(unsigned int i) const
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (i > 2)
|
||||
{
|
||||
NazaraError("Index out of range: (" + NzString::Number(i) + " > 2)");
|
||||
return NzVector2f();
|
||||
}
|
||||
#endif
|
||||
|
||||
return m_vertexMapper.GetTexCoords(m_triangleIndices[i]);
|
||||
}
|
||||
|
||||
void NzTriangleIterator::SetNormal(unsigned int i, const NzVector3f& normal)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (i > 2)
|
||||
{
|
||||
NazaraError("Index out of range: (" + NzString::Number(i) + " > 2)");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_vertexMapper.SetNormal(m_triangleIndices[i], normal);
|
||||
}
|
||||
|
||||
void NzTriangleIterator::SetPosition(unsigned int i, const NzVector3f& position)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (i > 2)
|
||||
{
|
||||
NazaraError("Index out of range: (" + NzString::Number(i) + " > 2)");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_vertexMapper.SetPosition(m_triangleIndices[i], position);
|
||||
}
|
||||
|
||||
void NzTriangleIterator::SetTangent(unsigned int i, const NzVector3f& tangent)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (i > 2)
|
||||
{
|
||||
NazaraError("Index out of range: (" + NzString::Number(i) + " > 2)");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_vertexMapper.SetTangent(m_triangleIndices[i], tangent);
|
||||
}
|
||||
|
||||
void NzTriangleIterator::SetTexCoords(unsigned int i, const NzVector2f& texCoords)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (i > 2)
|
||||
{
|
||||
NazaraError("Index out of range: (" + NzString::Number(i) + " > 2)");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_vertexMapper.SetTexCoords(m_triangleIndices[i], texCoords);
|
||||
}
|
||||
|
||||
void NzTriangleIterator::Unmap()
|
||||
{
|
||||
// Peut très bien être appellé plusieurs fois de suite, seul le premier appel sera pris en compte
|
||||
m_indexMapper.Unmap();
|
||||
m_vertexMapper.Unmap();
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class NzVertexMapperImpl
|
||||
virtual NzVector3f GetPosition(unsigned int i) const = 0;
|
||||
virtual NzVector3f GetTangent(unsigned int i) const = 0;
|
||||
virtual NzVector2f GetTexCoords(unsigned int i) const = 0;
|
||||
virtual unsigned int GetTotalVertexCount() const = 0;
|
||||
virtual unsigned int GetVertexCount() const = 0;
|
||||
|
||||
virtual void SetNormal(unsigned int i, const NzVector3f& normal) = 0;
|
||||
virtual void SetPosition(unsigned int i, const NzVector3f& position) = 0;
|
||||
@@ -90,7 +90,7 @@ namespace
|
||||
return m_mesh->GetTexCoords(i%m_vertexPerFrame);
|
||||
}
|
||||
|
||||
unsigned int GetTotalVertexCount() const
|
||||
unsigned int GetVertexCount() const
|
||||
{
|
||||
return m_vertexPerFrame*m_mesh->GetFrameCount();
|
||||
}
|
||||
@@ -157,7 +157,7 @@ namespace
|
||||
return m_vertices[i].uv;
|
||||
}
|
||||
|
||||
unsigned int GetTotalVertexCount() const
|
||||
unsigned int GetVertexCount() const
|
||||
{
|
||||
return m_mesh->GetVertexCount();
|
||||
}
|
||||
@@ -221,7 +221,7 @@ namespace
|
||||
return m_vertices[i].uv;
|
||||
}
|
||||
|
||||
unsigned int GetTotalVertexCount() const
|
||||
unsigned int GetVertexCount() const
|
||||
{
|
||||
return m_vertexMapper.GetBuffer()->GetVertexCount();
|
||||
}
|
||||
@@ -299,9 +299,9 @@ NzVector2f NzVertexMapper::GetTexCoords(unsigned int i) const
|
||||
return m_impl->GetTexCoords(i);
|
||||
}
|
||||
|
||||
unsigned int NzVertexMapper::GetTotalVertexCount()
|
||||
unsigned int NzVertexMapper::GetVertexCount()
|
||||
{
|
||||
return m_impl->GetTotalVertexCount();
|
||||
return m_impl->GetVertexCount();
|
||||
}
|
||||
|
||||
void NzVertexMapper::SetNormal(unsigned int i, const NzVector3f& normal)
|
||||
@@ -326,6 +326,9 @@ void NzVertexMapper::SetTexCoords(unsigned int i, const NzVector2f& texCoords)
|
||||
|
||||
void NzVertexMapper::Unmap()
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
if (m_impl)
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user