/** * @brief Sets the outer angle of the light cone * @param concentration Fall off of the light. The rate of falloff between the inner and outer cones. * 1.0 means a linear falloff, less means slower falloff, higher means faster falloff. */ void SpotLight::setConcentration( float concentration ) { // Check if the class is already released if ( !isValid() ) { LOG_ERROR( "Cannot setConcentration. Init needs to be called first to initialize the light" ); return; } // Set new falloff or concentration Ogre::Light* light = getOgreLight(); if ( light ) light->setSpotlightFalloff( concentration ); }
/** * @brief Sets the outer angle of the light cone * @param outerAngleRad Angle covered by the outer cone */ void SpotLight::setOuterAngle( float outerAngleRad ) { // Check if the class is already released if ( !isValid() ) { LOG_ERROR( "Cannot setOuterAngle. Init needs to be called first to initialize the light" ); return; } // Set new angle Ogre::Light* light = getOgreLight(); if ( light ) light->setSpotlightOuterAngle( Ogre::Radian(outerAngleRad) ); }
/** * @brief Sets the range of the lighet (inner and outer angles of the cone + the falloff between them) * @param innerAngleRad Angle covered by the bright inner cone The inner cone applicable only to Direct3D, it'll always treat as zero in OpenGL. * @param outerAngleRad Angle covered by the outer cone * @param concentration Fall off of the light. The rate of falloff between the inner and outer cones. * 1.0 means a linear falloff, less means slower falloff, higher means faster falloff. */ void SpotLight::setRange( float innerAngleRad, float outerAngleRad, float concentration /*= 1.0f*/ ) { // Check if the class is already released if ( !isValid() ) { LOG_ERROR( "Cannot setRange. Init needs to be called first to initialize the light" ); return; } // Set new range Ogre::Light* light = getOgreLight(); if ( light ) light->setSpotlightRange( Ogre::Radian(innerAngleRad), Ogre::Radian(outerAngleRad), concentration ); }
void LightEntity::notify(const LightInfo& linfo){ float32 ambientPower, shadowPower; ambientPower = computeClosestPower(linfo.mDiffuseColor, linfo.mAmbientColor * linfo.mPower); shadowPower = computeClosestPower(linfo.mSpecularColor, linfo.mShadowColor * linfo.mPower); Ogre::ColourValue diffuse_ambient ( toOgreRGBA(linfo.mDiffuseColor, ambientPower)); getOgreLight()->setDiffuseColour(diffuse_ambient); Ogre::ColourValue specular_shadow ( toOgreRGBA(linfo.mSpecularColor, shadowPower)); getOgreLight()->setSpecularColour(specular_shadow); getOgreLight()->setPowerScale(linfo.mPower); switch (linfo.mType) { case LightInfo::POINT: getOgreLight()->setType(Ogre::Light::LT_POINT); break; case LightInfo::SPOTLIGHT: getOgreLight()->setType(Ogre::Light::LT_SPOTLIGHT); break; case LightInfo::DIRECTIONAL: getOgreLight()->setType(Ogre::Light::LT_DIRECTIONAL); break; default:break; } if (linfo.mType!=LightInfo::DIRECTIONAL) { getOgreLight()->setAttenuation( linfo.mLightRange, linfo.mConstantFalloff, linfo.mLinearFalloff, linfo.mQuadraticFalloff); } if (linfo.mType==LightInfo::SPOTLIGHT) { getOgreLight()->setSpotlightRange( Ogre::Radian(linfo.mConeInnerRadians), Ogre::Radian(linfo.mConeOuterRadians), linfo.mConeFalloff); } getOgreLight()->setCastShadows(linfo.mCastsShadow); }
/** * @internal * @brief Initializes the class so it becomes valid. * * @param[in] r Red component of the diffuse color of the light. Value Range: 0..255 * @param[in] g Green component of the diffuse color of the light. Value Range: 0..255 * @param[in] b Blue component of the diffuse color of the light. Value Range: 0..255 * @param[in] x x coordinate (horizontal axis) of the light in the scene * @param[in] y y coordinate (vertical axis) of the light in the scene * @param[in] z z coordinate (depth) of the light in the scene * @param[in] nx x direction(horizontal axis) of the light in the scene * @param[in] ny y direction (vertical axis) of the light in the scene * @param[in] nz z direction (depth) of the light in the scene * @param[in] angleRad angle in radians of the spotlight cone. It is possible tolater control inner and outer angle of the light. * @param[in] concentration fall off of the light (Range: 0.0-1.0). Less means slower falloff, higher means faster falloff. * @return true if the initialization was ok | false otherwise */ bool SpotLight::init( float r, float g, float b, float x, float y, float z, float nx, float ny, float nz, float angleRad, float concentration ) { // Check if the class is already initialized if ( isValid() ) return true; // Init base light BaseLight::init( r, g, b, x, y, z ); // Set light type setLightType( Light::LT_SPOTLIGHT ); // Setup light setDirection( nx, ny, nz ); setDiffuseColor( r, g, b ); Ogre::Light* light = getOgreLight(); if ( light ) light->setSpotlightRange( Ogre::Radian(angleRad), Ogre::Radian(angleRad), concentration ); // The class is now initialized m_bIsValid = true; return true; }
Node::NodeSP SceneLoader::__loadLight(const QDomElement& og_component, Node::NodeSP dt_node) { Node::NodeSP node = dt_node; if ( !og_component.isNull() ) { QString name = og_component.attribute(SL_NAME); if ( node == nullptr ) { node = mScene->addChildNode(new Node(name + "_node")); QDomElement pos = og_component.firstChildElement(SL_POS); QDomElement dir = og_component.firstChildElement(SL_LIGHT_DIRECTION); node->setPosition(pos.attribute(SL_X).toFloat(), pos.attribute(SL_Y).toFloat(), pos.attribute(SL_Z).toFloat()); node->setDirection(Ogre::Vector3(dir.attribute(SL_X).toFloat(), dir.attribute(SL_Y).toFloat(), dir.attribute(SL_Z).toFloat())); } //add light component auto light = node->addComponent<LightComponent>(new LightComponent(name)); auto og_light = light->getOgreLight(); QDomElement colour_diffuse = og_component.firstChildElement(SL_LIGHT_DIFFUSE); QDomElement colour_specular = og_component.firstChildElement(SL_LIGHT_SPECULAR); QDomElement light_attenuation = og_component.firstChildElement(SL_LIGHT_ATTENUATION); //set light attributes og_light->setDiffuseColour(colour_diffuse.attribute(SL_COLOUR_R).toFloat(), colour_diffuse.attribute(SL_COLOUR_G).toFloat(), colour_diffuse.attribute(SL_COLOUR_B).toFloat()); og_light->setSpecularColour(colour_specular.attribute(SL_COLOUR_R).toFloat(), colour_specular.attribute(SL_COLOUR_G).toFloat(), colour_specular.attribute(SL_COLOUR_B).toFloat()); og_light->setAttenuation(light_attenuation.attribute(SL_LIGHT_ATTENUATION_RANGE).toFloat(), light_attenuation.attribute(SL_LIGHT_ATTENUATION_CONSTANT).toFloat(), light_attenuation.attribute(SL_LIGHT_ATTENUATION_LINEAR).toFloat(), light_attenuation.attribute(SL_LIGHT_ATTENUATION_QUADRATIC).toFloat()); QString light_type = og_component.attribute(SL_LIGHT_TYPE); if ( light_type == SL_LIGHT_TYPE_POINT ) { og_light->setType(Ogre::Light::LT_POINT); } else if ( light_type == SL_LIGHT_TYPE_DIRECTIONAL ) { og_light->setType(Ogre::Light::LT_DIRECTIONAL); } else if ( light_type == SL_LIGHT_TYPE_SPOT ) { og_light->setType(Ogre::Light::LT_SPOTLIGHT); QDomElement light_range = og_component.firstChildElement(SL_LIGHT_RANGE); og_light->setSpotlightRange(Ogre::Radian(light_range.attribute(SL_LIGHT_RANGE_INNER).toFloat()), Ogre::Radian(light_range.attribute(SL_LIGHT_RANGE_OUTER).toFloat()), light_range.attribute(SL_LIGHT_RANGE_FALLOFF).toFloat()); } QString cast_shadows = og_component.attribute(SL_CAST_SHADOWS); if ( cast_shadows == SL_TRUE ) { light->setCastShadows(true); } else if ( cast_shadows == SL_FALSE ) { light->setCastShadows(false); } light->enable(); } return node; }
LightEntity::~LightEntity() { Ogre::Light *toDestroy=getOgreLight(); init(NULL); mScene->getSceneManager()->destroyLight(toDestroy); getProxy().LightProvider::removeListener(this); }