Ecs::Entity createAttackArea( Threading::ConcurrentWriter<Ecs::World>& world, const Ecs::Entity& character ) { Ecs::Entity area = world->createEntity(); Vec3Df basePosition; Vec3Df rotation; unsigned int damages = 0; { Ecs::ComponentGroup::ComponentTypeCollection types; types.insert(StatisticsComponent::Type); types.insert(CharacterComponent::Type); types.insert(PositionComponent::Type); types.insert(RotationComponent::Type); Ecs::ComponentGroup prototype(types); Ecs::ComponentGroup group = world->getEntityComponents( character, prototype ); Threading::ConcurrentWriter<CharacterComponent> characterComponent = Threading::getConcurrentWriter<Ecs::Component, CharacterComponent>( group.getComponent(CharacterComponent::Type) ); Threading::ConcurrentReader<StatisticsComponent> statComponent = Threading::getConcurrentReader<Ecs::Component, StatisticsComponent>( group.getComponent(StatisticsComponent::Type) ); Threading::ConcurrentReader<PositionComponent> posComponent = Threading::getConcurrentReader<Ecs::Component, PositionComponent>( group.getComponent(PositionComponent::Type) ); Threading::ConcurrentReader<RotationComponent> rotComponent = Threading::getConcurrentReader<Ecs::Component, RotationComponent>( group.getComponent(RotationComponent::Type) ); damages = statComponent->getStatistics().getAttack().getCurrentValue(); characterComponent->setAttackArea(area); basePosition = posComponent->getPosition(); rotation = rotComponent->getRotation(); } Geometry::Vec2Df offset = Geometry::Vec2Df::fromPolar( rotation.getZ(), 1.5 ) - Geometry::Vec2Df(0.5, 0.5); Geometry::AxisAlignedBoundingBox bbox( Geometry::Vec3Df(0.0, 0.0, 0.0), Geometry::Vec3Df(1.0, 1.0, 1.0) ); world->addComponent(area, new PositionComponent( basePosition + Vec3Df(offset.getX(), offset.getY(), 0) )); world->addComponent(area, new RotationComponent( Vec3Df(0, 0, 0) )); world->addComponent(area, new Physics::CollisionComponent( new Physics::AABBCollisionBody(bbox) )); world->addComponent(area, new HarmComponent( damages )); return area; }
irr::core::vector3df fromVec3Df(const Vec3Df& vec) { return irr::core::vector3df(vec.getY(), vec.getZ(), vec.getX()); }