Merge remote-tracking branch 'refs/remotes/origin/master' into culling

This commit is contained in:
Lynix 2016-10-19 11:17:12 +02:00
commit 725dc6cdbc
151 changed files with 3726 additions and 1373 deletions

3
.gitignore vendored
View File

@ -4,6 +4,9 @@ build/config.lua
# Nazara libraries
lib/*
# Nazara plugin libraries
plugins/lib/*
# Nazara package
package/*

View File

@ -34,8 +34,13 @@ compiler:
- clang
env:
- COMPILER=clang++-3.7 CONFIG=debug
- COMPILER=clang++-3.7 CONFIG=release
global:
- COMPILER=clang++-3.7
- CFLAGS="-Wall -Wextra"
- CXXFLAGS="-Wall -Wextra"
matrix:
- CONFIG=debug
- CONFIG=release
script:
- cd build &&

View File

@ -374,8 +374,8 @@ namespace Ndk
}
inline Application::WindowInfo::WindowInfo(std::unique_ptr<Nz::Window>&& window) :
window(std::move(window)),
renderTarget(nullptr)
renderTarget(nullptr),
window(std::move(window))
{
}
#endif

View File

@ -15,8 +15,8 @@ namespace Ndk
*/
inline BaseSystem::BaseSystem(SystemIndex systemId) :
m_updateEnabled(true),
m_systemIndex(systemId)
m_systemIndex(systemId),
m_updateEnabled(true)
{
SetUpdateRate(30);
}

View File

@ -6,14 +6,14 @@
#define NDK_COMPONENTS_GLOBAL_HPP
#include <NDK/Components/CameraComponent.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <NDK/Components/GraphicsComponent.hpp>
#include <NDK/Components/LightComponent.hpp>
#include <NDK/Components/ListenerComponent.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/ParticleEmitterComponent.hpp>
#include <NDK/Components/ParticleGroupComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#endif // NDK_COMPONENTS_GLOBAL_HPP

View File

@ -7,53 +7,53 @@
#ifndef NDK_COMPONENTS_COLLISIONCOMPONENT_HPP
#define NDK_COMPONENTS_COLLISIONCOMPONENT_HPP
#include <Nazara/Physics/Geom.hpp>
#include <Nazara/Physics3D/Collider3D.hpp>
#include <NDK/Component.hpp>
#include <memory>
namespace Nz
{
class PhysObject;
class RigidBody3D;
}
namespace Ndk
{
class Entity;
class NDK_API CollisionComponent : public Component<CollisionComponent>
class NDK_API CollisionComponent3D : public Component<CollisionComponent3D>
{
friend class PhysicsSystem;
friend class PhysicsSystem3D;
friend class StaticCollisionSystem;
public:
CollisionComponent(Nz::PhysGeomRef geom = Nz::PhysGeomRef());
CollisionComponent(const CollisionComponent& collision);
~CollisionComponent() = default;
CollisionComponent3D(Nz::Collider3DRef geom = Nz::Collider3DRef());
CollisionComponent3D(const CollisionComponent3D& collision);
~CollisionComponent3D() = default;
const Nz::PhysGeomRef& GetGeom() const;
const Nz::Collider3DRef& GetGeom() const;
void SetGeom(Nz::PhysGeomRef geom);
void SetGeom(Nz::Collider3DRef geom);
CollisionComponent& operator=(Nz::PhysGeomRef geom);
CollisionComponent& operator=(CollisionComponent&& collision) = default;
CollisionComponent3D& operator=(Nz::Collider3DRef geom);
CollisionComponent3D& operator=(CollisionComponent3D&& collision) = default;
static ComponentIndex componentIndex;
private:
void InitializeStaticBody();
Nz::PhysObject* GetStaticBody();
Nz::RigidBody3D* GetStaticBody();
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
std::unique_ptr<Nz::PhysObject> m_staticBody;
Nz::PhysGeomRef m_geom;
std::unique_ptr<Nz::RigidBody3D> m_staticBody;
Nz::Collider3DRef m_geom;
bool m_bodyUpdated;
};
}
#include <NDK/Components/CollisionComponent.inl>
#include <NDK/Components/CollisionComponent3D.inl>
#endif // NDK_COMPONENTS_COLLISIONCOMPONENT_HPP

View File

@ -4,30 +4,30 @@
#include <NDK/Entity.hpp>
#include <NDK/World.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
namespace Ndk
{
/*!
* \brief Constructs a CollisionComponent object with a geometry
* \brief Constructs a CollisionComponent3D object with a geometry
*
* \param geom Reference to a geometry symbolizing the entity
*/
inline CollisionComponent::CollisionComponent(Nz::PhysGeomRef geom) :
inline CollisionComponent3D::CollisionComponent3D(Nz::Collider3DRef geom) :
m_geom(std::move(geom)),
m_bodyUpdated(false)
{
}
/*!
* \brief Constructs a CollisionComponent object by copy semantic
* \brief Constructs a CollisionComponent3D object by copy semantic
*
* \param collision CollisionComponent to copy
* \param collision CollisionComponent3D to copy
*/
inline CollisionComponent::CollisionComponent(const CollisionComponent& collision) :
inline CollisionComponent3D::CollisionComponent3D(const CollisionComponent3D& collision) :
m_geom(collision.m_geom),
m_bodyUpdated(false)
{
@ -38,7 +38,7 @@ namespace Ndk
* \return A constant reference to the physics geometry
*/
inline const Nz::PhysGeomRef& CollisionComponent::GetGeom() const
inline const Nz::Collider3DRef& CollisionComponent3D::GetGeom() const
{
return m_geom;
}
@ -50,7 +50,7 @@ namespace Ndk
* \param geom Reference to a geometry symbolizing the entity
*/
inline CollisionComponent& CollisionComponent::operator=(Nz::PhysGeomRef geom)
inline CollisionComponent3D& CollisionComponent3D::operator=(Nz::Collider3DRef geom)
{
SetGeom(geom);
@ -62,7 +62,7 @@ namespace Ndk
* \return A pointer to the entity
*/
inline Nz::PhysObject* CollisionComponent::GetStaticBody()
inline Nz::RigidBody3D* CollisionComponent3D::GetStaticBody()
{
return m_staticBody.get();
}

View File

@ -79,12 +79,12 @@ namespace Ndk
}
Renderable(Renderable&& renderable) noexcept :
data(std::move(renderable.data)),
renderable(std::move(renderable.renderable)),
dataUpdated(renderable.dataUpdated),
renderableBoundingVolumeInvalidationSlot(std::move(renderable.renderableBoundingVolumeInvalidationSlot)),
renderableDataInvalidationSlot(std::move(renderable.renderableDataInvalidationSlot)),
renderableReleaseSlot(std::move(renderable.renderableReleaseSlot))
renderableReleaseSlot(std::move(renderable.renderableReleaseSlot)),
data(std::move(renderable.data)),
renderable(std::move(renderable.renderable)),
dataUpdated(renderable.dataUpdated)
{
}

View File

@ -4,10 +4,10 @@
#pragma once
#ifndef NDK_COMPONENTS_PHYSICSCOMPONENT_HPP
#define NDK_COMPONENTS_PHYSICSCOMPONENT_HPP
#ifndef NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP
#define NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP
#include <Nazara/Physics/PhysObject.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Component.hpp>
#include <memory>
@ -15,15 +15,15 @@ namespace Ndk
{
class Entity;
class NDK_API PhysicsComponent : public Component<PhysicsComponent>
class NDK_API PhysicsComponent3D : public Component<PhysicsComponent3D>
{
friend class CollisionComponent;
friend class PhysicsSystem;
friend class CollisionComponent3D;
friend class PhysicsSystem3D;
public:
PhysicsComponent() = default;
PhysicsComponent(const PhysicsComponent& physics);
~PhysicsComponent() = default;
PhysicsComponent3D() = default;
PhysicsComponent3D(const PhysicsComponent3D& physics);
~PhysicsComponent3D() = default;
void AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys = Nz::CoordSys_Global);
void AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys = Nz::CoordSys_Global);
@ -56,17 +56,17 @@ namespace Ndk
static ComponentIndex componentIndex;
private:
Nz::PhysObject& GetPhysObject();
Nz::RigidBody3D& GetPhysObject();
void OnAttached() override;
void OnComponentAttached(BaseComponent& component) override;
void OnComponentDetached(BaseComponent& component) override;
void OnDetached() override;
std::unique_ptr<Nz::PhysObject> m_object;
std::unique_ptr<Nz::RigidBody3D> m_object;
};
}
#include <NDK/Components/PhysicsComponent.inl>
#include <NDK/Components/PhysicsComponent3D.inl>
#endif // NDK_COMPONENTS_PHYSICSCOMPONENT_HPP
#endif // NDK_COMPONENTS_PHYSICSCOMPONENT3D_HPP

View File

@ -7,12 +7,12 @@
namespace Ndk
{
/*!
* \brief Constructs a PhysicsComponent object by copy semantic
* \brief Constructs a PhysicsComponent3D object by copy semantic
*
* \param physics PhysicsComponent to copy
* \param physics PhysicsComponent3D to copy
*/
inline PhysicsComponent::PhysicsComponent(const PhysicsComponent& physics)
inline PhysicsComponent3D::PhysicsComponent3D(const PhysicsComponent3D& physics)
{
// No copy of physical object (because we only create it when attached to an entity)
NazaraUnused(physics);
@ -27,7 +27,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys)
inline void PhysicsComponent3D::AddForce(const Nz::Vector3f& force, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
@ -44,7 +44,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys)
inline void PhysicsComponent3D::AddForce(const Nz::Vector3f& force, const Nz::Vector3f& point, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
@ -60,7 +60,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys)
inline void PhysicsComponent3D::AddTorque(const Nz::Vector3f& torque, Nz::CoordSys coordSys)
{
NazaraAssert(m_object, "Invalid physics object");
@ -75,7 +75,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::EnableAutoSleep(bool autoSleep)
inline void PhysicsComponent3D::EnableAutoSleep(bool autoSleep)
{
NazaraAssert(m_object, "Invalid physics object");
@ -89,7 +89,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Boxf PhysicsComponent::GetAABB() const
inline Nz::Boxf PhysicsComponent3D::GetAABB() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -103,7 +103,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent::GetAngularVelocity() const
inline Nz::Vector3f PhysicsComponent3D::GetAngularVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -117,7 +117,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent::GetGravityFactor() const
inline float PhysicsComponent3D::GetGravityFactor() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -131,7 +131,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline float PhysicsComponent::GetMass() const
inline float PhysicsComponent3D::GetMass() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -147,7 +147,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent::GetMassCenter(Nz::CoordSys coordSys) const
inline Nz::Vector3f PhysicsComponent3D::GetMassCenter(Nz::CoordSys coordSys) const
{
NazaraAssert(m_object, "Invalid physics object");
@ -161,7 +161,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline const Nz::Matrix4f& PhysicsComponent::GetMatrix() const
inline const Nz::Matrix4f& PhysicsComponent3D::GetMatrix() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -175,7 +175,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent::GetPosition() const
inline Nz::Vector3f PhysicsComponent3D::GetPosition() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -189,7 +189,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Quaternionf PhysicsComponent::GetRotation() const
inline Nz::Quaternionf PhysicsComponent3D::GetRotation() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -203,7 +203,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline Nz::Vector3f PhysicsComponent::GetVelocity() const
inline Nz::Vector3f PhysicsComponent3D::GetVelocity() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -217,7 +217,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent::IsAutoSleepEnabled() const
inline bool PhysicsComponent3D::IsAutoSleepEnabled() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -231,7 +231,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline bool PhysicsComponent::IsSleeping() const
inline bool PhysicsComponent3D::IsSleeping() const
{
NazaraAssert(m_object, "Invalid physics object");
@ -246,7 +246,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetAngularVelocity(const Nz::Vector3f& angularVelocity)
inline void PhysicsComponent3D::SetAngularVelocity(const Nz::Vector3f& angularVelocity)
{
NazaraAssert(m_object, "Invalid physics object");
@ -261,7 +261,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetGravityFactor(float gravityFactor)
inline void PhysicsComponent3D::SetGravityFactor(float gravityFactor)
{
NazaraAssert(m_object, "Invalid physics object");
@ -277,7 +277,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the mass is negative
*/
inline void PhysicsComponent::SetMass(float mass)
inline void PhysicsComponent3D::SetMass(float mass)
{
NazaraAssert(m_object, "Invalid physics object");
NazaraAssert(mass > 0.f, "Mass should be positive");
@ -293,7 +293,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetMassCenter(const Nz::Vector3f& center)
inline void PhysicsComponent3D::SetMassCenter(const Nz::Vector3f& center)
{
NazaraAssert(m_object, "Invalid physics object");
@ -308,7 +308,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetPosition(const Nz::Vector3f& position)
inline void PhysicsComponent3D::SetPosition(const Nz::Vector3f& position)
{
NazaraAssert(m_object, "Invalid physics object");
@ -323,7 +323,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetRotation(const Nz::Quaternionf& rotation)
inline void PhysicsComponent3D::SetRotation(const Nz::Quaternionf& rotation)
{
NazaraAssert(m_object, "Invalid physics object");
@ -338,7 +338,7 @@ namespace Ndk
* \remark Produces a NazaraAssert if the physics object is invalid
*/
inline void PhysicsComponent::SetVelocity(const Nz::Vector3f& velocity)
inline void PhysicsComponent3D::SetVelocity(const Nz::Vector3f& velocity)
{
NazaraAssert(m_object, "Invalid physics object");
@ -350,7 +350,7 @@ namespace Ndk
* \return A reference to the physics object
*/
inline Nz::PhysObject& PhysicsComponent::GetPhysObject()
inline Nz::RigidBody3D& PhysicsComponent3D::GetPhysObject()
{
return *m_object.get();
}

View File

@ -7,7 +7,7 @@
#include <NDK/Systems/ListenerSystem.hpp>
#include <NDK/Systems/ParticleSystem.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <NDK/Systems/RenderSystem.hpp>
#include <NDK/Systems/VelocitySystem.hpp>

View File

@ -1,40 +0,0 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#pragma once
#ifndef NDK_SYSTEMS_PHYSICSSYSTEM_HPP
#define NDK_SYSTEMS_PHYSICSSYSTEM_HPP
#include <Nazara/Physics/PhysWorld.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
namespace Ndk
{
class NDK_API PhysicsSystem : public System<PhysicsSystem>
{
public:
PhysicsSystem();
PhysicsSystem(const PhysicsSystem& system);
~PhysicsSystem() = default;
Nz::PhysWorld& GetWorld();
const Nz::PhysWorld& GetWorld() const;
static SystemIndex systemIndex;
private:
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
EntityList m_dynamicObjects;
EntityList m_staticObjects;
Nz::PhysWorld m_world;
};
}
#include <NDK/Systems/PhysicsSystem.inl>
#endif // NDK_SYSTEMS_PHYSICSSYSTEM_HPP

View File

@ -0,0 +1,42 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#pragma once
#ifndef NDK_SYSTEMS_PHYSICSSYSTEM3D_HPP
#define NDK_SYSTEMS_PHYSICSSYSTEM3D_HPP
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <NDK/EntityList.hpp>
#include <NDK/System.hpp>
#include <memory>
namespace Ndk
{
class NDK_API PhysicsSystem3D : public System<PhysicsSystem3D>
{
public:
PhysicsSystem3D();
PhysicsSystem3D(const PhysicsSystem3D& system);
~PhysicsSystem3D() = default;
Nz::PhysWorld3D& GetWorld();
const Nz::PhysWorld3D& GetWorld() const;
static SystemIndex systemIndex;
private:
void CreatePhysWorld() const;
void OnEntityValidation(Entity* entity, bool justAdded) override;
void OnUpdate(float elapsedTime) override;
EntityList m_dynamicObjects;
EntityList m_staticObjects;
mutable std::unique_ptr<Nz::PhysWorld3D> m_world; ///TODO: std::optional (Should I make a Nz::Optional class?)
};
}
#include <NDK/Systems/PhysicsSystem3D.inl>
#endif // NDK_SYSTEMS_PHYSICSSYSTEM3D_HPP

View File

@ -9,9 +9,12 @@ namespace Ndk
* \return A reference to the physical world
*/
inline Nz::PhysWorld& PhysicsSystem::GetWorld()
inline Nz::PhysWorld3D& PhysicsSystem3D::GetWorld()
{
return m_world;
if (!m_world)
CreatePhysWorld();
return *m_world;
}
/*!
@ -19,8 +22,11 @@ namespace Ndk
* \return A constant reference to the physical world
*/
inline const Nz::PhysWorld& PhysicsSystem::GetWorld() const
inline const Nz::PhysWorld3D& PhysicsSystem3D::GetWorld() const
{
return m_world;
if (!m_world)
CreatePhysWorld();
return *m_world;
}
}

View File

@ -2,18 +2,18 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/CollisionComponent.hpp>
#include <Nazara/Physics/PhysObject.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/World.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::CollisionComponent
* \class Ndk::CollisionComponent3D
* \brief NDK class that represents the component for collision (meant for static objects)
*/
@ -25,14 +25,14 @@ namespace Ndk
* \remark Produces a NazaraAssert if the entity has no physics component and has no static body
*/
void CollisionComponent::SetGeom(Nz::PhysGeomRef geom)
void CollisionComponent3D::SetGeom(Nz::Collider3DRef geom)
{
m_geom = std::move(geom);
if (m_entity->HasComponent<PhysicsComponent>())
if (m_entity->HasComponent<PhysicsComponent3D>())
{
// We update the geometry of the PhysiscsObject linked to the PhysicsComponent
PhysicsComponent& physComponent = m_entity->GetComponent<PhysicsComponent>();
// We update the geometry of the PhysiscsObject linked to the PhysicsComponent3D
PhysicsComponent3D& physComponent = m_entity->GetComponent<PhysicsComponent3D>();
physComponent.GetPhysObject().SetGeom(m_geom);
}
else
@ -49,16 +49,16 @@ namespace Ndk
* \remark Produces a NazaraAssert if entity is not linked to a world, or the world has no physics system
*/
void CollisionComponent::InitializeStaticBody()
void CollisionComponent3D::InitializeStaticBody()
{
NazaraAssert(m_entity, "Invalid entity");
World* entityWorld = m_entity->GetWorld();
NazaraAssert(entityWorld, "Entity must have world");
NazaraAssert(entityWorld->HasSystem<PhysicsSystem>(), "World must have a physics system");
Nz::PhysWorld& physWorld = entityWorld->GetSystem<PhysicsSystem>().GetWorld();
NazaraAssert(entityWorld->HasSystem<PhysicsSystem3D>(), "World must have a physics system");
Nz::PhysWorld3D& physWorld = entityWorld->GetSystem<PhysicsSystem3D>().GetWorld();
m_staticBody.reset(new Nz::PhysObject(&physWorld, m_geom));
m_staticBody.reset(new Nz::RigidBody3D(&physWorld, m_geom));
m_staticBody->EnableAutoSleep(false);
}
@ -66,9 +66,9 @@ namespace Ndk
* \brief Operation to perform when component is attached to an entity
*/
void CollisionComponent::OnAttached()
void CollisionComponent3D::OnAttached()
{
if (!m_entity->HasComponent<PhysicsComponent>())
if (!m_entity->HasComponent<PhysicsComponent3D>())
InitializeStaticBody();
}
@ -78,9 +78,9 @@ namespace Ndk
* \param component Component being attached
*/
void CollisionComponent::OnComponentAttached(BaseComponent& component)
void CollisionComponent3D::OnComponentAttached(BaseComponent& component)
{
if (IsComponent<PhysicsComponent>(component))
if (IsComponent<PhysicsComponent3D>(component))
m_staticBody.reset();
}
@ -90,9 +90,9 @@ namespace Ndk
* \param component Component being detached
*/
void CollisionComponent::OnComponentDetached(BaseComponent& component)
void CollisionComponent3D::OnComponentDetached(BaseComponent& component)
{
if (IsComponent<PhysicsComponent>(component))
if (IsComponent<PhysicsComponent3D>(component))
InitializeStaticBody();
}
@ -100,10 +100,10 @@ namespace Ndk
* \brief Operation to perform when component is detached from an entity
*/
void CollisionComponent::OnDetached()
void CollisionComponent3D::OnDetached()
{
m_staticBody.reset();
}
ComponentIndex CollisionComponent::componentIndex;
ComponentIndex CollisionComponent3D::componentIndex;
}

View File

@ -2,19 +2,19 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Components/PhysicsComponent.hpp>
#include <Nazara/Physics/PhysObject.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/World.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
namespace Ndk
{
/*!
* \ingroup NDK
* \class Ndk::PhysicsComponent
* \class Ndk::PhysicsComponent3D
* \brief NDK class that represents the component for physics (meant for dynamic objects)
*/
@ -24,16 +24,16 @@ namespace Ndk
* \remark Produces a NazaraAssert if the world does not have a physics system
*/
void PhysicsComponent::OnAttached()
void PhysicsComponent3D::OnAttached()
{
World* entityWorld = m_entity->GetWorld();
NazaraAssert(entityWorld->HasSystem<PhysicsSystem>(), "World must have a physics system");
NazaraAssert(entityWorld->HasSystem<PhysicsSystem3D>(), "World must have a physics system");
Nz::PhysWorld& world = entityWorld->GetSystem<PhysicsSystem>().GetWorld();
Nz::PhysWorld3D& world = entityWorld->GetSystem<PhysicsSystem3D>().GetWorld();
Nz::PhysGeomRef geom;
if (m_entity->HasComponent<CollisionComponent>())
geom = m_entity->GetComponent<CollisionComponent>().GetGeom();
Nz::Collider3DRef geom;
if (m_entity->HasComponent<CollisionComponent3D>())
geom = m_entity->GetComponent<CollisionComponent3D>().GetGeom();
Nz::Matrix4f matrix;
if (m_entity->HasComponent<NodeComponent>())
@ -41,7 +41,7 @@ namespace Ndk
else
matrix.MakeIdentity();
m_object.reset(new Nz::PhysObject(&world, geom, matrix));
m_object.reset(new Nz::RigidBody3D(&world, geom, matrix));
m_object->SetMass(1.f);
}
@ -53,12 +53,12 @@ namespace Ndk
* \remark Produces a NazaraAssert if physical object is invalid
*/
void PhysicsComponent::OnComponentAttached(BaseComponent& component)
void PhysicsComponent3D::OnComponentAttached(BaseComponent& component)
{
if (IsComponent<CollisionComponent>(component))
if (IsComponent<CollisionComponent3D>(component))
{
NazaraAssert(m_object, "Invalid object");
m_object->SetGeom(static_cast<CollisionComponent&>(component).GetGeom());
m_object->SetGeom(static_cast<CollisionComponent3D&>(component).GetGeom());
}
}
@ -70,12 +70,12 @@ namespace Ndk
* \remark Produces a NazaraAssert if physical object is invalid
*/
void PhysicsComponent::OnComponentDetached(BaseComponent& component)
void PhysicsComponent3D::OnComponentDetached(BaseComponent& component)
{
if (IsComponent<CollisionComponent>(component))
if (IsComponent<CollisionComponent3D>(component))
{
NazaraAssert(m_object, "Invalid object");
m_object->SetGeom(Nz::NullGeom::New());
m_object->SetGeom(Nz::NullCollider3D::New());
}
}
@ -83,10 +83,10 @@ namespace Ndk
* \brief Operation to perform when component is detached from an entity
*/
void PhysicsComponent::OnDetached()
void PhysicsComponent3D::OnDetached()
{
m_object.reset();
}
ComponentIndex PhysicsComponent::componentIndex;
ComponentIndex PhysicsComponent3D::componentIndex;
}

View File

@ -13,7 +13,7 @@ namespace Ndk
void LuaBinding::BindCore()
{
/*********************************** Nz::Clock **********************************/
clockClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t argumentCount)
clockClass.SetConstructor([](Nz::LuaInstance& lua, Nz::Clock* clock, std::size_t /*argumentCount*/)
{
int argIndex = 1;
Nz::Int64 startingValue = lua.Check<Nz::Int64>(&argIndex, 0);

View File

@ -20,10 +20,8 @@ namespace Ndk
return reinterpret_cast<Nz::InstancedRenderableRef*>(model); //TODO: Make a ObjectRefCast
});
modelClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::ModelRef* model, std::size_t argumentCount)
modelClass.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::ModelRef* model, std::size_t /*argumentCount*/)
{
NazaraUnused(argumentCount);
Nz::PlacementNew(model, Nz::Model::New());
return true;
});

View File

@ -93,10 +93,8 @@ namespace Ndk
});
/*********************************** Nz::Font **********************************/
fontClass.SetConstructor([] (Nz::LuaInstance& lua, Nz::FontRef* font, std::size_t argumentCount)
fontClass.SetConstructor([] (Nz::LuaInstance& /*lua*/, Nz::FontRef* font, std::size_t /*argumentCount*/)
{
NazaraUnused(argumentCount);
Nz::PlacementNew(font, Nz::Font::New());
return true;
});

View File

@ -9,15 +9,15 @@
#include <Nazara/Graphics/Graphics.hpp>
#include <Nazara/Lua/Lua.hpp>
#include <Nazara/Noise/Noise.hpp>
#include <Nazara/Physics/Physics.hpp>
#include <Nazara/Physics3D/Physics3D.hpp>
#include <Nazara/Utility/Utility.hpp>
#include <NDK/Algorithm.hpp>
#include <NDK/BaseSystem.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <NDK/Systems/VelocitySystem.hpp>
#ifndef NDK_SERVER
@ -68,7 +68,7 @@ namespace Ndk
Nz::Lua::Initialize();
Nz::Noise::Initialize();
Nz::Physics::Initialize();
Nz::Physics3D::Initialize();
Nz::Utility::Initialize();
#ifndef NDK_SERVER
@ -83,9 +83,9 @@ namespace Ndk
BaseComponent::Initialize();
// Shared components
InitializeComponent<CollisionComponent>("NdkColli");
InitializeComponent<CollisionComponent3D>("NdkColli");
InitializeComponent<NodeComponent>("NdkNode");
InitializeComponent<PhysicsComponent>("NdkPhys");
InitializeComponent<PhysicsComponent3D>("NdkPhys");
InitializeComponent<VelocityComponent>("NdkVeloc");
#ifndef NDK_SERVER
@ -103,7 +103,7 @@ namespace Ndk
BaseSystem::Initialize();
// Shared systems
InitializeSystem<PhysicsSystem>();
InitializeSystem<PhysicsSystem3D>();
InitializeSystem<VelocitySystem>();
#ifndef NDK_SERVER
@ -161,7 +161,7 @@ namespace Ndk
// Shared modules
Nz::Lua::Uninitialize();
Nz::Noise::Uninitialize();
Nz::Physics::Uninitialize();
Nz::Physics3D::Uninitialize();
Nz::Utility::Uninitialize();
NazaraNotice("Uninitialized: SDK");

View File

@ -2,11 +2,11 @@
// This file is part of the "Nazara Development Kit"
// For conditions of distribution and use, see copyright notice in Prerequesites.hpp
#include <NDK/Systems/PhysicsSystem.hpp>
#include <Nazara/Physics/PhysObject.hpp>
#include <NDK/Components/CollisionComponent.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <NDK/Components/CollisionComponent3D.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
namespace Ndk
{
@ -15,7 +15,7 @@ namespace Ndk
* \class Ndk::PhysicsSystem
* \brief NDK class that represents the physics system
*
* \remark This system is enabled if the entity has the trait: NodeComponent and any of these two: CollisionComponent or PhysicsComponent
* \remark This system is enabled if the entity has the trait: NodeComponent and any of these two: CollisionComponent3D or PhysicsComponent3D
* \remark Static objects do not have a velocity specified by the physical engine
*/
@ -23,10 +23,10 @@ namespace Ndk
* \brief Constructs an PhysicsSystem object by default
*/
PhysicsSystem::PhysicsSystem()
PhysicsSystem3D::PhysicsSystem3D()
{
Requires<NodeComponent>();
RequiresAny<CollisionComponent, PhysicsComponent>();
RequiresAny<CollisionComponent3D, PhysicsComponent3D>();
}
/*!
@ -35,12 +35,19 @@ namespace Ndk
* \param system PhysicsSystem to copy
*/
PhysicsSystem::PhysicsSystem(const PhysicsSystem& system) :
PhysicsSystem3D::PhysicsSystem3D(const PhysicsSystem3D& system) :
System(system),
m_world()
{
}
void PhysicsSystem3D::CreatePhysWorld() const
{
NazaraAssert(!m_world, "Physics world should not be created twice");
m_world = std::make_unique<Nz::PhysWorld3D>();
}
/*!
* \brief Operation to perform when entity is validated for the system
*
@ -48,18 +55,21 @@ namespace Ndk
* \param justAdded Is the entity newly added
*/
void PhysicsSystem::OnEntityValidation(Entity* entity, bool justAdded)
void PhysicsSystem3D::OnEntityValidation(Entity* entity, bool justAdded)
{
// If entity has not been just added to the system, it is possible that it does not own to the right array
// It's possible our entity got revalidated because of the addition/removal of a PhysicsComponent3D
if (!justAdded)
{
// We take the inverted array from which the entity should belong to
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_staticObjects : m_dynamicObjects;
// We take the opposite array from which the entity should belong to
auto& entities = (entity->HasComponent<PhysicsComponent3D>()) ? m_staticObjects : m_dynamicObjects;
entities.Remove(entity);
}
auto& entities = (entity->HasComponent<PhysicsComponent>()) ? m_dynamicObjects : m_staticObjects;
auto& entities = (entity->HasComponent<PhysicsComponent3D>()) ? m_dynamicObjects : m_staticObjects;
entities.Insert(entity);
if (!m_world)
CreatePhysWorld();
}
/*!
@ -68,16 +78,19 @@ namespace Ndk
* \param elapsedTime Delta time used for the update
*/
void PhysicsSystem::OnUpdate(float elapsedTime)
void PhysicsSystem3D::OnUpdate(float elapsedTime)
{
m_world.Step(elapsedTime);
if (!m_world)
return;
m_world->Step(elapsedTime);
for (const Ndk::EntityHandle& entity : m_dynamicObjects)
{
NodeComponent& node = entity->GetComponent<NodeComponent>();
PhysicsComponent& phys = entity->GetComponent<PhysicsComponent>();
PhysicsComponent3D& phys = entity->GetComponent<PhysicsComponent3D>();
Nz::PhysObject& physObj = phys.GetPhysObject();
Nz::RigidBody3D& physObj = phys.GetPhysObject();
node.SetRotation(physObj.GetRotation(), Nz::CoordSys_Global);
node.SetPosition(physObj.GetPosition(), Nz::CoordSys_Global);
}
@ -85,10 +98,10 @@ namespace Ndk
float invElapsedTime = 1.f / elapsedTime;
for (const Ndk::EntityHandle& entity : m_staticObjects)
{
CollisionComponent& collision = entity->GetComponent<CollisionComponent>();
CollisionComponent3D& collision = entity->GetComponent<CollisionComponent3D>();
NodeComponent& node = entity->GetComponent<NodeComponent>();
Nz::PhysObject* physObj = collision.GetStaticBody();
Nz::RigidBody3D* physObj = collision.GetStaticBody();
Nz::Quaternionf oldRotation = physObj->GetRotation();
Nz::Vector3f oldPosition = physObj->GetPosition();
@ -121,5 +134,5 @@ namespace Ndk
}
}
SystemIndex PhysicsSystem::systemIndex;
SystemIndex PhysicsSystem3D::systemIndex;
}

View File

@ -234,7 +234,7 @@ namespace Ndk
* \param viewer Viewer of the scene
*/
void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& viewer)
void RenderSystem::UpdateDirectionalShadowMaps(const Nz::AbstractViewer& /*viewer*/)
{
if (!m_shadowRT.IsValid())
m_shadowRT.Create();
@ -265,7 +265,6 @@ namespace Ndk
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
@ -338,7 +337,6 @@ namespace Ndk
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}
@ -366,7 +364,6 @@ namespace Ndk
for (const Ndk::EntityHandle& drawable : m_drawables)
{
GraphicsComponent& graphicsComponent = drawable->GetComponent<GraphicsComponent>();
NodeComponent& drawableNode = drawable->GetComponent<NodeComponent>();
graphicsComponent.AddToRenderQueue(renderQueue);
}

View File

@ -4,7 +4,7 @@
#include <NDK/Systems/VelocitySystem.hpp>
#include <NDK/Components/NodeComponent.hpp>
#include <NDK/Components/PhysicsComponent.hpp>
#include <NDK/Components/PhysicsComponent3D.hpp>
#include <NDK/Components/VelocityComponent.hpp>
namespace Ndk
@ -15,7 +15,7 @@ namespace Ndk
* \brief NDK class that represents the velocity system
*
* \remark This system is enabled if the entity owns the trait: NodeComponent and VelocityComponent
* but it's disabled with the trait: PhysicsComponent
* but it's disabled with the trait: PhysicsComponent3D
*/
/*!
@ -25,7 +25,7 @@ namespace Ndk
VelocitySystem::VelocitySystem()
{
Requires<NodeComponent, VelocityComponent>();
Excludes<PhysicsComponent>();
Excludes<PhysicsComponent3D>();
}
/*!

View File

@ -5,7 +5,7 @@
#include <NDK/World.hpp>
#include <Nazara/Core/Error.hpp>
#include <NDK/BaseComponent.hpp>
#include <NDK/Systems/PhysicsSystem.hpp>
#include <NDK/Systems/PhysicsSystem3D.hpp>
#include <NDK/Systems/VelocitySystem.hpp>
#ifndef NDK_SERVER
@ -40,7 +40,7 @@ namespace Ndk
void World::AddDefaultSystems()
{
AddSystem<PhysicsSystem>();
AddSystem<PhysicsSystem3D>();
AddSystem<VelocitySystem>();
#ifndef NDK_SERVER

View File

@ -312,7 +312,7 @@ function NazaraBuild:Execute()
if (toolTable.Kind == "library") then
targetdir(toolTable.TargetDirectory .. "/" .. makeLibDir .. "/x86")
elseif (toolTable.Kind == "plugin") then
targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x86")
targetdir("../plugins/lib/" .. makeLibDir .. "/x86")
end
configuration({"codeblocks or codelite or gmake", "x64"})
@ -321,7 +321,7 @@ function NazaraBuild:Execute()
if (toolTable.Kind == "library") then
targetdir(toolTable.TargetDirectory .. "/" .. makeLibDir .. "/x64")
elseif (toolTable.Kind == "plugin") then
targetdir("../plugins/" .. toolTable.Name .. "/lib/" .. makeLibDir .. "/x64")
targetdir("../plugins/lib/" .. makeLibDir .. "/x64")
end
configuration({"vs*", "x32"})
@ -330,7 +330,7 @@ function NazaraBuild:Execute()
if (toolTable.Kind == "library") then
targetdir(toolTable.TargetDirectory .. "/msvc/x86")
elseif (toolTable.Kind == "plugin") then
targetdir("../plugins/" .. toolTable.Name .. "/lib/msvc/x86")
targetdir("../plugins/lib/msvc/x86")
end
configuration({"vs*", "x64"})
@ -339,7 +339,7 @@ function NazaraBuild:Execute()
if (toolTable.Kind == "library") then
targetdir(toolTable.TargetDirectory .. "/msvc/x64")
elseif (toolTable.Kind == "plugin") then
targetdir("../plugins/" .. toolTable.Name .. "/lib/msvc/x64")
targetdir("../plugins/lib/msvc/x64")
end
configuration({"xcode3 or xcode4", "x32"})
@ -348,7 +348,7 @@ function NazaraBuild:Execute()
if (toolTable.Kind == "library") then
targetdir(toolTable.TargetDirectory .. "/xcode/x86")
elseif (toolTable.Kind == "plugin") then
targetdir("../plugins/" .. toolTable.Name .. "/lib/xcode/x86")
targetdir("../plugins/lib/xcode/x86")
end
configuration({"xcode3 or xcode4", "x64"})
@ -357,7 +357,7 @@ function NazaraBuild:Execute()
if (toolTable.Kind == "library") then
targetdir(toolTable.TargetDirectory .. "/xcode/x64")
elseif (toolTable.Kind == "plugin") then
targetdir("../plugins/" .. toolTable.Name .. "/lib/xcode/x64")
targetdir("../plugins/lib/xcode/x64")
end
configuration("*Static")
@ -403,7 +403,7 @@ function NazaraBuild:Execute()
for k, exampleTable in ipairs(self.OrderedExamples) do
local destPath = "../examples/bin"
project("Demo" .. exampleTable.Name)
location(_ACTION .. "/examples")

View File

@ -0,0 +1,6 @@
MODULE.Name = "Physics2D"
MODULE.Libraries = {
"NazaraCore",
"chipmunk-s"
}

View File

@ -1,4 +1,4 @@
MODULE.Name = "Physics"
MODULE.Name = "Physics3D"
MODULE.Libraries = {
"NazaraCore",

View File

@ -26,6 +26,6 @@ TOOL.Libraries = function()
for k,v in pairs(NazaraBuild.Modules) do
table.insert(libraries, "Nazara" .. v.Name)
end
return libraries
end

View File

@ -44,6 +44,7 @@ TOOL.Libraries = {
"NazaraLua",
"NazaraNetwork",
"NazaraNoise",
"NazaraPhysics",
"NazaraPhysics2D",
"NazaraPhysics3D",
"NazaraUtility"
}

View File

@ -14,7 +14,9 @@ TOOL.Includes = {
TOOL.Files = {
"../tests/main.cpp",
"../tests/Engine/**.hpp",
"../tests/Engine/**.cpp",
"../tests/SDK/**.hpp",
"../tests/SDK/**.cpp"
}

View File

@ -15,7 +15,9 @@ TOOL.Includes = {
TOOL.Files = {
"../tests/main.cpp",
"../tests/Engine/**.hpp",
"../tests/Engine/**.cpp",
"../tests/SDK/**.hpp",
"../tests/SDK/**.cpp"
}
@ -23,6 +25,7 @@ TOOL.Files = {
TOOL.FilesExcluded = {
"../tests/Engine/Audio/**",
"../tests/Engine/Graphics/**",
"../tests/Engine/Utility/**",
"../tests/SDK/NDK/Application.cpp",
"../tests/SDK/NDK/Systems/ListenerSystem.cpp",
"../tests/SDK/NDK/Systems/RenderSystem.cpp"

View File

@ -13,7 +13,8 @@ EXAMPLE.Libraries = {
"NazaraLua",
"NazaraNetwork",
"NazaraNoise",
"NazaraPhysics",
"NazaraPhysics2D",
"NazaraPhysics3D",
"NazaraRenderer",
"NazaraUtility",
"NazaraSDK"

View File

@ -4,7 +4,8 @@
#include <Nazara/Lua.hpp>
#include <Nazara/Network.hpp>
#include <Nazara/Noise.hpp>
#include <Nazara/Physics.hpp>
#include <Nazara/Physics2D.hpp>
#include <Nazara/Physics3D.hpp>
#include <Nazara/Renderer.hpp>
#include <Nazara/Utility.hpp>
#include <NDK/Application.hpp>
@ -19,4 +20,4 @@ int main(int argc, char* argv[])
// Do what you want here
return EXIT_SUCCESS;
}
}

View File

@ -21,7 +21,7 @@ namespace Nz
virtual void EnableStdReplication(bool enable) = 0;
virtual bool IsStdReplicationEnabled() = 0;
virtual bool IsStdReplicationEnabled() const = 0;
virtual void Write(const String& string) = 0;
virtual void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);

View File

@ -123,9 +123,8 @@ namespace Nz
* \see CountOf
*/
template<typename T, std::size_t N>
constexpr std::size_t CountOf(T(&name)[N]) noexcept
constexpr std::size_t CountOf(T(&)[N]) noexcept
{
// NazaraUnused(name); //< Because "body of function is not a return-statement" >.>
return N;
}

View File

@ -25,8 +25,8 @@ namespace Nz
void EnableTimeLogging(bool enable);
void EnableStdReplication(bool enable) override;
bool IsStdReplicationEnabled() override;
bool IsTimeLoggingEnabled();
bool IsStdReplicationEnabled() const override;
bool IsTimeLoggingEnabled() const;
void Write(const String& string) override;
void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;

View File

@ -71,6 +71,8 @@ namespace Nz
template<typename T>
HandledObject<T>& HandledObject<T>::operator=(const HandledObject& object)
{
NazaraUnused(object);
// Nothing to do
return *this;
}

View File

@ -22,7 +22,7 @@ namespace Nz
void EnableStdReplication(bool enable) override;
bool IsStdReplicationEnabled() override;
bool IsStdReplicationEnabled() const override;
void Write(const String& string) override;
void WriteError(ErrorType type, const String& error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr) override;

View File

@ -78,7 +78,6 @@ namespace Nz
Color m_color;
MaterialRef m_material;
Recti m_localBounds;
mutable bool m_verticesUpdated;
float m_scale;
static TextSpriteLibrary::LibraryMap s_library;

View File

@ -8,6 +8,7 @@
#define NAZARA_VECTOR2_HPP
#include <Nazara/Core/String.hpp>
#include <functional>
namespace Nz
{
@ -119,6 +120,11 @@ template<typename T> std::ostream& operator<<(std::ostream& out, const Nz::Vecto
template<typename T> Nz::Vector2<T> operator*(T scale, const Nz::Vector2<T>& vec);
template<typename T> Nz::Vector2<T> operator/(T scale, const Nz::Vector2<T>& vec);
namespace std
{
template<class T> struct hash<Nz::Vector2<T>>;
}
#include <Nazara/Math/Vector2.inl>
#endif // NAZARA_VECTOR2_HPP

View File

@ -1057,6 +1057,29 @@ Nz::Vector2<T> operator/(T scale, const Nz::Vector2<T>& vec)
return Nz::Vector2<T>(scale / vec.x, scale / vec.y);
}
namespace std
{
template<class T>
struct hash<Nz::Vector2<T>>
{
/*!
* \brief Specialisation of std to hash
* \return Result of the hash
*
* \param v Vector2 to hash
*/
std::size_t operator()(const Nz::Vector2<T>& v) const
{
std::size_t seed {};
Nz::HashCombine(seed, v.x);
Nz::HashCombine(seed, v.y);
return seed;
}
};
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -8,6 +8,7 @@
#define NAZARA_VECTOR3_HPP
#include <Nazara/Core/String.hpp>
#include <functional>
namespace Nz
{
@ -141,6 +142,11 @@ template<typename T> std::ostream& operator<<(std::ostream& out, const Nz::Vecto
template<typename T> Nz::Vector3<T> operator*(T scale, const Nz::Vector3<T>& vec);
template<typename T> Nz::Vector3<T> operator/(T scale, const Nz::Vector3<T>& vec);
namespace std
{
template<class T> struct hash<Nz::Vector3<T>>;
}
#include <Nazara/Math/Vector3.inl>
#endif // NAZARA_VECTOR3_HPP

View File

@ -1347,6 +1347,31 @@ Nz::Vector3<T> operator/(T scale, const Nz::Vector3<T>& vec)
return Nz::Vector3<T>(scale / vec.x, scale / vec.y, scale / vec.z);
}
namespace std
{
template<class T>
struct hash<Nz::Vector3<T>>
{
/*!
* \brief Specialisation of std to hash
* \return Result of the hash
*
* \param v Vector3 to hash
*/
std::size_t operator()(const Nz::Vector3<T>& v) const
{
std::size_t seed {};
Nz::HashCombine(seed, v.x);
Nz::HashCombine(seed, v.y);
Nz::HashCombine(seed, v.z);
return seed;
}
};
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -8,6 +8,7 @@
#define NAZARA_VECTOR4_HPP
#include <Nazara/Core/String.hpp>
#include <functional>
namespace Nz
{
@ -117,6 +118,11 @@ template<typename T> std::ostream& operator<<(std::ostream& out, const Nz::Vecto
template<typename T> Nz::Vector4<T> operator*(T scale, const Nz::Vector4<T>& vec);
template<typename T> Nz::Vector4<T> operator/(T scale, const Nz::Vector4<T>& vec);
namespace std
{
template<class T> struct hash<Nz::Vector4<T>>;
}
#include <Nazara/Math/Vector4.inl>
#endif // NAZARA_VECTOR4_HPP

View File

@ -1120,6 +1120,31 @@ Nz::Vector4<T> operator/(T scale, const Nz::Vector4<T>& vec)
return Nz::Vector4<T>(scale / vec.x, scale / vec.y, scale / vec.z, scale / vec.w);
}
namespace std
{
template<class T>
struct hash<Nz::Vector4<T>>
{
/*!
* \brief Specialisation of std to hash
* \return Result of the hash
*
* \param v Vector4 to hash
*/
std::size_t operator()(const Nz::Vector4<T>& v) const
{
std::size_t seed {};
Nz::HashCombine(seed, v.x);
Nz::HashCombine(seed, v.y);
Nz::HashCombine(seed, v.z);
Nz::HashCombine(seed, v.w);
return seed;
}
};
}
#undef F
#include <Nazara/Core/DebugOff.hpp>

View File

@ -56,7 +56,7 @@ namespace Nz
*/
inline IpAddress::IpAddress(const UInt8& a, const UInt8& b, const UInt8& c, const UInt8& d, UInt16 port) :
IpAddress(IPv4{a, b, c, d}, port)
IpAddress(IPv4{{a, b, c, d}}, port)
{
}
@ -68,7 +68,7 @@ namespace Nz
*/
inline IpAddress::IpAddress(const UInt16& a, const UInt16& b, const UInt16& c, const UInt16& d, const UInt16& e, const UInt16& f, const UInt16& g, const UInt16& h, UInt16 port) :
IpAddress(IPv6{a, b, c, d, e, f, g, h}, port)
IpAddress(IPv6{{a, b, c, d, e, f, g, h}}, port)
{
}

View File

@ -79,8 +79,8 @@ namespace Nz
PendingPacket m_pendingPacket;
UInt64 m_keepAliveInterval;
UInt64 m_keepAliveTime;
bool m_isLowDelayEnabled;
bool m_isKeepAliveEnabled;
bool m_isLowDelayEnabled;
};
}

View File

@ -25,11 +25,6 @@ namespace Nz
private:
const NoiseBase& m_source;
float m_value;
float m_remainder;
float m_offset;
float m_weight;
float m_signal;
};
}

View File

@ -1,27 +0,0 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ENUMS_PHYSICS_HPP
#define NAZARA_ENUMS_PHYSICS_HPP
enum GeomType
{
GeomType_Box,
GeomType_Capsule,
GeomType_Cone,
GeomType_Compound,
GeomType_ConvexHull,
GeomType_Cylinder,
GeomType_Heightfield,
GeomType_Null,
GeomType_Scene,
GeomType_Sphere,
GeomType_Tree,
GeomType_Max = GeomType_Tree
};
#endif // NAZARA_ENUMS_PHYSICS_HPP

View File

@ -1,273 +0,0 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_GEOM_HPP
#define NAZARA_GEOM_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/PrimitiveList.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Physics/Config.hpp>
#include <Nazara/Physics/Enums.hpp>
#include <unordered_map>
class NewtonCollision;
namespace Nz
{
///TODO: CollisionModifier
///TODO: HeightfieldGeom
///TODO: PlaneGeom ?
///TODO: SceneGeom
///TODO: TreeGeom
class PhysGeom;
class PhysWorld;
using PhysGeomConstRef = ObjectRef<const PhysGeom>;
using PhysGeomLibrary = ObjectLibrary<PhysGeom>;
using PhysGeomRef = ObjectRef<PhysGeom>;
class NAZARA_PHYSICS_API PhysGeom : public RefCounted
{
friend PhysGeomLibrary;
friend class Physics;
public:
PhysGeom() = default;
PhysGeom(const PhysGeom&) = delete;
PhysGeom(PhysGeom&&) = delete;
virtual ~PhysGeom();
Boxf ComputeAABB(const Vector3f& translation, const Quaternionf& rotation, const Vector3f& scale) const;
virtual Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const;
virtual void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const;
virtual float ComputeVolume() const;
NewtonCollision* GetHandle(PhysWorld* world) const;
virtual GeomType GetType() const = 0;
PhysGeom& operator=(const PhysGeom&) = delete;
PhysGeom& operator=(PhysGeom&&) = delete;
static PhysGeomRef Build(const PrimitiveList& list);
// Signals:
NazaraSignal(OnPhysGeomRelease, const PhysGeom* /*physGeom*/);
protected:
virtual NewtonCollision* CreateHandle(PhysWorld* world) const = 0;
static bool Initialize();
static void Uninitialize();
mutable std::unordered_map<PhysWorld*, NewtonCollision*> m_handles;
static PhysGeomLibrary::LibraryMap s_library;
};
class BoxGeom;
using BoxGeomConstRef = ObjectRef<const BoxGeom>;
using BoxGeomRef = ObjectRef<BoxGeom>;
class NAZARA_PHYSICS_API BoxGeom : public PhysGeom
{
public:
BoxGeom(const Vector3f& lengths, const Matrix4f& transformMatrix = Matrix4f::Identity());
BoxGeom(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
float ComputeVolume() const override;
Vector3f GetLengths() const;
GeomType GetType() const override;
template<typename... Args> static BoxGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld* world) const override;
Matrix4f m_matrix;
Vector3f m_lengths;
};
class CapsuleGeom;
using CapsuleGeomConstRef = ObjectRef<const CapsuleGeom>;
using CapsuleGeomRef = ObjectRef<CapsuleGeom>;
class NAZARA_PHYSICS_API CapsuleGeom : public PhysGeom
{
public:
CapsuleGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
CapsuleGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
float GetLength() const;
float GetRadius() const;
GeomType GetType() const override;
template<typename... Args> static CapsuleGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld* world) const override;
Matrix4f m_matrix;
float m_length;
float m_radius;
};
class CompoundGeom;
using CompoundGeomConstRef = ObjectRef<const CompoundGeom>;
using CompoundGeomRef = ObjectRef<CompoundGeom>;
class NAZARA_PHYSICS_API CompoundGeom : public PhysGeom
{
public:
CompoundGeom(PhysGeom** geoms, std::size_t geomCount);
const std::vector<PhysGeomRef>& GetGeoms() const;
GeomType GetType() const override;
template<typename... Args> static CompoundGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld* world) const override;
std::vector<PhysGeomRef> m_geoms;
};
class ConeGeom;
using ConeGeomConstRef = ObjectRef<const ConeGeom>;
using ConeGeomRef = ObjectRef<ConeGeom>;
class NAZARA_PHYSICS_API ConeGeom : public PhysGeom
{
public:
ConeGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
ConeGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
float GetLength() const;
float GetRadius() const;
GeomType GetType() const override;
template<typename... Args> static ConeGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld* world) const override;
Matrix4f m_matrix;
float m_length;
float m_radius;
};
class ConvexHullGeom;
using ConvexHullGeomConstRef = ObjectRef<const ConvexHullGeom>;
using ConvexHullGeomRef = ObjectRef<ConvexHullGeom>;
class NAZARA_PHYSICS_API ConvexHullGeom : public PhysGeom
{
public:
ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride = sizeof(Vector3f), float tolerance = 0.002f, const Matrix4f& transformMatrix = Matrix4f::Identity());
ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
GeomType GetType() const override;
template<typename... Args> static ConvexHullGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld* world) const override;
std::vector<Vector3f> m_vertices;
Matrix4f m_matrix;
float m_tolerance;
unsigned int m_vertexStride;
};
class CylinderGeom;
using CylinderGeomConstRef = ObjectRef<const CylinderGeom>;
using CylinderGeomRef = ObjectRef<CylinderGeom>;
class NAZARA_PHYSICS_API CylinderGeom : public PhysGeom
{
public:
CylinderGeom(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
CylinderGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
float GetLength() const;
float GetRadius() const;
GeomType GetType() const override;
template<typename... Args> static CylinderGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld* world) const override;
Matrix4f m_matrix;
float m_length;
float m_radius;
};
class NullGeom;
using NullGeomConstRef = ObjectRef<const NullGeom>;
using NullGeomRef = ObjectRef<NullGeom>;
class NAZARA_PHYSICS_API NullGeom : public PhysGeom
{
public:
NullGeom();
void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const override;
GeomType GetType() const override;
template<typename... Args> static NullGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld* world) const override;
};
class SphereGeom;
using SphereGeomConstRef = ObjectRef<const SphereGeom>;
using SphereGeomRef = ObjectRef<SphereGeom>;
class NAZARA_PHYSICS_API SphereGeom : public PhysGeom
{
public:
SphereGeom(float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
SphereGeom(float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
float ComputeVolume() const override;
float GetRadius() const;
GeomType GetType() const override;
template<typename... Args> static SphereGeomRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld* world) const override;
Vector3f m_position;
float m_radius;
};
}
#include <Nazara/Physics/Geom.inl>
#endif // NAZARA_PHYSWORLD_HPP

View File

@ -1,83 +0,0 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Physics/Debug.hpp>
namespace Nz
{
template<typename... Args>
BoxGeomRef BoxGeom::New(Args&&... args)
{
std::unique_ptr<BoxGeom> object(new BoxGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
CapsuleGeomRef CapsuleGeom::New(Args&&... args)
{
std::unique_ptr<CapsuleGeom> object(new CapsuleGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
CompoundGeomRef CompoundGeom::New(Args&&... args)
{
std::unique_ptr<CompoundGeom> object(new CompoundGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
ConeGeomRef ConeGeom::New(Args&&... args)
{
std::unique_ptr<ConeGeom> object(new ConeGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
ConvexHullGeomRef ConvexHullGeom::New(Args&&... args)
{
std::unique_ptr<ConvexHullGeom> object(new ConvexHullGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
CylinderGeomRef CylinderGeom::New(Args&&... args)
{
std::unique_ptr<CylinderGeom> object(new CylinderGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NullGeomRef NullGeom::New(Args&&... args)
{
std::unique_ptr<NullGeom> object(new NullGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
SphereGeomRef SphereGeom::New(Args&&... args)
{
std::unique_ptr<SphereGeom> object(new SphereGeom(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Physics/DebugOff.hpp>

View File

@ -1,7 +1,7 @@
// This file was automatically generated on 24 Jun 2015 at 13:55:50
// This file was automatically generated on 14 Oct 2016 at 18:58:18
/*
Nazara Engine - Physics module
Nazara Engine - Physics 2D module
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
@ -26,14 +26,14 @@
#pragma once
#ifndef NAZARA_GLOBAL_PHYSICS_HPP
#define NAZARA_GLOBAL_PHYSICS_HPP
#ifndef NAZARA_GLOBAL_PHYSICS2D_HPP
#define NAZARA_GLOBAL_PHYSICS2D_HPP
#include <Nazara/Physics/Config.hpp>
#include <Nazara/Physics/Enums.hpp>
#include <Nazara/Physics/Geom.hpp>
#include <Nazara/Physics/Physics.hpp>
#include <Nazara/Physics/PhysObject.hpp>
#include <Nazara/Physics/PhysWorld.hpp>
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <Nazara/Physics2D/Physics2D.hpp>
#include <Nazara/Physics2D/Collider2D.hpp>
#include <Nazara/Physics2D/Enums.hpp>
#include <Nazara/Physics2D/Config.hpp>
#include <Nazara/Physics2D/RigidBody2D.hpp>
#endif // NAZARA_GLOBAL_PHYSICS_HPP
#endif // NAZARA_GLOBAL_PHYSICS2D_HPP

View File

@ -0,0 +1,132 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_COLLIDER2D_HPP
#define NAZARA_COLLIDER2D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Physics2D/Config.hpp>
#include <Nazara/Physics2D/Enums.hpp>
#include <vector>
struct cpShape;
struct cpSpace;
namespace Nz
{
class Collider2D;
class RigidBody2D;
using Collider2DConstRef = ObjectRef<const Collider2D>;
using Collider2DLibrary = ObjectLibrary<Collider2D>;
using Collider2DRef = ObjectRef<Collider2D>;
class NAZARA_PHYSICS2D_API Collider2D : public RefCounted
{
friend Collider2DLibrary;
friend RigidBody2D;
public:
Collider2D() = default;
Collider2D(const Collider2D&) = delete;
Collider2D(Collider2D&&) = delete;
virtual ~Collider2D();
virtual float ComputeInertialMatrix(float mass) const = 0;
virtual ColliderType2D GetType() const = 0;
Collider2D& operator=(const Collider2D&) = delete;
Collider2D& operator=(Collider2D&&) = delete;
// Signals:
NazaraSignal(OnColliderRelease, const Collider2D* /*collider*/);
protected:
virtual std::vector<cpShape*> CreateShapes(RigidBody2D* body) const = 0;
static Collider2DLibrary::LibraryMap s_library;
};
class BoxCollider2D;
using BoxCollider2DConstRef = ObjectRef<const BoxCollider2D>;
using BoxCollider2DRef = ObjectRef<BoxCollider2D>;
class NAZARA_PHYSICS2D_API BoxCollider2D : public Collider2D
{
public:
BoxCollider2D(const Vector2f& size, float radius = 0.f);
BoxCollider2D(const Rectf& rect, float radius = 0.f);
float ComputeInertialMatrix(float mass) const override;
inline const Rectf& GetRect() const;
inline Vector2f GetSize() const;
ColliderType2D GetType() const override;
template<typename... Args> static BoxCollider2DRef New(Args&&... args);
private:
std::vector<cpShape*> CreateShapes(RigidBody2D* body) const override;
Rectf m_rect;
float m_radius;
};
class CircleCollider2D;
using CircleCollider2DConstRef = ObjectRef<const CircleCollider2D>;
using CircleCollider2DRef = ObjectRef<CircleCollider2D>;
class NAZARA_PHYSICS2D_API CircleCollider2D : public Collider2D
{
public:
CircleCollider2D(float radius, const Vector2f& offset = Vector2f::Zero());
float ComputeInertialMatrix(float mass) const override;
inline float GetRadius() const;
ColliderType2D GetType() const override;
template<typename... Args> static CircleCollider2DRef New(Args&&... args);
private:
std::vector<cpShape*> CreateShapes(RigidBody2D* body) const override;
Vector2f m_offset;
float m_radius;
};
class NullCollider2D;
using NullCollider2DConstRef = ObjectRef<const NullCollider2D>;
using NullCollider2DRef = ObjectRef<NullCollider2D>;
class NAZARA_PHYSICS2D_API NullCollider2D : public Collider2D
{
public:
NullCollider2D() = default;
float ComputeInertialMatrix(float mass) const override;
ColliderType2D GetType() const override;
template<typename... Args> static NullCollider2DRef New(Args&&... args);
private:
std::vector<cpShape*> CreateShapes(RigidBody2D* body) const override;
};
}
#include <Nazara/Physics2D/Collider2D.inl>
#endif // NAZARA_COLLIDER2D_HPP

View File

@ -0,0 +1,54 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Physics2D/Debug.hpp>
namespace Nz
{
inline const Rectf& BoxCollider2D::GetRect() const
{
return m_rect;
}
inline Vector2f BoxCollider2D::GetSize() const
{
return m_rect.GetLengths();
}
template<typename... Args>
BoxCollider2DRef BoxCollider2D::New(Args&&... args)
{
std::unique_ptr<BoxCollider2D> object(new BoxCollider2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
inline float CircleCollider2D::GetRadius() const
{
return m_radius;
}
template<typename... Args>
CircleCollider2DRef CircleCollider2D::New(Args&&... args)
{
std::unique_ptr<CircleCollider2D> object(new CircleCollider2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NullCollider2DRef NullCollider2D::New(Args&&... args)
{
std::unique_ptr<NullCollider2D> object(new NullCollider2D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Physics2D/DebugOff.hpp>

View File

@ -1,5 +1,5 @@
/*
Nazara Engine - Physics module
Nazara Engine - Physics 2D module
Copyright (C) 2015 Jérôme "Lynix" Leclercq (Lynix680@gmail.com)
@ -24,28 +24,28 @@
#pragma once
#ifndef NAZARA_CONFIG_PHYSICS_HPP
#define NAZARA_CONFIG_PHYSICS_HPP
#ifndef NAZARA_CONFIG_PHYSICS2D_HPP
#define NAZARA_CONFIG_PHYSICS2D_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un manager de mémoire pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
#define NAZARA_PHYSICS_MANAGE_MEMORY 0
#define NAZARA_PHYSICS2D_MANAGE_MEMORY 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_PHYSICS_SAFE 1
#define NAZARA_PHYSICS2D_SAFE 1
/// Vérification des valeurs et types de certaines constantes
#include <Nazara/Physics/ConfigCheck.hpp>
#include <Nazara/Physics2D/ConfigCheck.hpp>
#if defined(NAZARA_STATIC)
#define NAZARA_PHYSICS_API
#define NAZARA_PHYSICS2D_API
#else
#ifdef NAZARA_PHYSICS_BUILD
#define NAZARA_PHYSICS_API NAZARA_EXPORT
#ifdef NAZARA_PHYSICS2D_BUILD
#define NAZARA_PHYSICS2D_API NAZARA_EXPORT
#else
#define NAZARA_PHYSICS_API NAZARA_IMPORT
#define NAZARA_PHYSICS2D_API NAZARA_IMPORT
#endif
#endif
#endif // NAZARA_CONFIG_PHYSICS_HPP
#endif // NAZARA_CONFIG_PHYSICS3D_HPP

View File

@ -1,5 +1,5 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
@ -12,7 +12,7 @@
// On force la valeur de MANAGE_MEMORY en mode debug
#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS_MANAGE_MEMORY
#undef NAZARA_PHYSICS_MANAGE_MEMORY
#define NAZARA_PHYSICS_MANAGE_MEMORY 0
#define NAZARA_PHYSICS3D_MANAGE_MEMORY 0
#endif
#endif // NAZARA_CONFIG_CHECK_PHYSICS_HPP

View File

@ -1,8 +1,8 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics/Config.hpp>
#include <Nazara/Physics3D/Config.hpp>
#if NAZARA_PHYSICS_MANAGE_MEMORY
#include <Nazara/Core/Debug/NewRedefinition.hpp>
#endif

View File

@ -1,5 +1,5 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp

View File

@ -0,0 +1,24 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ENUMS_PHYSICS2D_HPP
#define NAZARA_ENUMS_PHYSICS2D_HPP
namespace Nz
{
enum ColliderType2D
{
ColliderType2D_Box,
ColliderType2D_Convex,
ColliderType2D_Circle,
ColliderType2D_Null,
ColliderType2D_Segment,
ColliderType2D_Max = ColliderType2D_Segment
};
}
#endif // NAZARA_ENUMS_PHYSICS2D_HPP

View File

@ -0,0 +1,46 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PHYSWORLD2D_HPP
#define NAZARA_PHYSWORLD2D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Physics2D/Config.hpp>
struct cpSpace;
namespace Nz
{
class NAZARA_PHYSICS2D_API PhysWorld2D
{
public:
PhysWorld2D();
PhysWorld2D(const PhysWorld2D&) = delete;
PhysWorld2D(PhysWorld2D&&) = delete; ///TODO
~PhysWorld2D();
Vector2f GetGravity() const;
cpSpace* GetHandle() const;
float GetStepSize() const;
void SetGravity(const Vector2f& gravity);
void SetSolverModel(unsigned int model);
void SetStepSize(float stepSize);
void Step(float timestep);
PhysWorld2D& operator=(const PhysWorld2D&) = delete;
PhysWorld2D& operator=(PhysWorld2D&&) = delete; ///TODO
private:
cpSpace* m_handle;
float m_stepSize;
float m_timestepAccumulator;
};
}
#endif // NAZARA_PHYSWORLD2D_HPP

View File

@ -0,0 +1,33 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PHYSICS2D_HPP
#define NAZARA_PHYSICS2D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Physics2D/Config.hpp>
namespace Nz
{
class NAZARA_PHYSICS2D_API Physics2D
{
public:
Physics2D() = delete;
~Physics2D() = delete;
static bool Initialize();
static bool IsInitialized();
static void Uninitialize();
private:
static unsigned int s_moduleReferenceCounter;
};
}
#endif // NAZARA_PHYSICS2D_HPP

View File

@ -0,0 +1,74 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_RIGIDBODY2D_HPP
#define NAZARA_RIGIDBODY2D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Rect.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Physics2D/Config.hpp>
#include <Nazara/Physics2D/Collider2D.hpp>
struct cpBody;
namespace Nz
{
class PhysWorld2D;
class NAZARA_PHYSICS2D_API RigidBody2D
{
public:
RigidBody2D(PhysWorld2D* world, float mass);
RigidBody2D(PhysWorld2D* world, float mass, Collider2DRef geom);
RigidBody2D(const RigidBody2D& object);
RigidBody2D(RigidBody2D&& object);
~RigidBody2D();
void AddForce(const Vector2f& force, CoordSys coordSys = CoordSys_Global);
void AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys = CoordSys_Global);
void AddTorque(float torque);
Rectf GetAABB() const;
float GetAngularVelocity() const;
Vector2f GetCenterOfGravity(CoordSys coordSys = CoordSys_Local) const;
const Collider2DRef& GetGeom() const;
cpBody* GetHandle() const;
float GetMass() const;
Vector2f GetPosition() const;
float GetRotation() const;
Vector2f GetVelocity() const;
bool IsMoveable() const;
bool IsSleeping() const;
void SetAngularVelocity(float angularVelocity);
void SetMass(float mass);
void SetMassCenter(const Vector2f& center);
void SetPosition(const Vector2f& position);
void SetRotation(float rotation);
void SetVelocity(const Vector2f& velocity);
RigidBody2D& operator=(const RigidBody2D& object);
RigidBody2D& operator=(RigidBody2D&& object);
private:
void Destroy();
void SetGeom(Collider2DRef geom);
std::vector<cpShape*> m_shapes;
Collider2DRef m_geom;
cpBody* m_handle;
PhysWorld2D* m_world;
float m_gravityFactor;
float m_mass;
};
}
#endif // NAZARA_RIGIDBODY3D_HPP

View File

@ -0,0 +1,39 @@
// This file was automatically generated on 14 Oct 2016 at 18:58:18
/*
Nazara Engine - Physics 3D module
Copyright (C) 2015 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
#ifndef NAZARA_GLOBAL_PHYSICS3D_HPP
#define NAZARA_GLOBAL_PHYSICS3D_HPP
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <Nazara/Physics3D/Physics3D.hpp>
#include <Nazara/Physics3D/RigidBody3D.hpp>
#include <Nazara/Physics3D/Enums.hpp>
#include <Nazara/Physics3D/Config.hpp>
#include <Nazara/Physics3D/Collider3D.hpp>
#endif // NAZARA_GLOBAL_PHYSICS3D_HPP

View File

@ -0,0 +1,273 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_COLLIDER3D_HPP
#define NAZARA_COLLIDER3D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/PrimitiveList.hpp>
#include <Nazara/Core/ObjectLibrary.hpp>
#include <Nazara/Core/ObjectRef.hpp>
#include <Nazara/Core/RefCounted.hpp>
#include <Nazara/Core/Signal.hpp>
#include <Nazara/Core/SparsePtr.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Physics3D/Config.hpp>
#include <Nazara/Physics3D/Enums.hpp>
#include <unordered_map>
class NewtonCollision;
namespace Nz
{
///TODO: CollisionModifier
///TODO: HeightfieldGeom
///TODO: PlaneGeom ?
///TODO: SceneGeom
///TODO: TreeGeom
class Collider3D;
class PhysWorld3D;
using Collider3DConstRef = ObjectRef<const Collider3D>;
using Collider3DLibrary = ObjectLibrary<Collider3D>;
using Collider3DRef = ObjectRef<Collider3D>;
class NAZARA_PHYSICS3D_API Collider3D : public RefCounted
{
friend Collider3DLibrary;
friend class Physics3D;
public:
Collider3D() = default;
Collider3D(const Collider3D&) = delete;
Collider3D(Collider3D&&) = delete;
virtual ~Collider3D();
Boxf ComputeAABB(const Vector3f& translation, const Quaternionf& rotation, const Vector3f& scale) const;
virtual Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const;
virtual void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const;
virtual float ComputeVolume() const;
NewtonCollision* GetHandle(PhysWorld3D* world) const;
virtual ColliderType3D GetType() const = 0;
Collider3D& operator=(const Collider3D&) = delete;
Collider3D& operator=(Collider3D&&) = delete;
static Collider3DRef Build(const PrimitiveList& list);
// Signals:
NazaraSignal(OnColliderRelease, const Collider3D* /*collider*/);
protected:
virtual NewtonCollision* CreateHandle(PhysWorld3D* world) const = 0;
static bool Initialize();
static void Uninitialize();
mutable std::unordered_map<PhysWorld3D*, NewtonCollision*> m_handles;
static Collider3DLibrary::LibraryMap s_library;
};
class BoxCollider3D;
using BoxCollider3DConstRef = ObjectRef<const BoxCollider3D>;
using BoxCollider3DRef = ObjectRef<BoxCollider3D>;
class NAZARA_PHYSICS3D_API BoxCollider3D : public Collider3D
{
public:
BoxCollider3D(const Vector3f& lengths, const Matrix4f& transformMatrix = Matrix4f::Identity());
BoxCollider3D(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
float ComputeVolume() const override;
Vector3f GetLengths() const;
ColliderType3D GetType() const override;
template<typename... Args> static BoxCollider3DRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
Matrix4f m_matrix;
Vector3f m_lengths;
};
class CapsuleCollider3D;
using CapsuleCollider3DConstRef = ObjectRef<const CapsuleCollider3D>;
using CapsuleCollider3DRef = ObjectRef<CapsuleCollider3D>;
class NAZARA_PHYSICS3D_API CapsuleCollider3D : public Collider3D
{
public:
CapsuleCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
CapsuleCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
float GetLength() const;
float GetRadius() const;
ColliderType3D GetType() const override;
template<typename... Args> static CapsuleCollider3DRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
Matrix4f m_matrix;
float m_length;
float m_radius;
};
class CompoundCollider3D;
using CompoundCollider3DConstRef = ObjectRef<const CompoundCollider3D>;
using CompoundCollider3DRef = ObjectRef<CompoundCollider3D>;
class NAZARA_PHYSICS3D_API CompoundCollider3D : public Collider3D
{
public:
CompoundCollider3D(Collider3D** geoms, std::size_t geomCount);
const std::vector<Collider3DRef>& GetGeoms() const;
ColliderType3D GetType() const override;
template<typename... Args> static CompoundCollider3DRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
std::vector<Collider3DRef> m_geoms;
};
class ConeCollider3D;
using ConeCollider3DConstRef = ObjectRef<const ConeCollider3D>;
using ConeCollider3DRef = ObjectRef<ConeCollider3D>;
class NAZARA_PHYSICS3D_API ConeCollider3D : public Collider3D
{
public:
ConeCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
ConeCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
float GetLength() const;
float GetRadius() const;
ColliderType3D GetType() const override;
template<typename... Args> static ConeCollider3DRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
Matrix4f m_matrix;
float m_length;
float m_radius;
};
class ConvexCollider3D;
using ConvexCollider3DConstRef = ObjectRef<const ConvexCollider3D>;
using ConvexCollider3DRef = ObjectRef<ConvexCollider3D>;
class NAZARA_PHYSICS3D_API ConvexCollider3D : public Collider3D
{
public:
ConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount, float tolerance = 0.002f, const Matrix4f& transformMatrix = Matrix4f::Identity());
ConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount, float tolerance, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
ColliderType3D GetType() const override;
template<typename... Args> static ConvexCollider3DRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
std::vector<Vector3f> m_vertices;
Matrix4f m_matrix;
float m_tolerance;
};
class CylinderCollider3D;
using CylinderCollider3DConstRef = ObjectRef<const CylinderCollider3D>;
using CylinderCollider3DRef = ObjectRef<CylinderCollider3D>;
class NAZARA_PHYSICS3D_API CylinderCollider3D : public Collider3D
{
public:
CylinderCollider3D(float length, float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
CylinderCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
float GetLength() const;
float GetRadius() const;
ColliderType3D GetType() const override;
template<typename... Args> static CylinderCollider3DRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
Matrix4f m_matrix;
float m_length;
float m_radius;
};
class NullCollider3D;
using NullCollider3DConstRef = ObjectRef<const NullCollider3D>;
using NullCollider3DRef = ObjectRef<NullCollider3D>;
class NAZARA_PHYSICS3D_API NullCollider3D : public Collider3D
{
public:
NullCollider3D();
void ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const override;
ColliderType3D GetType() const override;
template<typename... Args> static NullCollider3DRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
};
class SphereCollider3D;
using SphereCollider3DConstRef = ObjectRef<const SphereCollider3D>;
using SphereCollider3DRef = ObjectRef<SphereCollider3D>;
class NAZARA_PHYSICS3D_API SphereCollider3D : public Collider3D
{
public:
SphereCollider3D(float radius, const Matrix4f& transformMatrix = Matrix4f::Identity());
SphereCollider3D(float radius, const Vector3f& translation, const Quaternionf& rotation = Quaternionf::Identity());
Boxf ComputeAABB(const Matrix4f& offsetMatrix = Matrix4f::Identity(), const Vector3f& scale = Vector3f::Unit()) const override;
float ComputeVolume() const override;
float GetRadius() const;
ColliderType3D GetType() const override;
template<typename... Args> static SphereCollider3DRef New(Args&&... args);
private:
NewtonCollision* CreateHandle(PhysWorld3D* world) const override;
Vector3f m_position;
float m_radius;
};
}
#include <Nazara/Physics3D/Collider3D.inl>
#endif // NAZARA_COLLIDER3D_HPP

View File

@ -0,0 +1,83 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <memory>
#include <Nazara/Physics3D/Debug.hpp>
namespace Nz
{
template<typename... Args>
BoxCollider3DRef BoxCollider3D::New(Args&&... args)
{
std::unique_ptr<BoxCollider3D> object(new BoxCollider3D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
CapsuleCollider3DRef CapsuleCollider3D::New(Args&&... args)
{
std::unique_ptr<CapsuleCollider3D> object(new CapsuleCollider3D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
CompoundCollider3DRef CompoundCollider3D::New(Args&&... args)
{
std::unique_ptr<CompoundCollider3D> object(new CompoundCollider3D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
ConeCollider3DRef ConeCollider3D::New(Args&&... args)
{
std::unique_ptr<ConeCollider3D> object(new ConeCollider3D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
ConvexCollider3DRef ConvexCollider3D::New(Args&&... args)
{
std::unique_ptr<ConvexCollider3D> object(new ConvexCollider3D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
CylinderCollider3DRef CylinderCollider3D::New(Args&&... args)
{
std::unique_ptr<CylinderCollider3D> object(new CylinderCollider3D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
NullCollider3DRef NullCollider3D::New(Args&&... args)
{
std::unique_ptr<NullCollider3D> object(new NullCollider3D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
template<typename... Args>
SphereCollider3DRef SphereCollider3D::New(Args&&... args)
{
std::unique_ptr<SphereCollider3D> object(new SphereCollider3D(std::forward<Args>(args)...));
object->SetPersistent(false);
return object.release();
}
}
#include <Nazara/Physics3D/DebugOff.hpp>

View File

@ -0,0 +1,51 @@
/*
Nazara Engine - Physics 3D module
Copyright (C) 2015 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
#ifndef NAZARA_CONFIG_PHYSICS3D_HPP
#define NAZARA_CONFIG_PHYSICS3D_HPP
/// Chaque modification d'un paramètre du module nécessite une recompilation de celui-ci
// Utilise un manager de mémoire pour gérer les allocations dynamiques (détecte les leaks au prix d'allocations/libérations dynamiques plus lentes)
#define NAZARA_PHYSICS3D_MANAGE_MEMORY 0
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_PHYSICS3D_SAFE 1
/// Vérification des valeurs et types de certaines constantes
#include <Nazara/Physics3D/ConfigCheck.hpp>
#if defined(NAZARA_STATIC)
#define NAZARA_PHYSICS3D_API
#else
#ifdef NAZARA_PHYSICS3D_BUILD
#define NAZARA_PHYSICS3D_API NAZARA_EXPORT
#else
#define NAZARA_PHYSICS3D_API NAZARA_IMPORT
#endif
#endif
#endif // NAZARA_CONFIG_PHYSICS3D_HPP

View File

@ -0,0 +1,18 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_CONFIG_CHECK_PHYSICS_HPP
#define NAZARA_CONFIG_CHECK_PHYSICS_HPP
/// Ce fichier sert à vérifier la valeur des constantes du fichier Config.hpp
// On force la valeur de MANAGE_MEMORY en mode debug
#if defined(NAZARA_DEBUG) && !NAZARA_PHYSICS_MANAGE_MEMORY
#undef NAZARA_PHYSICS_MANAGE_MEMORY
#define NAZARA_PHYSICS3D_MANAGE_MEMORY 0
#endif
#endif // NAZARA_CONFIG_CHECK_PHYSICS_HPP

View File

@ -0,0 +1,8 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics3D/Config.hpp>
#if NAZARA_PHYSICS_MANAGE_MEMORY
#include <Nazara/Core/Debug/NewRedefinition.hpp>
#endif

View File

@ -0,0 +1,9 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
// On suppose que Debug.hpp a déjà été inclus, tout comme Config.hpp
#if NAZARA_PHYSICS_MANAGE_MEMORY
#undef delete
#undef new
#endif

View File

@ -0,0 +1,30 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_ENUMS_PHYSICS3D_HPP
#define NAZARA_ENUMS_PHYSICS3D_HPP
namespace Nz
{
enum ColliderType3D
{
ColliderType3D_Box,
ColliderType3D_Capsule,
ColliderType3D_Cone,
ColliderType3D_Compound,
ColliderType3D_ConvexHull,
ColliderType3D_Cylinder,
ColliderType3D_Heightfield,
ColliderType3D_Null,
ColliderType3D_Scene,
ColliderType3D_Sphere,
ColliderType3D_Tree,
ColliderType3D_Max = ColliderType3D_Tree
};
};
#endif // NAZARA_ENUMS_PHYSICS3D_HPP

View File

@ -1,5 +1,5 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
@ -10,19 +10,19 @@
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Math/Box.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Physics/Config.hpp>
#include <Nazara/Physics3D/Config.hpp>
class NewtonWorld;
namespace Nz
{
class NAZARA_PHYSICS_API PhysWorld
class NAZARA_PHYSICS3D_API PhysWorld3D
{
public:
PhysWorld();
PhysWorld(const PhysWorld&) = delete;
PhysWorld(PhysWorld&&) = delete; ///TODO
~PhysWorld();
PhysWorld3D();
PhysWorld3D(const PhysWorld3D&) = delete;
PhysWorld3D(PhysWorld3D&&) = delete; ///TODO
~PhysWorld3D();
Vector3f GetGravity() const;
NewtonWorld* GetHandle() const;
@ -34,8 +34,8 @@ namespace Nz
void Step(float timestep);
PhysWorld& operator=(const PhysWorld&) = delete;
PhysWorld& operator=(PhysWorld&&) = delete; ///TODO
PhysWorld3D& operator=(const PhysWorld3D&) = delete;
PhysWorld3D& operator=(PhysWorld3D&&) = delete; ///TODO
private:
Vector3f m_gravity;

View File

@ -1,23 +1,23 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PHYSICS_HPP
#define NAZARA_PHYSICS_HPP
#ifndef NAZARA_PHYSICS3D_HPP
#define NAZARA_PHYSICS3D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Initializer.hpp>
#include <Nazara/Physics/Config.hpp>
#include <Nazara/Physics3D/Config.hpp>
namespace Nz
{
class NAZARA_PHYSICS_API Physics
class NAZARA_PHYSICS3D_API Physics3D
{
public:
Physics() = delete;
~Physics() = delete;
Physics3D() = delete;
~Physics3D() = delete;
static unsigned int GetMemoryUsed();
@ -32,4 +32,4 @@ namespace Nz
};
}
#endif // NAZARA_PHYSICS_HPP
#endif // NAZARA_PHYSICS3D_HPP

View File

@ -1,34 +1,34 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_PHYSOBJECT_HPP
#define NAZARA_PHYSOBJECT_HPP
#ifndef NAZARA_RIGIDBODY3D_HPP
#define NAZARA_RIGIDBODY3D_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Enums.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Quaternion.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Physics/Config.hpp>
#include <Nazara/Physics/Geom.hpp>
#include <Nazara/Physics3D/Config.hpp>
#include <Nazara/Physics3D/Collider3D.hpp>
class NewtonBody;
namespace Nz
{
class PhysWorld;
class PhysWorld3D;
class NAZARA_PHYSICS_API PhysObject
class NAZARA_PHYSICS3D_API RigidBody3D
{
public:
PhysObject(PhysWorld* world, const Matrix4f& mat = Matrix4f::Identity());
PhysObject(PhysWorld* world, PhysGeomRef geom, const Matrix4f& mat = Matrix4f::Identity());
PhysObject(const PhysObject& object);
PhysObject(PhysObject&& object);
~PhysObject();
RigidBody3D(PhysWorld3D* world, const Matrix4f& mat = Matrix4f::Identity());
RigidBody3D(PhysWorld3D* world, Collider3DRef geom, const Matrix4f& mat = Matrix4f::Identity());
RigidBody3D(const RigidBody3D& object);
RigidBody3D(RigidBody3D&& object);
~RigidBody3D();
void AddForce(const Vector3f& force, CoordSys coordSys = CoordSys_Global);
void AddForce(const Vector3f& force, const Vector3f& point, CoordSys coordSys = CoordSys_Global);
@ -38,7 +38,7 @@ namespace Nz
Boxf GetAABB() const;
Vector3f GetAngularVelocity() const;
const PhysGeomRef& GetGeom() const;
const Collider3DRef& GetGeom() const;
float GetGravityFactor() const;
NewtonBody* GetHandle() const;
float GetMass() const;
@ -53,7 +53,7 @@ namespace Nz
bool IsSleeping() const;
void SetAngularVelocity(const Vector3f& angularVelocity);
void SetGeom(PhysGeomRef geom);
void SetGeom(Collider3DRef geom);
void SetGravityFactor(float gravityFactor);
void SetMass(float mass);
void SetMassCenter(const Vector3f& center);
@ -61,23 +61,23 @@ namespace Nz
void SetRotation(const Quaternionf& rotation);
void SetVelocity(const Vector3f& velocity);
PhysObject& operator=(const PhysObject& object);
PhysObject& operator=(PhysObject&& object);
RigidBody3D& operator=(const RigidBody3D& object);
RigidBody3D& operator=(RigidBody3D&& object);
private:
void UpdateBody();
static void ForceAndTorqueCallback(const NewtonBody* body, float timeStep, int threadIndex);
static void TransformCallback(const NewtonBody* body, const float* matrix, int threadIndex);
Collider3DRef m_geom;
Matrix4f m_matrix;
PhysGeomRef m_geom;
Vector3f m_forceAccumulator;
Vector3f m_torqueAccumulator;
NewtonBody* m_body;
PhysWorld* m_world;
PhysWorld3D* m_world;
float m_gravityFactor;
float m_mass;
};
}
#endif // NAZARA_PHYSOBJECT_HPP
#endif // NAZARA_RIGIDBODY3D_HPP

View File

@ -71,7 +71,6 @@ namespace Nz
mutable StringStream m_outputStream;
bool m_keepLastLine;
unsigned int m_lineCount;
unsigned int m_streamFlags;
};
}

View File

@ -111,8 +111,8 @@ namespace Nz
if (content <= PixelFormatContent_Undefined || content > PixelFormatContent_Max)
return false;
std::array<const Nz::Bitset<>*, 4> masks = {&redMask, &greenMask, &blueMask, &alphaMask};
std::array<PixelFormatSubType, 4> types = {redType, greenType, blueType, alphaType};
std::array<const Nz::Bitset<>*, 4> masks = { {&redMask, &greenMask, &blueMask, &alphaMask} };
std::array<PixelFormatSubType, 4> types = { {redType, greenType, blueType, alphaType} };
for (unsigned int i = 0; i < 4; ++i)
{

View File

@ -40,6 +40,9 @@ aiReturn StreamSeek(aiFile* file, size_t offset, aiOrigin origin)
case aiOrigin_SET:
return (stream->SetCursorPos(offset)) ? aiReturn_SUCCESS : aiReturn_FAILURE;
case _AI_ORIGIN_ENFORCE_ENUM_SIZE: // To prevent a warning
break;
}
NazaraWarning("Unhandled aiOrigin enum (value: 0x" + String(origin, 16) + ')');

View File

@ -72,11 +72,11 @@ bool IsSupported(const String& extension)
return (aiIsExtensionSupported(dotExt.GetConstBuffer()) == AI_TRUE);
}
Ternary Check(Stream& stream, const MeshParams& parameters)
Ternary Check(Stream& /*stream*/, const MeshParams& parameters)
{
bool skip;
if (parameters.custom.GetBooleanParameter("SkipAssimpLoader", &skip) && skip)
return Ternary_False;
bool skip;
if (parameters.custom.GetBooleanParameter("SkipAssimpLoader", &skip) && skip)
return Ternary_False;
return Ternary_Unknown;
}

View File

@ -65,7 +65,7 @@ namespace Nz
* \return true If replication is enabled
*/
bool FileLogger::IsStdReplicationEnabled()
bool FileLogger::IsStdReplicationEnabled() const
{
return m_stdReplicationEnabled;
}
@ -75,7 +75,7 @@ namespace Nz
* \return true If logging of the time is enabled
*/
bool FileLogger::IsTimeLoggingEnabled()
bool FileLogger::IsTimeLoggingEnabled() const
{
return m_timeLoggingEnabled;
}
@ -147,14 +147,6 @@ namespace Nz
void FileLogger::WriteError(ErrorType type, const String& error, unsigned int line, const char* file, const char* function)
{
if (m_forceStdOutput || m_stdReplicationEnabled)
{
m_stdLogger.WriteError(type, error, line, file, function);
if (m_forceStdOutput)
return;
}
AbstractLogger::WriteError(type, error, line, file, function);
m_outputFile.Flush();
}

View File

@ -111,7 +111,9 @@ namespace Nz
bool Log::Initialize()
{
SetLogger(new FileLogger());
if (s_logger == &s_stdLogger)
SetLogger(new FileLogger());
return true;
}

View File

@ -208,8 +208,9 @@ namespace Nz
time_t FileImpl::GetCreationTime(const String& filePath)
{
NazaraWarning("Posix has no creation time information");
NazaraUnused(filePath);
NazaraWarning("Posix has no creation time information");
return 0;
}

View File

@ -47,7 +47,7 @@ namespace Nz
* \return Always returns true
*/
bool StdLogger::IsStdReplicationEnabled()
bool StdLogger::IsStdReplicationEnabled() const
{
return true;
}

View File

@ -82,7 +82,7 @@ namespace Nz
if (pipelineEntry.maxInstanceCount > 0)
{
bool instancing = (pipelineEntry.maxInstanceCount > NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT);
bool instancing = instancingEnabled && (pipelineEntry.maxInstanceCount > NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT);
UInt32 flags = ShaderFlags_Deferred;
if (instancing)

View File

@ -282,7 +282,6 @@ namespace Nz
{
for (auto& pipelinePair : layer.opaqueModels)
{
const MaterialPipeline* pipeline = pipelinePair.first;
auto& pipelineEntry = pipelinePair.second;
if (pipelineEntry.maxInstanceCount > 0)

View File

@ -52,7 +52,7 @@ namespace Nz
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
std::array<UInt8, 4> whitePixel = {255, 255, 255, 255};
std::array<UInt8, 4> whitePixel = { {255, 255, 255, 255} };
m_whiteTexture.Create(ImageType_2D, PixelFormatType_RGBA8, 1, 1);
m_whiteTexture.Update(whitePixel.data());
@ -431,7 +431,6 @@ namespace Nz
for (auto& matIt : pipelinePair.second.materialMap)
{
const Material* material = matIt.first;
auto& entry = matIt.second;
auto& billboardVector = entry.billboards;
@ -551,9 +550,7 @@ namespace Nz
const MeshData& meshData = meshIt.first;
auto& meshEntry = meshIt.second;
const Spheref& squaredBoundingSphere = meshEntry.squaredBoundingSphere;
std::vector<Matrix4f>& instances = meshEntry.instances;
if (!instances.empty())
{
const IndexBuffer* indexBuffer = meshData.indexBuffer;

View File

@ -560,9 +560,7 @@ namespace Nz
auto& overlayMap = matEntry.overlayMap;
for (auto& overlayIt : overlayMap)
{
const Texture* overlay = overlayIt.first;
auto& spriteChainVector = overlayIt.second.spriteChains;
spriteChainVector.clear();
}
@ -581,9 +579,7 @@ namespace Nz
{
for (auto& materialPair : pipelineEntry.materialMap)
{
const Material* material = materialPair.first;
auto& matEntry = materialPair.second;
if (matEntry.enabled)
{
MeshInstanceContainer& meshInstances = matEntry.meshMap;
@ -591,7 +587,6 @@ namespace Nz
for (auto& meshIt : meshInstances)
{
auto& meshEntry = meshIt.second;
meshEntry.instances.clear();
}
matEntry.enabled = false;

View File

@ -53,7 +53,7 @@ namespace Nz
{
ErrorFlags flags(ErrorFlag_ThrowException, true);
std::array<UInt8, 4> whitePixel = {255, 255, 255, 255};
std::array<UInt8, 4> whitePixel = { {255, 255, 255, 255} };
m_whiteTexture.Create(ImageType_2D, PixelFormatType_RGBA8, 1, 1);
m_whiteTexture.Update(whitePixel.data());
@ -412,7 +412,7 @@ namespace Nz
const Shader* lastShader = nullptr;
const ShaderUniforms* shaderUniforms = nullptr;
if (Renderer::HasCapability(RendererCap_Instancing))
if (m_instancingEnabled && Renderer::HasCapability(RendererCap_Instancing))
{
VertexBuffer* instanceBuffer = Renderer::GetInstanceBuffer();
instanceBuffer->SetVertexDeclaration(&s_billboardInstanceDeclaration);
@ -508,7 +508,6 @@ namespace Nz
for (auto& matIt : pipelinePair.second.materialMap)
{
const Material* material = matIt.first;
auto& entry = matIt.second;
auto& billboardVector = entry.billboards;
@ -591,7 +590,7 @@ namespace Nz
if (pipelineEntry.maxInstanceCount > 0)
{
bool instancing = (pipelineEntry.maxInstanceCount > NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT);
bool instancing = m_instancingEnabled && (pipelineEntry.maxInstanceCount > NAZARA_GRAPHICS_INSTANCING_MIN_INSTANCES_COUNT);
const MaterialPipeline::Instance& pipelineInstance = pipeline->Apply((instancing) ? ShaderFlags_Instancing : 0);
const Shader* shader = pipelineInstance.uberInstance->GetShader();

View File

@ -85,7 +85,7 @@ namespace Nz
}
m_activeSockets.clear();
if (activeSockets > 0U)
if (activeSockets > 0)
{
int socketCount = activeSockets;
for (int i = 0; i < socketCount; ++i)

View File

@ -54,7 +54,7 @@ namespace Nz
byteToInt hostOrder;
hostOrder.i = ntohl(addr.s_addr);
return { hostOrder.b[3], hostOrder.b[2], hostOrder.b[1], hostOrder.b[0] };
return { {hostOrder.b[3], hostOrder.b[2], hostOrder.b[1], hostOrder.b[0]} };
}
IpAddress::IPv6 convertSockaddr6ToIPv6(const in6_addr& addr)

View File

@ -74,7 +74,7 @@ namespace Nz
activeSockets = SocketImpl::Poll(m_sockets.data(), m_sockets.size(), static_cast<int>(msTimeout), error);
m_activeSockets.clear();
if (activeSockets > 0U)
if (activeSockets > 0)
{
int socketRemaining = activeSockets;
for (PollSocket& entry : m_sockets)

View File

@ -51,11 +51,12 @@ namespace Nz
d[2] = d[0] + Vector2f(1.f - 2.f * s_UnskewCoeff2D);
Vector2i offset(skewedCubeOrigin.x & 255, skewedCubeOrigin.y & 255);
std::array<std::size_t, 3> gi =
{
m_permutations[offset.x + m_permutations[offset.y]] & 7,
m_permutations[offset.x + off1.x + m_permutations[offset.y + off1.y]] & 7,
m_permutations[offset.x + 1 + m_permutations[offset.y + 1]] & 7
std::array<std::size_t, 3> gi = {
{
m_permutations[offset.x + m_permutations[offset.y]] & 7,
m_permutations[offset.x + off1.x + m_permutations[offset.y + off1.y]] & 7,
m_permutations[offset.x + 1 + m_permutations[offset.y + 1]] & 7
}
};
float n = 0.f;

View File

@ -12,12 +12,13 @@ namespace Nz
{
namespace
{
static constexpr std::array<float, 4> m_functionScales =
{
1.f / float(M_SQRT2),
0.5f / float(M_SQRT2),
0.5f / float(M_SQRT2),
0.5f / float(M_SQRT2)
static constexpr std::array<float, 4> m_functionScales = {
{
1.f / float(M_SQRT2),
0.5f / float(M_SQRT2),
0.5f / float(M_SQRT2),
0.5f / float(M_SQRT2)
}
};
}
Worley::Worley() :
@ -109,12 +110,12 @@ namespace Nz
return it->first * m_functionScales[functionIndex];
}
float Worley::Get(float x, float y, float z, float scale) const
float Worley::Get(float /*x*/, float /*y*/, float /*z*/, float /*scale*/) const
{
throw std::runtime_error("Worley 3D not available yet.");
}
float Worley::Get(float x, float y, float z, float w, float scale) const
float Worley::Get(float /*x*/, float /*y*/, float /*z*/, float /*w*/, float /*scale*/) const
{
throw std::runtime_error("Worley 4D not available yet.");
}

View File

@ -1,448 +0,0 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics/Geom.hpp>
#include <Nazara/Physics/PhysWorld.hpp>
#include <Newton/Newton.h>
#include <memory>
#include <Nazara/Physics/Debug.hpp>
namespace Nz
{
namespace
{
PhysGeomRef CreateGeomFromPrimitive(const Primitive& primitive)
{
switch (primitive.type)
{
case PrimitiveType_Box:
return BoxGeom::New(primitive.box.lengths, primitive.matrix);
case PrimitiveType_Cone:
return ConeGeom::New(primitive.cone.length, primitive.cone.radius, primitive.matrix);
case PrimitiveType_Plane:
return BoxGeom::New(Vector3f(primitive.plane.size.x, 0.01f, primitive.plane.size.y), primitive.matrix);
///TODO: PlaneGeom?
case PrimitiveType_Sphere:
return SphereGeom::New(primitive.sphere.size, primitive.matrix.GetTranslation());
}
NazaraError("Primitive type not handled (0x" + String::Number(primitive.type, 16) + ')');
return PhysGeomRef();
}
}
PhysGeom::~PhysGeom()
{
for (auto& pair : m_handles)
NewtonDestroyCollision(pair.second);
}
Boxf PhysGeom::ComputeAABB(const Vector3f& translation, const Quaternionf& rotation, const Vector3f& scale) const
{
return ComputeAABB(Matrix4f::Transform(translation, rotation), scale);
}
Boxf PhysGeom::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
{
Vector3f min, max;
// Si nous n'avons aucune instance, nous en créons une temporaire
if (m_handles.empty())
{
PhysWorld world;
NewtonCollision* collision = CreateHandle(&world);
{
NewtonCollisionCalculateAABB(collision, offsetMatrix, min, max);
}
NewtonDestroyCollision(collision);
}
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
NewtonCollisionCalculateAABB(m_handles.begin()->second, offsetMatrix, min, max);
return Boxf(scale * min, scale * max);
}
void PhysGeom::ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const
{
float inertiaMatrix[3];
float origin[3];
// Si nous n'avons aucune instance, nous en créons une temporaire
if (m_handles.empty())
{
PhysWorld world;
NewtonCollision* collision = CreateHandle(&world);
{
NewtonConvexCollisionCalculateInertialMatrix(collision, inertiaMatrix, origin);
}
NewtonDestroyCollision(collision);
}
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
NewtonConvexCollisionCalculateInertialMatrix(m_handles.begin()->second, inertiaMatrix, origin);
if (inertia)
inertia->Set(inertiaMatrix);
if (center)
center->Set(origin);
}
float PhysGeom::ComputeVolume() const
{
float volume;
// Si nous n'avons aucune instance, nous en créons une temporaire
if (m_handles.empty())
{
PhysWorld world;
NewtonCollision* collision = CreateHandle(&world);
{
volume = NewtonConvexCollisionCalculateVolume(collision);
}
NewtonDestroyCollision(collision);
}
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
volume = NewtonConvexCollisionCalculateVolume(m_handles.begin()->second);
return volume;
}
NewtonCollision* PhysGeom::GetHandle(PhysWorld* world) const
{
auto it = m_handles.find(world);
if (it == m_handles.end())
it = m_handles.insert(std::make_pair(world, CreateHandle(world))).first;
return it->second;
}
PhysGeomRef PhysGeom::Build(const PrimitiveList& list)
{
std::size_t primitiveCount = list.GetSize();
if (primitiveCount > 1)
{
std::vector<PhysGeom*> geoms(primitiveCount);
for (unsigned int i = 0; i < primitiveCount; ++i)
geoms[i] = CreateGeomFromPrimitive(list.GetPrimitive(i));
return CompoundGeom::New(&geoms[0], primitiveCount);
}
else if (primitiveCount > 0)
return CreateGeomFromPrimitive(list.GetPrimitive(0));
else
return NullGeom::New();
}
bool PhysGeom::Initialize()
{
if (!PhysGeomLibrary::Initialize())
{
NazaraError("Failed to initialise library");
return false;
}
return true;
}
void PhysGeom::Uninitialize()
{
PhysGeomLibrary::Uninitialize();
}
PhysGeomLibrary::LibraryMap PhysGeom::s_library;
/********************************** BoxGeom **********************************/
BoxGeom::BoxGeom(const Vector3f& lengths, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_lengths(lengths)
{
}
BoxGeom::BoxGeom(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation) :
BoxGeom(lengths, Matrix4f::Transform(translation, rotation))
{
}
Boxf BoxGeom::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
{
Vector3f halfLengths(m_lengths * 0.5f);
Boxf aabb(-halfLengths.x, -halfLengths.y, -halfLengths.z, m_lengths.x, m_lengths.y, m_lengths.z);
aabb.Transform(offsetMatrix, true);
aabb *= scale;
return aabb;
}
float BoxGeom::ComputeVolume() const
{
return m_lengths.x * m_lengths.y * m_lengths.z;
}
Vector3f BoxGeom::GetLengths() const
{
return m_lengths;
}
GeomType BoxGeom::GetType() const
{
return GeomType_Box;
}
NewtonCollision* BoxGeom::CreateHandle(PhysWorld* world) const
{
return NewtonCreateBox(world->GetHandle(), m_lengths.x, m_lengths.y, m_lengths.z, 0, m_matrix);
}
/******************************** CapsuleGeom ********************************/
CapsuleGeom::CapsuleGeom(float length, float radius, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_length(length),
m_radius(radius)
{
}
CapsuleGeom::CapsuleGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
CapsuleGeom(length, radius, Matrix4f::Transform(translation, rotation))
{
}
float CapsuleGeom::GetLength() const
{
return m_length;
}
float CapsuleGeom::GetRadius() const
{
return m_radius;
}
GeomType CapsuleGeom::GetType() const
{
return GeomType_Capsule;
}
NewtonCollision* CapsuleGeom::CreateHandle(PhysWorld* world) const
{
return NewtonCreateCapsule(world->GetHandle(), m_radius, m_length, 0, m_matrix);
}
/******************************* CompoundGeom ********************************/
CompoundGeom::CompoundGeom(PhysGeom** geoms, std::size_t geomCount)
{
m_geoms.reserve(geomCount);
for (std::size_t i = 0; i < geomCount; ++i)
m_geoms.emplace_back(geoms[i]);
}
const std::vector<PhysGeomRef>& CompoundGeom::GetGeoms() const
{
return m_geoms;
}
GeomType CompoundGeom::GetType() const
{
return GeomType_Compound;
}
NewtonCollision* CompoundGeom::CreateHandle(PhysWorld* world) const
{
NewtonCollision* compoundCollision = NewtonCreateCompoundCollision(world->GetHandle(), 0);
NewtonCompoundCollisionBeginAddRemove(compoundCollision);
for (const PhysGeomRef& geom : m_geoms)
{
if (geom->GetType() == GeomType_Compound)
{
CompoundGeom* compoundGeom = static_cast<CompoundGeom*>(geom.Get());
for (const PhysGeomRef& piece : compoundGeom->GetGeoms())
NewtonCompoundCollisionAddSubCollision(compoundCollision, piece->GetHandle(world));
}
else
NewtonCompoundCollisionAddSubCollision(compoundCollision, geom->GetHandle(world));
}
NewtonCompoundCollisionEndAddRemove(compoundCollision);
return compoundCollision;
}
/********************************* ConeGeom **********************************/
ConeGeom::ConeGeom(float length, float radius, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_length(length),
m_radius(radius)
{
}
ConeGeom::ConeGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
ConeGeom(length, radius, Matrix4f::Transform(translation, rotation))
{
}
float ConeGeom::GetLength() const
{
return m_length;
}
float ConeGeom::GetRadius() const
{
return m_radius;
}
GeomType ConeGeom::GetType() const
{
return GeomType_Cone;
}
NewtonCollision* ConeGeom::CreateHandle(PhysWorld* world) const
{
return NewtonCreateCone(world->GetHandle(), m_radius, m_length, 0, m_matrix);
}
/****************************** ConvexHullGeom *******************************/
ConvexHullGeom::ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_tolerance(tolerance),
m_vertexStride(stride)
{
const UInt8* ptr = static_cast<const UInt8*>(vertices);
m_vertices.resize(vertexCount);
if (stride != sizeof(Vector3f))
{
for (unsigned int i = 0; i < vertexCount; ++i)
m_vertices[i] = *reinterpret_cast<const Vector3f*>(ptr + stride*i);
}
else // Fast path
std::memcpy(m_vertices.data(), vertices, vertexCount*sizeof(Vector3f));
}
ConvexHullGeom::ConvexHullGeom(const void* vertices, unsigned int vertexCount, unsigned int stride, float tolerance, const Vector3f& translation, const Quaternionf& rotation) :
ConvexHullGeom(vertices, vertexCount, stride, tolerance, Matrix4f::Transform(translation, rotation))
{
}
GeomType ConvexHullGeom::GetType() const
{
return GeomType_Compound;
}
NewtonCollision* ConvexHullGeom::CreateHandle(PhysWorld* world) const
{
return NewtonCreateConvexHull(world->GetHandle(), static_cast<int>(m_vertices.size()), reinterpret_cast<const float*>(m_vertices.data()), sizeof(Vector3f), m_tolerance, 0, m_matrix);
}
/******************************* CylinderGeom ********************************/
CylinderGeom::CylinderGeom(float length, float radius, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_length(length),
m_radius(radius)
{
}
CylinderGeom::CylinderGeom(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
CylinderGeom(length, radius, Matrix4f::Transform(translation, rotation))
{
}
float CylinderGeom::GetLength() const
{
return m_length;
}
float CylinderGeom::GetRadius() const
{
return m_radius;
}
GeomType CylinderGeom::GetType() const
{
return GeomType_Cylinder;
}
NewtonCollision* CylinderGeom::CreateHandle(PhysWorld* world) const
{
return NewtonCreateCylinder(world->GetHandle(), m_radius, m_length, 0, m_matrix);
}
/********************************* NullGeom **********************************/
NullGeom::NullGeom()
{
}
GeomType NullGeom::GetType() const
{
return GeomType_Null;
}
void NullGeom::ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const
{
if (inertia)
inertia->MakeUnit();
if (center)
center->MakeZero();
}
NewtonCollision* NullGeom::CreateHandle(PhysWorld* world) const
{
return NewtonCreateNull(world->GetHandle());
}
/******************************** SphereGeom *********************************/
SphereGeom::SphereGeom(float radius, const Matrix4f& transformMatrix) :
SphereGeom(radius, transformMatrix.GetTranslation())
{
}
SphereGeom::SphereGeom(float radius, const Vector3f& translation, const Quaternionf& rotation) :
m_position(translation),
m_radius(radius)
{
NazaraUnused(rotation);
}
Boxf SphereGeom::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
{
Vector3f size(m_radius * NazaraSuffixMacro(M_SQRT3, f) * scale);
Vector3f position(offsetMatrix.GetTranslation());
return Boxf(position - size, position + size);
}
float SphereGeom::ComputeVolume() const
{
return float(M_PI) * m_radius * m_radius * m_radius / 3.f;
}
float SphereGeom::GetRadius() const
{
return m_radius;
}
GeomType SphereGeom::GetType() const
{
return GeomType_Sphere;
}
NewtonCollision* SphereGeom::CreateHandle(PhysWorld* world) const
{
return NewtonCreateSphere(world->GetHandle(), m_radius, 0, Matrix4f::Translate(m_position));
}
}

View File

@ -0,0 +1,87 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/Collider2D.hpp>
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <chipmunk/chipmunk.h>
#include <Nazara/Physics3D/Debug.hpp>
namespace Nz
{
Collider2D::~Collider2D() = default;
/******************************** BoxCollider2D *********************************/
BoxCollider2D::BoxCollider2D(const Vector2f& size, float radius) :
BoxCollider2D(Rectf(-size.x / 2.f, -size.y / 2.f, size.x / 2.f, size.y / 2.f), radius)
{
}
BoxCollider2D::BoxCollider2D(const Rectf& rect, float radius) :
m_rect(rect),
m_radius(radius)
{
}
float BoxCollider2D::ComputeInertialMatrix(float mass) const
{
return static_cast<float>(cpMomentForBox2(mass, cpBBNew(m_rect.x, m_rect.y + m_rect.height, m_rect.x + m_rect.width, m_rect.y)));
}
ColliderType2D BoxCollider2D::GetType() const
{
return ColliderType2D_Box;
}
std::vector<cpShape*> BoxCollider2D::CreateShapes(RigidBody2D* body) const
{
std::vector<cpShape*> shapes;
shapes.push_back(cpBoxShapeNew2(body->GetHandle(), cpBBNew(m_rect.x, m_rect.y + m_rect.height, m_rect.x + m_rect.width, m_rect.y), m_radius));
return shapes;
}
/******************************** CircleCollider2D *********************************/
CircleCollider2D::CircleCollider2D(float radius, const Vector2f& offset) :
m_offset(offset),
m_radius(radius)
{
}
float CircleCollider2D::ComputeInertialMatrix(float mass) const
{
return static_cast<float>(cpMomentForCircle(mass, 0.f, m_radius, cpv(m_offset.x, m_offset.y)));
}
ColliderType2D CircleCollider2D::GetType() const
{
return ColliderType2D_Circle;
}
std::vector<cpShape*> CircleCollider2D::CreateShapes(RigidBody2D* body) const
{
std::vector<cpShape*> shapes;
shapes.push_back(cpCircleShapeNew(body->GetHandle(), m_radius, cpv(m_offset.x, m_offset.y)));
return shapes;
}
/********************************* NullCollider2D **********************************/
ColliderType2D NullCollider2D::GetType() const
{
return ColliderType2D_Null;
}
float NullCollider2D::ComputeInertialMatrix(float /*mass*/) const
{
return 0.f;
}
std::vector<cpShape*> NullCollider2D::CreateShapes(RigidBody2D* /*body*/) const
{
return std::vector<cpShape*>();
}
}

View File

@ -1,8 +1,8 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics/Config.hpp>
#include <Nazara/Physics3D/Config.hpp>
#if NAZARA_PHYSICS_MANAGE_MEMORY
#include <Nazara/Core/MemoryManager.hpp>

View File

@ -0,0 +1,60 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <chipmunk/chipmunk.h>
#include <Nazara/Physics2D/Debug.hpp>
namespace Nz
{
PhysWorld2D::PhysWorld2D() :
m_stepSize(0.005f),
m_timestepAccumulator(0.f)
{
m_handle = cpSpaceNew();
cpSpaceSetUserData(m_handle, this);
}
PhysWorld2D::~PhysWorld2D()
{
cpSpaceFree(m_handle);
}
Vector2f PhysWorld2D::GetGravity() const
{
cpVect gravity = cpSpaceGetGravity(m_handle);
return Vector2f(gravity.x, gravity.y);
}
cpSpace* PhysWorld2D::GetHandle() const
{
return m_handle;
}
float PhysWorld2D::GetStepSize() const
{
return m_stepSize;
}
void PhysWorld2D::SetGravity(const Vector2f& gravity)
{
cpSpaceSetGravity(m_handle, cpv(gravity.x, gravity.y));
}
void PhysWorld2D::SetStepSize(float stepSize)
{
m_stepSize = stepSize;
}
void PhysWorld2D::Step(float timestep)
{
m_timestepAccumulator += timestep;
while (m_timestepAccumulator >= m_stepSize)
{
cpSpaceStep(m_handle, m_stepSize);
m_timestepAccumulator -= m_stepSize;
}
}
}

View File

@ -0,0 +1,59 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/Physics2D.hpp>
#include <Nazara/Core/Core.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Physics2D/Debug.hpp>
namespace Nz
{
bool Physics2D::Initialize()
{
if (s_moduleReferenceCounter > 0)
{
s_moduleReferenceCounter++;
return true; // Déjà initialisé
}
// Initialisation des dépendances
if (!Core::Initialize())
{
NazaraError("Failed to initialize core module");
return false;
}
s_moduleReferenceCounter++;
NazaraNotice("Initialized: Physics2D module");
return true;
}
bool Physics2D::IsInitialized()
{
return s_moduleReferenceCounter != 0;
}
void Physics2D::Uninitialize()
{
if (s_moduleReferenceCounter != 1)
{
// Le module est soit encore utilisé, soit pas initialisé
if (s_moduleReferenceCounter > 1)
s_moduleReferenceCounter--;
return;
}
// Libération du module
s_moduleReferenceCounter = 0;
NazaraNotice("Uninitialized: Physics2D module");
// Libération des dépendances
Core::Uninitialize();
}
unsigned int Physics2D::s_moduleReferenceCounter = 0;
}

View File

@ -0,0 +1,251 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 2D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics2D/RigidBody2D.hpp>
#include <Nazara/Math/Algorithm.hpp>
#include <Nazara/Physics2D/Config.hpp>
#include <Nazara/Physics2D/PhysWorld2D.hpp>
#include <chipmunk/chipmunk.h>
#include <chipmunk/chipmunk_private.h>
#include <algorithm>
#include <Nazara/Physics3D/Debug.hpp>
namespace Nz
{
RigidBody2D::RigidBody2D(PhysWorld2D* world, float mass) :
RigidBody2D(world, mass, nullptr)
{
}
RigidBody2D::RigidBody2D(PhysWorld2D* world, float mass, Collider2DRef geom) :
m_geom(),
m_world(world),
m_gravityFactor(1.f),
m_mass(0.f)
{
NazaraAssert(m_world, "Invalid world");
m_handle = cpBodyNew(0.f, 0.f);
cpBodySetUserData(m_handle, this);
cpSpaceAddBody(m_world->GetHandle(), m_handle);
SetGeom(geom);
SetMass(mass);
}
RigidBody2D::RigidBody2D(const RigidBody2D& object) :
m_geom(object.m_geom),
m_world(object.m_world),
m_gravityFactor(object.m_gravityFactor),
m_mass(0.f)
{
NazaraAssert(m_world, "Invalid world");
NazaraAssert(m_geom, "Invalid geometry");
m_handle = cpBodyNew(0.f, 0.f);
cpBodySetUserData(m_handle, this);
cpSpaceAddBody(m_world->GetHandle(), m_handle);
SetGeom(object.GetGeom());
SetMass(object.GetMass());
}
RigidBody2D::RigidBody2D(RigidBody2D&& object) :
m_shapes(std::move(object.m_shapes)),
m_geom(std::move(object.m_geom)),
m_handle(object.m_handle),
m_world(object.m_world),
m_gravityFactor(object.m_gravityFactor),
m_mass(object.m_mass)
{
object.m_handle = nullptr;
}
RigidBody2D::~RigidBody2D()
{
Destroy();
}
void RigidBody2D::AddForce(const Vector2f& force, CoordSys coordSys)
{
return AddForce(force, GetCenterOfGravity(coordSys), coordSys);
}
void RigidBody2D::AddForce(const Vector2f& force, const Vector2f& point, CoordSys coordSys)
{
switch (coordSys)
{
case CoordSys_Global:
cpBodyApplyForceAtWorldPoint(m_handle, cpv(force.x, force.y), cpv(force.x, force.y));
break;
case CoordSys_Local:
cpBodyApplyForceAtLocalPoint(m_handle, cpv(force.x, force.y), cpv(point.x, point.y));
break;
}
}
void RigidBody2D::AddTorque(float torque)
{
cpBodySetTorque(m_handle, cpBodyGetTorque(m_handle) + torque);
}
Rectf RigidBody2D::GetAABB() const
{
cpBB bb = cpBBNew(0.f, 0.f, 0.f, 0.f);
for (cpShape* shape : m_shapes)
bb = cpBBMerge(bb, cpShapeGetBB(shape));
return Rectf(Rect<cpFloat>(bb.l, bb.t, bb.r - bb.l, bb.b - bb.t));
}
float RigidBody2D::GetAngularVelocity() const
{
return static_cast<float>(cpBodyGetAngularVelocity(m_handle));
}
const Collider2DRef& RigidBody2D::GetGeom() const
{
return m_geom;
}
cpBody* RigidBody2D::GetHandle() const
{
return m_handle;
}
float RigidBody2D::GetMass() const
{
return m_mass;
}
Vector2f RigidBody2D::GetCenterOfGravity(CoordSys coordSys) const
{
cpVect cog = cpBodyGetCenterOfGravity(m_handle);
switch (coordSys)
{
case CoordSys_Global:
cog = cpBodyLocalToWorld(m_handle, cog);
break;
case CoordSys_Local:
break; // Nothing to do
}
return Vector2f(static_cast<float>(cog.x), static_cast<float>(cog.y));
}
Vector2f RigidBody2D::GetPosition() const
{
cpVect pos = cpBodyGetPosition(m_handle);
return Vector2f(static_cast<float>(pos.x), static_cast<float>(pos.y));
}
float RigidBody2D::GetRotation() const
{
return static_cast<float>(cpBodyGetAngle(m_handle));
}
Vector2f RigidBody2D::GetVelocity() const
{
cpVect vel = cpBodyGetVelocity(m_handle);
return Vector2f(static_cast<float>(vel.x), static_cast<float>(vel.y));
}
bool RigidBody2D::IsMoveable() const
{
return m_mass > 0.f;
}
bool RigidBody2D::IsSleeping() const
{
return cpBodyIsSleeping(m_handle) != 0;
}
void RigidBody2D::SetAngularVelocity(float angularVelocity)
{
cpBodySetAngularVelocity(m_handle, angularVelocity);
}
void RigidBody2D::SetMass(float mass)
{
if (m_mass > 0.f)
{
if (mass > 0.f)
cpBodySetMass(m_handle, mass);
else
cpBodySetType(m_handle, CP_BODY_TYPE_STATIC);
}
else if (mass > 0.f)
{
if (cpBodyGetType(m_handle) == CP_BODY_TYPE_STATIC)
cpBodySetType(m_handle, CP_BODY_TYPE_DYNAMIC);
}
m_mass = mass;
}
void RigidBody2D::SetMassCenter(const Vector2f& center)
{
if (m_mass > 0.f)
cpBodySetCenterOfGravity(m_handle, cpv(center.x, center.y));
}
void RigidBody2D::SetPosition(const Vector2f& position)
{
cpBodySetPosition(m_handle, cpv(position.x, position.y));
}
void RigidBody2D::SetRotation(float rotation)
{
cpBodySetAngle(m_handle, rotation);
}
void RigidBody2D::SetVelocity(const Vector2f& velocity)
{
cpBodySetVelocity(m_handle, cpv(velocity.x, velocity.y));
}
RigidBody2D& RigidBody2D::operator=(const RigidBody2D& object)
{
RigidBody2D physObj(object);
return operator=(std::move(physObj));
}
RigidBody2D& RigidBody2D::operator=(RigidBody2D&& object)
{
Destroy();
m_handle = object.m_handle;
m_geom = std::move(object.m_geom);
m_gravityFactor = object.m_gravityFactor;
m_mass = object.m_mass;
m_shapes = std::move(object.m_shapes);
m_world = object.m_world;
object.m_handle = nullptr;
return *this;
}
void RigidBody2D::Destroy()
{
for (cpShape* shape : m_shapes)
cpShapeFree(shape);
if (m_handle)
cpBodyFree(m_handle);
}
void RigidBody2D::SetGeom(Collider2DRef geom)
{
if (geom)
m_geom = geom;
else
m_geom = NullCollider2D::New();
m_shapes = m_geom->CreateShapes(this);
}
}

View File

@ -0,0 +1,445 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics3D/Collider3D.hpp>
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <Newton/Newton.h>
#include <memory>
#include <Nazara/Physics3D/Debug.hpp>
namespace Nz
{
namespace
{
Collider3DRef CreateGeomFromPrimitive(const Primitive& primitive)
{
switch (primitive.type)
{
case PrimitiveType_Box:
return BoxCollider3D::New(primitive.box.lengths, primitive.matrix);
case PrimitiveType_Cone:
return ConeCollider3D::New(primitive.cone.length, primitive.cone.radius, primitive.matrix);
case PrimitiveType_Plane:
return BoxCollider3D::New(Vector3f(primitive.plane.size.x, 0.01f, primitive.plane.size.y), primitive.matrix);
///TODO: PlaneGeom?
case PrimitiveType_Sphere:
return SphereCollider3D::New(primitive.sphere.size, primitive.matrix.GetTranslation());
}
NazaraError("Primitive type not handled (0x" + String::Number(primitive.type, 16) + ')');
return Collider3DRef();
}
}
Collider3D::~Collider3D()
{
for (auto& pair : m_handles)
NewtonDestroyCollision(pair.second);
}
Boxf Collider3D::ComputeAABB(const Vector3f& translation, const Quaternionf& rotation, const Vector3f& scale) const
{
return ComputeAABB(Matrix4f::Transform(translation, rotation), scale);
}
Boxf Collider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
{
Vector3f min, max;
// Si nous n'avons aucune instance, nous en créons une temporaire
if (m_handles.empty())
{
PhysWorld3D world;
NewtonCollision* collision = CreateHandle(&world);
{
NewtonCollisionCalculateAABB(collision, offsetMatrix, min, max);
}
NewtonDestroyCollision(collision);
}
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
NewtonCollisionCalculateAABB(m_handles.begin()->second, offsetMatrix, min, max);
return Boxf(scale * min, scale * max);
}
void Collider3D::ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const
{
float inertiaMatrix[3];
float origin[3];
// Si nous n'avons aucune instance, nous en créons une temporaire
if (m_handles.empty())
{
PhysWorld3D world;
NewtonCollision* collision = CreateHandle(&world);
{
NewtonConvexCollisionCalculateInertialMatrix(collision, inertiaMatrix, origin);
}
NewtonDestroyCollision(collision);
}
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
NewtonConvexCollisionCalculateInertialMatrix(m_handles.begin()->second, inertiaMatrix, origin);
if (inertia)
inertia->Set(inertiaMatrix);
if (center)
center->Set(origin);
}
float Collider3D::ComputeVolume() const
{
float volume;
// Si nous n'avons aucune instance, nous en créons une temporaire
if (m_handles.empty())
{
PhysWorld3D world;
NewtonCollision* collision = CreateHandle(&world);
{
volume = NewtonConvexCollisionCalculateVolume(collision);
}
NewtonDestroyCollision(collision);
}
else // Sinon on utilise une instance au hasard (elles sont toutes identiques de toute façon)
volume = NewtonConvexCollisionCalculateVolume(m_handles.begin()->second);
return volume;
}
NewtonCollision* Collider3D::GetHandle(PhysWorld3D* world) const
{
auto it = m_handles.find(world);
if (it == m_handles.end())
it = m_handles.insert(std::make_pair(world, CreateHandle(world))).first;
return it->second;
}
Collider3DRef Collider3D::Build(const PrimitiveList& list)
{
std::size_t primitiveCount = list.GetSize();
if (primitiveCount > 1)
{
std::vector<Collider3D*> geoms(primitiveCount);
for (unsigned int i = 0; i < primitiveCount; ++i)
geoms[i] = CreateGeomFromPrimitive(list.GetPrimitive(i));
return CompoundCollider3D::New(&geoms[0], primitiveCount);
}
else if (primitiveCount > 0)
return CreateGeomFromPrimitive(list.GetPrimitive(0));
else
return NullCollider3D::New();
}
bool Collider3D::Initialize()
{
if (!Collider3DLibrary::Initialize())
{
NazaraError("Failed to initialise library");
return false;
}
return true;
}
void Collider3D::Uninitialize()
{
Collider3DLibrary::Uninitialize();
}
Collider3DLibrary::LibraryMap Collider3D::s_library;
/********************************** BoxCollider3D **********************************/
BoxCollider3D::BoxCollider3D(const Vector3f& lengths, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_lengths(lengths)
{
}
BoxCollider3D::BoxCollider3D(const Vector3f& lengths, const Vector3f& translation, const Quaternionf& rotation) :
BoxCollider3D(lengths, Matrix4f::Transform(translation, rotation))
{
}
Boxf BoxCollider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
{
Vector3f halfLengths(m_lengths * 0.5f);
Boxf aabb(-halfLengths.x, -halfLengths.y, -halfLengths.z, m_lengths.x, m_lengths.y, m_lengths.z);
aabb.Transform(offsetMatrix, true);
aabb *= scale;
return aabb;
}
float BoxCollider3D::ComputeVolume() const
{
return m_lengths.x * m_lengths.y * m_lengths.z;
}
Vector3f BoxCollider3D::GetLengths() const
{
return m_lengths;
}
ColliderType3D BoxCollider3D::GetType() const
{
return ColliderType3D_Box;
}
NewtonCollision* BoxCollider3D::CreateHandle(PhysWorld3D* world) const
{
return NewtonCreateBox(world->GetHandle(), m_lengths.x, m_lengths.y, m_lengths.z, 0, m_matrix);
}
/******************************** CapsuleCollider3D ********************************/
CapsuleCollider3D::CapsuleCollider3D(float length, float radius, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_length(length),
m_radius(radius)
{
}
CapsuleCollider3D::CapsuleCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
CapsuleCollider3D(length, radius, Matrix4f::Transform(translation, rotation))
{
}
float CapsuleCollider3D::GetLength() const
{
return m_length;
}
float CapsuleCollider3D::GetRadius() const
{
return m_radius;
}
ColliderType3D CapsuleCollider3D::GetType() const
{
return ColliderType3D_Capsule;
}
NewtonCollision* CapsuleCollider3D::CreateHandle(PhysWorld3D* world) const
{
return NewtonCreateCapsule(world->GetHandle(), m_radius, m_length, 0, m_matrix);
}
/******************************* CompoundCollider3D ********************************/
CompoundCollider3D::CompoundCollider3D(Collider3D** geoms, std::size_t geomCount)
{
m_geoms.reserve(geomCount);
for (std::size_t i = 0; i < geomCount; ++i)
m_geoms.emplace_back(geoms[i]);
}
const std::vector<Collider3DRef>& CompoundCollider3D::GetGeoms() const
{
return m_geoms;
}
ColliderType3D CompoundCollider3D::GetType() const
{
return ColliderType3D_Compound;
}
NewtonCollision* CompoundCollider3D::CreateHandle(PhysWorld3D* world) const
{
NewtonCollision* compoundCollision = NewtonCreateCompoundCollision(world->GetHandle(), 0);
NewtonCompoundCollisionBeginAddRemove(compoundCollision);
for (const Collider3DRef& geom : m_geoms)
{
if (geom->GetType() == ColliderType3D_Compound)
{
CompoundCollider3D* compoundGeom = static_cast<CompoundCollider3D*>(geom.Get());
for (const Collider3DRef& piece : compoundGeom->GetGeoms())
NewtonCompoundCollisionAddSubCollision(compoundCollision, piece->GetHandle(world));
}
else
NewtonCompoundCollisionAddSubCollision(compoundCollision, geom->GetHandle(world));
}
NewtonCompoundCollisionEndAddRemove(compoundCollision);
return compoundCollision;
}
/********************************* ConeCollider3D **********************************/
ConeCollider3D::ConeCollider3D(float length, float radius, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_length(length),
m_radius(radius)
{
}
ConeCollider3D::ConeCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
ConeCollider3D(length, radius, Matrix4f::Transform(translation, rotation))
{
}
float ConeCollider3D::GetLength() const
{
return m_length;
}
float ConeCollider3D::GetRadius() const
{
return m_radius;
}
ColliderType3D ConeCollider3D::GetType() const
{
return ColliderType3D_Cone;
}
NewtonCollision* ConeCollider3D::CreateHandle(PhysWorld3D* world) const
{
return NewtonCreateCone(world->GetHandle(), m_radius, m_length, 0, m_matrix);
}
/****************************** ConvexCollider3D *******************************/
ConvexCollider3D::ConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount, float tolerance, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_tolerance(tolerance)
{
m_vertices.resize(vertexCount);
if (vertices.GetStride() != sizeof(Vector3f))
{
for (unsigned int i = 0; i < vertexCount; ++i)
m_vertices[i] = *vertices++;
}
else // Fast path
std::memcpy(m_vertices.data(), vertices, vertexCount*sizeof(Vector3f));
}
ConvexCollider3D::ConvexCollider3D(SparsePtr<const Vector3f> vertices, unsigned int vertexCount, float tolerance, const Vector3f& translation, const Quaternionf& rotation) :
ConvexCollider3D(vertices, vertexCount, tolerance, Matrix4f::Transform(translation, rotation))
{
}
ColliderType3D ConvexCollider3D::GetType() const
{
return ColliderType3D_Compound;
}
NewtonCollision* ConvexCollider3D::CreateHandle(PhysWorld3D* world) const
{
return NewtonCreateConvexHull(world->GetHandle(), static_cast<int>(m_vertices.size()), reinterpret_cast<const float*>(m_vertices.data()), sizeof(Vector3f), m_tolerance, 0, m_matrix);
}
/******************************* CylinderCollider3D ********************************/
CylinderCollider3D::CylinderCollider3D(float length, float radius, const Matrix4f& transformMatrix) :
m_matrix(transformMatrix),
m_length(length),
m_radius(radius)
{
}
CylinderCollider3D::CylinderCollider3D(float length, float radius, const Vector3f& translation, const Quaternionf& rotation) :
CylinderCollider3D(length, radius, Matrix4f::Transform(translation, rotation))
{
}
float CylinderCollider3D::GetLength() const
{
return m_length;
}
float CylinderCollider3D::GetRadius() const
{
return m_radius;
}
ColliderType3D CylinderCollider3D::GetType() const
{
return ColliderType3D_Cylinder;
}
NewtonCollision* CylinderCollider3D::CreateHandle(PhysWorld3D* world) const
{
return NewtonCreateCylinder(world->GetHandle(), m_radius, m_length, 0, m_matrix);
}
/********************************* NullCollider3D **********************************/
NullCollider3D::NullCollider3D()
{
}
ColliderType3D NullCollider3D::GetType() const
{
return ColliderType3D_Null;
}
void NullCollider3D::ComputeInertialMatrix(Vector3f* inertia, Vector3f* center) const
{
if (inertia)
inertia->MakeUnit();
if (center)
center->MakeZero();
}
NewtonCollision* NullCollider3D::CreateHandle(PhysWorld3D* world) const
{
return NewtonCreateNull(world->GetHandle());
}
/******************************** SphereCollider3D *********************************/
SphereCollider3D::SphereCollider3D(float radius, const Matrix4f& transformMatrix) :
SphereCollider3D(radius, transformMatrix.GetTranslation())
{
}
SphereCollider3D::SphereCollider3D(float radius, const Vector3f& translation, const Quaternionf& rotation) :
m_position(translation),
m_radius(radius)
{
NazaraUnused(rotation);
}
Boxf SphereCollider3D::ComputeAABB(const Matrix4f& offsetMatrix, const Vector3f& scale) const
{
Vector3f size(m_radius * NazaraSuffixMacro(M_SQRT3, f) * scale);
Vector3f position(offsetMatrix.GetTranslation());
return Boxf(position - size, position + size);
}
float SphereCollider3D::ComputeVolume() const
{
return float(M_PI) * m_radius * m_radius * m_radius / 3.f;
}
float SphereCollider3D::GetRadius() const
{
return m_radius;
}
ColliderType3D SphereCollider3D::GetType() const
{
return ColliderType3D_Sphere;
}
NewtonCollision* SphereCollider3D::CreateHandle(PhysWorld3D* world) const
{
return NewtonCreateSphere(world->GetHandle(), m_radius, 0, Matrix4f::Translate(m_position));
}
}

View File

@ -0,0 +1,31 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics3D/Config.hpp>
#if NAZARA_PHYSICS_MANAGE_MEMORY
#include <Nazara/Core/MemoryManager.hpp>
#include <new> // Nécessaire ?
void* operator new(std::size_t size)
{
return Nz::MemoryManager::Allocate(size, false);
}
void* operator new[](std::size_t size)
{
return Nz::MemoryManager::Allocate(size, true);
}
void operator delete(void* pointer) noexcept
{
Nz::MemoryManager::Free(pointer, false);
}
void operator delete[](void* pointer) noexcept
{
Nz::MemoryManager::Free(pointer, true);
}
#endif // NAZARA_PHYSICS_MANAGE_MEMORY

View File

@ -1,14 +1,14 @@
// Copyright (C) 2015 Jérôme Leclercq
// This file is part of the "Nazara Engine - Physics module"
// This file is part of the "Nazara Engine - Physics 3D module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Physics/PhysWorld.hpp>
#include <Nazara/Physics3D/PhysWorld3D.hpp>
#include <Newton/Newton.h>
#include <Nazara/Physics/Debug.hpp>
#include <Nazara/Physics3D/Debug.hpp>
namespace Nz
{
PhysWorld::PhysWorld() :
PhysWorld3D::PhysWorld3D() :
m_gravity(Vector3f::Zero()),
m_stepSize(0.005f),
m_timestepAccumulator(0.f)
@ -17,42 +17,42 @@ namespace Nz
NewtonWorldSetUserData(m_world, this);
}
PhysWorld::~PhysWorld()
PhysWorld3D::~PhysWorld3D()
{
NewtonDestroy(m_world);
}
Vector3f PhysWorld::GetGravity() const
Vector3f PhysWorld3D::GetGravity() const
{
return m_gravity;
}
NewtonWorld* PhysWorld::GetHandle() const
NewtonWorld* PhysWorld3D::GetHandle() const
{
return m_world;
}
float PhysWorld::GetStepSize() const
float PhysWorld3D::GetStepSize() const
{
return m_stepSize;
}
void PhysWorld::SetGravity(const Vector3f& gravity)
void PhysWorld3D::SetGravity(const Vector3f& gravity)
{
m_gravity = gravity;
}
void PhysWorld::SetSolverModel(unsigned int model)
void PhysWorld3D::SetSolverModel(unsigned int model)
{
NewtonSetSolverModel(m_world, model);
}
void PhysWorld::SetStepSize(float stepSize)
void PhysWorld3D::SetStepSize(float stepSize)
{
m_stepSize = stepSize;
}
void PhysWorld::Step(float timestep)
void PhysWorld3D::Step(float timestep)
{
m_timestepAccumulator += timestep;

Some files were not shown because too many files have changed in this diff Show More