Exemple #1
0
Star::Star(int temperature, double radius, Ogre::SceneNode *systemNode, Ogre::SceneManager *sceneMgr, int x, int y) {
	kelvin = temperature;
	radius = radius;
	int rand2 = rand()%1000;
	double colorEvener = 0.35;

	std::string starNodeName = "Star" + Ogre::StringConverter::toString(temperature) + Ogre::StringConverter::toString(rand2);
	std::string starParticleName = "starParticle" + Ogre::StringConverter::toString(temperature) + Ogre::StringConverter::toString(rand2);
	std::string starParticleNodeName = "starParticleNode" + Ogre::StringConverter::toString(temperature) + Ogre::StringConverter::toString(rand2);

	starNode = systemNode->createChildSceneNode(starNodeName, Ogre::Vector3(0,0,0));

	//Particle Gen
	Ogre::ParticleSystem* starParticle = sceneMgr->createParticleSystem(starParticleName, "StarWhite");
	Ogre::SceneNode* particleNode = systemNode->createChildSceneNode(starParticleNodeName,Ogre::Vector3((-0.5+x),(0+y),0.5));
	particleNode->attachObject(starParticle);
	setColor(color);
	starParticle->getEmitter(0)->setColour(Ogre::ColourValue(color[0]*colorEvener,color[1]*colorEvener,color[2]*colorEvener,color[3]));

	//Light Gen
	Ogre::SceneNode* lightNode = NULL;
	Ogre::Light* lightPoint = sceneMgr->createLight();
	lightPoint->setType(Ogre::Light::LT_POINT);
	lightPoint->setDiffuseColour(color[0], color[1], color[2]);
	lightPoint->setSpecularColour(color[0], color[1], color[2]);

	lightNode = systemNode->createChildSceneNode();
	lightNode->attachObject(lightPoint);
	

	//Rotation
	starRotationDegree = 1.0;
}
Exemple #2
0
Monster* MonsterFactory::createInstance(SceneManager* sceneMgr, Maze* maze, MonsterManager* monsterMgr)
{
	Ogre::SceneNode* monsterNode = sceneMgr->getRootSceneNode()->createChildSceneNode();
	Ogre::Entity* entity = sceneMgr->createEntity(mParams["mesh"]);
	//entity->setCastShadows(true);
	monsterNode->attachObject(entity);
	Monster* mon;
	mon = new Monster(monsterNode, entity, maze, monsterMgr);
	if (mParams.find("radius") != mParams.end())
		mon->setRadius((float)atof(mParams["radius"].c_str()));

	if (mParams.find("blood") != mParams.end())
	{
		mon->setBlood((float)atof(mParams["blood"].c_str()));
		mon->setMaxBlood(mon->getBlood());
	}

	if (mParams.find("speed") != mParams.end())
		mon->setSpeed((float)atof(mParams["speed"].c_str()));

	if (mParams.find("spell") != mParams.end())
		mon->setType((mParams["spell"].c_str()));

	if (mParams.find("scale") != mParams.end())
	{
		float scale = (float)atof(mParams["scale"].c_str());
		mon->setScale(scale, scale, scale);
	}

	//mon->setScale(2, 2, 2);

	// 创建怪物头顶血条
	BillboardSet* healthHUD = sceneMgr->createBillboardSet();
	healthHUD->setMaterialName("Glass/Billboard");
	healthHUD->setDefaultWidth(100);
	healthHUD->setDefaultHeight(14);
	SceneNode* hudNode = monsterNode->createChildSceneNode();
	hudNode->attachObject(healthHUD);
	/*Billboard* b2 = healthHUD->createBillboard(0, entity->getBoundingBox().getSize().y, 0);
	b2->setColour(ColourValue::Black);*/
	Billboard* b = healthHUD->createBillboard(0, entity->getBoundingBox().getSize().y, 0);
	//b->setColour(ColourValue(0, 0.75f, 0));
	//b->setDimensions(96, 12);
	mon->setHealthHUD(healthHUD);

	// 测试粒子by kid
    Ogre::ParticleSystem* ps = sceneMgr->createParticleSystem(monsterNode->getName() + "frozen", "Glass/MonsterFrozen");
	monsterNode->attachObject(ps);
	ps->setVisible(false);
    ps = sceneMgr->createParticleSystem(monsterNode->getName() + "burn", "Glass/MonsterBurn");
	monsterNode->attachObject(ps);
	ps->setVisible(false);

	return mon;
}
        Indicator(const ObjectPtr &object, SceneManipulator *sceneManipulator)
			: mProxy(NULL)
        {
            assert(sceneManipulator);

			mUserAny = Ogre::Any();

			mProxy = new ObjectProxy(object);

            // 根据光源位置来定节点位置
            Ogre::Vector3 pos = VariantCast<Ogre::Vector3>(object->getProperty("position"));
            mIndicatorSceneNode = sceneManipulator->getIndicatorRootSceneNode()->createChildSceneNode(pos);

            Real radius = 5;
            int rings = 16;
            int segments = 16;

            Ogre::MeshPtr sphereMesh = createCommonSphere(radius, rings, segments);
            Ogre::MaterialPtr material = createPureColourMaterial(
                Ogre::ColourValue(1, 0, 0, 0.75)   );

            mIndicatorEntity = sceneManipulator->getSceneManager()->createEntity(mIndicatorSceneNode->getName(), sphereMesh->getName());
			//david-<<
            //mIndicatorEntity->setNormaliseNormals(true);
			//david->>
            mIndicatorEntity->setMaterialName(material->getName());
            setUserObject(mProxy);

            mIndicatorSceneNode->attachObject(mIndicatorEntity);

            // 选择时不考虑粒子系统的包围盒,用的是指示器的包围盒
            ParticleSystemObject *particleSystemObject = static_cast<ParticleSystemObject *> (object.get());
			Ogre::ParticleSystem *system = particleSystemObject->getParticleSystem();

            if (system)
				system->setQueryFlags(0);

            // 根据光源类型来挂接模型
            showIndicator(false);
        }
void ProjectileManager::createExplosion(const Ogre::Vector3& location){
	std::ostringstream oss;
	oss << "Explosion" << time(0) << explosions.size() << counter++;	

	Ogre::ParticleSystem* ps = mSceneMgr->createParticleSystem(oss.str(), "explosionTemplate");
	ps->fastForward(1.0f);

	//scaleBy(0.5f, ps);

	Ogre::Vector3 loc = location;

	loc.y += 10.f;

	Ogre::SceneNode* explosionSn = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	explosionSn->attachObject(ps);
	explosionSn->setPosition(loc);
	//explosionSn->scale(Ogre::Vector3(0.1f));
	
	explosions.insert(new Explosion(explosionSn, 1.8f));

	soundPlayer->playExplosionSound();
}
void gkOgreParticleResource::createParticle(const gkParticleSettingsProperties& props)
{
	GK_ASSERT(m_psys == 0);

	try
	{
		Ogre::ParticleSystemManager& mgr = Ogre::ParticleSystemManager::getSingleton();
		Ogre::ParticleSystem* psys = mgr.getTemplate(getName());
		if (!psys)
		{
			psys = mgr.createTemplate(getName(), getGroupName());			

			m_isTemplateOwner = true;

			gkOgreParticleAffector* affector = static_cast<gkOgreParticleAffector*>(psys->addAffector(gkOgreParticleAffector::NAME));
			affector->setCreator(this);

			gkOgreParticleEmitter*  emitter  = static_cast<gkOgreParticleEmitter*>(psys->addEmitter(gkOgreParticleEmitter::NAME));
			emitter->setCreator(this);

			psys->setCullIndividually(false);
			psys->setDefaultDimensions(props.m_size, props.m_size);

			psys->setParticleQuota(props.m_amount);
			//emitter->setStartTime(props.m_start);
			
			//emitter->setTimeToLive(props.m_lifetime);
			//emitter->setDirection(props.m_velocity);
			//emitter->setParticleVelocity(props.m_velocity.length());

			psys->setParameter("billboard_type", "oriented_self");
			//emitter->setEmissionRate(props.m_velNormal);
		}

		m_particleProps = props;
		m_psys = psys;
	}
	catch (Ogre::Exception& e)
	{
		gkLogMessage("gkOgreParticleResource: " << e.getDescription());
	}
}
Exemple #6
0
void GameState::init()
{

	createRenderScene();

	setUpQuaternion();

	//LoadingThread::Begin();
	createPhysicScene();
	//LoadingThread::End();
	

	mSceneMgr->setAmbientLight(Ogre::ColourValue(0.8f, 0.8f, 0.8f));

	vai2 = new VehicleAI;
	vai2->bindPredator(car2->getCarNode());
	vai2->setPredatorMode(VehicleAI::DISTANCE);
	for (int i=1;i<21;i++)
	{
		char* ich = new char[3];
		sprintf(ich, "%d", i);
		vai2->addNavigationPoint(mSceneMgr->getSceneNode("R1P" + Ogre::String(ich))->getPosition());
	}
	

	vai1 = new VehicleAI;
	vai3 = new VehicleAI;
	vai4 = new VehicleAI;

	*vai1 = *vai2;
	*vai3 = *vai2;
	*vai4 = *vai2;

	vai3->setDistancePrecision(1.8f);
	vai4->setDistancePrecision(1.8f);

	vai1->bindPredator(car->getCarNode());
	vai3->bindPredator(car3->getCarNode());
	vai4->bindPredator(car4->getCarNode());

	//vai3->setPredatorMode(VehicleAI::DEGREE);

	AIManager::getSingleton()->addAIObject(vai1);
	AIManager::getSingleton()->addAIObject(vai2);
	AIManager::getSingleton()->addAIObject(vai3);
	AIManager::getSingleton()->addAIObject(vai4);

	mTempSceneNode = mSceneMgr->createSceneNode();

	srand((unsigned int)time(NULL));
	for (int i=0;i<4;i++)
	{
		float ranf = (float)(rand()%10 + 10);
		times.push_back(0.0f);
		timeReach.push_back(ranf);
		cur.push_back(0);
		win.push_back(false);
	}

	mChar = new wchar_t[256];



	
	//particle
	Ogre::ParticleSystem* Lizi_qidian1 = mSceneMgr->createParticleSystem("Lizi_qidian1","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_qidian1")->createChildSceneNode()->attachObject(Lizi_qidian1);
	Ogre::ParticleSystem* Lizi_qidian2 = mSceneMgr->createParticleSystem("Lizi_qidian2","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_qidian2")->createChildSceneNode()->attachObject(Lizi_qidian2);
	Ogre::ParticleSystem* Lizi_qidian3 = mSceneMgr->createParticleSystem("Lizi_qidian3","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_qidian3")->createChildSceneNode()->attachObject(Lizi_qidian3);
	Ogre::ParticleSystem* Lizi_qidian4 = mSceneMgr->createParticleSystem("Lizi_qidian4","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_qidian4")->createChildSceneNode()->attachObject(Lizi_qidian4);
	Ogre::ParticleSystem* Lizi_qidian5 = mSceneMgr->createParticleSystem("Lizi_qidian5","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_qidian5")->createChildSceneNode()->attachObject(Lizi_qidian5);
	Ogre::ParticleSystem* Lizi_qidian6 = mSceneMgr->createParticleSystem("Lizi_qidian6","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_qidian6")->createChildSceneNode()->attachObject(Lizi_qidian6);
	Ogre::ParticleSystem* Lizi_qidian7 = mSceneMgr->createParticleSystem("Lizi_qidian7","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_qidian7")->createChildSceneNode()->attachObject(Lizi_qidian7);
	Ogre::ParticleSystem* Lizi_qidian8 = mSceneMgr->createParticleSystem("Lizi_qidian8","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_qidian8")->createChildSceneNode()->attachObject(Lizi_qidian8);

	Ogre::ParticleSystem* Lizi_zhongdian1 = mSceneMgr->createParticleSystem("Lizi_zhongdian1","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_zhongdian1")->createChildSceneNode()->attachObject(Lizi_zhongdian1);
	Ogre::ParticleSystem* Lizi_zhongdian2 = mSceneMgr->createParticleSystem("Lizi_zhongdian2","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_zhongdian2")->createChildSceneNode()->attachObject(Lizi_zhongdian2);
	Ogre::ParticleSystem* Lizi_zhongdian3 = mSceneMgr->createParticleSystem("Lizi_zhongdian3","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_zhongdian3")->createChildSceneNode()->attachObject(Lizi_zhongdian3);
	Ogre::ParticleSystem* Lizi_zhongdian4 = mSceneMgr->createParticleSystem("Lizi_zhongdian4","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_zhongdian4")->createChildSceneNode()->attachObject(Lizi_zhongdian4);
	Ogre::ParticleSystem* Lizi_zhongdian5 = mSceneMgr->createParticleSystem("Lizi_zhongdian5","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_zhongdian5")->createChildSceneNode()->attachObject(Lizi_zhongdian5);
	Ogre::ParticleSystem* Lizi_zhongdian6 = mSceneMgr->createParticleSystem("Lizi_zhongdian6","PurpleFountain");
	mSceneMgr->getSceneNode("Lizi_zhongdian6")->createChildSceneNode()->attachObject(Lizi_zhongdian6);

	Ogre::ParticleSystem* Lizi_luzhong1 = mSceneMgr->createParticleSystem("Lizi_luzhong1","Pentagram");
	mSceneMgr->getSceneNode("Lizi_luzhong1")->createChildSceneNode()->attachObject(Lizi_luzhong1);
	Ogre::ParticleSystem* Lizi_luzhong2 = mSceneMgr->createParticleSystem("Lizi_luzhong2","Pentagram");
	mSceneMgr->getSceneNode("Lizi_luzhong2")->createChildSceneNode()->attachObject(Lizi_luzhong2);

	Ogre::ParticleSystem* Lizi_luzhong5 = mSceneMgr->createParticleSystem("Lizi_luzhong5","Pentagram");
	mSceneMgr->getSceneNode("Lizi_luzhong5")->createChildSceneNode()->attachObject(Lizi_luzhong5);
	Ogre::ParticleSystem* Lizi_luzhong6 = mSceneMgr->createParticleSystem("Lizi_luzhong6","Pentagram");
	mSceneMgr->getSceneNode("Lizi_luzhong6")->createChildSceneNode()->attachObject(Lizi_luzhong6);

	Ogre::ParticleSystem* dust1 = mSceneMgr->createParticleSystem("dust1_0","GBoot/particle/dusttrail");
	Ogre::ParticleSystem* dust2 = mSceneMgr->createParticleSystem("dust2_0","GBoot/particle/dusttrail");
	car->mWheels[Vehicle::Bottom_LEFT].mSceneNode->attachObject(dust1);
	car->mWheels[Vehicle::Bottom_RIGHT].mSceneNode->attachObject(dust2);
	dust1->setEmitting(false);
	dust2->setEmitting(false);

	dust1 = mSceneMgr->createParticleSystem("dust1_1","GBoot/particle/dusttrail");
	dust2 = mSceneMgr->createParticleSystem("dust2_1","GBoot/particle/dusttrail");
	car2->mWheels[Vehicle::Bottom_LEFT].mSceneNode->attachObject(dust1);
	car2->mWheels[Vehicle::Bottom_RIGHT].mSceneNode->attachObject(dust2);
	dust1->setEmitting(false);
	dust2->setEmitting(false);

	dust1 = mSceneMgr->createParticleSystem("dust1_2","GBoot/particle/dusttrail");
	dust2 = mSceneMgr->createParticleSystem("dust2_2","GBoot/particle/dusttrail");
	car3->mWheels[Vehicle::Bottom_LEFT].mSceneNode->attachObject(dust1);
	car3->mWheels[Vehicle::Bottom_RIGHT].mSceneNode->attachObject(dust2);
	dust1->setEmitting(false);
	dust2->setEmitting(false);

	dust1 = mSceneMgr->createParticleSystem("dust1_3","GBoot/particle/dusttrail");
	dust2 = mSceneMgr->createParticleSystem("dust2_3","GBoot/particle/dusttrail");
	car4->mWheels[Vehicle::Bottom_LEFT].mSceneNode->attachObject(dust1);
	car4->mWheels[Vehicle::Bottom_RIGHT].mSceneNode->attachObject(dust2);
	dust1->setEmitting(false);
	dust2->setEmitting(false);

	Ogre::ParticleSystem* flare = mSceneMgr->createParticleSystem("no2","no2");
	flare->setEmitting(false);
	Ogre::SceneNode* sn = car4->getCarNode()->createChildSceneNode();
	sn->setScale(0.002f, 0.002, 0.002f);
	sn->attachObject(flare);
}
Exemple #7
0
void GameState::createScene() {
  graphics = new Graphics(m_pSceneMgr);
  physics = new Physics(graphics);
  graphics->setPhysics(physics);
  physics->initialize();
  PenguinNode = m_pSceneMgr->getSceneNode("penguin");

  m_pSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8);
  
  // Create a snowstorm
  Ogre::ParticleSystem* snow = m_pSceneMgr->createParticleSystem("snow", "Examples/Snow");
  Ogre::SceneNode* sNode = m_pSceneMgr->getRootSceneNode()->createChildSceneNode("snowNode");
  sNode->translate(0, 1200, 2000);
  sNode->attachObject(snow);
  snow->fastForward(100);

  CEGUI::WindowManager &wmgr = CEGUI::WindowManager::getSingleton();
  CEGUI::Window *gameWindow = wmgr.createWindow("DefaultWindow", "CEGUI/GameGUI");

  // penguin portrait
  face = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/StaticImage", "FacePng");
  face->setSize(CEGUI::UVector2(CEGUI::UDim(0.1, 0), CEGUI::UDim(0.13, 0)));
  face->setPosition(CEGUI::UVector2(CEGUI::UDim(0, 0), CEGUI::UDim(0, 0)));
  face->setProperty("Image","set:Face image:full_image");
  face->setProperty("FrameEnabled", "False");
  face->setProperty("BackgroundEnabled", "False");
  gameWindow->addChildWindow(face);

  // life
  life = wmgr.createWindow("TaharezLook/StaticText", "CEGUI/Life");
  stringstream s;
  s << physics->getLives();
  life->setText("x"+s.str());
  life->setSize(CEGUI::UVector2(CEGUI::UDim(0.04, 0), CEGUI::UDim(0.05, 0)));
  life->setPosition(CEGUI::UVector2(CEGUI::UDim(0.08, 0), CEGUI::UDim(0.048, 0)));
  life->setProperty("FrameEnabled", "False");
  life->setProperty("BackgroundEnabled", "False");
  // life->setProperty("Font", "Jura-18");
  gameWindow->addChildWindow(life);

  // health bar for certain stages
  hp = 1.0f;
  showHealth = false;
  health = wmgr.createWindow("TaharezLook/ProgressBar", "CEGUI/Health");
  health->setSize(CEGUI::UVector2(CEGUI::UDim(0.5, 0), CEGUI::UDim(0.04, 0)));
  health->setPosition(CEGUI::UVector2(CEGUI::UDim(0.08, 0), CEGUI::UDim(0.01, 0)));
  health->setProperty("Visible", "False");
  gameWindow->addChildWindow(health);

  // Pause menu
  pauseWindow = wmgr.createWindow("TaharezLook/StaticText", "CEGUI/PauseWindow");
  pauseWindow->setSize(CEGUI::UVector2(CEGUI::UDim(0.4, 0), CEGUI::UDim(0.35, 0)));
  pauseWindow->setPosition(CEGUI::UVector2(CEGUI::UDim(0.3, 0), CEGUI::UDim(0.35, 0)));
  pauseWindow->setProperty("Visible", "False");
  gameWindow->addChildWindow(pauseWindow);

  CEGUI::Window *ret = wmgr.createWindow("TaharezLook/Button", "CEGUI/ReturnToGameButton");
  ret->setText("Resume Game");
  ret->setSize(CEGUI::UVector2(CEGUI::UDim(0.8, 0), CEGUI::UDim(0.2, 0)));
  ret->setPosition(CEGUI::UVector2(CEGUI::UDim(0.1, 0), CEGUI::UDim(0.25, 0)));
  pauseWindow->addChildWindow(ret);

  CEGUI::Window *bac = wmgr.createWindow("TaharezLook/Button", "CEGUI/BackToTitleButton");
  bac->setText("Back to Title");
  bac->setSize(CEGUI::UVector2(CEGUI::UDim(0.8, 0), CEGUI::UDim(0.2, 0)));
  bac->setPosition(CEGUI::UVector2(CEGUI::UDim(0.1, 0), CEGUI::UDim(0.55, 0)));
  pauseWindow->addChildWindow(bac);
  
  CEGUI::System::getSingleton().setGUISheet(gameWindow);

  // event calls
  ret->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&GameState::returnToGame, this));
  bac->subscribeEvent(CEGUI::PushButton::EventClicked, CEGUI::Event::Subscriber(&GameState::backToTitle, this));
}
Exemple #8
0
void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh, bool light)
{
    Ogre::SceneNode* insert = ptr.getRefData().getBaseNode();
    assert(insert);

    Ogre::AxisAlignedBox bounds = Ogre::AxisAlignedBox::BOX_NULL;
    NifOgre::ObjectList objects = NifOgre::Loader::createObjects(insert, mesh);
    for(size_t i = 0;i < objects.mEntities.size();i++)
        bounds.merge(objects.mEntities[i]->getWorldBoundingBox(true));

    Ogre::Vector3 extents = bounds.getSize();
    extents *= insert->getScale();
    float size = std::max(std::max(extents.x, extents.y), extents.z);

    bool small = (size < Settings::Manager::getInt("small object size", "Viewing distance")) && Settings::Manager::getBool("limit small object distance", "Viewing distance");

    // do not fade out doors. that will cause holes and look stupid
    if (ptr.getTypeName().find("Door") != std::string::npos)
        small = false;

    if (mBounds.find(ptr.getCell()) == mBounds.end())
        mBounds[ptr.getCell()] = Ogre::AxisAlignedBox::BOX_NULL;
    mBounds[ptr.getCell()].merge(bounds);

    bool anyTransparency = false;
    for(size_t i = 0;!anyTransparency && i < objects.mEntities.size();i++)
    {
        Ogre::Entity *ent = objects.mEntities[i];
        for(unsigned int i=0;!anyTransparency && i < ent->getNumSubEntities(); ++i)
        {
            anyTransparency = ent->getSubEntity(i)->getMaterial()->isTransparent();
        }
    }

    if(!mIsStatic || !Settings::Manager::getBool("use static geometry", "Objects") ||
       anyTransparency || objects.mParticles.size() > 0)
    {
        for(size_t i = 0;i < objects.mEntities.size();i++)
        {
            Ogre::Entity *ent = objects.mEntities[i];
            for(unsigned int i=0; i < ent->getNumSubEntities(); ++i)
            {
                Ogre::SubEntity* subEnt = ent->getSubEntity(i);
                subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? RQG_Alpha : RQG_Main);
            }
            ent->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0);
            ent->setVisibilityFlags(mIsStatic ? (small ? RV_StaticsSmall : RV_Statics) : RV_Misc);
        }
        for(size_t i = 0;i < objects.mParticles.size();i++)
        {
            Ogre::ParticleSystem *part = objects.mParticles[i];
            // TODO: Check the particle system's material for actual transparency
            part->setRenderQueueGroup(RQG_Alpha);
            part->setRenderingDistance(small ? Settings::Manager::getInt("small object distance", "Viewing distance") : 0);
            part->setVisibilityFlags(mIsStatic ? (small ? RV_StaticsSmall : RV_Statics) : RV_Misc);
        }
    }
    else
    {
        Ogre::StaticGeometry* sg = 0;

        if (small)
        {
            if( mStaticGeometrySmall.find(ptr.getCell()) == mStaticGeometrySmall.end())
            {
                uniqueID = uniqueID +1;
                sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
                mStaticGeometrySmall[ptr.getCell()] = sg;

                sg->setRenderingDistance(Settings::Manager::getInt("small object distance", "Viewing distance"));
            }
            else
                sg = mStaticGeometrySmall[ptr.getCell()];
        }
        else
        {
            if( mStaticGeometry.find(ptr.getCell()) == mStaticGeometry.end())
            {

                uniqueID = uniqueID +1;
                sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID));
                mStaticGeometry[ptr.getCell()] = sg;
            }
            else
                sg = mStaticGeometry[ptr.getCell()];
        }

        // This specifies the size of a single batch region.
        // If it is set too high:
        //  - there will be problems choosing the correct lights
        //  - the culling will be more inefficient
        // If it is set too low:
        //  - there will be too many batches.
        sg->setRegionDimensions(Ogre::Vector3(2500,2500,2500));

        sg->setVisibilityFlags(small ? RV_StaticsSmall : RV_Statics);

        sg->setCastShadows(true);

        sg->setRenderQueueGroup(RQG_Main);

        std::vector<Ogre::Entity*>::reverse_iterator iter = objects.mEntities.rbegin();
        while(iter != objects.mEntities.rend())
        {
            Ogre::Node *node = (*iter)->getParentNode();
            sg->addEntity(*iter, node->_getDerivedPosition(), node->_getDerivedOrientation(), node->_getDerivedScale());

            (*iter)->detachFromParent();
            mRenderer.getScene()->destroyEntity(*iter);
            iter++;
        }
    }

    if (light)
    {
        insertLight(ptr, objects.mSkelBase, bounds.getCenter() - insert->_getDerivedPosition());
    }
}
Exemple #9
0
void MaterialSelector::OnMaterialRightClicked(wxListEvent& event)
{
	long item = mMaterialList->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
	if(item >= 0)
	{
		wxString name = mMaterialList->GetItemText(item);
		Ogre::MaterialPtr pMaterial = Ogre::MaterialManager::getSingleton().getByName(name.c_str());
		if (!pMaterial.isNull())
		{
			
			int iSelectedPage = m_Frame->GetEditorNotebook()->GetSelection();

			if(iSelectedPage == 0)
			{
				Fairy::EffectElement* pEffectElement = dynamic_cast<Fairy::EffectElement*>(m_Frame->GetEffectObjectEditor()->GetSelectedObject());
				if(pEffectElement)
				{
					Ogre::String elementType = pEffectElement->getType();
					if(elementType == "Mesh" || elementType == "BillboardSet" || 
						elementType == "Projector" || elementType == "Beam")
					{
						wxPoint pt = event.GetPoint();
						wxMenu menu;
						wxString menuText = wxT("效果:");
						menuText.Append(elementType.c_str());
						menu.Append(feID_SET_EFFECT_MATERIAL,menuText);
						wxPoint clientpt = event.GetPoint();
						PopupMenu(&menu, pt);

					}
					
				}
				Ogre::ParticleSystem* pParticleSystem = dynamic_cast<Ogre::ParticleSystem*>(m_Frame->GetEffectObjectEditor()->GetSelectedObject());
				if(pParticleSystem)
				{
					wxPoint pt = event.GetPoint();
					wxMenu menu;
					wxString menuText = wxT("粒子:");
					menuText.Append(pParticleSystem->getName().c_str());
					menu.Append(feID_SET_EFFECT_MATERIAL,menuText);
					wxPoint clientpt = event.GetPoint();
					PopupMenu(&menu, pt);

				}
			}
			else if(iSelectedPage == 1)
			{
				Ogre::StringInterface* pElement = m_Frame->GetSkillObjectEidtor()->GetSelectedSkllElement();
				if(!pElement)
					return;
				Fairy::AnimationRibbon* pRibbon = dynamic_cast<Fairy::AnimationRibbon*>(pElement);
				if(pRibbon)
				{
					wxPoint pt = event.GetPoint();
					wxMenu menu;
					wxString menuText = wxT("技能:Ribbon ");
					menu.Append(feID_SET_SKILL_MATERIAL,menuText);
					wxPoint clientpt = event.GetPoint();
					PopupMenu(&menu, pt);
				}
			}

			//#if wxUSE_MENUS
			//	wxMenu menu(title);
			//	menu.Append(TreeTest_About, wxT("&About..."));
			//	menu.AppendSeparator();
			//	menu.Append(TreeTest_Highlight, wxT("&Highlight item"));
			//	menu.Append(TreeTest_Dump, wxT("&Dump"));
			//
			//	PopupMenu(&menu, pt);
			//#endif // wxUSE_MENUS
		}
	}
}
void MaterialEditorDialog::setMeshMaterial(void)
{
	Fairy::Scene::ObjectsByTypeRange particles =
		mSceneManipulator->getSceneInfo()->findObjectsByType(Fairy::ParticleSystemObject::msType);

	for (Fairy::Scene::ObjectsByTypeIterator it = particles.first; it != particles.second; ++it)
	{
		const Fairy::ObjectPtr& object = *it;
		Fairy::ParticleSystemObject* particleObject = static_cast<Fairy::ParticleSystemObject *>(object.get());

		Ogre::ParticleSystem *system = particleObject->getParticleSystem();
		Ogre::String templateName = particleObject->getPropertyAsString("particle system name");

		// 现在做的是直接对模板的修改,所以要修改全部的同个模板的特效
		if ( system && templateName == gEffectSettingGlobalData.mCurrentParticleTemplateName )
		{
			Ogre::MeshParticleRenderer *renderer = static_cast<Ogre::MeshParticleRenderer *>
				(system->getRenderer());

			assert (renderer->getType() == "mesh");

			renderer->setMaterialName(mCurrentMaterial->getName());
		}
	}

	// 已经创建的effect中的粒子也要相应修改
	Fairy::Scene::ObjectsByTypeRange effects =
		mSceneManipulator->getSceneInfo()->findObjectsByType(Fairy::EffectObject::msType);

	for (Fairy::Scene::ObjectsByTypeIterator it = effects.first; it != effects.second; ++it)
	{
		const Fairy::ObjectPtr& object = *it;
		const Fairy::EffectObject* effectObject = static_cast<Fairy::EffectObject *>(object.get());

		Fairy::Effect *effect = effectObject->getEffect();

		assert (effect);

		for ( size_t i=0; i<effect->getNumElements(); ++i )
		{
			Fairy::EffectElement *element = effect->getElement(i);

			if ( element->getType() == "Particle" )
			{
				Ogre::String name = static_cast<Fairy::ParticleElement *>(element)->getParticleSystemName();
				if (name == gEffectSettingGlobalData.mCurrentParticleTemplateName)
				{
					Ogre::ParticleSystem *system = static_cast<Fairy::ParticleElement *>(element)->getParticleSystem();

					Ogre::MeshParticleRenderer *renderer = static_cast<Ogre::MeshParticleRenderer *>
						(system->getRenderer());

					assert (renderer->getType() == "mesh");

					renderer->setMaterialName(mCurrentMaterial->getName());
				}
			}
		}		
	}

	if (gEffectSettingGlobalData.mCurrentSkill)
	{
		for ( unsigned short i = 0; i < gEffectSettingGlobalData.mCurrentSkill->getNumAnimationEffectInfos(); ++i )
		{
			Fairy::AnimationEffectInfo *effectInfo = gEffectSettingGlobalData.mCurrentSkill->getAnimationEffectInfo(i);
			assert (effectInfo);

			Fairy::Effect *effect = effectInfo->getEffect();

			assert (effect);

			for ( size_t i=0; i<effect->getNumElements(); ++i )
			{
				Fairy::EffectElement *element = effect->getElement(i);

				if ( element->getType() == "Particle" )
				{
					Ogre::String name = static_cast<Fairy::ParticleElement *>(element)->getParticleSystemName();
					if (name == gEffectSettingGlobalData.mCurrentParticleTemplateName)
					{
						Ogre::ParticleSystem *system = static_cast<Fairy::ParticleElement *>(element)->getParticleSystem();

						Ogre::MeshParticleRenderer *renderer = static_cast<Ogre::MeshParticleRenderer *>
							(system->getRenderer());

						assert (renderer->getType() == "mesh");

						renderer->setMaterialName(mCurrentMaterial->getName());
					}
				}
			}		
		}
	}

	Ogre::MeshParticleRenderer *renderer = static_cast<Ogre::MeshParticleRenderer *>
		(gEffectSettingGlobalData.mCurrentParticleSystem->getRenderer());

	assert (renderer->getType() == "mesh");

	renderer->setMaterialName(mCurrentMaterial->getName());
}
void MaterialEditorDialog::InitDialog( Fairy::SceneManipulator *manipulator )
{
	assert (manipulator);
	mSceneManipulator = manipulator;

	//InitMaterialCombo();

	// 根据当前所编辑的东西自动地选择或创建材质

	// 如果当前选择了粒子系统,就编辑该粒子系统的材质
	CurrentEditEffectType currentEditItem = gEffectSettingGlobalData.mCurrentEditEffectType;

	switch (currentEditItem)
	{
	case CEFT_PARTICLE:
		{
			Ogre::ParticleSystem *currentSystem = gEffectSettingGlobalData.mCurrentParticleSystem;
			Ogre::String currentTemplateName = gEffectSettingGlobalData.mCurrentParticleTemplateName;

			assert (currentSystem);

			if (currentSystem->getMaterialName() != currentSystem->getName())
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(currentSystem->getName());

				if (mCurrentMaterial.isNull())
				{
					mCurrentMaterial = Ogre::MaterialManager::getSingleton().create(currentSystem->getName(),"General");
				}

				Fairy::Scene::ObjectsByTypeRange particles =
					mSceneManipulator->getSceneInfo()->findObjectsByType(Fairy::ParticleSystemObject::msType);

				for (Fairy::Scene::ObjectsByTypeIterator it = particles.first; it != particles.second; ++it)
				{
					const Fairy::ObjectPtr& object = *it;
					Fairy::ParticleSystemObject* particleObject = static_cast<Fairy::ParticleSystemObject *>(object.get());

					Ogre::ParticleSystem *system = particleObject->getParticleSystem();
					Ogre::String templateName = particleObject->getPropertyAsString("particle system name");

					// 现在做的是直接对模板的修改,所以要修改全部的同个模板的特效
					if ( system && templateName == currentTemplateName )
					{
						system->setMaterialName(mCurrentMaterial->getName());
					}
				}

				// 已经创建的effect中的粒子也要相应修改
				Fairy::Scene::ObjectsByTypeRange effects =
					mSceneManipulator->getSceneInfo()->findObjectsByType(Fairy::EffectObject::msType);

				for (Fairy::Scene::ObjectsByTypeIterator it = effects.first; it != effects.second; ++it)
				{
					const Fairy::ObjectPtr& object = *it;
					const Fairy::EffectObject* effectObject = static_cast<Fairy::EffectObject *>(object.get());

					Fairy::Effect *effect = effectObject->getEffect();

					assert (effect);

					for ( size_t i=0; i<effect->getNumElements(); ++i )
					{
						Fairy::EffectElement *element = effect->getElement(i);

						if ( element->getType() == "Particle" )
						{
							Ogre::String name = static_cast<Fairy::ParticleElement *>(element)->getParticleSystemName();
							if (name == currentTemplateName)
							{
								Ogre::ParticleSystem *system = static_cast<Fairy::ParticleElement *>(element)->getParticleSystem();

								system->setMaterialName(mCurrentMaterial->getName());
							}
						}
					}		
				}

				currentSystem->setMaterialName(mCurrentMaterial->getName());	
			}
			else
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(currentSystem->getName());

				assert ( false == mCurrentMaterial.isNull() );
			}
			InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );

			break;
		}

	case CEFT_RIBBON:
		{
			unsigned short currentRibbonIndex = gEffectSettingGlobalData.mCurrentRibbonIndex;

			Fairy::AnimationRibbon *ribbon = gEffectSettingGlobalData.mCurrentSkill->getAnimationRibbon(currentRibbonIndex);

			assert (ribbon);

			Ogre::String currRibbonMatName = ribbon->getMaterialName();

			// ribbon该有的名称
			Ogre::String ribbonMatName = gEffectSettingGlobalData.mCurrentSkill->getSkillName() +
				"ribbon" + Ogre::StringConverter::toString(currentRibbonIndex);

			if ( currRibbonMatName != ribbonMatName )
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(ribbonMatName);

				if (mCurrentMaterial.isNull())
				{
					mCurrentMaterial = Ogre::MaterialManager::getSingleton().create(ribbonMatName,"General");
				}

				ribbon->setMaterial(ribbonMatName);
			}
			else
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(ribbonMatName);

				assert ( false == mCurrentMaterial.isNull() );
			}

			InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );

			break;
		}

	case CEFT_EFFECT_BEAM:
		{
			Fairy::BeamElement *beam = static_cast<Fairy::BeamElement *>
				( gEffectSettingGlobalData.mCurrentEffect->getElement(gEffectSettingGlobalData.mCurrentEffectElementIndex) );

			assert (beam);

			Ogre::String currBeamMatName = beam->getMaterialName();

			// ribbon该有的名称
			Ogre::String beamMatName = gEffectSettingGlobalData.mCurrentEffect->getTemplateName() +
				"beam" + Ogre::StringConverter::toString(gEffectSettingGlobalData.mCurrentEffectElementIndex);

			if ( currBeamMatName != beamMatName )
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(beamMatName);

				if (mCurrentMaterial.isNull())
				{
					mCurrentMaterial = Ogre::MaterialManager::getSingleton().create(beamMatName,"General");
				}

				beam->setMaterialName(beamMatName);
			}
			else
			{
				mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(beamMatName);

				assert ( false == mCurrentMaterial.isNull() );
			}

			InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );

			break;
		}

	case CEFT_EFFECT_PROJECTOR:
		{
			Fairy::ProjectorElement *projectorElement = static_cast<Fairy::ProjectorElement *>
				( gEffectSettingGlobalData.mCurrentEffect->getElement(gEffectSettingGlobalData.mCurrentEffectElementIndex) );

			assert (projectorElement);

			gEffectSettingGlobalData.mOriginProjectorMaterial = projectorElement->getMaterialName();

			mCurrentMaterial = projectorElement->getProjector()->_getPatchMaterial();

			if ( false == mCurrentMaterial.isNull() )
				InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );
			else
			{
				wxMessageBox(_("Please select the material in effect editor first!"));
			}
		}

    case CEFT_EFFECT_BILLBOARDSET:
        {
            Fairy::BillboardSetElement *billboardSet = static_cast<Fairy::BillboardSetElement *>
                ( gEffectSettingGlobalData.mCurrentEffect->getElement(gEffectSettingGlobalData.mCurrentEffectElementIndex) );

            assert (billboardSet);

            Ogre::String currBillboardMatName = billboardSet->getBillboardMaterial();

            // ribbon该有的名称
            Ogre::String billboardMatName = gEffectSettingGlobalData.mCurrentEffect->getTemplateName() +
                "billboardset" + Ogre::StringConverter::toString(gEffectSettingGlobalData.mCurrentEffectElementIndex);

            if ( currBillboardMatName != billboardMatName )
            {
                mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(billboardMatName);

                if (mCurrentMaterial.isNull())
                {
                    mCurrentMaterial = Ogre::MaterialManager::getSingleton().create(billboardMatName,"General");
                }

                billboardSet->setBillboardMaterial(billboardMatName);
            }
            else
            {
                mCurrentMaterial = Ogre::MaterialManager::getSingleton().getByName(billboardMatName);

                assert ( false == mCurrentMaterial.isNull() );
            }

            InitMaterialInfo( Ogre::String(mCurrentMaterial->getName()) );

            break;
        }

	}
}