Refactored mathematics module
Added AABBs Added code examples Added experimental support for texture arrays (1D/2D) Added initialisers (new way of initialising modules) Added global headers (Plus a global header generator script) Added pattern support for directory Added support for spinlocks critical section on Windows Added NzRenderWindow::SetFramerateLimit Core project now includes Mathematics files Fixed color implementation using double Fixed declaration needing renderer include Fixed MLT not clearing nextFree(File/Line) after Free Fixed move operators not being noexcept Fixed thread-safety (Now working correctly - If I'm lucky) Moved Resource to core New interface for modules New interface for the renderer Put some global functions to anonymous namespace Removed empty modules Renamed ThreadCondition to ConditionVariable Replaced redirect to cerr log option by duplicate to cout Setting mouse position relative to a window will make this window ignore the event Shaders sending methods no longer takes the uniform variable name (it's using ID instead) Using new OpenGL 4.3 header
This commit is contained in:
@@ -48,7 +48,7 @@ namespace
|
||||
}
|
||||
|
||||
// Les fichiers MD2 sont en little endian
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&header.ident, sizeof(nzUInt32));
|
||||
#endif
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&header.version, sizeof(nzUInt32));
|
||||
#endif
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&header.skinwidth, sizeof(nzUInt32));
|
||||
NzByteSwap(&header.skinheight, sizeof(nzUInt32));
|
||||
NzByteSwap(&header.framesize, sizeof(nzUInt32));
|
||||
@@ -129,6 +129,7 @@ namespace
|
||||
NzAnimation* animation = new NzAnimation;
|
||||
if (animation->Create(nzAnimationType_Keyframe, endFrame-startFrame+1))
|
||||
{
|
||||
// Décodage des séquences
|
||||
NzString frameName;
|
||||
|
||||
NzSequence sequence;
|
||||
@@ -154,7 +155,7 @@ namespace
|
||||
stream.SetCursorPos(header.offset_frames + i*header.framesize + offsetof(md2_frame, name));
|
||||
stream.Read(name, 16*sizeof(char));
|
||||
|
||||
int pos = std::strlen(name)-1;
|
||||
pos = std::strlen(name)-1;
|
||||
for (unsigned int j = 0; j < 2; ++j)
|
||||
{
|
||||
if (!std::isdigit(name[pos]))
|
||||
@@ -217,7 +218,7 @@ namespace
|
||||
|
||||
const md2_header* header = reinterpret_cast<const md2_header*>(data);
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
nzUInt32 ident = header->ident;
|
||||
nzUInt32 version = header->version;
|
||||
|
||||
@@ -238,7 +239,7 @@ namespace
|
||||
if (stream.Read(&magic[0], 2*sizeof(nzUInt32)) != 2*sizeof(nzUInt32))
|
||||
return false;
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&magic[0], sizeof(nzUInt32));
|
||||
NzByteSwap(&magic[1], sizeof(nzUInt32));
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
stream.SetCursorPos(header.offset_st);
|
||||
stream.Read(&texCoords[0], header.num_st*sizeof(md2_texCoord));
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
for (unsigned int i = 0; i < header.num_st; ++i)
|
||||
{
|
||||
NzByteSwap(&texCoords[i].u, sizeof(nzInt16));
|
||||
@@ -52,7 +52,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
stream.SetCursorPos(header.offset_tris);
|
||||
stream.Read(&triangles[0], header.num_tris*sizeof(md2_triangle));
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
for (unsigned int i = 0; i < header.num_tris; ++i)
|
||||
{
|
||||
NzByteSwap(&triangles[i].vertices[0], sizeof(nzUInt16));
|
||||
@@ -72,9 +72,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
frame.vertices.resize(header.num_vertices);
|
||||
|
||||
// Pour que le modèle soit correctement aligné, on génère une matrice de rotation que nous appliquerons à chacune des vertices
|
||||
NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(-90.f, 0.f, -90.f));
|
||||
//NzMatrix4f rotationMatrix;
|
||||
//rotationMatrix.SetIdentity();
|
||||
NzMatrix4f rotationMatrix = NzMatrix4f::Rotate(NzEulerAnglesf(90.f, -90.f, 0.f));
|
||||
|
||||
unsigned int stride = s_declaration.GetStride(nzElementStream_VertexData);
|
||||
|
||||
@@ -86,7 +84,7 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
stream.Read(&frame.name, 16*sizeof(char));
|
||||
stream.Read(&frame.vertices[0], header.num_vertices*sizeof(md2_vertex));
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
NzByteSwap(&frame.scale.x, sizeof(float));
|
||||
NzByteSwap(&frame.scale.y, sizeof(float));
|
||||
NzByteSwap(&frame.scale.z, sizeof(float));
|
||||
@@ -98,6 +96,8 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
|
||||
m_frames[i].normal = new nzUInt8[m_vertexCount]; // Nous stockons l'indice de la normale plutôt que la normale (gain d'espace)
|
||||
m_frames[i].vertices = new NzVector3f[m_vertexCount];
|
||||
|
||||
NzVector3f max, min;
|
||||
for (unsigned int t = 0; t < header.num_tris; ++t)
|
||||
{
|
||||
for (unsigned int v = 0; v < 3; ++v)
|
||||
@@ -105,17 +105,19 @@ bool NzMD2Mesh::Create(const md2_header& header, NzInputStream& stream, const Nz
|
||||
const md2_vertex& vert = frame.vertices[triangles[t].vertices[v]];
|
||||
|
||||
NzVector3f vertex = rotationMatrix * NzVector3f(vert.x * frame.scale.x + frame.translate.x, vert.y * frame.scale.y + frame.translate.y, vert.z * frame.scale.z + frame.translate.z);
|
||||
max.MakeCeil(vertex);
|
||||
min.MakeFloor(vertex);
|
||||
|
||||
m_frames[i].normal[t*3+v] = vert.n;
|
||||
m_frames[i].vertices[t*3+v] = vertex;
|
||||
}
|
||||
}
|
||||
|
||||
m_frames[i].aabb.SetExtends(min, max);
|
||||
}
|
||||
|
||||
nzBufferStorage storage = (NzBuffer::IsSupported(nzBufferStorage_Hardware) && !parameters.forceSoftware) ? nzBufferStorage_Hardware : nzBufferStorage_Software;
|
||||
|
||||
m_indexBuffer = nullptr; // Pas d'indexbuffer pour l'instant
|
||||
m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), storage, nzBufferUsage_Dynamic);
|
||||
m_vertexBuffer = new NzVertexBuffer(m_vertexCount, (3+3+2)*sizeof(float), parameters.storage, nzBufferUsage_Dynamic);
|
||||
|
||||
nzUInt8* ptr = reinterpret_cast<nzUInt8*>(m_vertexBuffer->Map(nzBufferAccess_WriteOnly));
|
||||
if (!ptr)
|
||||
@@ -185,6 +187,11 @@ void NzMD2Mesh::Destroy()
|
||||
}
|
||||
}
|
||||
|
||||
const NzAxisAlignedBox& NzMD2Mesh::GetAABB() const
|
||||
{
|
||||
return m_aabb;
|
||||
}
|
||||
|
||||
nzAnimationType NzMD2Mesh::GetAnimationType() const
|
||||
{
|
||||
if (m_frameCount > 1)
|
||||
@@ -262,14 +269,19 @@ void NzMD2Mesh::AnimateImpl(unsigned int frameA, unsigned int frameB, float inte
|
||||
NzVector3f* position = reinterpret_cast<NzVector3f*>(ptr + positionOffset);
|
||||
NzVector3f* normal = reinterpret_cast<NzVector3f*>(ptr + normalOffset);
|
||||
|
||||
*position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]);
|
||||
*normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]);
|
||||
*position = fA->vertices[i] + interpolation * (fB->vertices[i] - fA->vertices[i]);
|
||||
*normal = md2Normals[fA->normal[i]] + interpolation * (md2Normals[fB->normal[i]] - md2Normals[fA->normal[i]]);
|
||||
|
||||
ptr += stride;
|
||||
}
|
||||
|
||||
if (!m_vertexBuffer->Unmap())
|
||||
NazaraWarning("Failed to unmap vertex buffer, expect mesh corruption");
|
||||
|
||||
// Interpolation de l'AABB
|
||||
NzVector3f max1 = fA->aabb.GetMaximum();
|
||||
NzVector3f min1 = fA->aabb.GetMinimum();
|
||||
m_aabb.SetExtends(min1 + interpolation * (fB->aabb.GetMinimum() - min1), max1 + interpolation * (fB->aabb.GetMaximum() - max1));
|
||||
}
|
||||
|
||||
NzVertexDeclaration NzMD2Mesh::s_declaration;
|
||||
|
||||
@@ -27,6 +27,7 @@ class NAZARA_API NzMD2Mesh : public NzKeyframeMesh
|
||||
bool Create(const md2_header& header, NzInputStream& stream, const NzMeshParams& parameters);
|
||||
void Destroy();
|
||||
|
||||
const NzAxisAlignedBox& GetAABB() const;
|
||||
nzAnimationType GetAnimationType() const;
|
||||
unsigned int GetFrameCount() const;
|
||||
const NzIndexBuffer* GetIndexBuffer() const;
|
||||
@@ -44,14 +45,14 @@ class NAZARA_API NzMD2Mesh : public NzKeyframeMesh
|
||||
|
||||
struct Frame
|
||||
{
|
||||
//AxisAlignedBox aabb;
|
||||
NzAxisAlignedBox aabb;
|
||||
nzUInt8* normal;
|
||||
NzVector3f* tangents;
|
||||
NzVector3f* vertices;
|
||||
char name[16];
|
||||
};
|
||||
|
||||
//AxisAlignedBox m_aabb;
|
||||
NzAxisAlignedBox m_aabb;
|
||||
Frame* m_frames;
|
||||
NzIndexBuffer* m_indexBuffer;
|
||||
NzVertexBuffer* m_vertexBuffer;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace
|
||||
return false;
|
||||
}
|
||||
|
||||
#if NAZARA_BIG_ENDIAN
|
||||
#if defined(NAZARA_BIG_ENDIAN)
|
||||
// Les fichiers PCX sont en little endian
|
||||
NzByteSwap(&header.xmin, sizeof(nzUInt16));
|
||||
NzByteSwap(&header.ymin, sizeof(nzUInt16));
|
||||
|
||||
Reference in New Issue
Block a user