// 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 { void PhysicsComponent::OnAttached() { World* entityWorld = m_entity->GetWorld(); NazaraAssert(entityWorld->HasSystem(), "World must have a physics system"); NzPhysWorld& world = entityWorld->GetSystem().GetWorld(); NzPhysGeomRef geom; if (m_entity->HasComponent()) geom = m_entity->GetComponent().GetGeom(); NzMatrix4f matrix; if (m_entity->HasComponent()) matrix = m_entity->GetComponent().GetTransformMatrix(); else matrix.MakeIdentity(); m_object.reset(new NzPhysObject(&world, geom, matrix)); m_object->SetMass(1.f); } void PhysicsComponent::OnComponentAttached(BaseComponent& component) { if (IsComponent(component)) { NazaraAssert(m_object, "Invalid object"); m_object->SetGeom(static_cast(component).GetGeom()); } } void PhysicsComponent::OnComponentDetached(BaseComponent& component) { if (IsComponent(component)) { NazaraAssert(m_object, "Invalid object"); m_object->SetGeom(NzNullGeom::New()); } } void PhysicsComponent::OnDetached() { m_object.reset(); } ComponentIndex PhysicsComponent::componentIndex; }