//----------------------------------------------------------------------------------------- bool CBillboardSetEditor::load(bool async) { if(mLoaded->get()) return true; if(CNodeEditor::load()) { mBillboardSetHandle = mOgitorsRoot->GetSceneManager()->createBillboardSet(mName->get()); mHandle->attachObject(mBillboardSetHandle); mBillboardSetHandle->setBillboardType((Ogre::BillboardType)mBillboardType->get()); mBillboardSetHandle->setSortingEnabled(mSorting->get()); mBillboardSetHandle->setBillboardOrigin((Ogre::BillboardOrigin)mOrigin->get()); mBillboardSetHandle->setBillboardRotationType((Ogre::BillboardRotationType)mRotation->get()); mBillboardSetHandle->setDefaultWidth(mDefaultWidth->get()); mBillboardSetHandle->setDefaultHeight(mDefaultHeight->get()); mBillboardSetHandle->setVisibilityFlags(1 << mLayer->get()); if(mMaterial->get() != "") mBillboardSetHandle->setMaterialName(mMaterial->get()); mBillboardSetHandle->setPointRenderingEnabled(mPointRendering->get()); mBillboardSetHandle->setRenderingDistance(mRenderDistance->get()); Ogre::Vector2 v2val; Ogre::Vector3 v3val; Ogre::Vector4 v4val; Ogre::ColourValue cval; Ogre::Real rval; int ival; Ogre::String propname; int count = mBillboardCount->get(); for(int ix = 0;ix < count;ix++) { propname = "billboard" + Ogre::StringConverter::toString(ix); Ogre::Billboard *pBillboard = mBillboardSetHandle->createBillboard(Ogre::Vector3::ZERO); mProperties.getValue(propname + "::position", v3val); pBillboard->setPosition(v3val); mProperties.getValue(propname + "::colour", cval); pBillboard->setColour(cval); mProperties.getValue(propname + "::dimensions", v2val); pBillboard->setDimensions(v2val.x, v2val.y); mProperties.getValue(propname + "::rotation", rval); pBillboard->setRotation(Ogre::Degree(rval)); mProperties.getValue(propname + "::texcoordindex", ival); pBillboard->setTexcoordIndex(ival); mProperties.getValue(propname + "::texrect", v4val); pBillboard->setTexcoordRect(v4val.x, v4val.y, v4val.z, v4val.w); } } else return false; return true; }
void Lightning::create() { remove(); Ogre::Vector3 end = mOrigin + mDirection*mLength; Ogre::Vector3 current, last = mOrigin; // Create ray segments for(Ogre::uint32 k = 1; k < mDivisions+1; k++) { Ogre::Vector3 current = mOrigin + mDirection*mLength*(static_cast<Ogre::Real>(k)/mDivisions); current += (mLength/(mDivisions*3))*Ogre::Vector3( Ogre::Math::RangeRandom(-1, 1), Ogre::Math::RangeRandom(-1, 1), Ogre::Math::RangeRandom(-1, 1)); mSegments.push_back(Segment(last, current)); mRealLength += (current-last).length(); last = current; } // Create the associated billboard set mBillboardSet = mSceneManager->createBillboardSet(); mBillboardSet->setMaterialName("SkyX_Lightning"); mBillboardSet->setBillboardType(Ogre::BBT_ORIENTED_SELF); Ogre::Real width = mWidthMultiplier*3*(static_cast<Ogre::Real>(mRecursivity)/4+1)*Ogre::Math::RangeRandom(0.5f, 2.5f-mRecursivity/3); // Create the associated billboard for each segment Ogre::Real delta; Ogre::Vector2 bounds; Ogre::Billboard* bb; for(Ogre::uint32 k = 0; k < mSegments.size(); k++) { delta = 1.0f / mSegments.size(); bounds = Ogre::Vector2(k*delta,(k+1)*delta); bounds = Ogre::Vector2(mBounds.x, mBounds.x) + bounds*(mBounds.y-mBounds.x); bb = mBillboardSet->createBillboard((mSegments.at(k).a+mSegments.at(k).b)/2); bb->setDimensions(width, (mSegments.at(k).a-mSegments.at(k).b).length()); bb->setColour(Ogre::ColourValue(0,bounds.x,bounds.y)); bb->mDirection = (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy(); bb = mBillboardSet->createBillboard(mSegments.at(k).a + (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy()*width/2); bb->setDimensions(width, width); bb->setColour(Ogre::ColourValue(1,bounds.x,bounds.x)); bb->mDirection = (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy(); bb = mBillboardSet->createBillboard(mSegments.at(k).b - (mSegments.at(k).a-mSegments.at(k).b).normalisedCopy()*width/2); bb->setDimensions(width, width); bb->setColour(Ogre::ColourValue(1,bounds.y,bounds.y)); bb->mDirection = -(mSegments.at(k).a-mSegments.at(k).b).normalisedCopy(); width *= 1-(1.0f/(mRecursivity*mRecursivity))*(1.0f/mSegments.size()); } mBillboardSet->_updateBounds(); mSceneNode->attachObject(mBillboardSet); mBillboardSet->setCustomParameter(0, Ogre::Vector4(1,0,0,0)); // Ramifications if (mRecursivity > 0) { Ogre::Real angle; Ogre::Vector3 dir; Ogre::Real lengthMult; for (Ogre::uint32 k = 0; k < mDivisions-1; k++) { angle = (mSegments.at(k).b-mSegments.at(k).a).normalisedCopy().dotProduct( ((mSegments.at(k+1).b-mSegments.at(k+1).a).normalisedCopy())); if (angle < Ogre::Math::RangeRandom(mAngleRange.x, mAngleRange.y)) { dir = (mSegments.at(k).b-mSegments.at(k).a).normalisedCopy(); dir.x *= Ogre::Math::RangeRandom(0.8f, 1.2f); dir.y *= Ogre::Math::RangeRandom(0.8f, 1.2f); dir.z *= Ogre::Math::RangeRandom(0.8f, 1.2f); dir.normalise(); delta = 1.0f / mSegments.size(); bounds = Ogre::Vector2(mBounds.x+(mBounds.y-mBounds.x)*(k+1)*delta,1); lengthMult = Ogre::Math::RangeRandom(0.1f, 0.7f); Lightning* lightning = new Lightning(mSceneManager, mSceneNode, mSegments.at(k).b, dir, lengthMult*mLength, 2+mDivisions*lengthMult, mRecursivity-1, mTimeMultiplier, mWidthMultiplier, bounds); lightning->create(); mChildren.push_back(lightning); } } } mCreated = true; }
//--------------------------------------------------------------------- void BillboardSetElement::updateRenderInstance( Real time, TransformInfo &info ) { if (mBillboardSet) { bool updateTexIndex = false; if (mSlices > 1 || mStacks > 1) { mCurrentTexIntervalTime += time; if (mCurrentTexIntervalTime >= mTexIntervalTime) { updateTexIndex = true; mCurrentTexIntervalTime = 0.0f; } } for ( int i = 0; i < mBillboardSet->getNumBillboards(); ++i ) { Ogre::Billboard* billboard = mBillboardSet->getBillboard(i); if (updateTexIndex) { uint16 texIndex = billboard->getTexcoordIndex(); ++texIndex; if (texIndex == mStacks * mSlices) texIndex = 0; billboard->setTexcoordIndex(texIndex); } if (mColourChanged) billboard->setColour(mBillboardColour * mAlphaValue); if (mSizeChanged) { _CurrentScaleInfo& info = mCurrentScaleInfos[i]; info.mCurrentScaleIntervalTime += time; float colourPersent = fmod( info.mCurrentScaleIntervalTime, mScaleIntervalTime ); if (info.mCurrentScaleIntervalTime > mScaleIntervalTime) { info.mCurrentScaleIntervalTime = colourPersent; ++(info.mCurrentIndex); if (info.mCurrentIndex == MAX_STAGES) info.mCurrentIndex = 0; } Ogre::Vector3 resultColour; Real rate = colourPersent / mScaleIntervalTime; int incIndex = info.mCurrentIndex + 1; if (incIndex == MAX_STAGES) incIndex = 0; resultColour = mBillboardScale[info.mCurrentIndex] * (1-rate) + mBillboardScale[incIndex] * rate; billboard->setDimensions(mBillboardWidth * resultColour.x, mBillboardHeight * resultColour.y); } } if (mColourChanged) mColourChanged = false; } }