// 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 #include #include #include #include #include #include #include namespace Ndk { /*! * \ingroup NDK * \class Ndk::PhysicsComponent * \brief NDK class that represents the component for physics (meant for dynamic objects) */ /*! * \brief Operation to perform when component is attached to an entity * * \remark Produces a NazaraAssert if the world does not have a physics system */ void PhysicsComponent::OnAttached() { World* entityWorld = m_entity->GetWorld(); NazaraAssert(entityWorld->HasSystem(), "World must have a physics system"); Nz::PhysWorld& world = entityWorld->GetSystem().GetWorld(); Nz::PhysGeomRef geom; if (m_entity->HasComponent()) geom = m_entity->GetComponent().GetGeom(); Nz::Matrix4f matrix; if (m_entity->HasComponent()) matrix = m_entity->GetComponent().GetTransformMatrix(); else matrix.MakeIdentity(); m_object.reset(new Nz::PhysObject(&world, geom, matrix)); m_object->SetMass(1.f); } /*! * \brief Operation to perform when component is attached to this component * * \param component Component being attached * * \remark Produces a NazaraAssert if physical object is invalid */ void PhysicsComponent::OnComponentAttached(BaseComponent& component) { if (IsComponent(component)) { NazaraAssert(m_object, "Invalid object"); m_object->SetGeom(static_cast(component).GetGeom()); } } /*! * \brief Operation to perform when component is detached from this component * * \param component Component being detached * * \remark Produces a NazaraAssert if physical object is invalid */ void PhysicsComponent::OnComponentDetached(BaseComponent& component) { if (IsComponent(component)) { NazaraAssert(m_object, "Invalid object"); m_object->SetGeom(Nz::NullGeom::New()); } } /*! * \brief Operation to perform when component is detached from an entity */ void PhysicsComponent::OnDetached() { m_object.reset(); } ComponentIndex PhysicsComponent::componentIndex; }