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:
Lynix
2012-08-08 04:44:17 +02:00
parent 06eda4eba9
commit b442ab0bd2
142 changed files with 6861 additions and 2326 deletions

View File

@@ -1,11 +0,0 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Audio/Config.hpp>
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

60
include/Nazara/Core.hpp Normal file
View File

@@ -0,0 +1,60 @@
// This file was automatically generated by Nazara
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/ConditionVariable.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Directory.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Endianness.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/Format.hpp>
#include <Nazara/Core/Functor.hpp>
#include <Nazara/Core/Hash.hpp>
#include <Nazara/Core/Hashable.hpp>
#include <Nazara/Core/HashDigest.hpp>
#include <Nazara/Core/HashImpl.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/LockGuard.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Core/MemoryStream.hpp>
#include <Nazara/Core/Mutex.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/Semaphore.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/StringStream.hpp>
#include <Nazara/Core/Thread.hpp>
#include <Nazara/Core/Tuple.hpp>
#include <Nazara/Core/Unicode.hpp>

View File

@@ -8,10 +8,10 @@
#define NAZARA_BYTEARRAY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Conig.hpp>
#include <Nazara/Core/Config.hpp>
#include <Nazara/Core/Hashable.hpp>
#if NAZARA_THREADSAFETY_BYTEARRAY
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_BYTEARRAY
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@@ -28,7 +28,7 @@ class NAZARA_API NzByteArray : public NzHashable
NzByteArray();
NzByteArray(const nzUInt8* buffer, unsigned int bufferLength);
NzByteArray(const NzByteArray& buffer);
NzByteArray(NzByteArray&& buffer);
NzByteArray(NzByteArray&& buffer) noexcept;
NzByteArray(SharedArray* sharedArray);
~NzByteArray();
@@ -80,7 +80,7 @@ class NAZARA_API NzByteArray : public NzHashable
nzUInt8 operator[](unsigned int pos) const;
NzByteArray& operator=(const NzByteArray& byteArray);
NzByteArray& operator=(NzByteArray&& byteArray);
NzByteArray& operator=(NzByteArray&& byteArray) noexcept;
NzByteArray operator+(const NzByteArray& byteArray) const;
NzByteArray& operator+=(const NzByteArray& byteArray);
@@ -89,10 +89,7 @@ class NAZARA_API NzByteArray : public NzHashable
struct NAZARA_API SharedArray
{
SharedArray() :
refCount(1)
{
}
SharedArray() = default;
SharedArray(unsigned short referenceCount, unsigned int bufferSize, unsigned int arraySize, nzUInt8* ptr) :
capacity(bufferSize),
@@ -104,7 +101,7 @@ class NAZARA_API NzByteArray : public NzHashable
unsigned int capacity;
unsigned int size;
unsigned short refCount;
unsigned short refCount = 1;
nzUInt8* buffer;
NazaraMutex(mutex)

View File

@@ -9,7 +9,7 @@
#include <Nazara/Prerequesites.hpp>
#if NAZARA_THREADSAFETY_CLOCK
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_CLOCK
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>

View File

@@ -8,7 +8,7 @@
#include <cmath>
#include <cstdlib>
#include <stdexcept>
#include <Nazara/Utility/Debug.hpp>
#include <Nazara/Core/Debug.hpp>
inline NzColor::NzColor()
{
@@ -198,26 +198,26 @@ inline NzColor NzColor::FromXYZ(float x, float y, float z)
y /= 100; // Y from 0 to 100.000
z /= 100; // Z from 0 to 108.883
double r = x * 3.2406 + y * -1.5372 + z * -0.4986;
double g = x * -0.9689 + y * 1.8758 + z * 0.0415;
double b = x * 0.0557 + y * -0.2040 + z * 1.0570;
float r = x * 3.2406f + y * -1.5372f + z * -0.4986f;
float g = x * -0.9689f + y * 1.8758f + z * 0.0415f;
float b = x * 0.0557f + y * -0.2040f + z * 1.0570f;
if (r > 0.0031308f)
r = 1.055 * (std::pow(r, 1.0/2.4)) - 0.055;
r = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
r *= 12.92;
r *= 12.92f;
if (g > 0.0031308f)
g = 1.055 * (std::pow(g, 1.0/2.4)) - 0.055;
g = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
g *= 12.92;
g *= 12.92f;
if (b > 0.0031308f)
b = 1.055 * (std::pow(b, 1.0/2.4)) - 0.055;
b = 1.055f * (std::pow(r, 1.f/2.4f)) - 0.055f;
else
b *= 12.92;
b *= 12.92f;
return NzColor(r * 255.0, g * 255.0, b * 255.0);
return NzColor(r * 255.f, g * 255.f, b * 255.f);
}
inline void NzColor::ToCMY(const NzColor& color, float* cyan, float* magenta, float* yellow)
@@ -409,4 +409,4 @@ inline std::ostream& operator<<(std::ostream& out, const NzColor& color)
return out << color.ToString();
}
#include <Nazara/Utility/DebugOff.hpp>
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -4,19 +4,19 @@
#pragma once
#ifndef NAZARA_THREADCONDITION_HPP
#define NAZARA_THREADCONDITION_HPP
#ifndef NAZARA_CONDITIONVARIABLE_HPP
#define NAZARA_CONDITIONVARIABLE_HPP
#include <Nazara/Prerequesites.hpp>
class NzConditionVariableImpl;
class NzMutex;
class NzThreadConditionImpl;
class NAZARA_API NzThreadCondition
class NAZARA_API NzConditionVariable
{
public:
NzThreadCondition();
~NzThreadCondition();
NzConditionVariable();
~NzConditionVariable();
void Signal();
void SignalAll();
@@ -25,7 +25,7 @@ class NAZARA_API NzThreadCondition
bool Wait(NzMutex* mutex, nzUInt32 timeout);
private:
NzThreadConditionImpl* m_impl;
NzConditionVariableImpl* m_impl;
};
#endif // NAZARA_THREADCONDITION_HPP
#endif // NAZARA_CONDITIONVARIABLE_HPP

View File

@@ -44,34 +44,36 @@
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_CORE_MEMORYLEAKTRACKER 0
// Standardise les séparateurs des dossiers selon le système d'exploitation courant
// Standardise les séparateurs des dossiers selon le système d'exploitation courant (Léger coût à l'exécution)
#define NAZARA_CORE_NORMALIZE_DIRECTORY_SEPARATORS 1
// Précision des réels lors de la transformation en texte (Max. chiffres après la virgule)
#define NAZARA_CORE_REAL_PRECISION 6
// Redirige la sortie du log sur le flux d'erreur standard (cerr) en cas d'erreur d'écriture (ou d'ouverture du fichier)
#define NAZARA_CORE_REDIRECT_TO_CERR_ON_LOG_FAILURE 1
// Duplique la sortie du log sur le flux de sortie standard (cout)
#define NAZARA_CORE_DUPLICATE_TO_COUT 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_CORE_SAFE 1
// Protège le module des accès concurrentiels
// Protège les classes des accès concurrentiels
#define NAZARA_CORE_THREADSAFE 1
#if NAZARA_CORE_THREADSAFE
#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW)
#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock
#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory
#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib
#define NAZARA_THREADSAFETY_FILE 1 // NzFile
#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest
#define NAZARA_THREADSAFETY_LOG 1 // NzLog
#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW)
#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream
#endif
// Les classes à protéger des accès concurrentiels
#define NAZARA_THREADSAFETY_BYTEARRAY 1 // NzByteArray (COW)
#define NAZARA_THREADSAFETY_CLOCK 0 // NzClock
#define NAZARA_THREADSAFETY_DIRECTORY 1 // NzDirectory
#define NAZARA_THREADSAFETY_DYNLIB 1 // NzDynLib
#define NAZARA_THREADSAFETY_FILE 1 // NzFile
#define NAZARA_THREADSAFETY_HASHDIGEST 0 // NzHashDigest
#define NAZARA_THREADSAFETY_LOG 1 // NzLog
#define NAZARA_THREADSAFETY_STRING 1 // NzString (COW)
#define NAZARA_THREADSAFETY_STRINGSTREAM 0 // NzStringStream
// Optimise certaines parties du code avec les avancées venues de Windows Vista (Nécessite Vista ou supérieur et compilateur compatible)
// Le nombre de spinlocks à utiliser avec les critical sections de Windows (0 pour désactiver)
#define NAZARA_CORE_WINDOWS_CS_SPINLOCKS 4096
// Optimise certaines parties du code avec certaines avancées venues de Windows Vista (Casse la compatibilité XP mais n'affecte pas les autres OS)
#define NAZARA_CORE_WINDOWS_VISTA 0
/*

View File

@@ -0,0 +1,29 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CORE_HPP
#define NAZARA_CORE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzCore
{
public:
NzCore() = delete;
~NzCore() = delete;
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_CORE_HPP

View File

@@ -19,7 +19,7 @@
#define NAZARA_DIRECTORY_SEPARATOR '/'
#endif
#if NAZARA_THREADSAFETY_DIRECTORY
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DIRECTORY
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@@ -36,10 +36,12 @@ class NAZARA_API NzDirectory
void Close();
NzString GetPattern() const;
NzString GetResultName() const;
NzString GetResultPath() const;
nzUInt64 GetResultSize() const;
bool IsOpen() const;
bool IsResultDirectory() const;
bool NextResult(bool skipDots = true);
@@ -47,6 +49,7 @@ class NAZARA_API NzDirectory
bool Open();
void SetDirectory(const NzString& dirPath);
void SetPattern(const NzString& pattern);
static bool Copy(const NzString& sourcePath, const NzString& destPath);
static bool Create(const NzString& dirPath, bool recursive = false);
@@ -59,7 +62,8 @@ class NAZARA_API NzDirectory
NazaraMutexAttrib(m_mutex, mutable)
NzString m_dirPath;
NzDirectoryImpl* m_impl;
NzString m_pattern;
NzDirectoryImpl* m_impl = nullptr;
};
#endif // NAZARA_DIRECTORY_HPP

View File

@@ -11,7 +11,7 @@
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_THREADSAFETY_DYNLIB
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_DYNLIB
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>

View File

@@ -16,7 +16,7 @@
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_THREADSAFETY_FILE
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_FILE
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@@ -50,7 +50,7 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
NzFile();
NzFile(const NzString& filePath);
NzFile(const NzString& filePath, unsigned long openMode);
NzFile(NzFile&& file);
NzFile(NzFile&& file) noexcept;
~NzFile();
bool Copy(const NzString& newFilePath);
@@ -92,7 +92,7 @@ class NAZARA_API NzFile : public NzHashable, public NzInputStream, NzNonCopyable
std::size_t Write(const void* buffer, std::size_t typeSize, unsigned int count);
NzFile& operator=(const NzString& filePath);
NzFile& operator=(NzFile&& file);
NzFile& operator=(NzFile&& file) noexcept;
static NzString AbsolutePath(const NzString& filePath);
static bool Copy(const NzString& sourcePath, const NzString& targetPath);

View File

@@ -17,7 +17,7 @@ class NAZARA_API NzHashDigest
NzHashDigest();
NzHashDigest(const NzString& hashName, const nzUInt8* digest, unsigned int length);
NzHashDigest(const NzHashDigest& rhs);
NzHashDigest(NzHashDigest&& rhs);
NzHashDigest(NzHashDigest&& rhs) noexcept;
~NzHashDigest();
bool IsValid() const;
@@ -31,7 +31,7 @@ class NAZARA_API NzHashDigest
nzUInt8 operator[](unsigned short pos) const;
NzHashDigest& operator=(const NzHashDigest& rhs);
NzHashDigest& operator=(NzHashDigest&& rhs);
NzHashDigest& operator=(NzHashDigest&& rhs) noexcept;
bool operator==(const NzHashDigest& rhs) const;
bool operator!=(const NzHashDigest& rhs) const;

View File

@@ -0,0 +1,26 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_INITIALIZER_HPP
#define NAZARA_INITIALIZER_HPP
#include <Nazara/Prerequesites.hpp>
template<typename T>
class NzInitializer
{
public:
template<typename... Args> NzInitializer(Args... args);
~NzInitializer();
bool IsInitialized() const;
operator bool() const;
};
#include <Nazara/Core/Initializer.inl>
#endif // NAZARA_INITIALIZER_HPP

View File

@@ -0,0 +1,35 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
// http://www.easyrgb.com/index.php?X=MATH
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Core/Debug.hpp>
template<typename T>
template<typename... Args>
NzInitializer<T>::NzInitializer(Args... args)
{
T::Initialize(args...);
}
template<typename T>
NzInitializer<T>::~NzInitializer()
{
T::Uninitialize();
}
template<typename T>
bool NzInitializer<T>::IsInitialized() const
{
return T::IsInitialized();
}
template<typename T>
NzInitializer<T>::operator bool() const
{
return T::IsInitialized();
}
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -12,7 +12,7 @@
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#if NAZARA_THREADSAFETY_LOG
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_LOG
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>

View File

@@ -11,11 +11,11 @@
#include <Nazara/Core/NonCopyable.hpp>
class NzMutexImpl;
class NzThreadCondition;
class NzConditionVariable;
class NAZARA_API NzMutex : NzNonCopyable
{
friend class NzThreadCondition;
friend class NzConditionVariable;
public:
NzMutex();

View File

@@ -13,7 +13,7 @@
#include <string>
#include <vector>
#if NAZARA_THREADSAFETY_STRING
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRING
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@@ -41,7 +41,7 @@ class NAZARA_API NzString : public NzHashable
NzString(const char* string);
NzString(const std::string& string);
NzString(const NzString& string);
NzString(NzString&& string);
NzString(NzString&& string) noexcept;
NzString(SharedString* sharedString);
~NzString();
@@ -112,8 +112,8 @@ class NAZARA_API NzString : public NzHashable
unsigned int Replace(const char* oldString, const char* replaceString, int start = 0, nzUInt32 flags = None);
unsigned int Replace(const NzString& oldString, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const char* oldCharacters, char replaceCharacter, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None);
unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
//unsigned int ReplaceAny(const char* oldCharacters, const char* replaceString, int start = 0, nzUInt32 flags = None);
//unsigned int ReplaceAny(const NzString& oldCharacters, const NzString& replaceString, int start = 0, nzUInt32 flags = None);
void Reserve(unsigned int bufferSize);
@@ -184,7 +184,7 @@ class NAZARA_API NzString : public NzHashable
NzString& operator=(const char* string);
NzString& operator=(const std::string& string);
NzString& operator=(const NzString& string);
NzString& operator=(NzString&& string);
NzString& operator=(NzString&& string) noexcept;
NzString operator+(char character) const;
NzString operator+(const char* string) const;
@@ -282,10 +282,7 @@ class NAZARA_API NzString : public NzHashable
struct NAZARA_API SharedString
{
SharedString() :
refCount(1)
{
}
SharedString() = default;
SharedString(unsigned short referenceCount, unsigned int bufferSize, unsigned int stringSize, char* str) :
capacity(bufferSize),
@@ -299,7 +296,7 @@ class NAZARA_API NzString : public NzHashable
unsigned int size;
char* string;
unsigned short refCount;
unsigned short refCount = 1;
NazaraMutex(mutex)
};

View File

@@ -12,7 +12,7 @@
#include <string>
#include <vector>
#if NAZARA_THREADSAFETY_STRINGSTREAM
#if NAZARA_CORE_THREADSAFE && NAZARA_THREADSAFETY_STRINGSTREAM
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>

View File

@@ -26,7 +26,7 @@ class NAZARA_API NzThread : NzNonCopyable
friend class NzThreadImpl;
public:
Id() : m_handle(nullptr) {}
Id() = default;
Id(Id&& rhs) = default;
~Id();
@@ -38,7 +38,7 @@ class NAZARA_API NzThread : NzNonCopyable
Id(void* handle) : m_handle(handle) {}
Id(const NzThreadImpl* thread);
void* m_handle;
void* m_handle = nullptr;
};
template<typename F> NzThread(F function);

View File

@@ -2,7 +2,7 @@
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)

View File

@@ -2,7 +2,5 @@
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#if NAZARA_AUDIO_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#undef delete
#undef new
#endif
#undef delete
#undef new

View File

@@ -1,7 +1,10 @@
// This file was automatically generated by Nazara
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Rémi "overdrivr" Bèges (remi.beges@laposte.net)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@@ -24,12 +27,14 @@
#pragma once
#ifndef NAZARA_CONFIG_NETWORK_HPP
#define NAZARA_CONFIG_NETWORK_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_NETWORK_MEMORYLEAKTRACKER 0
#endif // NAZARA_CONFIG_NETWORK_HPP
#include <Nazara/Math/Basic.hpp>
#include <Nazara/Math/Config.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <Nazara/Math/Math.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>

View File

@@ -10,6 +10,8 @@
#include <cstring>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
T NzApproach(T value, T objective, T increment)
{
@@ -45,7 +47,7 @@ T NzDegrees(T degrees)
template<typename T>
T NzDegreeToRadian(T degrees)
{
return degrees * (M_PI/180.0);
return degrees * F(M_PI/180.0);
}
unsigned int NzGetNumberLength(signed char number)
@@ -53,7 +55,15 @@ unsigned int NzGetNumberLength(signed char number)
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(std::abs(number)))+(number < 0 ? 2 : 1);
// Le standard définit le char comme étant codé sur un octet
static_assert(sizeof(number) == 1, "Signed char must be one byte-sized");
if (number >= 100)
return 3;
else if (number >= 10)
return 2;
else
return 1;
}
unsigned int NzGetNumberLength(unsigned char number)
@@ -61,7 +71,15 @@ unsigned int NzGetNumberLength(unsigned char number)
if (number == 0)
return 1;
return static_cast<unsigned int>(std::log10(number))+1;
// Le standard définit le char comme étant codé sur un octet
static_assert(sizeof(number) == 1, "Signed char must be one byte-sized");
if (number >= 100)
return 3;
else if (number >= 10)
return 2;
else
return 1;
}
unsigned int NzGetNumberLength(short number)
@@ -152,20 +170,20 @@ T NzNormalizeAngle(T angle)
#if NAZARA_MATH_ANGLE_RADIAN
const T limit = M_PI;
#else
const T limit = 180.0;
const T limit = F(180.0);
#endif
///TODO: Trouver une solution sans duplication
if (angle > 0.0)
if (angle > F(0.0))
{
angle += limit;
angle -= static_cast<int>(angle/(2.0*limit))*(2.0*limit);
angle -= static_cast<int>(angle/(F(2.0)*limit))*(F(2.0)*limit);
angle -= limit;
}
else
{
angle -= limit;
angle -= static_cast<int>(angle/(2.0*limit))*(2.0*limit);
angle -= static_cast<int>(angle/(F(2.0)*limit))*(F(2.0)*limit);
angle += limit;
}
@@ -175,11 +193,7 @@ T NzNormalizeAngle(T angle)
template<typename T>
bool NzNumberEquals(T a, T b)
{
if (a > b)
return (a-b) <= std::numeric_limits<T>::epsilon();
else
return (b-a) <= std::numeric_limits<T>::epsilon();
return std::fabs(a-b) <= std::numeric_limits<T>::epsilon();
}
NzString NzNumberToString(long long number, nzUInt8 radix)
@@ -235,7 +249,7 @@ T NzRadians(T radians)
template<typename T>
T NzRadianToDegree(T radians)
{
return radians * (180.0/M_PI);
return radians * F(180.0/M_PI);
}
long long NzStringToNumber(NzString str, nzUInt8 radix, bool* ok)
@@ -288,4 +302,6 @@ long long NzStringToNumber(NzString str, nzUInt8 radix, bool* ok)
return (negative) ? -static_cast<long long>(total) : total;
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -36,15 +36,17 @@
// Définit la disposition des matrices en colonnes (Façon OpenGL)
#define NAZARA_MATH_MATRIX_COLUMN_MAJOR 1
// Optimise les opérations entre matrices affines (Demande plusieurs comparaisons pour déterminer si une matrice est affine)
#define NAZARA_MATH_MATRIX4_CHECK_AFFINE 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_MATH_SAFE 1
// Protège le module des accès concurrentiels
// Protège les classes des accès concurrentiels
#define NAZARA_MATH_THREADSAFE 1
#if NAZARA_MATH_THREADSAFE
#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW)
#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW)
#endif
// Les classes à protéger des accès concurrentiels
#define NAZARA_THREADSAFETY_MATRIX3 1 // NzMatrix3 (COW)
#define NAZARA_THREADSAFETY_MATRIX4 1 // NzMatrix4 (COW)
#endif // NAZARA_CONFIG_MATH_HPP

View File

@@ -17,8 +17,9 @@ class NzCube
public:
NzCube();
NzCube(T X, T Y, T Z, T Width, T Height, T Depth);
NzCube(T cube[6]);
NzCube(const T cube[6]);
NzCube(const NzRect<T>& rect);
NzCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> explicit NzCube(const NzCube<U>& rect);
NzCube(const NzCube& rect) = default;
~NzCube() = default;
@@ -32,11 +33,16 @@ class NzCube
NzVector3<T> GetCenter() const;
bool Intersect(const NzCube& rect) const;
bool Intersect(const NzCube& rect, NzCube& intersection) const;
bool Intersect(const NzCube& rect, NzCube* intersection = nullptr) const;
bool IsValid() const;
void Set(T X, T Y, T Z, T Width, T Height, T Depth);
void Set(const T rect[6]);
void Set(const NzRect<T>& rect);
void Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2);
template<typename U> void Set(const NzCube<U>& rect);
NzString ToString() const;
operator NzString() const;

View File

@@ -6,54 +6,42 @@
#include <algorithm>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzCube<T>::NzCube()
{
}
template<typename T>
NzCube<T>::NzCube(T X, T Y, T Z, T Width, T Height, T Depth) :
x(X),
y(Y),
z(Z),
width(Width),
height(Height),
depth(Depth)
NzCube<T>::NzCube(T X, T Y, T Z, T Width, T Height, T Depth)
{
Set(X, Y, Z, Width, Height, Depth);
}
template<typename T>
NzCube<T>::NzCube(T vec[6]) :
x(vec[0]),
y(vec[1]),
z(vec[2]),
width(vec[3]),
height(vec[4]),
depth(vec[5])
NzCube<T>::NzCube(const T vec[6])
{
Set(vec);
}
template<typename T>
NzCube<T>::NzCube(const NzRect<T>& rect) :
x(rect.x),
y(rect.y),
z(0),
width(rect.width),
height(rect.height),
depth(1)
NzCube<T>::NzCube(const NzRect<T>& rect)
{
Set(rect);
}
template<typename T>
NzCube<T>::NzCube(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
Set(vec1, vec2);
}
template<typename T>
template<typename U>
NzCube<T>::NzCube(const NzCube<U>& rect) :
x(static_cast<T>(rect.x)),
y(static_cast<T>(rect.y)),
z(static_cast<T>(rect.z)),
width(static_cast<T>(rect.width)),
height(static_cast<T>(rect.height)),
depth(static_cast<T>(rect.depth))
NzCube<T>::NzCube(const NzCube<U>& rect)
{
Set(rect);
}
template<typename T>
@@ -102,18 +90,11 @@ void NzCube<T>::ExtendTo(const NzCube& rect)
template<typename T>
NzVector3<T> NzCube<T>::GetCenter() const
{
return NzVector3<T>((x+width)/2, (y+height)/2, (z+depth)/2);
return NzVector3<T>((x+width)/F(2.0), (y+height)/F(2.0), (z+depth)/F(2.0));
}
template<typename T>
bool NzCube<T>::Intersect(const NzCube& rect) const
{
NzCube intersection; // Optimisé par le compilateur
return Intersect(rect, intersection);
}
template<typename T>
bool NzCube<T>::Intersect(const NzCube& rect, NzCube& intersection) const
bool NzCube<T>::Intersect(const NzCube& rect, NzCube* intersection) const
{
T left = std::max(x, rect.x);
T right = std::min(x+width, rect.x+rect.width);
@@ -124,12 +105,15 @@ bool NzCube<T>::Intersect(const NzCube& rect, NzCube& intersection) const
if (left < right && top < bottom && up < down)
{
intersection.x = left;
intersection.y = top;
intersection.z = up;
intersection.width = right-left;
intersection.height = bottom-top;
intersection.depth = down-up;
if (intersection)
{
intersection->x = left;
intersection->y = top;
intersection->z = up;
intersection->width = right-left;
intersection->height = bottom-top;
intersection->depth = down-up;
}
return true;
}
@@ -140,7 +124,63 @@ bool NzCube<T>::Intersect(const NzCube& rect, NzCube& intersection) const
template<typename T>
bool NzCube<T>::IsValid() const
{
return width > 0 && height > 0 && depth > 0;
return width > F(0.0) && height > F(0.0) && depth > F(0.0);
}
template<typename T>
void NzCube<T>::Set(T X, T Y, T Z, T Width, T Height, T Depth)
{
x = X;
y = Y;
z = Z;
width = Width;
height = Height;
depth = Depth;
}
template<typename T>
void NzCube<T>::Set(const T rect[6])
{
x = rect[0];
y = rect[1];
z = rect[2];
width = rect[3];
height = rect[4];
depth = rect[5];
}
template<typename T>
void NzCube<T>::Set(const NzRect<T>& rect)
{
x = rect.x;
y = rect.y;
z = 0;
width = rect.width;
height = rect.height;
depth = 1;
}
template<typename T>
void NzCube<T>::Set(const NzVector3<T>& vec1, const NzVector3<T>& vec2)
{
x = std::min(vec1.x, vec2.x);
y = std::min(vec1.y, vec2.y);
z = std::min(vec1.z, vec2.z);
width = (vec2.x > vec1.x) ? vec2.x-vec1.x : vec1.x-vec2.x;
height = (vec2.y > vec1.y) ? vec2.y-vec1.y : vec1.y-vec2.y;
depth = (vec2.z > vec1.z) ? vec2.z-vec1.z : vec1.z-vec2.z;
}
template<typename T>
template<typename U>
void NzCube<T>::Set(const NzCube<U>& cube)
{
x = F(cube.x);
y = F(cube.y);
z = F(cube.z);
width = F(cube.width);
height = F(cube.height);
depth = F(cube.depth);
}
template<typename T>
@@ -160,13 +200,15 @@ NzCube<T>::operator NzString() const
template<typename T>
T& NzCube<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 6)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 6)";
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -174,13 +216,15 @@ T& NzCube<T>::operator[](unsigned int i)
template<typename T>
T NzCube<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 6)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 4)";
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 6)";
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -191,4 +235,6 @@ std::ostream& operator<<(std::ostream& out, const NzCube<T>& rect)
return out << rect.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -9,9 +9,8 @@
#define NAZARA_EULERANGLES_HPP
#include <Nazara/Core/String.hpp>
template<typename T> class NzQuaternion;
template<typename T> class NzVector3;
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
template<typename T> class NzEulerAngles
{
@@ -25,9 +24,7 @@ template<typename T> class NzEulerAngles
NzEulerAngles(const NzEulerAngles& angles) = default;
~NzEulerAngles() = default;
NzVector3<T> GetForward() const;
NzVector3<T> GetRight() const;
NzVector3<T> GetUp() const;
void MakeZero();
void Normalize();
@@ -37,25 +34,28 @@ template<typename T> class NzEulerAngles
//void Set(const NzMatrix3<T>& mat);
void Set(const NzQuaternion<T>& quat);
template<typename U> void Set(const NzEulerAngles<U>& angles);
void SetZero();
//NzMatrix3<T> ToRotationMatrix() const;
NzQuaternion<T> ToQuaternion() const;
NzString ToString() const;
operator NzString() const;
NzEulerAngles operator+(const NzEulerAngles& angles) const;
NzEulerAngles operator-(const NzEulerAngles& angles) const;
NzEulerAngles operator*(const NzEulerAngles& angles) const;
NzEulerAngles operator/(const NzEulerAngles& angles) const;
/*NzEulerAngles operator*(const NzEulerAngles& angles) const;
NzEulerAngles operator/(const NzEulerAngles& angles) const;*/
NzEulerAngles operator+=(const NzEulerAngles& angles);
NzEulerAngles operator-=(const NzEulerAngles& angles);
NzEulerAngles operator*=(const NzEulerAngles& angles);
NzEulerAngles operator/=(const NzEulerAngles& angles);
/*NzEulerAngles operator*=(const NzEulerAngles& angles);
NzEulerAngles operator/=(const NzEulerAngles& angles);*/
bool operator==(const NzEulerAngles& angles) const;
bool operator!=(const NzEulerAngles& angles) const;
static NzEulerAngles Zero();
T pitch, yaw, roll;
};

View File

@@ -7,9 +7,10 @@
#include <Nazara/Math/Config.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <cmath>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzEulerAngles<T>::NzEulerAngles()
{
@@ -41,33 +42,9 @@ NzEulerAngles<T>::NzEulerAngles(const NzEulerAngles<U>& angles)
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetForward() const
void NzEulerAngles<T>::MakeZero()
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::cos(yaw), std::sin(roll), std::sin(yaw));
#else
return NzVector3<T>(std::cos(NzDegreeToRadian(yaw)), std::sin(NzDegreeToRadian(roll)), std::sin(NzDegreeToRadian(yaw)));
#endif
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetRight() const
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::sin(yaw), std::sin(pitch), std::cos(pitch));
#else
return NzVector3<T>(std::sin(NzDegreeToRadian(yaw)), std::sin(NzDegreeToRadian(pitch)), std::cos(NzDegreeToRadian(pitch)));
#endif
}
template<typename T>
NzVector3<T> NzEulerAngles<T>::GetUp() const
{
#if NAZARA_MATH_ANGLE_RADIAN
return NzVector3<T>(std::sin(roll), std::cos(pitch), -std::sin(pitch));
#else
return NzVector3<T>(std::sin(NzDegreeToRadian(roll)), std::cos(NzDegreeToRadian(pitch)), -std::sin(NzDegreeToRadian(pitch)));
#endif
Set(F(0.0), F(0.0), F(0.0));
}
template<typename T>
@@ -117,20 +94,14 @@ void NzEulerAngles<T>::Set(const NzEulerAngles<U>& angles)
roll = static_cast<T>(angles.roll);
}
template<typename T>
void NzEulerAngles<T>::SetZero()
{
Set(0.0, 0.0, 0.0);
}
template<typename T>
NzQuaternion<T> NzEulerAngles<T>::ToQuaternion() const
{
NzQuaternion<T> Qx(pitch, NzVector3<T>(1.0, 0.0, 0.0));
NzQuaternion<T> Qy(yaw, NzVector3<T>(0.0, 1.0, 0.0));
NzQuaternion<T> Qz(roll, NzVector3<T>(0.0, 0.0, 1.0));
NzQuaternion<T> rotX(pitch, NzVector3<T>(F(1.0), F(0.0), F(0.0)));
NzQuaternion<T> rotY(yaw, NzVector3<T>(F(0.0), F(1.0), F(0.0)));
NzQuaternion<T> rotZ(roll, NzVector3<T>(F(0.0), F(0.0), F(1.0)));
return Qx * Qy * Qz;
return rotY * rotX * rotZ;
}
template<typename T>
@@ -141,6 +112,12 @@ NzString NzEulerAngles<T>::ToString() const
return ss << "EulerAngles(" << pitch << ", " << yaw << ", " << roll << ')';
}
template<typename T>
NzEulerAngles<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzEulerAngles<T> NzEulerAngles<T>::operator+(const NzEulerAngles& angles) const
{
@@ -191,10 +168,21 @@ bool NzEulerAngles<T>::operator!=(const NzEulerAngles& angles) const
return !operator==(angles);
}
template<typename T>
NzEulerAngles<T> NzEulerAngles<T>::Zero()
{
NzEulerAngles angles;
angles.MakeZero();
return angles;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzEulerAngles<T>& angles)
{
return out << angles.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -20,16 +20,4 @@
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef NAZARA_CONFIG_AUDIO_HPP
#define NAZARA_CONFIG_AUDIO_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_AUDIO_MEMORYLEAKTRACKER 0
#endif // NAZARA_CONFIG_AUDIOs_HPP
*/

View File

@@ -8,8 +8,9 @@
#define NAZARA_MATRIX4_HPP
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Config.hpp>
#if NAZARA_THREADSAFETY_MATRIX4
#if NAZARA_MATH_THREADSAFE && NAZARA_THREADSAFETY_MATRIX4
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@@ -26,18 +27,21 @@ template<typename T> class NzMatrix4
public:
NzMatrix4();
NzMatrix4(T r11, T r12, T r13, T r14,
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
NzMatrix4(const T matrix[16]);
//NzMatrix4(const NzMatrix3<T>& matrix);
template<typename U> explicit NzMatrix4(const NzMatrix4<U>& matrix);
NzMatrix4(const NzMatrix4& matrix);
NzMatrix4(NzMatrix4&& matrix);
NzMatrix4(NzMatrix4&& matrix) noexcept;
~NzMatrix4();
NzMatrix4 Concatenate(const NzMatrix4& matrix) const;
T GetDeterminant() const;
NzMatrix4 GetInverse() const;
NzQuaternion<T> GetRotation() const;
//NzMatrix3 GetRotationMatrix() const;
NzVector3<T> GetScale() const;
NzVector3<T> GetTranslation() const;
@@ -46,23 +50,30 @@ template<typename T> class NzMatrix4
bool HasNegativeScale() const;
bool HasScale() const;
bool IsAffine() const;
bool IsDefined() const;
void MakeIdentity();
void MakeLookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
void MakeOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0);
void MakePerspective(T angle, T ratio, T zNear, T zFar);
void MakeRotation(const NzQuaternion<T>& rotation);
void MakeScale(const NzVector3<T>& scale);
void MakeTranslation(const NzVector3<T>& translation);
void MakeZero();
void Set(T r11, T r12, T r13, T r14,
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
T r21, T r22, T r23, T r24,
T r31, T r32, T r33, T r34,
T r41, T r42, T r43, T r44);
void Set(const T matrix[16]);
//NzMatrix4(const NzMatrix3<T>& matrix);
void Set(const NzMatrix4& matrix);
void Set(NzMatrix4&& matrix);
template<typename U> void Set(const NzMatrix4<U>& matrix);
void SetIdentity();
void SetLookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
void SetOrtho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0);
void SetPerspective(T angle, T ratio, T zNear, T zFar);
void SetRotation(const NzQuaternion<T>& rotation);
void SetScale(const NzVector3<T>& scale);
void SetTranslation(const NzVector3<T>& translation);
void SetZero();
NzString ToString() const;
@@ -72,6 +83,8 @@ template<typename T> class NzMatrix4
NzMatrix4& Transpose();
operator NzString() const;
operator T*();
operator const T*() const;
@@ -79,7 +92,7 @@ template<typename T> class NzMatrix4
const T& operator()(unsigned int x, unsigned int y) const;
NzMatrix4& operator=(const NzMatrix4& matrix);
NzMatrix4& operator=(NzMatrix4&& matrix);
NzMatrix4& operator=(NzMatrix4&& matrix) noexcept;
NzMatrix4 operator*(const NzMatrix4& matrix) const;
NzVector2<T> operator*(const NzVector2<T>& vector) const;
@@ -90,12 +103,16 @@ template<typename T> class NzMatrix4
NzMatrix4& operator*=(const NzMatrix4& matrix);
NzMatrix4& operator*=(T scalar);
static NzMatrix4 Concatenate(const NzMatrix4& m1, const NzMatrix4& m2);
static NzMatrix4 ConcatenateAffine(const NzMatrix4& m1, const NzMatrix4& m2);
static NzMatrix4 Identity();
static NzMatrix4 LookAt(const NzVector3<T>& eye, const NzVector3<T>& center, const NzVector3<T>& up);
static NzMatrix4 Ortho(T left, T top, T width, T height, T zNear = -1.0, T zFar = 1.0);
static NzMatrix4 Perspective(T angle, T ratio, T zNear, T zFar);
static NzMatrix4 Rotate(const NzQuaternion<T>& rotation);
static NzMatrix4 Scale(const NzVector3<T>& scale);
static NzMatrix4 Translate(const NzVector3<T>& translation);
static NzMatrix4 Zero();
struct SharedMatrix
{
@@ -112,11 +129,13 @@ template<typename T> class NzMatrix4
void EnsureOwnership();
void ReleaseMatrix();
SharedMatrix* m_sharedMatrix;
SharedMatrix* m_sharedMatrix = nullptr;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzMatrix4<T>& matrix);
template<typename T> NzMatrix4<T> operator*(T scale, const NzMatrix4<T>& matrix);
typedef NzMatrix4<double> NzMatrix4d;
typedef NzMatrix4<float> NzMatrix4f;

File diff suppressed because it is too large Load Diff

View File

@@ -31,9 +31,12 @@ template<typename T> class NzQuaternion
NzQuaternion GetConjugate() const;
NzQuaternion GetNormalized() const;
void MakeIdentity();
void MakeZero();
T Magnitude() const;
T Normalize();
T SquaredMagnitude() const;
void Set(T W, T X, T Y, T Z);
void Set(T quat[4]);
@@ -42,13 +45,17 @@ template<typename T> class NzQuaternion
//void Set(const NzMatrix3<T>& mat);
void Set(const NzQuaternion& quat);
template<typename U> void Set(const NzQuaternion<U>& quat);
void SetIdentity();
void SetZero();
T SquaredMagnitude() const;
NzEulerAngles<T> ToEulerAngles() const;
//NzMatrix3<T> ToRotationMatrix() const;
NzString ToString() const;
operator NzString() const;
NzQuaternion& operator=(const NzQuaternion& quat);
NzQuaternion operator+(const NzQuaternion& quat) const;
NzQuaternion operator*(const NzQuaternion& quat) const;
NzVector3<T> operator*(const NzVector3<T>& vec) const;
@@ -67,7 +74,9 @@ template<typename T> class NzQuaternion
bool operator>(const NzQuaternion& quat) const;
bool operator>=(const NzQuaternion& quat) const;
static NzQuaternion Identity();
static NzQuaternion Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp);
static NzQuaternion Zero();
T w, x, y, z;
};

View File

@@ -8,8 +8,11 @@
#include <Nazara/Math/Config.hpp>
#include <Nazara/Math/EulerAngles.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <limits>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzQuaternion<T>::NzQuaternion()
{
@@ -53,9 +56,9 @@ NzQuaternion<T>::NzQuaternion(const NzQuaternion<U>& quat)
}
template<typename T>
T NzQuaternion<T>::DotProduct(const NzQuaternion& vec) const
T NzQuaternion<T>::DotProduct(const NzQuaternion& quat) const
{
return w*vec.w + x*vec.x + y*vec.y + z.vec.z;
return w*quat.w + x*quat.x + y*quat.y + z*quat.z;
}
template<typename T>
@@ -73,6 +76,18 @@ NzQuaternion<T> NzQuaternion<T>::GetNormalized() const
return quat;
}
template<typename T>
void NzQuaternion<T>::MakeIdentity()
{
Set(1.0, 0.0, 0.0, 0.0);
}
template<typename T>
void NzQuaternion<T>::MakeZero()
{
Set(0.0, 0.0, 0.0, 0.0);
}
template<typename T>
T NzQuaternion<T>::Magnitude() const
{
@@ -82,27 +97,21 @@ T NzQuaternion<T>::Magnitude() const
template<typename T>
T NzQuaternion<T>::Normalize()
{
T squaredLength = SquaredMagnitude();
T squaredMagnitude = SquaredMagnitude();
if (std::fabs(squaredLength) > 0.00001 && std::fabs(squaredLength - 1.0) > 0.00001)
if (squaredMagnitude-F(1.0) > std::numeric_limits<T>::epsilon())
{
T length = std::sqrt(squaredLength);
T magnitude = std::sqrt(squaredMagnitude);
w /= length;
x /= length;
y /= length;
z /= length;
w /= magnitude;
x /= magnitude;
y /= magnitude;
z /= magnitude;
return length;
return magnitude;
}
else
return 1.0; // Le quaternion est déjà normalisé
}
template<typename T>
T NzQuaternion<T>::SquaredMagnitude() const
{
return w * w + x * x + y * y + z * z;
return F(1.0); // Le quaternion est déjà normalisé
}
template<typename T>
@@ -166,81 +175,29 @@ void NzQuaternion<T>::Set(const NzQuaternion& quat)
}
template<typename T>
void NzQuaternion<T>::SetIdentity()
T NzQuaternion<T>::SquaredMagnitude() const
{
Set(1.0, 0.0, 0.0, 0.0);
}
template<typename T>
void NzQuaternion<T>::SetZero()
{
Set(0.0, 0.0, 0.0, 0.0);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp)
{
if (interp <= 0.0)
return quatA;
if (interp >= 1.0)
return quatB;
NzQuaternion q;
T cosOmega = quatA.DotProduct(quatB);
if (cosOmega < 0.0)
{
// On inverse tout
q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z);
cosOmega = -cosOmega;
}
else
q.Set(quatB);
T k0, k1;
if (cosOmega > 0.9999)
{
// Interpolation linéaire pour éviter une division par zéro
k0 = 1.0 - interp;
k1 = interp;
}
else
{
T sinOmega = std::sqrt(1.0f - (cosOmega * cosOmega));
T omega = std::atan2(sinOmega, cosOmega);
// Pour éviter deux divisions
sinOmega = 1/sinOmega;
k0 = std::sin((1.0 - interp) * omega) * sinOmega;
k1 = std::sin(interp * omega) * sinOmega;
}
NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z);
return result += q;
return w*w + x*x + y*y + z*z;
}
template<typename T>
NzEulerAngles<T> NzQuaternion<T>::ToEulerAngles() const
{
Normalize();
T test = x*y + z*w;
if (test > 0.499)
if (test > F(0.499))
// singularity at north pole
return NzEulerAngles<T>(NzDegrees(90.0), NzRadians(2.0 * std::atan2(x, w)), 0.0);
return NzEulerAngles<T>(NzDegrees(F(90.0)), NzRadians(F(2.0) * std::atan2(x, w)), F(0.0));
if (test < -0.499)
return NzEulerAngles<T>(NzDegrees(-90.0), NzRadians(-2.0 * std::atan2(x, w)), 0.0);
if (test < F(-0.499))
return NzEulerAngles<T>(NzDegrees(F(-90.0)), NzRadians(F(-2.0) * std::atan2(x, w)), F(0.0));
T xx = x*x;
T yy = y*y;
T zz = z*z;
return NzEulerAngles<T>(NzRadians(std::atan2(2.0*x*w - 2.0*y*z, 1.0 - 2.0*xx - 2.0*zz)),
NzRadians(std::atan2(2.0*y*w - 2.0*x*z, 1.f - 2.0*yy - 2.0*zz)),
NzRadians(std::asin(2.0*test)));
return NzEulerAngles<T>(NzRadians(std::atan2(F(2.0)*x*w - F(2.0)*y*z, F(1.0) - F(2.0)*xx - F(2.0)*zz)),
NzRadians(std::atan2(F(2.0)*y*w - F(2.0)*x*z, F(1.0) - F(2.0)*yy - F(2.0)*zz)),
NzRadians(std::asin(F(2.0)*test)));
}
template<typename T>
@@ -251,6 +208,20 @@ NzString NzQuaternion<T>::ToString() const
return ss << "Quaternion(" << w << " | " << x << ", " << y << ", " << z << ')';
}
template<typename T>
NzQuaternion<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzQuaternion<T>& NzQuaternion<T>::operator=(const NzQuaternion& quat)
{
Set(quat);
return *this;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator+(const NzQuaternion& quat) const
{
@@ -263,10 +234,10 @@ NzQuaternion<T> NzQuaternion<T>::operator+(const NzQuaternion& quat) const
template<typename T>
NzQuaternion<T> NzQuaternion<T>::operator*(const NzQuaternion& quat) const
{
return NzQuaternion(w * quat.w - x * quat.x - y * quat.y - z * quat.z,
w * quat.x + x * quat.w + y * quat.z - z * quat.y,
w * quat.y + y * quat.w + z * quat.x - x * quat.z,
w * quat.z + z * quat.w + x * quat.y - y * quat.x);
return NzQuaternion(w*quat.w - x*quat.x - y*quat.y - z*quat.z,
w*quat.x + x*quat.w + y*quat.z - z*quat.y,
w*quat.y + y*quat.w + z*quat.x - x*quat.z,
w*quat.z + z*quat.w + x*quat.y - y*quat.x);
}
template<typename T>
@@ -276,7 +247,7 @@ NzVector3<T> NzQuaternion<T>::operator*(const NzVector3<T>& vec) const
normal.Normalize();
NzQuaternion qvec(0.0, normal.x, normal.y, normal.z);
NzQuaternion result = operator*(qvec * GetConjugate());
NzQuaternion result(operator*(qvec * GetConjugate()));
return NzVector3<T>(result.x, result.y, result.z);
@@ -360,10 +331,74 @@ bool NzQuaternion<T>::operator>=(const NzQuaternion& quat) const
return !operator<(quat);
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Identity()
{
NzQuaternion quaternion;
quaternion.MakeIdentity();
return quaternion;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Slerp(const NzQuaternion& quatA, const NzQuaternion& quatB, T interp)
{
if (interp <= F(0.0))
return quatA;
if (interp >= F(1.0))
return quatB;
NzQuaternion q;
T cosOmega = quatA.DotProduct(quatB);
if (cosOmega < F(0.0))
{
// On inverse tout
q.Set(-quatB.w, -quatB.x, -quatB.y, -quatB.z);
cosOmega = -cosOmega;
}
else
q.Set(quatB);
T k0, k1;
if (cosOmega > F(0.9999))
{
// Interpolation linéaire pour éviter une division par zéro
k0 = F(1.0) - interp;
k1 = interp;
}
else
{
T sinOmega = std::sqrt(F(1.0) - cosOmega*cosOmega);
T omega = std::atan2(sinOmega, cosOmega);
// Pour éviter deux divisions
sinOmega = F(1.0)/sinOmega;
k0 = std::sin((F(1.0) - interp) * omega) * sinOmega;
k1 = std::sin(interp*omega) * sinOmega;
}
NzQuaternion result(k0 * quatA.w, k0 * quatA.x, k0 * quatA.y, k0 * quatA.z);
return result += q*k1;
}
template<typename T>
NzQuaternion<T> NzQuaternion<T>::Zero()
{
NzQuaternion quaternion;
quaternion.MakeZero();
return quaternion;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzQuaternion<T>& quat)
{
return out << quat.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -16,7 +16,8 @@ class NzRect
public:
NzRect();
NzRect(T X, T Y, T Width, T Height);
NzRect(T rect[4]);
NzRect(const T rect[4]);
NzRect(const NzVector2<T>& vec1, const NzVector2<T>& vec2);
template<typename U> explicit NzRect(const NzRect<U>& rect);
NzRect(const NzRect& rect) = default;
~NzRect() = default;
@@ -30,11 +31,15 @@ class NzRect
NzVector2<T> GetCenter() const;
bool Intersect(const NzRect& rect) const;
bool Intersect(const NzRect& rect, NzRect& intersection) const;
bool Intersect(const NzRect& rect, NzRect* intersection = nullptr) const;
bool IsValid() const;
void Set(T X, T Y, T Width, T Height);
void Set(const T rect[4]);
void Set(const NzVector2<T>& vec1, const NzVector2<T>& vec2);
template<typename U> void Set(const NzRect<U>& rect);
NzString ToString() const;
operator NzString() const;

View File

@@ -6,37 +6,36 @@
#include <algorithm>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzRect<T>::NzRect()
{
}
template<typename T>
NzRect<T>::NzRect(T X, T Y, T Width, T Height) :
x(X),
y(Y),
width(Width),
height(Height)
NzRect<T>::NzRect(T X, T Y, T Width, T Height)
{
Set(X, Y, Width, Height);
}
template<typename T>
NzRect<T>::NzRect(T vec[4]) :
x(vec[0]),
y(vec[1]),
width(vec[2]),
height(vec[3])
NzRect<T>::NzRect(const T vec[4])
{
Set(vec);
}
template<typename T>
NzRect<T>::NzRect(const NzVector2<T>& vec1, const NzVector2<T>& vec2)
{
Set(vec1, vec2);
}
template<typename T>
template<typename U>
NzRect<T>::NzRect(const NzRect<U>& rect) :
x(static_cast<T>(rect.x)),
y(static_cast<T>(rect.y)),
width(static_cast<T>(rect.width)),
height(static_cast<T>(rect.height))
NzRect<T>::NzRect(const NzRect<U>& rect)
{
Set(rect);
}
template<typename T>
@@ -80,18 +79,11 @@ void NzRect<T>::ExtendTo(const NzRect& rect)
template<typename T>
NzVector2<T> NzRect<T>::GetCenter() const
{
return NzVector2<T>((x+width)/2, (y+height)/2);
return NzVector2<T>((x+width)/F(2.0), (y+height)/F(2.0));
}
template<typename T>
bool NzRect<T>::Intersect(const NzRect& rect) const
{
NzRect intersection; // Optimisé par le compilateur
return Intersect(rect, intersection);
}
template<typename T>
bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
bool NzRect<T>::Intersect(const NzRect& rect, NzRect* intersection) const
{
T left = std::max(x, rect.x);
T right = std::min(x+width, rect.x+rect.width);
@@ -100,10 +92,13 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
if (left < right && top < bottom)
{
intersection.x = left;
intersection.y = top;
intersection.width = right-left;
intersection.height = bottom-top;
if (intersection)
{
intersection->x = left;
intersection->y = top;
intersection->width = right-left;
intersection->height = bottom-top;
}
return true;
}
@@ -114,7 +109,44 @@ bool NzRect<T>::Intersect(const NzRect& rect, NzRect& intersection) const
template<typename T>
bool NzRect<T>::IsValid() const
{
return width > 0 && height > 0;
return width > F(0.0) && height > F(0.0);
}
template<typename T>
void NzRect<T>::Set(T X, T Y, T Width, T Height)
{
x = X;
y = Y;
width = Width;
height = Height;
}
template<typename T>
void NzRect<T>::Set(const T rect[4])
{
x = rect[0];
y = rect[1];
width = rect[2];
height = rect[3];
}
template<typename T>
void NzRect<T>::Set(const NzVector2<T>& vec1, const NzVector2<T>& vec2)
{
x = std::min(vec1.x, vec2.x);
y = std::min(vec1.y, vec2.y);
width = (vec2.x > vec1.x) ? vec2.x-vec1.x : vec1.x-vec2.x;
height = (vec2.y > vec1.y) ? vec2.y-vec1.y : vec1.y-vec2.y;
}
template<typename T>
template<typename U>
void NzRect<T>::Set(const NzRect<U>& rect)
{
x = F(rect.x);
y = F(rect.y);
width = F(rect.width);
height = F(rect.height);
}
template<typename T>
@@ -134,6 +166,7 @@ NzRect<T>::operator NzString() const
template<typename T>
T& NzRect<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 4)
{
NzStringStream ss;
@@ -141,6 +174,7 @@ T& NzRect<T>::operator[](unsigned int i)
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -148,6 +182,7 @@ T& NzRect<T>::operator[](unsigned int i)
template<typename T>
T NzRect<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 4)
{
NzStringStream ss;
@@ -155,6 +190,7 @@ T NzRect<T>::operator[](unsigned int i) const
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -165,4 +201,6 @@ std::ostream& operator<<(std::ostream& out, const NzRect<T>& rect)
return out << rect.ToString();
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -21,20 +21,37 @@ template<typename T> class NzVector2
~NzVector2() = default;
T AbsDotProduct(const NzVector2& vec) const;
T Distance(const NzVector2& vec) const;
float Distancef(const NzVector2& vec) const;
T DotProduct(const NzVector2& vec) const;
NzVector2 GetNormal() const;
void MakeCeil(const NzVector2& vec);
void MakeFloor(const NzVector2& vec);
void MakeUnitX();
void MakeUnitY();
void MakeZero();
T Length() const;
float Lengthf() const;
void Normalize();
void Set(T X, T Y);
void Set(T scale);
void Set(T vec[2]);
template<typename U> void Set(const NzVector2<U>& vec);
T SquaredDistance(const NzVector2& vec) const;
T SquaredLength() const;
NzString ToString() const;
operator NzString() const;
operator T*();
operator const T*() const;
@@ -65,8 +82,11 @@ template<typename T> class NzVector2
bool operator>(const NzVector2& vec) const;
bool operator>=(const NzVector2& vec) const;
T x;
T y;
static NzVector2 UnitX();
static NzVector2 UnitY();
static NzVector2 Zero();
T x, y;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector2<T>& vec);

View File

@@ -6,41 +6,40 @@
#include <Nazara/Math/Basic.hpp>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzVector2<T>::NzVector2()
{
}
template<typename T>
NzVector2<T>::NzVector2(T X, T Y) :
x(X),
y(Y)
NzVector2<T>::NzVector2(T X, T Y)
{
Set(X, Y);
}
template<typename T>
NzVector2<T>::NzVector2(T scale) :
x(scale),
y(scale)
NzVector2<T>::NzVector2(T scale)
{
Set(scale);
}
template<typename T>
NzVector2<T>::NzVector2(T vec[2]) :
x(vec[0]),
y(vec[1])
NzVector2<T>::NzVector2(T vec[2])
{
Set(vec);
}
template<typename T>
template<typename U>
NzVector2<T>::NzVector2(const NzVector2<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y))
NzVector2<T>::NzVector2(const NzVector2<U>& vec)
{
Set(vec);
}
template<typename T>
@@ -76,7 +75,7 @@ float NzVector2<T>::Distancef(const NzVector2& vec) const
template<typename T>
T NzVector2<T>::DotProduct(const NzVector2& vec) const
{
return x * vec.x + y * vec.y;
return x*vec.x + y*vec.y;
}
template<typename T>
@@ -88,6 +87,18 @@ NzVector2<T> NzVector2<T>::GetNormal() const
return vec;
}
template<typename T>
T NzVector2<T>::Length() const
{
return std::sqrt(SquaredLength());
}
template<typename T>
float NzVector2<T>::Lengthf() const
{
return std::sqrt(static_cast<float>(SquaredLength()));
}
template<typename T>
void NzVector2<T>::MakeCeil(const NzVector2& vec)
{
@@ -109,29 +120,65 @@ void NzVector2<T>::MakeFloor(const NzVector2& vec)
}
template<typename T>
T NzVector2<T>::Length() const
void NzVector2<T>::MakeUnitX()
{
return std::sqrt(SquaredLength());
Set(F(1.0), F(0.0));
}
template<typename T>
float NzVector2<T>::Lengthf() const
void NzVector2<T>::MakeUnitY()
{
return std::sqrt(static_cast<float>(SquaredLength()));
Set(F(0.0), F(1.0));
}
template<typename T>
void NzVector2<T>::MakeZero()
{
Set(F(0.0), F(0.0));
}
template<typename T>
void NzVector2<T>::Normalize()
{
auto length = Length();
T squaredLength = SquaredLength();
if (!NzNumberEquals(length, static_cast<T>(0.0)))
if (squaredLength-F(1.0) > std::numeric_limits<T>::epsilon())
{
T length = std::sqrt(squaredLength);
x /= length;
y /= length;
}
}
template<typename T>
void NzVector2<T>::Set(T X, T Y)
{
x = X;
y = Y;
}
template<typename T>
void NzVector2<T>::Set(T scale)
{
x = scale;
y = scale;
}
template<typename T>
void NzVector2<T>::Set(T vec[2])
{
std::memcpy(&x, vec, 2*sizeof(T));
}
template<typename T>
template<typename U>
void NzVector2<T>::Set(const NzVector2<U>& vec)
{
x = F(vec.x);
y = F(vec.y);
}
template<typename T>
T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
{
@@ -141,7 +188,7 @@ T NzVector2<T>::SquaredDistance(const NzVector2& vec) const
template<typename T>
T NzVector2<T>::SquaredLength() const
{
return x * x + y * y;
return x*x + y*y;
}
template<typename T>
@@ -152,6 +199,12 @@ NzString NzVector2<T>::ToString() const
return ss << "Vector2(" << x << ", " << y << ')';
}
template<typename T>
NzVector2<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzVector2<T>::operator T*()
{
@@ -167,6 +220,7 @@ NzVector2<T>::operator const T*() const
template<typename T>
T& NzVector2<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 2)
{
NzStringStream ss;
@@ -174,6 +228,7 @@ T& NzVector2<T>::operator[](unsigned int i)
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -181,6 +236,7 @@ T& NzVector2<T>::operator[](unsigned int i)
template<typename T>
T NzVector2<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 2)
{
NzStringStream ss;
@@ -188,6 +244,7 @@ T NzVector2<T>::operator[](unsigned int i) const
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -231,13 +288,15 @@ NzVector2<T> NzVector2<T>::operator*(T scale) const
template<typename T>
NzVector2<T> NzVector2<T>::operator/(const NzVector2& vec) const
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector2(x / vec.x, y / vec.y);
}
@@ -245,13 +304,15 @@ NzVector2<T> NzVector2<T>::operator/(const NzVector2& vec) const
template<typename T>
NzVector2<T> NzVector2<T>::operator/(T scale) const
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector2(x / scale, y / scale);
}
@@ -295,13 +356,15 @@ NzVector2<T>& NzVector2<T>::operator*=(T scale)
template<typename T>
NzVector2<T>& NzVector2<T>::operator/=(const NzVector2& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
x /= vec.x;
y /= vec.y;
@@ -312,13 +375,15 @@ NzVector2<T>& NzVector2<T>::operator/=(const NzVector2& vec)
template<typename T>
NzVector2<T>& NzVector2<T>::operator/=(T scale)
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
x /= scale;
y /= scale;
@@ -363,6 +428,33 @@ bool NzVector2<T>::operator>=(const NzVector2& vec) const
return !operator<(vec);
}
template<typename T>
NzVector2<T> NzVector2<T>::UnitX()
{
NzVector2 vector;
vector.MakeUnitX();
return vector;
}
template<typename T>
NzVector2<T> NzVector2<T>::UnitY()
{
NzVector2 vector;
vector.MakeUnitY();
return vector;
}
template<typename T>
NzVector2<T> NzVector2<T>::Zero()
{
NzVector2 vector;
vector.MakeZero();
return vector;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector2<T>& vec)
{
@@ -378,15 +470,19 @@ NzVector2<T> operator*(T scale, const NzVector2<T>& vec)
template<typename T>
NzVector2<T> operator/(T scale, const NzVector2<T>& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector2<T>(scale/vec.x, scale/vec.y);
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -23,21 +23,41 @@ template<typename T> class NzVector3
~NzVector3() = default;
T AbsDotProduct(const NzVector3& vec) const;
NzVector3 CrossProduct(const NzVector3& vec) const;
T Distance(const NzVector3& vec) const;
float Distancef(const NzVector3& vec) const;
T DotProduct(const NzVector3& vec) const;
NzVector3 GetNormal() const;
void MakeCeil(const NzVector3& vec);
void MakeFloor(const NzVector3& vec);
T Length() const;
float Lengthf() const;
void MakeCeil(const NzVector3& vec);
void MakeFloor(const NzVector3& vec);
void MakeUnitX();
void MakeUnitY();
void MakeUnitZ();
void MakeZero();
void Normalize();
void Set(T X, T Y, T Z);
void Set(T scale);
void Set(T vec[3]);
void Set(const NzVector2<T>& vec, T Z = 0.0);
template<typename U> void Set(const NzVector3<U>& vec);
T SquaredDistance(const NzVector3& vec) const;
T SquaredLength() const;
NzString ToString() const;
operator NzString() const;
operator T*();
operator const T*() const;
@@ -68,9 +88,12 @@ template<typename T> class NzVector3
bool operator>(const NzVector3& vec) const;
bool operator>=(const NzVector3& vec) const;
T x;
T y;
T z;
static NzVector3 UnitX();
static NzVector3 UnitY();
static NzVector3 UnitZ();
static NzVector3 Zero();
T x, y, z;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector3<T>& vec);

View File

@@ -6,53 +6,46 @@
#include <Nazara/Math/Basic.hpp>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
#define F(a) static_cast<T>(a)
template<typename T>
NzVector3<T>::NzVector3()
{
}
template<typename T>
NzVector3<T>::NzVector3(T X, T Y, T Z) :
x(X),
y(Y),
z(Z)
NzVector3<T>::NzVector3(T X, T Y, T Z)
{
Set(X, Y, Z);
}
template<typename T>
NzVector3<T>::NzVector3(T scale) :
x(scale),
y(scale),
z(scale)
NzVector3<T>::NzVector3(T scale)
{
Set(scale);
}
template<typename T>
NzVector3<T>::NzVector3(T vec[3]) :
x(vec[0]),
y(vec[1]),
z(vec[2])
NzVector3<T>::NzVector3(T vec[3])
{
Set(vec);
}
template<typename T>
NzVector3<T>::NzVector3(const NzVector2<T>& vec, T Z) :
x(vec.x),
y(vec.y),
z(Z)
NzVector3<T>::NzVector3(const NzVector2<T>& vec, T Z)
{
Set(vec, Z);
}
template<typename T>
template<typename U>
NzVector3<T>::NzVector3(const NzVector3<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y)),
z(static_cast<T>(vec.z))
NzVector3<T>::NzVector3(const NzVector3<U>& vec)
{
Set(vec);
}
template<typename T>
@@ -94,7 +87,7 @@ float NzVector3<T>::Distancef(const NzVector3& vec) const
template<typename T>
T NzVector3<T>::DotProduct(const NzVector3& vec) const
{
return x * vec.x + y * vec.y + z * vec.z;
return x*vec.x + y*vec.y + z*vec.z;
}
template<typename T>
@@ -132,6 +125,30 @@ void NzVector3<T>::MakeFloor(const NzVector3& vec)
z = vec.z;
}
template<typename T>
void NzVector3<T>::MakeUnitX()
{
Set(F(1.0), F(0.0), F(0.0));
}
template<typename T>
void NzVector3<T>::MakeUnitY()
{
Set(F(0.0), F(1.0), F(0.0));
}
template<typename T>
void NzVector3<T>::MakeUnitZ()
{
Set(F(0.0), F(0.0), F(1.0));
}
template<typename T>
void NzVector3<T>::MakeZero()
{
Set(F(0.0), F(0.0), F(0.0));
}
template<typename T>
T NzVector3<T>::Length() const
{
@@ -147,16 +164,57 @@ float NzVector3<T>::Lengthf() const
template<typename T>
void NzVector3<T>::Normalize()
{
T length = Length();
T squaredLength = SquaredLength();
if (!NzNumberEquals(length, static_cast<T>(0.0)))
if (squaredLength-F(1.0) > std::numeric_limits<T>::epsilon())
{
T length = std::sqrt(squaredLength);
x /= length;
y /= length;
z /= length;
}
}
template<typename T>
void NzVector3<T>::Set(T X, T Y, T Z)
{
x = X;
y = Y;
z = Z;
}
template<typename T>
void NzVector3<T>::Set(T scale)
{
x = scale;
y = scale;
z = scale;
}
template<typename T>
void NzVector3<T>::Set(T vec[3])
{
std::memcpy(&x, vec, 3*sizeof(T));
}
template<typename T>
void NzVector3<T>::Set(const NzVector2<T>& vec, T Z)
{
x = vec.x;
y = vec.y;
z = Z;
}
template<typename T>
template<typename U>
void NzVector3<T>::Set(const NzVector3<U>& vec)
{
x = F(vec.x);
y = F(vec.y);
z = F(vec.z);
}
template<typename T>
T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
{
@@ -166,7 +224,7 @@ T NzVector3<T>::SquaredDistance(const NzVector3& vec) const
template<typename T>
T NzVector3<T>::SquaredLength() const
{
return x * x + y * y + z * z;
return x*x + y*y + z*z;
}
template<typename T>
@@ -177,6 +235,12 @@ NzString NzVector3<T>::ToString() const
return ss << "Vector3(" << x << ", " << y << ", " << z <<')';
}
template<typename T>
NzVector3<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzVector3<T>::operator T*()
{
@@ -192,13 +256,15 @@ NzVector3<T>::operator const T*() const
template<typename T>
T& NzVector3<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 3)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)";
throw std::domain_error(ss.ToString());
throw std::out_of_range(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -206,13 +272,15 @@ T& NzVector3<T>::operator[](unsigned int i)
template<typename T>
T NzVector3<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 3)
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Index out of range (" << i << " >= 3)";
throw std::domain_error(ss.ToString());
throw std::out_of_range(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -256,13 +324,15 @@ NzVector3<T> NzVector3<T>::operator*(T scale) const
template<typename T>
NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector3(x / vec.x, y / vec.y, z / vec.z);
}
@@ -270,13 +340,15 @@ NzVector3<T> NzVector3<T>::operator/(const NzVector3& vec) const
template<typename T>
NzVector3<T> NzVector3<T>::operator/(T scale) const
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector3(x / scale, y / scale, z / scale);
}
@@ -324,7 +396,7 @@ NzVector3<T>& NzVector3<T>::operator*=(T scale)
template<typename T>
NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
@@ -342,7 +414,7 @@ NzVector3<T>& NzVector3<T>::operator/=(const NzVector3& vec)
template<typename T>
NzVector3<T>& NzVector3<T>::operator/=(T scale)
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
@@ -395,6 +467,42 @@ bool NzVector3<T>::operator>=(const NzVector3& vec) const
return !operator<(vec);
}
template<typename T>
NzVector3<T> NzVector3<T>::UnitX()
{
NzVector3 vector;
vector.MakeUnitX();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::UnitY()
{
NzVector3 vector;
vector.MakeUnitY();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::UnitZ()
{
NzVector3 vector;
vector.MakeUnitZ();
return vector;
}
template<typename T>
NzVector3<T> NzVector3<T>::Zero()
{
NzVector3 vector;
vector.MakeZero();
return vector;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector3<T>& vec)
{
@@ -410,15 +518,19 @@ NzVector3<T> operator*(T scale, const NzVector3<T>& vec)
template<typename T>
NzVector3<T> operator/(T scale, const NzVector3<T>& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector3<T>(scale / vec.x, scale / vec.y, scale / vec.z);
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -17,19 +17,34 @@ template<typename T> class NzVector4
NzVector4(T X, T Y, T Z, T W = 1.0);
explicit NzVector4(T scale);
NzVector4(T vec[4]);
template<typename U> explicit NzVector4(const NzVector4<U>& vec);
NzVector4(const NzVector3<T>& vec, T W = 1.0);
template<typename U> explicit NzVector4(const NzVector4<U>& vec);
NzVector4(const NzVector4& vec) = default;
~NzVector4() = default;
T AbsDotProduct(const NzVector4& vec) const;
T DotProduct(const NzVector4& vec) const;
void MakeCeil(const NzVector4& vec);
void MakeFloor(const NzVector4& vec);
void MakeUnitX();
void MakeUnitY();
void MakeUnitZ();
void MakeZero();
void Normalize();
void Set(T X, T Y, T Z, T W = 1.0);
void Set(T scale);
void Set(T vec[4]);
void Set(const NzVector3<T>& vec, T W = 1.0);
template<typename U> void Set(const NzVector4<U>& vec);
NzString ToString() const;
operator NzString() const;
operator T*();
operator const T*() const;
@@ -60,10 +75,12 @@ template<typename T> class NzVector4
bool operator>(const NzVector4& vec) const;
bool operator>=(const NzVector4& vec) const;
T x;
T y;
T z;
T w;
static NzVector4 UnitX();
static NzVector4 UnitY();
static NzVector4 UnitZ();
static NzVector4 Zero();
T x, y, z, w;
};
template<typename T> std::ostream& operator<<(std::ostream& out, const NzVector4<T>& vec);

View File

@@ -9,55 +9,44 @@
#include <stdexcept>
#include <Nazara/Core/Debug.hpp>
///FIXME: Les calculs effectués ici sont probablements tous faux, la composante W étant spéciale dans le monde de la 3D
#define F(a) static_cast<T>(a)
template<typename T>
NzVector4<T>::NzVector4()
{
}
template<typename T>
NzVector4<T>::NzVector4(T X, T Y, T Z, T W) :
x(X),
y(Y),
z(Z),
w(W)
NzVector4<T>::NzVector4(T X, T Y, T Z, T W)
{
Set(X, Y, Z, W);
}
template<typename T>
NzVector4<T>::NzVector4(T scale) :
x(scale),
y(scale),
z(scale),
w(scale)
NzVector4<T>::NzVector4(T scale)
{
Set(scale);
}
template<typename T>
NzVector4<T>::NzVector4(T vec[4]) :
x(vec[0]),
y(vec[1]),
z(vec[2]),
w(vec[3])
NzVector4<T>::NzVector4(T vec[4])
{
Set(vec);
}
template<typename T>
NzVector4<T>::NzVector4(const NzVector3<T>& vec, T W)
{
Set(vec, W);
}
template<typename T>
template<typename U>
NzVector4<T>::NzVector4(const NzVector4<U>& vec) :
x(static_cast<T>(vec.x)),
y(static_cast<T>(vec.y)),
z(static_cast<T>(vec.z)),
w(static_cast<T>(vec.w))
{
}
template<typename T>
NzVector4<T>::NzVector4(const NzVector3<T>& vec, T W) :
x(vec.x),
y(vec.y),
z(vec.z),
w(W)
NzVector4<T>::NzVector4(const NzVector4<U>& vec)
{
Set(vec);
}
template<typename T>
@@ -81,7 +70,7 @@ inline unsigned int NzVector4<unsigned int>::AbsDotProduct(const NzVector4<unsig
template<typename T>
T NzVector4<T>::DotProduct(const NzVector4& vec) const
{
return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
return x*vec.x + y*vec.y + z*vec.z + w*vec.w;
}
template<typename T>
@@ -116,10 +105,34 @@ void NzVector4<T>::MakeFloor(const NzVector4& vec)
w = vec.w;
}
template<typename T>
void NzVector4<T>::MakeUnitX()
{
Set(F(1.0), F(0.0), F(0.0), F(1.0));
}
template<typename T>
void NzVector4<T>::MakeUnitY()
{
Set(F(0.0), F(1.0), F(0.0), F(1.0));
}
template<typename T>
void NzVector4<T>::MakeUnitZ()
{
Set(F(0.0), F(0.0), F(1.0), F(1.0));
}
template<typename T>
void NzVector4<T>::MakeZero()
{
Set(F(0.0), F(0.0), F(0.0), F(0.0));
}
template<typename T>
void NzVector4<T>::Normalize()
{
if (!NzNumberEquals(w, static_cast<T>(0.0)))
if (!NzNumberEquals(w, F(0.0)))
{
x /= w;
y /= w;
@@ -127,6 +140,49 @@ void NzVector4<T>::Normalize()
}
}
template<typename T>
void NzVector4<T>::Set(T X, T Y, T Z, T W)
{
w = W;
x = X;
y = Y;
z = Z;
}
template<typename T>
void NzVector4<T>::Set(T scale)
{
w = scale;
x = scale;
y = scale;
z = scale;
}
template<typename T>
void NzVector4<T>::Set(T vec[4])
{
std::memcpy(&x, vec, 4*sizeof(T));
}
template<typename T>
void NzVector4<T>::Set(const NzVector3<T>& vec, T W)
{
w = W;
x = vec.x;
y = vec.y;
z = vec.z;
}
template<typename T>
template<typename U>
void NzVector4<T>::Set(const NzVector4<U>& vec)
{
w = F(vec.w);
x = F(vec.x);
y = F(vec.y);
z = F(vec.z);
}
template<typename T>
NzString NzVector4<T>::ToString() const
{
@@ -135,6 +191,12 @@ NzString NzVector4<T>::ToString() const
return ss << "Vector4(" << x << ", " << y << ", " << z << ", " << w << ')';
}
template<typename T>
NzVector4<T>::operator NzString() const
{
return ToString();
}
template<typename T>
NzVector4<T>::operator T*()
{
@@ -150,6 +212,7 @@ NzVector4<T>::operator const T*() const
template<typename T>
T& NzVector4<T>::operator[](unsigned int i)
{
#if NAZARA_MATH_SAFE
if (i >= 4)
{
NzStringStream ss;
@@ -157,6 +220,7 @@ T& NzVector4<T>::operator[](unsigned int i)
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -164,6 +228,7 @@ T& NzVector4<T>::operator[](unsigned int i)
template<typename T>
T NzVector4<T>::operator[](unsigned int i) const
{
#if NAZARA_MATH_SAFE
if (i >= 4)
{
NzStringStream ss;
@@ -171,6 +236,7 @@ T NzVector4<T>::operator[](unsigned int i) const
throw std::domain_error(ss.ToString());
}
#endif
return *(&x+i);
}
@@ -214,13 +280,15 @@ NzVector4<T> NzVector4<T>::operator*(T scale) const
template<typename T>
NzVector4<T> NzVector4<T>::operator/(const NzVector4& vec) const
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector4(x / vec.x, y / vec.y, z / vec.z, w / vec.w);
}
@@ -228,13 +296,15 @@ NzVector4<T> NzVector4<T>::operator/(const NzVector4& vec) const
template<typename T>
NzVector4<T> NzVector4<T>::operator/(T scale) const
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector4(x / scale, y / scale, z / scale, w / scale);
}
@@ -286,13 +356,15 @@ NzVector4<T>& NzVector4<T>::operator*=(T scale)
template<typename T>
NzVector4<T>& NzVector4<T>::operator/=(const NzVector4& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
x /= vec.x;
y /= vec.y;
@@ -305,13 +377,15 @@ NzVector4<T>& NzVector4<T>::operator/=(const NzVector4& vec)
template<typename T>
NzVector4<T>& NzVector4<T>::operator/=(T scale)
{
if (NzNumberEquals(scale, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(scale, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
x /= scale;
y /= scale;
@@ -360,6 +434,42 @@ bool NzVector4<T>::operator>=(const NzVector4& vec) const
return !operator<(vec);
}
template<typename T>
NzVector4<T> NzVector4<T>::UnitX()
{
NzVector4 vector;
vector.MakeUnitX();
return vector;
}
template<typename T>
NzVector4<T> NzVector4<T>::UnitY()
{
NzVector4 vector;
vector.MakeUnitY();
return vector;
}
template<typename T>
NzVector4<T> NzVector4<T>::UnitZ()
{
NzVector4 vector;
vector.MakeUnitZ();
return vector;
}
template<typename T>
NzVector4<T> NzVector4<T>::Zero()
{
NzVector4 vector;
vector.MakeZero();
return vector;
}
template<typename T>
std::ostream& operator<<(std::ostream& out, const NzVector4<T>& vec)
{
@@ -375,15 +485,19 @@ NzVector4<T> operator*(T scale, const NzVector4<T>& vec)
template<typename T>
NzVector4<T> operator/(T scale, const NzVector4<T>& vec)
{
if (NzNumberEquals(vec.x, static_cast<T>(0.0)) || NzNumberEquals(vec.y, static_cast<T>(0.0)) || NzNumberEquals(vec.z, static_cast<T>(0.0)) || NzNumberEquals(vec.w, static_cast<T>(0.0)))
#if NAZARA_MATH_SAFE
if (NzNumberEquals(vec.x, F(0.0)) || NzNumberEquals(vec.y, F(0.0)) || NzNumberEquals(vec.z, F(0.0)) || NzNumberEquals(vec.w, F(0.0)))
{
NzStringStream ss;
ss << __FILE__ << ':' << __LINE__ << ": Division by zero";
throw std::domain_error(ss.ToString());
}
#endif
return NzVector4<T>(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w);
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@@ -1,11 +0,0 @@
// Copyright (C) 2012 Jérôme Leclercq
// This file is part of the "Nazara Engine".
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Network/Config.hpp>
#if NAZARA_NETWORK_MEMORYLEAKTRACKER || defined(NAZARA_DEBUG)
#include <Nazara/Core/Debug/MemoryLeakTracker.hpp>
#define delete NzMemoryManager::NextFree(__FILE__, __LINE__), delete
#define new new(__FILE__, __LINE__)
#endif

39
include/Nazara/Noise.hpp Normal file
View File

@@ -0,0 +1,39 @@
// This file was automatically generated by Nazara
/*
Nazara Engine - NzNoise Module
Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <Nazara/Noise/ComplexNoiseBase.hpp>
#include <Nazara/Noise/Config.hpp>
#include <Nazara/Noise/Noise.hpp>
#include <Nazara/Noise/NoiseBase.hpp>
#include <Nazara/Noise/NoiseMachine.hpp>
#include <Nazara/Noise/Perlin2D.hpp>
#include <Nazara/Noise/Perlin3D.hpp>
#include <Nazara/Noise/Perlin4D.hpp>
#include <Nazara/Noise/Simplex2D.hpp>
#include <Nazara/Noise/Simplex3D.hpp>
#include <Nazara/Noise/Simplex4D.hpp>

View File

@@ -1,8 +1,4 @@
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Nazara Engine - NzNoise Module
Copyright (C) 2012 Rémi "Overdrivr" Bèges (remi.beges@laposte.net)

View File

@@ -8,20 +8,22 @@
#define NAZARA_NOISE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzNoise
{
public:
NzNoise();
~NzNoise();
NzNoise() = delete;
~NzNoise() = delete;
bool Initialize();
void Uninitialize();
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static bool s_initialized;
static unsigned int s_moduleReferenceCouter;
};
#endif // NOISE_HPP
#endif // NAZARA_NOISE_HPP

View File

@@ -6,7 +6,7 @@
#define NAZARA_PREREQUESITES_HPP
#if __cplusplus < 201103L
#error Nazara requires a C++11 compliant compiler
#error Nazara requires a C++11 compliant compiler
#endif
// Version du moteur
@@ -42,7 +42,7 @@
#define NazaraUnused(a) (void) a
#if defined(_WIN32) || defined(__WIN32__) || defined(NAZARA_PLATFORM_WINDOWSVISTA)
#if defined(_WIN32) || defined(__WIN32__)
#if !defined(NAZARA_STATIC)
#ifdef NAZARA_BUILD
#define NAZARA_API __declspec(dllexport)
@@ -71,6 +71,7 @@
#define NAZARA_WINNT 0x0501
#endif
// Pour ne pas casser le define déjà en place s'il est applicable
#if defined(_WIN32_WINNT)
#if _WIN32_WINNT < NAZARA_WINNT
#undef _WIN32_WINNT
@@ -110,6 +111,16 @@
#include <cstdint>
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
typedef int8_t nzInt8;
typedef uint8_t nzUInt8;

View File

@@ -0,0 +1,40 @@
// This file was automatically generated by Nazara
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/ContextParameters.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/OcclusionQuery.hpp>
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/RenderTargetParameters.hpp>
#include <Nazara/Renderer/RenderWindow.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/Texture.hpp>

View File

@@ -32,9 +32,6 @@
// Active une fenêtre de rendu (NzRenderWindow) lors de sa création
#define NAZARA_RENDERER_ACTIVATE_RENDERWINDOW_ON_CREATION 1
// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire)
#define NAZARA_RENDERER_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_RENDERER_MEMORYLEAKTRACKER 0

View File

@@ -35,6 +35,15 @@ enum nzFaceFilling
nzFaceFilling_Fill
};
enum nzMatrixType
{
nzMatrixType_Projection,
nzMatrixType_View,
nzMatrixType_World,
nzMatrixType_Max = nzMatrixType_World
};
enum nzPixelBufferType
{
nzPixelBufferType_Pack,

View File

@@ -3,7 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#ifdef NAZARA_RENDERER_COMMON
#error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it
#error This file is not part of the common renderer interface, you must undefine NAZARA_RENDERER_COMMON to use it
#endif
#pragma once
@@ -12,18 +12,16 @@
#define NAZARA_OPENGL_HPP
// gl3.h définit WIN32_LEAN_AND_MEAN qui entre en conflit avec la définition de Nazara et doit donc être inclut en premier
#include <GL3/gl3.h>
#include <GL3/glcorearb.h>
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
// Il semblerait qu'il ne soit pas conseillé d'inclure gl3.h t glext.h en même temps, mais je ne vois pas oomment gérer les extensions autrement...
// Inclusion des extensions
#include <GL3/glext.h>
#if defined(NAZARA_PLATFORM_WINDOWS)
#include <GL3/wglext.h>
#elif defined(NAZARA_PLATFORM_LINUX)
#include <GL3/glxext.h>
#else
#error OS not handled
#endif
typedef void (*NzOpenGLFunc)();
@@ -40,11 +38,12 @@ class NAZARA_API NzOpenGL
PixelBufferObject,
SeparateShaderObjects,
Texture3D,
TextureArray,
TextureCompression_s3tc,
TextureStorage,
VertexArrayObject,
Count
Max = VertexArrayObject
};
static NzOpenGLFunc GetEntry(const NzString& entryPoint);

View File

@@ -10,6 +10,7 @@
#define NAZARA_RENDERWINDOW_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/ContextParameters.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
@@ -23,7 +24,7 @@ struct NzContextParameters;
class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
{
public:
NzRenderWindow();
NzRenderWindow() = default;
NzRenderWindow(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default, const NzContextParameters& parameters = NzContextParameters());
NzRenderWindow(NzWindowHandle handle, const NzContextParameters& parameters = NzContextParameters());
virtual ~NzRenderWindow();
@@ -52,15 +53,19 @@ class NAZARA_API NzRenderWindow : public NzRenderTarget, public NzWindow
bool IsValid() const;
void SetFramerateLimit(unsigned int limit);
protected:
bool Activate();
virtual bool Activate() override;
private:
void OnClose();
bool OnCreate();
virtual void OnWindowDestroying() override;
virtual bool OnWindowCreated() override;
NzContext* m_context;
NzClock m_clock;
NzContextParameters m_parameters;
NzContext* m_context = nullptr;
unsigned int m_framerateLimit = 0;
};
#endif // NAZARA_RENDERWINDOW_HPP

View File

@@ -8,99 +8,76 @@
#define NAZARA_RENDERER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <map>
#include <tuple>
#define NazaraRenderer NzRenderer::Instance()
class NzColor;
class NzContext;
class NzIndexBuffer;
class NzRenderTarget;
class NzShader;
class NzUtility;
class NzVertexBuffer;
class NzVertexDeclaration;
class NAZARA_API NzRenderer
{
public:
NzRenderer();
~NzRenderer();
NzRenderer() = delete;
~NzRenderer() = delete;
void Clear(unsigned long flags = nzRendererClear_Color | nzRendererClear_Depth);
static void Clear(unsigned long flags = nzRendererClear_Color | nzRendererClear_Depth);
void DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount);
void DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount);
static void DrawIndexedPrimitives(nzPrimitiveType primitive, unsigned int firstIndex, unsigned int indexCount);
static void DrawPrimitives(nzPrimitiveType primitive, unsigned int firstVertex, unsigned int vertexCount);
void Enable(nzRendererParameter parameter, bool enable);
static void Enable(nzRendererParameter parameter, bool enable);
unsigned int GetMaxAnisotropyLevel() const;
unsigned int GetMaxRenderTargets() const;
unsigned int GetMaxTextureUnits() const;
NzShader* GetShader() const;
NzRenderTarget* GetTarget() const;
NzRectui GetViewport() const;
//static NzMatrix4f GetMatrix(nzMatrixCombination combination);
static NzMatrix4f GetMatrix(nzMatrixType type);
static unsigned int GetMaxAnisotropyLevel();
static unsigned int GetMaxRenderTargets();
static unsigned int GetMaxTextureUnits();
static NzShader* GetShader();
static NzRenderTarget* GetTarget();
static NzRectui GetViewport();
bool HasCapability(nzRendererCap capability) const;
bool Initialize();
static bool HasCapability(nzRendererCap capability);
void SetBlendFunc(nzBlendFunc src, nzBlendFunc dest);
void SetClearColor(const NzColor& color);
void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255);
void SetClearDepth(double depth);
void SetClearStencil(unsigned int value);
void SetFaceCulling(nzFaceCulling cullingMode);
void SetFaceFilling(nzFaceFilling fillingMode);
bool SetIndexBuffer(const NzIndexBuffer* indexBuffer);
bool SetShader(NzShader* shader);
void SetStencilCompareFunction(nzRendererComparison compareFunc);
void SetStencilFailOperation(nzStencilOperation failOperation);
void SetStencilMask(nzUInt32 mask);
void SetStencilPassOperation(nzStencilOperation passOperation);
void SetStencilReferenceValue(unsigned int refValue);
void SetStencilZFailOperation(nzStencilOperation zfailOperation);
bool SetTarget(NzRenderTarget* target);
bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer);
bool SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration);
void SetViewport(const NzRectui& viewport);
static bool Initialize();
void Uninitialize();
static NzRenderer* Instance();
static bool IsInitialized();
static void SetBlendFunc(nzBlendFunc src, nzBlendFunc dest);
static void SetClearColor(const NzColor& color);
static void SetClearColor(nzUInt8 r, nzUInt8 g, nzUInt8 b, nzUInt8 a = 255);
static void SetClearDepth(double depth);
static void SetClearStencil(unsigned int value);
static void SetFaceCulling(nzFaceCulling cullingMode);
static void SetFaceFilling(nzFaceFilling fillingMode);
static bool SetIndexBuffer(const NzIndexBuffer* indexBuffer);
static void SetMatrix(nzMatrixType type, const NzMatrix4f& matrix);
static bool SetShader(NzShader* shader);
static void SetStencilCompareFunction(nzRendererComparison compareFunc);
static void SetStencilFailOperation(nzStencilOperation failOperation);
static void SetStencilMask(nzUInt32 mask);
static void SetStencilPassOperation(nzStencilOperation passOperation);
static void SetStencilReferenceValue(unsigned int refValue);
static void SetStencilZFailOperation(nzStencilOperation zfailOperation);
static bool SetTarget(NzRenderTarget* target);
static bool SetVertexBuffer(const NzVertexBuffer* vertexBuffer);
static bool SetVertexDeclaration(const NzVertexDeclaration* vertexDeclaration);
static void SetViewport(const NzRectui& viewport);
static void Uninitialize();
private:
bool EnsureStateUpdate();
static bool EnsureStateUpdate();
typedef std::tuple<const NzContext*, const NzIndexBuffer*, const NzVertexBuffer*, const NzVertexDeclaration*> VAO_Key;
std::map<VAO_Key, unsigned int> m_vaos;
nzRendererComparison m_stencilCompare;
nzStencilOperation m_stencilFail;
nzStencilOperation m_stencilPass;
nzStencilOperation m_stencilZFail;
nzUInt32 m_stencilMask;
const NzIndexBuffer* m_indexBuffer;
NzRenderTarget* m_target;
NzShader* m_shader;
NzUtility* m_utilityModule;
const NzVertexBuffer* m_vertexBuffer;
const NzVertexDeclaration* m_vertexDeclaration;
bool m_vaoUpdated;
bool m_capabilities[nzRendererCap_Max+1];
bool m_stencilFuncUpdated;
bool m_stencilOpUpdated;
unsigned int m_maxAnisotropyLevel;
unsigned int m_maxRenderTarget;
unsigned int m_maxTextureUnit;
unsigned int m_stencilReference;
static NzRenderer* s_instance;
static bool s_initialized;
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_RENDERER_HPP

View File

@@ -9,13 +9,13 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
class NzRenderer;
class NzShaderImpl;
@@ -38,6 +38,9 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
NzString GetLog() const;
nzShaderLanguage GetLanguage() const;
NzString GetSourceCode(nzShaderType type) const;
int GetUniformLocation(const NzString& name) const;
bool HasUniform(const NzString& name) const;
bool IsCompiled() const;
bool IsLoaded(nzShaderType type) const;
@@ -47,19 +50,19 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable
bool Lock();
bool SendBoolean(const NzString& name, bool value);
bool SendDouble(const NzString& name, double value);
bool SendFloat(const NzString& name, float value);
bool SendInteger(const NzString& name, int value);
bool SendMatrix(const NzString& name, const NzMatrix4d& matrix);
bool SendMatrix(const NzString& name, const NzMatrix4f& matrix);
bool SendVector(const NzString& name, const NzVector2d& vector);
bool SendVector(const NzString& name, const NzVector2f& vector);
bool SendVector(const NzString& name, const NzVector3d& vector);
bool SendVector(const NzString& name, const NzVector3f& vector);
bool SendVector(const NzString& name, const NzVector4d& vector);
bool SendVector(const NzString& name, const NzVector4f& vector);
bool SendTexture(const NzString& name, NzTexture* texture);
bool SendBoolean(int location, bool value);
bool SendDouble(int location, double value);
bool SendFloat(int location, float value);
bool SendInteger(int location, int value);
bool SendMatrix(int location, const NzMatrix4d& matrix);
bool SendMatrix(int location, const NzMatrix4f& matrix);
bool SendTexture(int location, const NzTexture* texture);
bool SendVector(int location, const NzVector2d& vector);
bool SendVector(int location, const NzVector2f& vector);
bool SendVector(int location, const NzVector3d& vector);
bool SendVector(int location, const NzVector3f& vector);
bool SendVector(int location, const NzVector4d& vector);
bool SendVector(int location, const NzVector4f& vector);
void Unlock();

View File

@@ -0,0 +1,53 @@
// This file was automatically generated by Nazara
/*
Nazara Engine
Copyright (C) 2012 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/BufferImpl.hpp>
#include <Nazara/Utility/Config.hpp>
#include <Nazara/Utility/Cursor.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Event.hpp>
#include <Nazara/Utility/Icon.hpp>
#include <Nazara/Utility/Image.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Keyboard.hpp>
#include <Nazara/Utility/KeyframeMesh.hpp>
#include <Nazara/Utility/Mesh.hpp>
#include <Nazara/Utility/Mouse.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/StaticMesh.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
#include <Nazara/Utility/VideoMode.hpp>
#include <Nazara/Utility/Window.hpp>
#include <Nazara/Utility/WindowHandle.hpp>

View File

@@ -8,9 +8,9 @@
#define NAZARA_ANIMATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <list>
#include <map>

View File

@@ -0,0 +1,50 @@
// Copyright (C) 2011 Jérôme Leclercq
// This file is part of the "Ungine".
// For conditions of distribution and use, see copyright notice in Core.h
#ifndef NAZARA_AXISALIGNEDBOX_HPP
#define NAZARA_AXISALIGNEDBOX_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Enums.hpp>
class NAZARA_API NzAxisAlignedBox
{
public:
NzAxisAlignedBox();
NzAxisAlignedBox(const NzVector3f& vec1, const NzVector3f& vec2);
NzAxisAlignedBox(nzExtend extend);
bool Contains(const NzAxisAlignedBox& box);
void ExtendTo(const NzAxisAlignedBox& box);
void ExtendTo(const NzVector3f& vector);
nzExtend GetExtend() const;
NzVector3f GetMaximum() const;
NzVector3f GetMinimum() const;
bool IsFinite() const;
bool IsInfinite() const;
bool IsNull() const;
void SetInfinite();
void SetExtends(const NzVector3f& vec1, const NzVector3f& vec2);
void SetNull();
NzString ToString() const;
static const NzAxisAlignedBox Infinite;
static const NzAxisAlignedBox Null;
private:
nzExtend m_extend;
NzCubef m_cube;
};
NAZARA_API std::ostream& operator<<(std::ostream& out, const NzAxisAlignedBox& aabb);
#endif // NAZARA_AXISALIGNEDBOX_HPP

View File

@@ -9,8 +9,8 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
class NzBufferImpl;
class NzRenderer;

View File

@@ -29,6 +29,9 @@
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Force les buffers à posséder un stride multiple de 32 bytes (Gain de performances sur certaines cartes/plus de consommation mémoire)
#define NAZARA_UTILITY_FORCE_DECLARATION_STRIDE_MULTIPLE_OF_32 0
// Utilise un tracker pour repérer les éventuels leaks (Ralentit l'exécution)
#define NAZARA_UTILITY_MEMORYLEAKTRACKER 0
@@ -38,12 +41,11 @@
// Fait tourner chaque fenêtre dans un thread séparé si le système le supporte
#define NAZARA_UTILITY_THREADED_WINDOW 0 ///FIXME: Buggé depuis GCC 4.7
// Protège le module des accès concurrentiels
// Protège les classes des accès concurrentiels
#define NAZARA_UTILITY_THREADSAFE 1
#if NAZARA_UTILITY_THREADSAFE
#define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW)
#define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW)
#endif
// Les classes à protéger des accès concurrentiels
#define NAZARA_THREADSAFETY_IMAGE 1 // NzImage (COW)
#define NAZARA_THREADSAFETY_VERTEXDECLARATION 1 // NzVertexDeclaration (COW)
#endif // NAZARA_CONFIG_UTILITY_HPP

View File

@@ -24,6 +24,7 @@ enum nzBufferAccess
enum nzBufferStorage
{
//nzBufferStorage_Both,
nzBufferStorage_Hardware,
nzBufferStorage_Software,
@@ -44,8 +45,8 @@ enum nzBufferUsage
enum nzCubemapFace
{
// L'ordre est X, -X, Y, -Y, Z, -Z
// Cette énumération est prévue pour remplacer l'argument "z" des méthodes de NzImage contenant un cubemap
// L'ordre est X, -X, Y, -Y, Z, -Z
nzCubemapFace_PositiveX = 0,
nzCubemapFace_PositiveY = 2,
nzCubemapFace_PositiveZ = 4,
@@ -86,10 +87,38 @@ enum nzElementUsage
nzElementUsage_Max = nzElementUsage_TexCoord
};
enum nzEventType
{
nzEventType_GainedFocus,
nzEventType_LostFocus,
nzEventType_KeyPressed,
nzEventType_KeyReleased,
nzEventType_MouseButtonDoubleClicked,
nzEventType_MouseButtonPressed,
nzEventType_MouseButtonReleased,
nzEventType_MouseEntered,
nzEventType_MouseLeft,
nzEventType_MouseMoved,
nzEventType_MouseWheelMoved,
nzEventType_Moved,
nzEventType_Quit,
nzEventType_Resized,
nzEventType_TextEntered
};
enum nzExtend
{
nzExtend_Finite,
nzExtend_Infinite,
nzExtend_Null
};
enum nzImageType
{
nzImageType_1D,
nzImageType_1D_Array,
nzImageType_2D,
nzImageType_2D_Array,
nzImageType_3D,
nzImageType_Cubemap,

View File

@@ -14,15 +14,22 @@
struct NzEvent
{
// Utilisé par:
// -nzEventType_KeyPressed
// -nzEventType_KeyReleased
struct KeyEvent
{
NzKeyboard::Key code;
bool alt;
bool control;
bool repeated;
bool shift;
bool system;
};
// Utilisé par:
// -nzEventType_MouseButtonDoubleClicked
// -nzEventType_MouseButtonPressed
struct MouseButtonEvent
{
NzMouse::Button button;
@@ -30,63 +37,79 @@ struct NzEvent
unsigned int y;
};
// Utilisé par:
// -nzEventType_MouseMoved
struct MouseMoveEvent
{
int x;
int y;
int deltaX;
int deltaY;
unsigned int x;
unsigned int y;
};
// Utilisé par:
// -nzEventType_MouseWheelMoved
struct MouseWheelEvent
{
float delta;
};
// Utilisé par:
// -nzEventType_Moved
struct PositionEvent
{
int x;
int y;
};
// Utilisé par:
// -nzEventType_Resized
struct SizeEvent
{
unsigned int height;
unsigned int width;
};
// Utilisé par:
// -nzEventType_TextEntered
struct TextEvent
{
bool repeated;
char32_t character;
};
enum Type
{
GainedFocus,
LostFocus,
KeyPressed,
KeyReleased,
MouseButtonDoubleClicked,
MouseButtonPressed,
MouseButtonReleased,
MouseEntered,
MouseLeft,
MouseMoved,
MouseWheelMoved,
Moved,
Quit,
Resized,
TextEntered
};
Type type;
nzEventType type;
union
{
// Utilisé par:
// -nzEventType_KeyPressed
// -nzEventType_KeyReleased
KeyEvent key;
// Utilisé par:
// -nzEventType_MouseButtonDoubleClicked
// -nzEventType_MouseButtonPressed
MouseButtonEvent mouseButton;
// Utilisé par:
// -nzEventType_MouseMoved
MouseMoveEvent mouseMove;
// Utilisé par:
// -nzEventType_MouseWheelMoved
MouseWheelEvent mouseWheel;
// Utilisé par:
// -nzEventType_Moved
PositionEvent position;
// Utilisé par:
// -nzEventType_Resized
SizeEvent size;
// Utilisé par:
// -nzEventType_TextEntered
TextEvent text;
};
};

View File

@@ -10,17 +10,17 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Math/Cube.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/PixelFormat.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <list>
#include <map>
#if NAZARA_THREADSAFETY_IMAGE
#if NAZARA_UTILITY_THREADSAFE && NAZARA_THREADSAFETY_IMAGE
#include <Nazara/Core/ThreadSafety.hpp>
#else
#include <Nazara/Core/ThreadSafetyOff.hpp>
@@ -49,7 +49,7 @@ class NAZARA_API NzImage : public NzResource
NzImage();
NzImage(const NzImage& image);
NzImage(NzImage&& image);
NzImage(NzImage&& image) noexcept;
NzImage(SharedImage* sharedImage);
~NzImage();
@@ -68,14 +68,14 @@ class NAZARA_API NzImage : public NzResource
bool FlipVertically();
nzUInt8 GetBPP() const;
const nzUInt8* GetConstPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 0) const;
const nzUInt8* GetConstPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0) const;
unsigned int GetDepth(nzUInt8 level = 0) const;
nzPixelFormat GetFormat() const;
unsigned int GetHeight(nzUInt8 level = 0) const;
nzUInt8 GetLevelCount() const;
nzUInt8 GetMaxLevel() const;
NzColor GetPixelColor(unsigned int x, unsigned int y = 0, unsigned int z = 0) const;
nzUInt8* GetPixels(nzUInt8 level = 0, unsigned int x = 0, unsigned int y = 0, unsigned int z = 0);
nzUInt8* GetPixels(unsigned int x = 0, unsigned int y = 0, unsigned int z = 0, nzUInt8 level = 0);
unsigned int GetSize() const;
unsigned int GetSize(nzUInt8 level) const;
nzImageType GetType() const;
@@ -97,7 +97,7 @@ class NAZARA_API NzImage : public NzResource
bool Update(const nzUInt8* pixels, const NzCubeui& cube, nzUInt8 level = 0);
NzImage& operator=(const NzImage& image);
NzImage& operator=(NzImage&& image);
NzImage& operator=(NzImage&& image) noexcept;
static nzUInt8 GetMaxLevel(unsigned int width, unsigned int height, unsigned int depth = 1);

View File

@@ -8,8 +8,8 @@
#define NAZARA_INDEXBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzIndexBuffer : public NzResource
{

View File

@@ -9,21 +9,22 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/InputStream.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Utility/Animation.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/ResourceLoader.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/SubMesh.hpp>
#include <list>
#include <map>
class NzSubMesh;
class NzVertexDeclaration;
struct NzMeshParams
{
NzAnimationParams animation;
//const NzVertexDeclaration* declaration = nullptr;
bool forceSoftware = false;
nzBufferStorage storage = nzBufferStorage_Hardware;
bool loadAnimations = true;
bool IsValid() const;
@@ -52,6 +53,7 @@ class NAZARA_API NzMesh : public NzResource
bool Create(nzAnimationType type);
void Destroy();
const NzAxisAlignedBox& GetAABB() const;
const NzAnimation* GetAnimation() const;
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
@@ -69,6 +71,8 @@ class NAZARA_API NzMesh : public NzResource
bool HasSubMesh(const NzString& identifier) const;
bool HasSubMesh(nzUInt8 index = 0) const;
void InvalidateAABB() const;
bool IsAnimable() const;
bool IsValid() const;

View File

@@ -25,7 +25,7 @@ class NAZARA_API NzMouse
XButton1,
XButton2,
Count
Max = XButton2
};
static NzVector2i GetPosition();

View File

@@ -361,7 +361,7 @@ inline NzString NzPixelFormat::ToString(nzPixelFormat format)
return "RGBA8";
case nzPixelFormat_Undefined:
break;
return "Undefined";
}
NazaraError("Invalid pixel format");

View File

@@ -14,12 +14,15 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh
{
public:
NzStaticMesh(const NzMesh* parent);
NzStaticMesh(const NzMesh* parent, const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr);
NzStaticMesh(const NzMesh* parent, const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr);
virtual ~NzStaticMesh();
bool Create(const NzVertexBuffer* vertexBuffer, const NzVertexDeclaration* vertexDeclaration, const NzIndexBuffer* indexBuffer = nullptr);
bool Create(const NzVertexDeclaration* vertexDeclaration, NzVertexBuffer* vertexBuffer, NzIndexBuffer* indexBuffer = nullptr);
void Destroy();
bool GenerateAABB();
const NzAxisAlignedBox& GetAABB() const;
nzAnimationType GetAnimationType() const;
unsigned int GetFrameCount() const;
const NzIndexBuffer* GetIndexBuffer() const;
@@ -30,14 +33,16 @@ class NAZARA_API NzStaticMesh final : public NzSubMesh
bool IsAnimated() const;
bool IsValid() const;
void SetAABB(const NzAxisAlignedBox& aabb);
void SetPrimitiveType(nzPrimitiveType primitiveType);
private:
void AnimateImpl(unsigned int frameA, unsigned int frameB, float interpolation);
nzPrimitiveType m_primitiveType = nzPrimitiveType_TriangleList;
const NzIndexBuffer* m_indexBuffer = nullptr;
const NzVertexBuffer* m_vertexBuffer = nullptr;
NzAxisAlignedBox m_aabb;
NzIndexBuffer* m_indexBuffer = nullptr;
NzVertexBuffer* m_vertexBuffer = nullptr;
const NzVertexDeclaration* m_vertexDeclaration = nullptr;
};

View File

@@ -8,9 +8,10 @@
#define NAZARA_SUBMESH_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/Resource.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
@@ -26,6 +27,7 @@ class NAZARA_API NzSubMesh : public NzResource
void Animate(unsigned int frameA, unsigned int frameB, float interpolation);
virtual const NzAxisAlignedBox& GetAABB() const = 0;
virtual const NzIndexBuffer* GetIndexBuffer() const = 0;
const NzMesh* GetParent() const;
virtual nzPrimitiveType GetPrimitiveType() const = 0;

View File

@@ -8,20 +8,22 @@
#define NAZARA_UTILITY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
class NAZARA_API NzUtility
{
public:
NzUtility();
~NzUtility();
NzUtility() = delete;
~NzUtility() = delete;
bool Initialize();
void Uninitialize();
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static bool s_initialized;
static unsigned int s_moduleReferenceCouter;
};
#endif // NAZARA_UTILITY_HPP

View File

@@ -8,8 +8,8 @@
#define NAZARA_VERTEXBUFFER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Buffer.hpp>
#include <Nazara/Utility/Resource.hpp>
class NAZARA_API NzVertexBuffer : public NzResource
{

View File

@@ -6,8 +6,8 @@
#define NAZARA_VERTEXDECLARATION_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Utility/Enums.hpp>
#include <Nazara/Utility/Resource.hpp>
struct NzVertexElement
{
@@ -26,7 +26,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource
NzVertexDeclaration() = default;
NzVertexDeclaration(const NzVertexElement* elements, unsigned int elementCount);
NzVertexDeclaration(const NzVertexDeclaration& declaration);
NzVertexDeclaration(NzVertexDeclaration&& declaration);
NzVertexDeclaration(NzVertexDeclaration&& declaration) noexcept;
~NzVertexDeclaration();
bool Create(const NzVertexElement* elements, unsigned int elementCount);
@@ -44,7 +44,7 @@ class NAZARA_API NzVertexDeclaration : public NzResource
bool IsValid() const;
NzVertexDeclaration& operator=(const NzVertexDeclaration& declaration);
NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration);
NzVertexDeclaration& operator=(NzVertexDeclaration&& declaration) noexcept;
private:
NzVertexDeclarationImpl* m_sharedImpl = nullptr;

View File

@@ -28,11 +28,13 @@
class NzCursor;
class NzImage;
class NzIcon;
class NzMouse;
class NzUtility;
class NzWindowImpl;
class NAZARA_API NzWindow : NzNonCopyable
{
friend class NzMouse;
friend class NzUtility;
friend class NzWindowImpl;
@@ -42,11 +44,11 @@ class NAZARA_API NzWindow : NzNonCopyable
NzWindow(NzWindowHandle handle);
virtual ~NzWindow();
void Close();
bool Create(NzVideoMode mode, const NzString& title, nzUInt32 style = nzWindowStyle_Default);
bool Create(NzWindowHandle handle);
void Destroy();
void EnableKeyRepeat(bool enable);
void EnableSmoothScrolling(bool enable);
@@ -78,20 +80,20 @@ class NAZARA_API NzWindow : NzNonCopyable
void SetPosition(int x, int y);
void SetSize(const NzVector2i& size);
void SetSize(unsigned int width, unsigned int height);
void SetStayOnTop(bool stayOnTop);
void SetTitle(const NzString& title);
void SetVisible(bool visible);
void StayOnTop(bool stayOnTop);
bool WaitEvent(NzEvent* event);
protected:
virtual void OnClose();
virtual bool OnCreate();
virtual void OnWindowDestroying();
virtual bool OnWindowCreated();
NzWindowImpl* m_impl;
private:
void IgnoreNextMouseEvent(int mouseX, int mouseY) const;
void PushEvent(const NzEvent& event);
static bool Initialize();
@@ -99,9 +101,9 @@ class NAZARA_API NzWindow : NzNonCopyable
std::queue<NzEvent> m_events;
#if NAZARA_UTILITY_THREADED_WINDOW
NzConditionVariable m_eventCondition;
NzMutex m_eventMutex;
NzMutex m_eventConditionMutex;
NzThreadCondition m_eventCondition;
bool m_eventListener;
bool m_waitForEvent;
#endif