本文整理汇总了C++中SPtr::addLight方法的典型用法代码示例。如果您正苦于以下问题:C++ SPtr::addLight方法的具体用法?C++ SPtr::addLight怎么用?C++ SPtr::addLight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPtr
的用法示例。
在下文中一共展示了SPtr::addLight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: use
bool ThrowAbility::use() {
if (isOnCooldown()) {
return false;
}
SPtr<Scene> scene = gameObject.getScene().lock();
if (!scene) {
return false;
}
const glm::vec3 &position = gameObject.getCameraComponent().getCameraPosition();
const glm::vec3 &front = gameObject.getCameraComponent().getFrontVector();
const glm::vec3 &right = gameObject.getCameraComponent().getRightVector();
SPtr<GameObject> projectile(std::make_shared<GameObject>());
projectile->setPosition(position + front + right * 0.25f);
projectile->setScale(glm::vec3(PROJECTILE_SCALE));
// Graphics
SPtr<Model> playerModel = gameObject.getGraphicsComponent().getModel();
SPtr<Mesh> mesh = Context::getInstance().getAssetManager().loadMesh("meshes/rock_attack.obj");
glm::vec3 color(1.0f, 0.75f, 0.15f);
PlayerLogicComponent *playerLogic = dynamic_cast<PlayerLogicComponent*>(&gameObject.getLogicComponent());
if (playerLogic) {
color = playerLogic->getColor();
}
SPtr<Material> material(std::make_shared<PhongMaterial>(color * 0.2f, color * 0.6f, glm::vec3(0.2f), color * 0.2f, 50.0f));
SPtr<Model> model(std::make_shared<Model>(playerModel->getShaderProgram(), mesh));
model->attachMaterial(material);
projectile->setGraphicsComponent(std::make_shared<GeometricGraphicsComponent>(*projectile));
projectile->getGraphicsComponent().setModel(model);
// Physics
projectile->setPhysicsComponent(std::make_shared<MeshPhysicsComponent>(*projectile, 0.05f, CollisionGroup::Projectiles, CollisionGroup::Everything));
btRigidBody *projectileRigidBody = dynamic_cast<btRigidBody*>(projectile->getPhysicsComponent().getCollisionObject());
projectileRigidBody->setFriction(1.0f);
projectileRigidBody->setRollingFriction(0.25f);
projectileRigidBody->setRestitution(0.5f);
projectileRigidBody->applyCentralForce(toBt(front * 100.0f));
// Logic
SPtr<ProjectileLogicComponent> logic(std::make_shared<ProjectileLogicComponent>(*projectile));
WPtr<GameObject> wProjectile(projectile);
GameObject &creator = gameObject;
logic->setCollisionCallback([wProjectile, color, &creator](GameObject &gameObject, const btCollisionObject *objectCollidedWidth, const float dt) {
if (objectCollidedWidth == creator.getPhysicsComponent().getCollisionObject()) {
return;
}
SPtr<Scene> scene = gameObject.getScene().lock();
if (!scene) {
return;
}
SPtr<GameObject> projectile = wProjectile.lock();
if (!projectile) {
return;
}
scene->removeObject(projectile);
SPtr<GameObject> explosion(createExplosion(projectile->getPosition(), 1.0f, color));
scene->addLight(explosion);
scene->addObject(explosion);
});
projectile->setLogicComponent(logic);
// Audio
SPtr<AudioComponent> audioComponent(std::make_shared<AudioComponent>(*projectile));
audioComponent->registerSoundEvent(Event::SET_SCENE, SoundGroup::THROW);
projectile->setAudioComponent(audioComponent);
scene->addObject(projectile);
resetTimeSinceLastUse();
return true;
}