//----------------------------------------------------------------------- void EntityRenderer::_rotateTexture(VisualParticle* particle, Ogre::Entity* entity) { Ogre::TextureUnitState::EffectMap::const_iterator it; // Get the material and rotate it unsigned int numberOfSubEntities = entity->getNumSubEntities(); for (unsigned short u = 0; u < numberOfSubEntities; ++u) { Ogre::MaterialPtr material = entity->getSubEntity(u)->getMaterial(); unsigned short numberOfTechniques = material->getNumTechniques(); for (unsigned short v = 0; v < numberOfTechniques; ++v) { Ogre::Technique* technique = material->getTechnique(v); unsigned short numberOfPasses = technique->getNumPasses(); for (unsigned short w = 0; w < numberOfPasses; ++w) { Ogre::Pass* pass = technique->getPass(w); unsigned short numberOfTextureUnitStates = pass->getNumTextureUnitStates(); for (unsigned short x = 0; x < numberOfTextureUnitStates; ++x) { // Set the rotation if not already available. // This can only be done once! Changing the rotationspeed or removing the rotation // and resetting it doesn´t seem to work. Ogre::TextureUnitState* textureUnitState = pass->getTextureUnitState(x); it = textureUnitState->getEffects().find(Ogre::TextureUnitState::ET_ROTATE); if (it == textureUnitState->getEffects().end()) { textureUnitState->setRotateAnimation((particle->zRotationSpeed.valueRadians())); } } } } } }
//----------------------------------------------------------------------- void PrimitiveShapeSet::rotateTexture(Ogre::Real speed) { // Get the material and rotate it, assume the material is loaded already, otherwise skip. Ogre::MaterialPtr material = getMaterial(); if (material.isNull()) return; Ogre::TextureUnitState::EffectMap::const_iterator it; unsigned short numberOfTechniques = material->getNumTechniques(); for (unsigned short u = 0; u < numberOfTechniques; ++u) { Ogre::Technique* technique = material->getTechnique(u); unsigned short numberOfPasses = technique->getNumPasses(); for (unsigned short v = 0; v < numberOfPasses; ++v) { Ogre::Pass* pass = technique->getPass(v); unsigned short numberOfTextureUnitStates = pass->getNumTextureUnitStates(); for (unsigned short w = 0; w < numberOfTextureUnitStates; ++w) { // Set the rotation if not already available. // This can only be done once! Changing the rotationspeed or removing the rotation // and resetting it doesn´t seem to work. Ogre::TextureUnitState* textureUnitState = pass->getTextureUnitState(w); it = textureUnitState->getEffects().find(Ogre::TextureUnitState::ET_ROTATE); if (it == textureUnitState->getEffects().end()) { textureUnitState->setRotateAnimation(speed); } } } } }
void _makeScene() { mCamera->setNearClipDistance(1); mCamera->setFarClipDistance(1000); // Create the texture Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().createManual( "DynamicTexture", // name Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, // type 128, 128, // width & height 0, // number of mipmaps Ogre::PF_BYTE_BGRA, // pixel format Ogre::TU_DEFAULT); // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for // textures updated very often (e.g. each frame) // Get the pixel buffer Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer(); // Lock the pixel buffer and get a pixel box pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL); // for best performance use HBL_DISCARD! const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock(); Ogre::uint8* pDest = static_cast<Ogre::uint8*>(pixelBox.data); // Fill in some pixel data. This will give a semi-transparent blue, // but this is of course dependent on the chosen pixel format. for (size_t j = 0; j < 128; j++) for(size_t i = 0; i < 128; i++) { *pDest++ = 82 + (Ogre::Math::Sin(i) + Ogre::Math::Cos(j) * 10.5); *pDest++ = 45 + (Ogre::Math::Cos(i) + Ogre::Math::Sin(j) * 10.5); *pDest++ = 128 + (Ogre::Math::Tan(i) + Ogre::Math::Cos(j) * 10.5); *pDest++ = 255; // A } // Unlock the pixel buffer pixelBuffer->unlock(); // Create a material using the texture Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create( "DynamicTextureMaterial", // name Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); Ogre::TextureUnitState* tus = material->getTechnique(0)->getPass(0)->createTextureUnitState("DynamicTexture"); tus->setScrollAnimation(0.005f, 0.0025f); tus->setRotateAnimation(0.009f); material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0); Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 1, 1, true, 1, 1, 1, Ogre::Vector3::UNIT_Z); Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground"); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround); entGround->setMaterialName("DynamicTextureMaterial"); entGround->setCastShadows(false); mCamera->setPosition(25,100,30); mCamera->lookAt(0,0,0); }