bool ParticleSystem::objectRendering(const Ogre::MovableObject* movable, const Ogre::Camera*) { //Adjust all emitters so that mDirection is applied in world space Ogre::Quaternion rotation = movable->getParentNode()->convertWorldToLocalOrientation(Ogre::Quaternion(Ogre::Degree(0), mDirection)); for (unsigned short i = 0; i < mOgreParticleSystem->getNumEmitters(); ++i) { Ogre::ParticleEmitter* emitter = mOgreParticleSystem->getEmitter(i); emitter->setDirection(rotation * mDirection); } return true; }
/* Code for this method taken from http://www.ogre3d.org/forums/viewtopic.php?p=176603&sid=ffef6c25bddf82213f3b1e0daf228657#p176603 Adapted for use in this program by Michael Y.M. Kong */ void ProjectileManager::scaleBy(Ogre::Real factor, Ogre::ParticleSystem* pSys_) { Ogre::Real temp; temp = pSys_->getDefaultWidth(); temp *= factor; pSys_->setDefaultWidth( temp ); temp = pSys_->getDefaultHeight(); temp *= factor; pSys_->setDefaultHeight( temp ); for(unsigned short i=0; i<pSys_->getNumEmitters(); ++i) { Ogre::ParticleEmitter* emitt = pSys_->getEmitter(i); Ogre::Vector3 pos = emitt->getPosition(); Ogre::Real particleVelocity = emitt->getParticleVelocity(); Ogre::Real minParticleVelocity = emitt->getMinParticleVelocity(); Ogre::Real maxParticleVelocity = emitt->getMaxParticleVelocity(); pos *= factor; particleVelocity *= factor; minParticleVelocity *= factor; maxParticleVelocity *= factor; emitt->setPosition(pos); emitt->setParticleVelocity(particleVelocity); emitt->setMinParticleVelocity(minParticleVelocity); emitt->setMaxParticleVelocity(maxParticleVelocity); } }
bool Explosion::isAlive() { for (unsigned i = 0; i < m_ps->getNumEmitters(); i++) { Ogre::ParticleEmitter * emitter = m_ps->getEmitter(i); if (!emitter->getEnabled()) { return false; } } return true; }
void EffectsFactory::requestSpillBlood(float x, float y, float z) { assert(my_blood_ps.size() > 0); assert(my_sn.size()); my_blood_ps.front()->getParentSceneNode()->setPosition(x, y, z); my_blood_ps.front()->setEmitting(true); int numEmitters = my_blood_ps.front()->getNumEmitters(); std::cout << "Num emitters:" << numEmitters << std::endl; for(int x = 0; x < numEmitters; x++) { Ogre::ParticleEmitter* emitter = my_blood_ps.front()->getEmitter(x); emitter->setEnabled(true); std::cout << "EMITTER ENABLED" << std::endl; } }
void Main::onInitialize() { auto scene = addScene(new dt::Scene("testscene")); dt::ResourceManager::get()->addResourceLocation("sinbad.zip","Zip", true); dt::ResourceManager::get()->addResourceLocation("particle/","FileSystem", true); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // make a scene auto camnode = scene->addChildNode(new dt::Node("camnode")); camnode->setPosition(Ogre::Vector3(0, 2, 10)); camnode->addComponent(new dt::CameraComponent("cam"))->lookAt(Ogre::Vector3(0, 2, 0));; auto p = scene->addChildNode(new dt::Node("p")); p->setScale(0.2); auto mesh = p->addComponent(new dt::MeshComponent("Sinbad.mesh")); mesh->setAnimation("RunBase"); mesh->setLoopAnimation(true); mesh->playAnimation(); auto path = p->addComponent(new dt::FollowPathComponent(dt::FollowPathComponent::LOOP)); path->addPoint(Ogre::Vector3(-10, 0, 0)); path->addPoint(Ogre::Vector3(10, 0, 0)); path->setDuration(2.f); path->setFollowRotation(true); // create the particle system auto p_sys = p->addComponent(new dt::ParticleSystemComponent("p_sys")); p_sys->setMaterialName("Test/Particle"); p_sys->setParticleCountLimit(1000); p_sys->getOgreParticleSystem()->setDefaultDimensions(0.03, 0.03); Ogre::ParticleEmitter* e = p_sys->addEmitter("emit1", "Point"); e->setAngle(Ogre::Degree(10)); e->setColour(Ogre::ColourValue(1.f, 0.6f, 0.f), Ogre::ColourValue(0.2f, 0.8f, 0.2f)); e->setEmissionRate(100); e->setParticleVelocity(3.f, 4.f); e->setTimeToLive(1.f, 2.f); p_sys->addScalerAffector("scaler", 1.05); p_sys->addLinearForceAffector("force", Ogre::Vector3(0, 5, 0)); Ogre::ParticleAffector* a = p_sys->addAffector("colour_interpolator", "ColourInterpolator"); a->setParameter("time0", "0"); a->setParameter("colour0", "1 1 0 1"); a->setParameter("time1", "0.5"); a->setParameter("colour1", "1 0.3 0 1"); a->setParameter("time2", "1"); a->setParameter("colour2", "1 0 0 0"); }
void OGRERendererRacer::update() { mpVehicle = mpApp->mRacer; const cml::vector3d& pos = mpVehicle->mPos; mVehicleNode->setPosition(pos[0], pos[1], pos[2]); Ogre::Quaternion q; const quat& orientation = mpVehicle->getOrientation(); q.w = orientation.as_vector()[0]; q.x = orientation.as_vector()[1]; q.y = orientation.as_vector()[2]; q.z = orientation.as_vector()[3]; if (q != mOrientation) { Ogre::Quaternion transition = q * mOrientation.Inverse(); Ogre::Radian a; Ogre::Vector3 v; transition.ToAngleAxis(a, v); if (a.valueDegrees() > 0.1) { Ogre::Quaternion t2; // TODO 3: Make rotation speed configurable t2.FromAngleAxis(a * 0.05, v); mOrientation = t2 * mOrientation; } else { mOrientation = q; } } //################# BEGIN Construct Sideward thrust roll quaternion ################ // cml::vector3f velDirSidewardComponent = cml::dot(mpVehicle->mDirLeft, mpVehicle->mVelocity) * mpVehicle->mDirLeft; if (mpVehicle->mAddThrustLeft || mpVehicle->mAddThrustRight) { mRollAngle = -mpVehicle->mThrustSideward * 500; } else { mRollAngle *= 0.98; } float dot = cml::dot(mpVehicle->mDirLeft, mpVehicle->mVelocity); mRollAngle = -dot * 50; Ogre::Quaternion qSidewardThrustRoll(Ogre::Degree(mRollAngle), Ogre::Vector3(0, 0, -1)); cml::vector3f g = mpVehicle->getGravity(); cml::vector3f velDirGravityComponent = cml::dot(g, mpVehicle->mVelocity) * g; dot = cml::dot(velDirGravityComponent, g); if (velDirGravityComponent.length() > 0.000001) { mPitchAngle = -cml::sign(dot) * velDirGravityComponent.length() * 500000; } else { if (mpVehicle->mAddThrustForward && mPitchAngle > -7) { mPitchAngle -= 0.1; } else { mPitchAngle *= 0.95; } } Ogre::Quaternion qForwardThrustPitch(Ogre::Degree(mPitchAngle), Ogre::Vector3(1, 0, 0)); //################# END Construct Sideward thrust roll quaternion ################ bool mSidewardThrustRollCamera = false; if (mSidewardThrustRollCamera) { // Roll both vehicle and camera: mVehicleNode->setOrientation(q * qSidewardThrustRoll * qForwardThrustPitch); } else { // Roll only the vehicle, not the camera: mVehicleNode->setOrientation(mOrientation); mVehicleMeshNode->setOrientation(qSidewardThrustRoll * qForwardThrustPitch); } //############# BEGIN Update engine particle emitters #################### // TODO 1: Reimplement bool emit = (mpVehicle->mGameState == 0) && mpVehicle->mThrustForward > 0; mEngineFlameParticleSystem->setEmitting(emit); mEngineSmokeParticleSystem->setEmitting(emit); Ogre::ParticleEmitter* emitter = mEngineFlameParticleSystem->getEmitter(0); emitter->setParticleVelocity(mpVehicle->mThrustForward * 6000); emitter->setEmissionRate(mpVehicle->mThrustForward * 10000); emitter = mEngineSmokeParticleSystem->getEmitter(0); emitter->setEmissionRate(mpVehicle->mThrustForward * 7000); //############# END Update engine particle emitters #################### }