Merge branch 'master' into vulkan
This commit is contained in:
@@ -31,7 +31,7 @@ namespace Nz
|
||||
namespace
|
||||
{
|
||||
//FIXME: MinGW seems to dislike thread_local shared_ptr.. (using a std::string is a working hackfix)
|
||||
thread_local std::string currentPath(DirectoryImpl::GetCurrent());
|
||||
thread_local std::string currentPath(DirectoryImpl::GetCurrent().ToStdString());
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -395,7 +395,7 @@ namespace Nz
|
||||
return false;
|
||||
|
||||
#ifdef NAZARA_PLATFORM_WINDOWS
|
||||
// Unlike to disk (Ex: "C:"), the netwrok path is not considered as a directory (Ex: "\\Laptop")
|
||||
// Unlike to disk (Ex: "C:"), the network path is not considered as a directory (Ex: "\\Laptop")
|
||||
if (path.Match("\\\\*"))
|
||||
{
|
||||
foundPos = path.Find('\\', 2);
|
||||
@@ -414,11 +414,14 @@ namespace Nz
|
||||
if (p.EndsWith(NAZARA_DIRECTORY_SEPARATOR))
|
||||
p = p.SubString(0, -2);
|
||||
|
||||
if (!DirectoryImpl::Exists(p) && !DirectoryImpl::Create(p))
|
||||
return false;
|
||||
if (!p.IsEmpty())
|
||||
{
|
||||
if (!DirectoryImpl::Exists(p) && !DirectoryImpl::Create(p))
|
||||
return false;
|
||||
|
||||
if (foundPos == String::npos)
|
||||
break;
|
||||
if (foundPos == String::npos)
|
||||
break;
|
||||
}
|
||||
|
||||
foundPos = path.Find(NAZARA_DIRECTORY_SEPARATOR, foundPos + 1);
|
||||
}
|
||||
@@ -523,7 +526,7 @@ namespace Nz
|
||||
String path = File::AbsolutePath(dirPath);
|
||||
if (DirectoryImpl::Exists(path))
|
||||
{
|
||||
currentPath = path;
|
||||
currentPath = path.ToStdString();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace Nz
|
||||
|
||||
if (type == ErrorType_AssertFailed || (type != ErrorType_Warning &&
|
||||
(s_flags & ErrorFlag_ThrowException) != 0 && (s_flags & ErrorFlag_ThrowExceptionDisabled) == 0))
|
||||
throw std::runtime_error(error);
|
||||
throw std::runtime_error(error.ToStdString());
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -183,7 +183,7 @@ namespace Nz
|
||||
|
||||
if (type == ErrorType_AssertFailed || (type != ErrorType_Warning &&
|
||||
(s_flags & ErrorFlag_ThrowException) != 0 && (s_flags & ErrorFlag_ThrowExceptionDisabled) == 0))
|
||||
throw std::runtime_error(error);
|
||||
throw std::runtime_error(error.ToStdString());
|
||||
}
|
||||
|
||||
UInt32 Error::s_flags = ErrorFlag_None;
|
||||
|
||||
@@ -130,15 +130,19 @@ namespace Nz
|
||||
|
||||
std::size_t MemoryStream::WriteBlock(const void* buffer, std::size_t size)
|
||||
{
|
||||
std::size_t endPos = static_cast<std::size_t>(m_pos + size);
|
||||
if (endPos > m_buffer->GetSize())
|
||||
m_buffer->Resize(endPos);
|
||||
if (size > 0)
|
||||
{
|
||||
std::size_t endPos = static_cast<std::size_t>(m_pos + size);
|
||||
if (endPos > m_buffer->GetSize())
|
||||
m_buffer->Resize(endPos);
|
||||
|
||||
NazaraAssert(buffer, "Invalid buffer");
|
||||
NazaraAssert(buffer, "Invalid buffer");
|
||||
|
||||
std::memcpy(m_buffer->GetBuffer() + m_pos, buffer, size);
|
||||
std::memcpy(m_buffer->GetBuffer() + m_pos, buffer, size);
|
||||
|
||||
m_pos = endPos;
|
||||
}
|
||||
|
||||
m_pos = endPos;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Nz
|
||||
|
||||
bool DirectoryImpl::Create(const String& dirPath)
|
||||
{
|
||||
mode_t permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; // TODO: check permissions, no right to execute but read and write for every others.
|
||||
mode_t permissions = S_IRWXU | S_IRWXG | S_IRWXO; // 777
|
||||
return mkdir(dirPath.GetConstBuffer(), permissions) != -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,11 @@ namespace Nz
|
||||
flags |= O_TRUNC;
|
||||
|
||||
m_fileDescriptor = open64(filePath.GetConstBuffer(), flags, permissions);
|
||||
if (m_fileDescriptor == -1)
|
||||
{
|
||||
NazaraError("Failed to open \"" + filePath + "\" : " + Error::GetLastSystemError());
|
||||
return false;
|
||||
}
|
||||
|
||||
static struct flock lock;
|
||||
|
||||
@@ -116,7 +121,7 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
return m_fileDescriptor != -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::size_t FileImpl::Read(void* buffer, std::size_t size)
|
||||
|
||||
@@ -4197,13 +4197,21 @@ namespace Nz
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the string to std::string
|
||||
* \return std::string representation
|
||||
*/
|
||||
std::string String::ToStdString() const
|
||||
{
|
||||
return std::string(m_sharedString->string.get(), m_sharedString->size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Converts the string to upper
|
||||
* \return Upper string
|
||||
*
|
||||
* \param flags Flag for the look up
|
||||
*/
|
||||
|
||||
String String::ToUpper(UInt32 flags) const
|
||||
{
|
||||
if (m_sharedString->size == 0)
|
||||
@@ -4481,16 +4489,6 @@ namespace Nz
|
||||
}
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Converts the string to std::string
|
||||
* \return std::string representation
|
||||
*/
|
||||
|
||||
String::operator std::string() const
|
||||
{
|
||||
return std::string(m_sharedString->string.get(), m_sharedString->size);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Gets the ith character in the string
|
||||
* \return A reference to the character
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/HardwareInfo.hpp>
|
||||
#include <Nazara/Core/MovablePtr.hpp>
|
||||
#include <ostream>
|
||||
|
||||
#if defined(NAZARA_PLATFORM_WINDOWS)
|
||||
#include <Nazara/Core/Win32/ThreadImpl.hpp>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <Nazara/Graphics/AbstractViewer.hpp>
|
||||
#include <Nazara/Renderer/Renderer.hpp>
|
||||
#include <Nazara/Renderer/RenderStates.hpp>
|
||||
#include <Nazara/Renderer/RenderTarget.hpp>
|
||||
#include <Nazara/Renderer/Shader.hpp>
|
||||
#include <Nazara/Utility/IndexBuffer.hpp>
|
||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||
@@ -52,6 +53,11 @@ namespace Nz
|
||||
|
||||
void SkyboxBackground::Draw(const AbstractViewer* viewer) const
|
||||
{
|
||||
const Nz::RenderTarget* target = viewer->GetTarget();
|
||||
Nz::Vector2ui targetSize = target->GetSize();
|
||||
|
||||
Matrix4f projectionMatrix = Nz::Matrix4f::Perspective(45.f, float(targetSize.x) / targetSize.y, viewer->GetZNear(), viewer->GetZFar());
|
||||
|
||||
Matrix4f skyboxMatrix(viewer->GetViewMatrix());
|
||||
skyboxMatrix.SetTranslation(Vector3f::Zero());
|
||||
|
||||
@@ -71,6 +77,7 @@ namespace Nz
|
||||
world.SetTranslation(offset);
|
||||
|
||||
Renderer::SetIndexBuffer(s_indexBuffer);
|
||||
Renderer::SetMatrix(MatrixType_Projection, projectionMatrix);
|
||||
Renderer::SetMatrix(MatrixType_View, skyboxMatrix);
|
||||
Renderer::SetMatrix(MatrixType_World, world);
|
||||
Renderer::SetRenderStates(s_renderStates);
|
||||
@@ -81,6 +88,7 @@ namespace Nz
|
||||
|
||||
Renderer::DrawIndexedPrimitives(PrimitiveMode_TriangleList, 0, 36);
|
||||
|
||||
Renderer::SetMatrix(MatrixType_Projection, viewer->GetProjectionMatrix());
|
||||
Renderer::SetMatrix(MatrixType_View, viewer->GetViewMatrix());
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Nz
|
||||
{
|
||||
String lastError(lua_tostring(internalState, -1));
|
||||
|
||||
throw std::runtime_error("Lua panic: " + lastError);
|
||||
throw std::runtime_error("Lua panic: " + lastError.ToStdString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,15 +38,45 @@ namespace Nz
|
||||
luaL_openlibs(m_state);
|
||||
}
|
||||
|
||||
LuaInstance::LuaInstance(LuaInstance&& instance) :
|
||||
LuaState(std::move(instance))
|
||||
{
|
||||
std::swap(m_memoryLimit, instance.m_memoryLimit);
|
||||
std::swap(m_memoryUsage, instance.m_memoryUsage);
|
||||
std::swap(m_timeLimit, instance.m_timeLimit);
|
||||
std::swap(m_clock, instance.m_clock);
|
||||
std::swap(m_level, instance.m_level);
|
||||
|
||||
if (m_state)
|
||||
lua_setallocf(m_state, MemoryAllocator, this);
|
||||
|
||||
if (instance.m_state)
|
||||
lua_setallocf(instance.m_state, MemoryAllocator, &instance);
|
||||
}
|
||||
|
||||
LuaInstance::~LuaInstance()
|
||||
{
|
||||
if (m_state)
|
||||
lua_close(m_state);
|
||||
}
|
||||
|
||||
inline void LuaInstance::SetMemoryUsage(std::size_t memoryUsage)
|
||||
LuaInstance& LuaInstance::operator=(LuaInstance&& instance)
|
||||
{
|
||||
m_memoryUsage = memoryUsage;
|
||||
LuaState::operator=(std::move(instance));
|
||||
|
||||
std::swap(m_memoryLimit, instance.m_memoryLimit);
|
||||
std::swap(m_memoryUsage, instance.m_memoryUsage);
|
||||
std::swap(m_timeLimit, instance.m_timeLimit);
|
||||
std::swap(m_clock, instance.m_clock);
|
||||
std::swap(m_level, instance.m_level);
|
||||
|
||||
if (m_state)
|
||||
lua_setallocf(m_state, MemoryAllocator, this);
|
||||
|
||||
if (instance.m_state)
|
||||
lua_setallocf(instance.m_state, MemoryAllocator, &instance);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void* LuaInstance::MemoryAllocator(void* ud, void* ptr, std::size_t osize, std::size_t nsize)
|
||||
|
||||
@@ -894,6 +894,8 @@ namespace Nz
|
||||
break;
|
||||
}
|
||||
|
||||
++currentCommand;
|
||||
|
||||
if (channel && outgoingCommand->sendAttempts < 1)
|
||||
{
|
||||
channel->usedReliableWindows |= 1 << reliableWindow;
|
||||
@@ -912,8 +914,8 @@ namespace Nz
|
||||
peer->m_nextTimeout = m_serviceTime + outgoingCommand->roundTripTimeout;
|
||||
|
||||
peer->m_sentReliableCommands.emplace_back(std::move(*outgoingCommand));
|
||||
currentCommand = peer->m_outgoingReliableCommands.erase(outgoingCommand);
|
||||
|
||||
peer->m_outgoingReliableCommands.erase(outgoingCommand);
|
||||
outgoingCommand = peer->m_sentReliableCommands.end();
|
||||
--outgoingCommand;
|
||||
|
||||
|
||||
@@ -621,7 +621,7 @@ namespace Nz
|
||||
UInt32 totalLength = NetToHost(command->sendFragment.totalLength);
|
||||
|
||||
if (fragmentCount > ENetConstants::ENetProtocol_MaximumFragmentCount || fragmentNumber >= fragmentCount || totalLength > m_host->m_maximumPacketSize ||
|
||||
fragmentOffset >= totalLength || fragmentLength > totalLength - fragmentOffset)
|
||||
fragmentOffset >= totalLength || fragmentLength > totalLength - fragmentOffset)
|
||||
return false;
|
||||
|
||||
ENetPeer::IncomingCommmand* startCommand = nullptr;
|
||||
@@ -643,7 +643,7 @@ namespace Nz
|
||||
break;
|
||||
|
||||
if ((incomingCommand.command.header.command & ENetProtocolCommand_Mask) != ENetProtocolCommand_SendFragment ||
|
||||
totalLength != incomingCommand.packet->data.GetDataSize() || fragmentCount != incomingCommand.fragments.GetSize())
|
||||
totalLength != incomingCommand.packet->data.GetDataSize() || fragmentCount != incomingCommand.fragments.GetSize())
|
||||
return false;
|
||||
|
||||
startCommand = &incomingCommand;
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace Nz
|
||||
NazaraAssert(!IsRegistered(socket), "Socket is already registered");
|
||||
|
||||
epoll_event entry;
|
||||
entry.events = 0;
|
||||
std::memset(&entry, 0, sizeof(epoll_event));
|
||||
|
||||
entry.data.fd = socket;
|
||||
|
||||
if (eventFlags & SocketPollEvent_Read)
|
||||
|
||||
@@ -25,6 +25,8 @@ namespace Nz
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
socklen_t bufferLength = sizeof(sockaddr_in);
|
||||
|
||||
SocketHandle newClient = accept(handle, reinterpret_cast<sockaddr*>(&nameBuffer), &bufferLength);
|
||||
@@ -150,7 +152,7 @@ namespace Nz
|
||||
tv.tv_sec = static_cast<long>(msTimeout / 1000ULL);
|
||||
tv.tv_usec = static_cast<long>((msTimeout % 1000ULL) * 1000ULL);
|
||||
|
||||
int ret = select(0, nullptr, &localSet, &localSet, (msTimeout > 0) ? &tv : nullptr);
|
||||
int ret = select(handle + 1, nullptr, &localSet, &localSet, (msTimeout > 0) ? &tv : nullptr);
|
||||
if (ret == SOCKET_ERROR)
|
||||
{
|
||||
int code = GetLastErrorCode(handle, error);
|
||||
@@ -376,7 +378,9 @@ namespace Nz
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
socklen_t bufferLength = sizeof(sockaddr_in);
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
socklen_t bufferLength = sizeof(nameBuffer.size());
|
||||
|
||||
if (getpeername(handle, reinterpret_cast<sockaddr*>(nameBuffer.data()), &bufferLength) == SOCKET_ERROR)
|
||||
{
|
||||
@@ -416,6 +420,8 @@ namespace Nz
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
socklen_t bufferLength = sizeof(sockaddr_in);
|
||||
|
||||
if (getsockname(handle, reinterpret_cast<sockaddr*>(nameBuffer.data()), &bufferLength) == SOCKET_ERROR)
|
||||
@@ -509,6 +515,8 @@ namespace Nz
|
||||
NazaraAssert(buffer && length > 0, "Invalid buffer");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
socklen_t bufferLength = static_cast<socklen_t>(nameBuffer.size());
|
||||
|
||||
IpAddress senderIp;
|
||||
@@ -580,6 +588,8 @@ namespace Nz
|
||||
msgHdr.msg_iovlen = static_cast<int>(bufferCount);
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
if (from)
|
||||
{
|
||||
msgHdr.msg_name = nameBuffer.data();
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace Nz
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
int bufferLength = static_cast<int>(nameBuffer.size());
|
||||
|
||||
SocketHandle newClient = accept(handle, reinterpret_cast<sockaddr*>(&nameBuffer), &bufferLength);
|
||||
@@ -392,6 +394,8 @@ namespace Nz
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
int bufferLength = static_cast<int>(nameBuffer.size());
|
||||
|
||||
if (getpeername(handle, reinterpret_cast<sockaddr*>(nameBuffer.data()), &bufferLength) == SOCKET_ERROR)
|
||||
@@ -413,6 +417,8 @@ namespace Nz
|
||||
NazaraAssert(handle != InvalidHandle, "Invalid handle");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
int bufferLength = static_cast<int>(nameBuffer.size());
|
||||
|
||||
if (getsockname(handle, reinterpret_cast<sockaddr*>(nameBuffer.data()), &bufferLength) == SOCKET_ERROR)
|
||||
@@ -537,6 +543,8 @@ namespace Nz
|
||||
NazaraAssert(buffer && length > 0, "Invalid buffer");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
int bufferLength = static_cast<int>(nameBuffer.size());
|
||||
|
||||
IpAddress senderIp;
|
||||
@@ -592,6 +600,8 @@ namespace Nz
|
||||
NazaraAssert(buffers && bufferCount > 0, "Invalid buffers");
|
||||
|
||||
IpAddressImpl::SockAddrBuffer nameBuffer;
|
||||
std::fill(nameBuffer.begin(), nameBuffer.end(), 0);
|
||||
|
||||
int bufferLength = static_cast<int>(nameBuffer.size());
|
||||
|
||||
IpAddress senderIp;
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
Constraint2D::Constraint2D(PhysWorld2D& world, cpConstraint* constraint) :
|
||||
Constraint2D::Constraint2D(Nz::PhysWorld2D* world, cpConstraint* constraint) :
|
||||
m_constraint(constraint)
|
||||
{
|
||||
cpConstraintSetUserData(m_constraint, this);
|
||||
cpSpaceAddConstraint(world.GetHandle(), m_constraint);
|
||||
cpSpaceAddConstraint(world->GetHandle(), m_constraint);
|
||||
}
|
||||
|
||||
Constraint2D::Constraint2D(Constraint2D&& rhs) :
|
||||
@@ -105,320 +105,319 @@ namespace Nz
|
||||
}
|
||||
|
||||
|
||||
DampedSpring2D::DampedSpring2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) :
|
||||
Constraint2D(world, cpDampedSpringNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), restLength, stiffness, damping))
|
||||
DampedSpringConstraint2D::DampedSpringConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float restLength, float stiffness, float damping) :
|
||||
Constraint2D(first.GetWorld(), cpDampedSpringNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), restLength, stiffness, damping))
|
||||
{
|
||||
}
|
||||
|
||||
float DampedSpring2D::GetDamping() const
|
||||
float DampedSpringConstraint2D::GetDamping() const
|
||||
{
|
||||
return float(cpDampedSpringGetDamping(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f DampedSpring2D::GetFirstAnchor() const
|
||||
Vector2f DampedSpringConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpDampedSpringGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float DampedSpring2D::GetRestLength() const
|
||||
float DampedSpringConstraint2D::GetRestLength() const
|
||||
{
|
||||
return float(cpDampedSpringGetRestLength(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f DampedSpring2D::GetSecondAnchor() const
|
||||
Vector2f DampedSpringConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpDampedSpringGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float DampedSpring2D::GetStiffness() const
|
||||
float DampedSpringConstraint2D::GetStiffness() const
|
||||
{
|
||||
return float(cpDampedSpringGetStiffness(m_constraint));
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetDamping(float newDamping)
|
||||
void DampedSpringConstraint2D::SetDamping(float newDamping)
|
||||
{
|
||||
cpDampedSpringSetDamping(m_constraint, newDamping);
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
void DampedSpringConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpDampedSpringSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetRestLength(float newLength)
|
||||
void DampedSpringConstraint2D::SetRestLength(float newLength)
|
||||
{
|
||||
cpDampedSpringSetRestLength(m_constraint, newLength);
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
void DampedSpringConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpDampedSpringSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void DampedSpring2D::SetStiffness(float newStiffness)
|
||||
void DampedSpringConstraint2D::SetStiffness(float newStiffness)
|
||||
{
|
||||
cpDampedSpringSetStiffness(m_constraint, newStiffness);
|
||||
}
|
||||
|
||||
|
||||
DampedRotarySpring2D::DampedRotarySpring2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping) :
|
||||
Constraint2D(world, cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle, stiffness, damping))
|
||||
DampedRotarySpringConstraint2D::DampedRotarySpringConstraint2D(RigidBody2D& first, RigidBody2D& second, float restAngle, float stiffness, float damping) :
|
||||
Constraint2D(first.GetWorld(), cpDampedRotarySpringNew(first.GetHandle(), second.GetHandle(), restAngle, stiffness, damping))
|
||||
{
|
||||
}
|
||||
|
||||
float DampedRotarySpring2D::GetDamping() const
|
||||
float DampedRotarySpringConstraint2D::GetDamping() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetDamping(m_constraint));
|
||||
}
|
||||
|
||||
float DampedRotarySpring2D::GetRestAngle() const
|
||||
float DampedRotarySpringConstraint2D::GetRestAngle() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetRestAngle(m_constraint));
|
||||
}
|
||||
|
||||
float DampedRotarySpring2D::GetStiffness() const
|
||||
float DampedRotarySpringConstraint2D::GetStiffness() const
|
||||
{
|
||||
return float(cpDampedRotarySpringGetStiffness(m_constraint));
|
||||
}
|
||||
|
||||
void DampedRotarySpring2D::SetDamping(float newDamping)
|
||||
void DampedRotarySpringConstraint2D::SetDamping(float newDamping)
|
||||
{
|
||||
cpDampedSpringSetDamping(m_constraint, newDamping);
|
||||
}
|
||||
|
||||
void DampedRotarySpring2D::SetRestAngle(float newAngle)
|
||||
void DampedRotarySpringConstraint2D::SetRestAngle(float newAngle)
|
||||
{
|
||||
cpDampedRotarySpringSetRestAngle(m_constraint, newAngle);
|
||||
}
|
||||
|
||||
void DampedRotarySpring2D::SetStiffness(float newStiffness)
|
||||
void DampedRotarySpringConstraint2D::SetStiffness(float newStiffness)
|
||||
{
|
||||
cpDampedRotarySpringSetStiffness(m_constraint, newStiffness);
|
||||
}
|
||||
|
||||
|
||||
GearJoint2D::GearJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratio) :
|
||||
Constraint2D(world, cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio))
|
||||
GearConstraint2D::GearConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratio) :
|
||||
Constraint2D(first.GetWorld(), cpGearJointNew(first.GetHandle(), second.GetHandle(), phase, ratio))
|
||||
{
|
||||
}
|
||||
|
||||
float GearJoint2D::GetPhase() const
|
||||
float GearConstraint2D::GetPhase() const
|
||||
{
|
||||
return float(cpGearJointGetPhase(m_constraint));
|
||||
}
|
||||
|
||||
float GearJoint2D::GetRatio() const
|
||||
float GearConstraint2D::GetRatio() const
|
||||
{
|
||||
return float(cpGearJointGetRatio(m_constraint));
|
||||
}
|
||||
|
||||
void GearJoint2D::SetPhase(float phase)
|
||||
void GearConstraint2D::SetPhase(float phase)
|
||||
{
|
||||
cpGearJointSetPhase(m_constraint, phase);
|
||||
}
|
||||
|
||||
void GearJoint2D::SetRatio(float ratio)
|
||||
void GearConstraint2D::SetRatio(float ratio)
|
||||
{
|
||||
cpGearJointSetRatio(m_constraint, ratio);
|
||||
}
|
||||
|
||||
|
||||
MotorJoint2D::MotorJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float rate) :
|
||||
Constraint2D(world, cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate))
|
||||
MotorConstraint2D::MotorConstraint2D(RigidBody2D& first, RigidBody2D& second, float rate) :
|
||||
Constraint2D(first.GetWorld(), cpSimpleMotorNew(first.GetHandle(), second.GetHandle(), rate))
|
||||
{
|
||||
}
|
||||
|
||||
float MotorJoint2D::GetRate() const
|
||||
float MotorConstraint2D::GetRate() const
|
||||
{
|
||||
return float(cpSimpleMotorGetRate(m_constraint));
|
||||
}
|
||||
|
||||
void MotorJoint2D::SetRate(float rate)
|
||||
void MotorConstraint2D::SetRate(float rate)
|
||||
{
|
||||
cpSimpleMotorSetRate(m_constraint, rate);
|
||||
}
|
||||
|
||||
|
||||
PinJoint2D::PinJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor) :
|
||||
Constraint2D(world, cpPinJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
|
||||
PinConstraint2D::PinConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
|
||||
Constraint2D(first.GetWorld(), cpPinJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
|
||||
{
|
||||
}
|
||||
|
||||
float PinJoint2D::GetDistance() const
|
||||
float PinConstraint2D::GetDistance() const
|
||||
{
|
||||
return float(cpPinJointGetDist(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f PinJoint2D::GetFirstAnchor() const
|
||||
Vector2f PinConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpPinJointGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
Vector2f PinJoint2D::GetSecondAnchor() const
|
||||
Vector2f PinConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpPinJointGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
void PinJoint2D::SetDistance(float newDistance)
|
||||
void PinConstraint2D::SetDistance(float newDistance)
|
||||
{
|
||||
cpPinJointSetDist(m_constraint, newDistance);
|
||||
}
|
||||
|
||||
void PinJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
void PinConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPinJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void PinJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
void PinConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPinJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
|
||||
PivotJoint2D::PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor) :
|
||||
Constraint2D(world, cpPivotJointNew(first.GetHandle(), second.GetHandle(), cpv(anchor.x, anchor.y)))
|
||||
PivotConstraint2D::PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& anchor) :
|
||||
Constraint2D(first.GetWorld(), cpPivotJointNew(first.GetHandle(), second.GetHandle(), cpv(anchor.x, anchor.y)))
|
||||
{
|
||||
}
|
||||
|
||||
PivotJoint2D::PivotJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor) :
|
||||
Constraint2D(world, cpPivotJointNew2(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
|
||||
PivotConstraint2D::PivotConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor) :
|
||||
Constraint2D(first.GetWorld(), cpPivotJointNew2(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y)))
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f PivotJoint2D::GetFirstAnchor() const
|
||||
Vector2f PivotConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpPivotJointGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
Vector2f PivotJoint2D::GetSecondAnchor() const
|
||||
Vector2f PivotConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpPivotJointGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
void PivotJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
void PivotConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPivotJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void PivotJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
void PivotConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpPivotJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
|
||||
RatchetJoint2D::RatchetJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float phase, float ratchet) :
|
||||
Constraint2D(world, cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet))
|
||||
RatchetConstraint2D::RatchetConstraint2D(RigidBody2D& first, RigidBody2D& second, float phase, float ratchet) :
|
||||
Constraint2D(first.GetWorld(), cpRatchetJointNew(first.GetHandle(), second.GetHandle(), phase, ratchet))
|
||||
{
|
||||
}
|
||||
|
||||
float RatchetJoint2D::GetAngle() const
|
||||
float RatchetConstraint2D::GetAngle() const
|
||||
{
|
||||
return float(cpRatchetJointGetAngle(m_constraint));
|
||||
}
|
||||
|
||||
float RatchetJoint2D::GetPhase() const
|
||||
float RatchetConstraint2D::GetPhase() const
|
||||
{
|
||||
return float(cpRatchetJointGetPhase(m_constraint));
|
||||
}
|
||||
|
||||
float RatchetJoint2D::GetRatchet() const
|
||||
float RatchetConstraint2D::GetRatchet() const
|
||||
{
|
||||
return float(cpRatchetJointGetRatchet(m_constraint));
|
||||
}
|
||||
|
||||
void RatchetJoint2D::SetAngle(float angle)
|
||||
void RatchetConstraint2D::SetAngle(float angle)
|
||||
{
|
||||
cpRatchetJointSetAngle(m_constraint, angle);
|
||||
}
|
||||
|
||||
void RatchetJoint2D::SetPhase(float phase)
|
||||
void RatchetConstraint2D::SetPhase(float phase)
|
||||
{
|
||||
cpRatchetJointSetPhase(m_constraint, phase);
|
||||
}
|
||||
|
||||
void RatchetJoint2D::SetRatchet(float ratchet)
|
||||
void RatchetConstraint2D::SetRatchet(float ratchet)
|
||||
{
|
||||
cpRatchetJointSetRatchet(m_constraint, ratchet);
|
||||
}
|
||||
|
||||
|
||||
RotaryLimitJoint2D::RotaryLimitJoint2D(PhysWorld2D& world, RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle) :
|
||||
Constraint2D(world, cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle, maxAngle))
|
||||
RotaryLimitConstraint2D::RotaryLimitConstraint2D(RigidBody2D& first, RigidBody2D& second, float minAngle, float maxAngle) :
|
||||
Constraint2D(first.GetWorld(), cpRotaryLimitJointNew(first.GetHandle(), second.GetHandle(), minAngle, maxAngle))
|
||||
{
|
||||
}
|
||||
|
||||
float RotaryLimitJoint2D::GetMaxAngle() const
|
||||
float RotaryLimitConstraint2D::GetMaxAngle() const
|
||||
{
|
||||
return float(cpRotaryLimitJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
float RotaryLimitJoint2D::GetMinAngle() const
|
||||
float RotaryLimitConstraint2D::GetMinAngle() const
|
||||
{
|
||||
return float(cpRotaryLimitJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
void RotaryLimitJoint2D::SetMaxAngle(float maxAngle)
|
||||
void RotaryLimitConstraint2D::SetMaxAngle(float maxAngle)
|
||||
{
|
||||
cpRotaryLimitJointSetMax(m_constraint, maxAngle);
|
||||
}
|
||||
|
||||
void RotaryLimitJoint2D::SetMinAngle(float minAngle)
|
||||
void RotaryLimitConstraint2D::SetMinAngle(float minAngle)
|
||||
{
|
||||
cpRotaryLimitJointSetMin(m_constraint, minAngle);
|
||||
}
|
||||
|
||||
|
||||
SlideJoint2D::SlideJoint2D(PhysWorld2D& world, RigidBody2D& first, const Vector2f& firstAnchor, RigidBody2D& second, const Vector2f& secondAnchor, float min, float max) :
|
||||
Constraint2D(world, cpSlideJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), min, max))
|
||||
SlideConstraint2D::SlideConstraint2D(RigidBody2D& first, RigidBody2D& second, const Vector2f& firstAnchor, const Vector2f& secondAnchor, float min, float max) :
|
||||
Constraint2D(first.GetWorld(), cpSlideJointNew(first.GetHandle(), second.GetHandle(), cpv(firstAnchor.x, firstAnchor.y), cpv(secondAnchor.x, secondAnchor.y), min, max))
|
||||
{
|
||||
}
|
||||
|
||||
Vector2f SlideJoint2D::GetFirstAnchor() const
|
||||
Vector2f SlideConstraint2D::GetFirstAnchor() const
|
||||
{
|
||||
cpVect anchor = cpSlideJointGetAnchorA(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
float SlideJoint2D::GetMaxDistance() const
|
||||
float SlideConstraint2D::GetMaxDistance() const
|
||||
{
|
||||
return float(cpSlideJointGetMax(m_constraint));
|
||||
}
|
||||
|
||||
float SlideJoint2D::GetMinDistance() const
|
||||
float SlideConstraint2D::GetMinDistance() const
|
||||
{
|
||||
return float(cpSlideJointGetMin(m_constraint));
|
||||
}
|
||||
|
||||
Vector2f SlideJoint2D::GetSecondAnchor() const
|
||||
Vector2f SlideConstraint2D::GetSecondAnchor() const
|
||||
{
|
||||
cpVect anchor = cpSlideJointGetAnchorB(m_constraint);
|
||||
return Vector2f(static_cast<float>(anchor.x), static_cast<float>(anchor.y));
|
||||
}
|
||||
|
||||
void SlideJoint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
void SlideConstraint2D::SetFirstAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpSlideJointSetAnchorA(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
void SlideJoint2D::SetMaxDistance(float newMaxDistance)
|
||||
void SlideConstraint2D::SetMaxDistance(float newMaxDistance)
|
||||
{
|
||||
cpSlideJointSetMax(m_constraint, newMaxDistance);
|
||||
}
|
||||
|
||||
void SlideJoint2D::SetMinDistance(float newMinDistance)
|
||||
void SlideConstraint2D::SetMinDistance(float newMinDistance)
|
||||
{
|
||||
cpSlideJointSetMin(m_constraint, newMinDistance);
|
||||
}
|
||||
|
||||
void SlideJoint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
void SlideConstraint2D::SetSecondAnchor(const Vector2f& firstAnchor)
|
||||
{
|
||||
cpSlideJointSetAnchorB(m_constraint, cpv(firstAnchor.x, firstAnchor.y));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Nz
|
||||
m_handle = Create(m_mass, object.GetMomentOfInertia());
|
||||
SetGeom(object.GetGeom(), false);
|
||||
|
||||
CopyBodyData(object.GetHandle());
|
||||
CopyBodyData(object.GetHandle(), m_handle);
|
||||
|
||||
for (std::size_t i = 0; i < m_shapes.size(); ++i)
|
||||
m_shapes[i]->bb = cpShapeCacheBB(object.m_shapes[i]);
|
||||
@@ -243,7 +243,7 @@ namespace Nz
|
||||
|
||||
cpBody* newHandle = Create(static_cast<float>(mass), static_cast<float>(moment));
|
||||
|
||||
CopyBodyData(m_handle);
|
||||
CopyBodyData(m_handle, newHandle);
|
||||
Destroy();
|
||||
|
||||
m_handle = newHandle;
|
||||
@@ -403,25 +403,20 @@ namespace Nz
|
||||
return *this;
|
||||
}
|
||||
|
||||
void RigidBody2D::CopyBodyData(cpBody* body)
|
||||
{
|
||||
cpBodySetAngle(m_handle, cpBodyGetAngle(body));
|
||||
cpBodySetAngularVelocity(m_handle, cpBodyGetAngularVelocity(body));
|
||||
cpBodySetCenterOfGravity(m_handle, cpBodyGetCenterOfGravity(body));
|
||||
cpBodySetForce(m_handle, cpBodyGetForce(body));
|
||||
cpBodySetPosition(m_handle, cpBodyGetPosition(body));
|
||||
cpBodySetTorque(m_handle, cpBodyGetTorque(body));
|
||||
cpBodySetVelocity(m_handle, cpBodyGetVelocity(body));
|
||||
}
|
||||
|
||||
cpBody* RigidBody2D::Create(float mass, float moment)
|
||||
{
|
||||
cpBody* handle = cpBodyNew(mass, moment);
|
||||
cpBody* handle;
|
||||
if (IsKinematic())
|
||||
{
|
||||
if (IsStatic())
|
||||
handle = cpBodyNewStatic();
|
||||
else
|
||||
handle = cpBodyNewKinematic();
|
||||
}
|
||||
else
|
||||
handle = cpBodyNew(mass, moment);
|
||||
|
||||
cpBodySetUserData(handle, this);
|
||||
|
||||
if (mass <= 0.f)
|
||||
cpBodySetType(handle, CP_BODY_TYPE_KINEMATIC);
|
||||
|
||||
cpSpaceAddBody(m_world->GetHandle(), handle);
|
||||
|
||||
return handle;
|
||||
@@ -443,4 +438,16 @@ namespace Nz
|
||||
}
|
||||
m_shapes.clear();
|
||||
}
|
||||
|
||||
void RigidBody2D::CopyBodyData(cpBody* from, cpBody* to)
|
||||
{
|
||||
cpBodySetAngle(to, cpBodyGetAngle(from));
|
||||
cpBodySetAngularVelocity(to, cpBodyGetAngularVelocity(from));
|
||||
cpBodySetCenterOfGravity(to, cpBodyGetCenterOfGravity(from));
|
||||
cpBodySetForce(to, cpBodyGetForce(from));
|
||||
cpBodySetPosition(to, cpBodyGetPosition(from));
|
||||
cpBodySetTorque(to, cpBodyGetTorque(from));
|
||||
cpBodySetVelocity(to, cpBodyGetVelocity(from));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Nazara/Physics3D/PhysWorld3D.hpp>
|
||||
#include <Newton/Newton.h>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <Nazara/Physics3D/Debug.hpp>
|
||||
|
||||
namespace Nz
|
||||
@@ -31,6 +32,7 @@ namespace Nz
|
||||
|
||||
m_body = NewtonCreateDynamicBody(m_world->GetHandle(), m_geom->GetHandle(m_world), m_matrix);
|
||||
NewtonBodySetUserData(m_body, this);
|
||||
NewtonBodySetTransformCallback(m_body, &TransformCallback);
|
||||
}
|
||||
|
||||
RigidBody3D::RigidBody3D(const RigidBody3D& object) :
|
||||
@@ -47,7 +49,16 @@ namespace Nz
|
||||
|
||||
m_body = NewtonCreateDynamicBody(m_world->GetHandle(), m_geom->GetHandle(m_world), m_matrix);
|
||||
NewtonBodySetUserData(m_body, this);
|
||||
NewtonBodySetTransformCallback(m_body, &TransformCallback);
|
||||
|
||||
SetMass(object.m_mass);
|
||||
SetAngularDamping(object.GetAngularDamping());
|
||||
SetAngularVelocity(object.GetAngularVelocity());
|
||||
SetLinearDamping(object.GetLinearDamping());
|
||||
SetLinearVelocity(object.GetLinearVelocity());
|
||||
SetMassCenter(object.GetMassCenter());
|
||||
SetPosition(object.GetPosition());
|
||||
SetRotation(object.GetRotation());
|
||||
}
|
||||
|
||||
RigidBody3D::RigidBody3D(RigidBody3D&& object) :
|
||||
@@ -125,6 +136,11 @@ namespace Nz
|
||||
NewtonBodySetAutoSleep(m_body, autoSleep);
|
||||
}
|
||||
|
||||
void RigidBody3D::EnableSimulation(bool simulation)
|
||||
{
|
||||
NewtonBodySetSimulationState(m_body, simulation);
|
||||
}
|
||||
|
||||
Boxf RigidBody3D::GetAABB() const
|
||||
{
|
||||
Vector3f min, max;
|
||||
@@ -133,6 +149,14 @@ namespace Nz
|
||||
return Boxf(min, max);
|
||||
}
|
||||
|
||||
Vector3f RigidBody3D::GetAngularDamping() const
|
||||
{
|
||||
Vector3f angularDamping;
|
||||
NewtonBodyGetAngularDamping(m_body, angularDamping);
|
||||
|
||||
return angularDamping;
|
||||
}
|
||||
|
||||
Vector3f RigidBody3D::GetAngularVelocity() const
|
||||
{
|
||||
Vector3f angularVelocity;
|
||||
@@ -156,6 +180,19 @@ namespace Nz
|
||||
return m_body;
|
||||
}
|
||||
|
||||
float RigidBody3D::GetLinearDamping() const
|
||||
{
|
||||
return NewtonBodyGetLinearDamping(m_body);
|
||||
}
|
||||
|
||||
Vector3f RigidBody3D::GetLinearVelocity() const
|
||||
{
|
||||
Vector3f velocity;
|
||||
NewtonBodyGetVelocity(m_body, velocity);
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
float RigidBody3D::GetMass() const
|
||||
{
|
||||
return m_mass;
|
||||
@@ -194,14 +231,6 @@ namespace Nz
|
||||
return m_matrix.GetRotation();
|
||||
}
|
||||
|
||||
Vector3f RigidBody3D::GetVelocity() const
|
||||
{
|
||||
Vector3f velocity;
|
||||
NewtonBodyGetVelocity(m_body, velocity);
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
PhysWorld3D* RigidBody3D::GetWorld() const
|
||||
{
|
||||
return m_world;
|
||||
@@ -217,11 +246,21 @@ namespace Nz
|
||||
return m_mass > 0.f;
|
||||
}
|
||||
|
||||
bool RigidBody3D::IsSimulationEnabled() const
|
||||
{
|
||||
return NewtonBodyGetSimulationState(m_body) != 0;
|
||||
}
|
||||
|
||||
bool RigidBody3D::IsSleeping() const
|
||||
{
|
||||
return NewtonBodyGetSleepState(m_body) != 0;
|
||||
}
|
||||
|
||||
void RigidBody3D::SetAngularDamping(const Nz::Vector3f& angularDamping)
|
||||
{
|
||||
NewtonBodySetAngularDamping(m_body, angularDamping);
|
||||
}
|
||||
|
||||
void RigidBody3D::SetAngularVelocity(const Vector3f& angularVelocity)
|
||||
{
|
||||
NewtonBodySetOmega(m_body, angularVelocity);
|
||||
@@ -245,18 +284,39 @@ namespace Nz
|
||||
m_gravityFactor = gravityFactor;
|
||||
}
|
||||
|
||||
void RigidBody3D::SetLinearDamping(float damping)
|
||||
{
|
||||
NewtonBodySetLinearDamping(m_body, damping);
|
||||
}
|
||||
|
||||
void RigidBody3D::SetLinearVelocity(const Vector3f& velocity)
|
||||
{
|
||||
NewtonBodySetVelocity(m_body, velocity);
|
||||
}
|
||||
|
||||
void RigidBody3D::SetMass(float mass)
|
||||
{
|
||||
NazaraAssert(mass >= 0.f, "Mass must be positive and finite");
|
||||
NazaraAssert(std::isfinite(mass), "Mass must be positive and finite");
|
||||
|
||||
if (m_mass > 0.f)
|
||||
{
|
||||
// If we already have a mass, we already have an inertial matrix as well, just rescale it
|
||||
float Ix, Iy, Iz;
|
||||
NewtonBodyGetMassMatrix(m_body, &m_mass, &Ix, &Iy, &Iz);
|
||||
if (mass > 0.f)
|
||||
{
|
||||
// If we already have a mass, we already have an inertial matrix as well, just rescale it
|
||||
float Ix, Iy, Iz;
|
||||
NewtonBodyGetMassMatrix(m_body, &m_mass, &Ix, &Iy, &Iz);
|
||||
|
||||
float scale = mass/m_mass;
|
||||
NewtonBodySetMassMatrix(m_body, mass, Ix*scale, Iy*scale, Iz*scale);
|
||||
float scale = mass / m_mass;
|
||||
NewtonBodySetMassMatrix(m_body, mass, Ix*scale, Iy*scale, Iz*scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
NewtonBodySetMassMatrix(m_body, 0.f, 0.f, 0.f, 0.f);
|
||||
NewtonBodySetForceAndTorqueCallback(m_body, nullptr);
|
||||
}
|
||||
}
|
||||
else if (mass > 0.f)
|
||||
else
|
||||
{
|
||||
Vector3f inertia, origin;
|
||||
m_geom->ComputeInertialMatrix(&inertia, &origin);
|
||||
@@ -264,7 +324,6 @@ namespace Nz
|
||||
NewtonBodySetCentreOfMass(m_body, &origin.x);
|
||||
NewtonBodySetMassMatrix(m_body, mass, inertia.x*mass, inertia.y*mass, inertia.z*mass);
|
||||
NewtonBodySetForceAndTorqueCallback(m_body, &ForceAndTorqueCallback);
|
||||
NewtonBodySetTransformCallback(m_body, &TransformCallback);
|
||||
}
|
||||
|
||||
m_mass = mass;
|
||||
@@ -290,11 +349,6 @@ namespace Nz
|
||||
UpdateBody();
|
||||
}
|
||||
|
||||
void RigidBody3D::SetVelocity(const Vector3f& velocity)
|
||||
{
|
||||
NewtonBodySetVelocity(m_body, velocity);
|
||||
}
|
||||
|
||||
RigidBody3D& RigidBody3D::operator=(const RigidBody3D& object)
|
||||
{
|
||||
RigidBody3D physObj(object);
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Nz
|
||||
if (varPtr->type != type)
|
||||
{
|
||||
//TODO: AstParseError
|
||||
throw std::runtime_error("Function uses parameter \"" + name + "\" with a different type than specified in the function arguments");
|
||||
throw std::runtime_error("Function uses parameter \"" + name.ToStdString() + "\" with a different type than specified in the function arguments");
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -98,7 +98,7 @@ namespace Nz
|
||||
|
||||
if (!found)
|
||||
//TODO: AstParseError
|
||||
throw std::runtime_error("Function has no parameter \"" + name + "\"");
|
||||
throw std::runtime_error("Function has no parameter \"" + name.ToStdString() + "\"");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -227,35 +227,41 @@ namespace Nz
|
||||
|
||||
if (p < 0)
|
||||
{
|
||||
p += static_cast<int>(m_positions.size() - 1);
|
||||
p += static_cast<int>(m_positions.size());
|
||||
if (p < 0)
|
||||
{
|
||||
Error("Vertex index out of range (" + String::Number(p) + " < 0");
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++p;
|
||||
}
|
||||
|
||||
if (n < 0)
|
||||
{
|
||||
n += static_cast<int>(m_normals.size() - 1);
|
||||
n += static_cast<int>(m_normals.size());
|
||||
if (n < 0)
|
||||
{
|
||||
Error("Normal index out of range (" + String::Number(n) + " < 0");
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++n;
|
||||
}
|
||||
|
||||
if (t < 0)
|
||||
{
|
||||
t += static_cast<int>(m_texCoords.size() - 1);
|
||||
t += static_cast<int>(m_texCoords.size());
|
||||
if (t < 0)
|
||||
{
|
||||
Error("Texture coordinates index out of range (" + String::Number(t) + " < 0");
|
||||
error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++t;
|
||||
}
|
||||
|
||||
if (static_cast<std::size_t>(p) > m_positions.size())
|
||||
|
||||
@@ -161,6 +161,38 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveJPEG(const Image& image, const ImageParams& parameters, Stream& stream)
|
||||
{
|
||||
Image tempImage(image); //< We're using COW here to prevent Image copy unless required
|
||||
|
||||
int componentCount = ConvertToIntegerFormat(tempImage);
|
||||
if (componentCount == 0)
|
||||
{
|
||||
NazaraError("Failed to convert image to suitable format");
|
||||
return false;
|
||||
}
|
||||
|
||||
long long imageQuality;
|
||||
if (parameters.custom.GetIntegerParameter("NativeJPEGSaver_Quality", &imageQuality))
|
||||
{
|
||||
if (imageQuality <= 0 || imageQuality > 100)
|
||||
{
|
||||
NazaraError("NativeJPEGSaver_Quality value (" + Nz::String::Number(imageQuality) + ") does not fit in bounds ]0, 100], clamping...");
|
||||
imageQuality = Nz::Clamp(imageQuality, 1LL, 100LL);
|
||||
}
|
||||
}
|
||||
else
|
||||
imageQuality = 100;
|
||||
|
||||
if (!stbi_write_jpg_to_func(&WriteToStream, &stream, tempImage.GetWidth(), tempImage.GetHeight(), componentCount, tempImage.GetConstPixels(), int(imageQuality)))
|
||||
{
|
||||
NazaraError("Failed to write JPEG to stream");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveHDR(const Image& image, const ImageParams& parameters, Stream& stream)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
@@ -232,10 +264,12 @@ namespace Nz
|
||||
{
|
||||
void RegisterSTBSaver()
|
||||
{
|
||||
s_formatHandlers["bmp"] = &SaveBMP;
|
||||
s_formatHandlers["hdr"] = &SaveHDR;
|
||||
s_formatHandlers["png"] = &SavePNG;
|
||||
s_formatHandlers["tga"] = &SaveTGA;
|
||||
s_formatHandlers["bmp"] = &SaveBMP;
|
||||
s_formatHandlers["hdr"] = &SaveHDR;
|
||||
s_formatHandlers["jpg"] = &SaveJPEG;
|
||||
s_formatHandlers["jpeg"] = &SaveJPEG;
|
||||
s_formatHandlers["png"] = &SavePNG;
|
||||
s_formatHandlers["tga"] = &SaveTGA;
|
||||
|
||||
ImageSaver::RegisterSaver(FormatQuerier, SaveToStream);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user