本文整理汇总了C++中std::shared_ptr::CreateGameObject方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::CreateGameObject方法的具体用法?C++ shared_ptr::CreateGameObject怎么用?C++ shared_ptr::CreateGameObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::shared_ptr
的用法示例。
在下文中一共展示了shared_ptr::CreateGameObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateGameObject
void LaserTowerFactory::CreateGameObject(std::shared_ptr<Engine::GameObject> gameObject) const
{
// Add a transform attribute to the base.
std::shared_ptr<Engine::Attribute::Transform> baseTransform =
gameObject->CreateAttribute<Engine::Attribute::Transform>();
baseTransform->SetScale(20.0f);
// Add a shader program to the base.
gameObject->CreateAttribute<Engine::Attribute::ShaderProgram>(
"resources/shaders/Phong.vert",
"resources/shaders/Phong.frag"
);
// Add a model attribute to the base.
gameObject->CreateAttribute<Engine::Attribute::Model>("resources/models/lasertower/LaserTowerBase.dae");
// Add a child game object to the base for the turret.
std::shared_ptr<Engine::GameObject> turret = gameObject->CreateGameObject();
// Add a transform attribute to the turret.
std::shared_ptr<Engine::Attribute::Transform> turretTransform =
turret->CreateAttribute<Engine::Attribute::Transform>();
turretTransform->SetLocalPosition(glm::vec3(0.0f, 25.0f, 0.0f));
// Add a shader program attribute to the turret.
turret->CreateAttribute<Engine::Attribute::ShaderProgram>(
"resources/shaders/Phong.vert",
"resources/shaders/Phong.frag"
);
// Add a model attribute to the turret.
turret->CreateAttribute<Engine::Attribute::Model>("resources/models/lasertower/LaserTowerTurret.dae");
// Add a bounding sphere attribute to the turret.
// This represents the range of the laser tower's radar.
// Note that the sphere radius is multiplied by the transform's scale.
turret->CreateAttribute<Engine::Attribute::BoundingSphere>(4.0f, "Radar");
// Add a tags attribute to the turret.
std::shared_ptr<Attribute::Tags> turretTags = turret->CreateAttribute<Attribute::Tags>();
// Add a nearest target acquisition behaviour to the turret.
turret->CreateBehaviour<Behaviour::AcquireNearestTarget>(turretTransform, turretTags, "Enemy");
// Add a face target behaviour to the turret.
turret->CreateBehaviour<Behaviour::FaceAcquiredTarget>(
turretTransform,
0.75f * 2.0f * M_PI // Rotation speed (radians per second)
);
// Add a fire laser at acquired target behaviour to the turret.
// Add a fire rockets at acquired targe behaviour to the turret.
turret->CreateBehaviour<Behaviour::FireLaserAtAcquiredTarget>(turretTransform);
// Add a child game object to the base for the range display.
RangeFactory factory(4.0f);
gameObject->CreateGameObject(factory);
}