diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 35df52a18..3d9c4df90 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -136,7 +136,7 @@ namespace MWWorld }; - void ProjectileManager::createModel(State &state, const std::string &model, const osg::Vec3f& pos, const osg::Quat& orient, bool rotate, std::string texture) + void ProjectileManager::createModel(State &state, const std::string &model, const osg::Vec3f& pos, const osg::Quat& orient, bool rotate, bool createLight, std::string texture) { state.mNode = new osg::PositionAttitudeTransform; state.mNode->setNodeMask(MWRender::Mask_Effect); @@ -167,6 +167,55 @@ namespace MWWorld mResourceSystem->getSceneManager()->getInstance("meshes\\" + weapon->mModel, findVisitor.mFoundNode); } + if (createLight) + { + // Case: magical effects (combine colors of individual effects) + osg::Vec4 lightDiffuseColor; + if (state.mIdMagic.size() > 0) + { + float lightDiffuseRed = 0.0f; + float lightDiffuseGreen = 0.0f; + float lightDiffuseBlue = 0.0f; + for (std::vector::const_iterator it = ((MagicBoltState&)state).mEffects.mList.begin(); it != ((MagicBoltState&)state).mEffects.mList.end(); ++it) + { + const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get().find( + it->mEffectID); + lightDiffuseRed += ((float) magicEffect->mData.mRed / 255.f); + lightDiffuseGreen += ((float) magicEffect->mData.mGreen / 255.f); + lightDiffuseBlue += ((float) magicEffect->mData.mBlue / 255.f); + } + int numberOfEffects = ((MagicBoltState&)state).mEffects.mList.size(); + lightDiffuseColor = osg::Vec4(lightDiffuseRed / numberOfEffects + , lightDiffuseGreen / numberOfEffects + , lightDiffuseBlue / numberOfEffects + , 1.0f); + } + else + { + // Case: no magical effects, but still creating light + lightDiffuseColor = osg::Vec4(0.814f, 0.682f, 0.652f, 1.0f); + } + + // Add light + osg::ref_ptr projectileLight(new osg::Light); + projectileLight->setAmbient(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); + projectileLight->setDiffuse(lightDiffuseColor); + projectileLight->setSpecular(osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f)); + projectileLight->setConstantAttenuation(0.f); + projectileLight->setLinearAttenuation(0.1f); + projectileLight->setQuadraticAttenuation(0.f); + projectileLight->setPosition(osg::Vec4(pos, 1.0)); + + // Add light source + SceneUtil::LightSource* projectileLightSource = new SceneUtil::LightSource; + projectileLightSource->setNodeMask(MWRender::Mask_Lighting); + projectileLightSource->setRadius(66.f); + + // Attach to scene node + state.mNode->addChild(projectileLightSource); + projectileLightSource->setLight(projectileLight); + } + SceneUtil::DisableFreezeOnCullVisitor disableFreezeOnCullVisitor; state.mNode->accept(disableFreezeOnCullVisitor); @@ -229,7 +278,7 @@ namespace MWWorld MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), state.mIdMagic.at(0)); MWWorld::Ptr ptr = ref.getPtr(); - createModel(state, ptr.getClass().getModel(ptr), pos, orient, true, texture); + createModel(state, ptr.getClass().getModel(ptr), pos, orient, true, true, texture); MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); for (size_t it = 0; it != state.mSoundIds.size(); it++) @@ -253,7 +302,7 @@ namespace MWWorld MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), projectile.getCellRef().getRefId()); MWWorld::Ptr ptr = ref.getPtr(); - createModel(state, ptr.getClass().getModel(ptr), pos, orient, false); + createModel(state, ptr.getClass().getModel(ptr), pos, orient, false, false); mProjectiles.push_back(state); } @@ -483,7 +532,7 @@ namespace MWWorld return true; } - createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), false); + createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), false, false); mProjectiles.push_back(state); return true; @@ -518,7 +567,7 @@ namespace MWWorld return true; } - createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), true, texture); + createModel(state, model, osg::Vec3f(esm.mPosition), osg::Quat(esm.mOrientation), true, true, texture); MWBase::SoundManager *sndMgr = MWBase::Environment::get().getSoundManager(); diff --git a/apps/openmw/mwworld/projectilemanager.hpp b/apps/openmw/mwworld/projectilemanager.hpp index a8769fcf9..db090eaef 100644 --- a/apps/openmw/mwworld/projectilemanager.hpp +++ b/apps/openmw/mwworld/projectilemanager.hpp @@ -122,7 +122,7 @@ namespace MWWorld void moveProjectiles(float dt); void moveMagicBolts(float dt); - void createModel (State& state, const std::string& model, const osg::Vec3f& pos, const osg::Quat& orient, bool rotate, std::string texture = ""); + void createModel (State& state, const std::string& model, const osg::Vec3f& pos, const osg::Quat& orient, bool rotate, bool createLight, std::string texture = ""); void update (State& state, float duration); void operator=(const ProjectileManager&);