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; }
void Environment::addStars(Vector3 pos, Vector3 size, float scale, string material, ColourValue color, int random, int number) { BillboardSet* billy = this->mSceneManager->createBillboardSet("Stars"+StringConverter::toString(this->starsnumber), number); this->starsnumber++; billy->setMaterialName(material); billy->setRenderQueueGroup(RENDER_QUEUE_SKIES_EARLY); billy->setDefaultDimensions(scale, scale); for(unsigned int i=0; i<number; i++){ billy->createBillboard(Math::RangeRandom(-size.x, size.x), Math::RangeRandom(-size.y, size.y), Math::RangeRandom(-size.z, size.z)); } Ogre::SceneNode *billynode = this->mSkyNode->createChildSceneNode("StarsNode"+StringConverter::toString(this->starsnumber), pos); billynode->attachObject(billy); }
void OgreSample19App::createScene() { mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE); mSceneMgr->setShadowTextureSize(512); mSceneMgr->setShadowColour(ColourValue(0.6f, 0.6f, 0.6f)); mSceneMgr->setShadowTextureCount(2); // add a little ambient lighting mSceneMgr->setAmbientLight(ColourValue(0.5f, 0.5f, 0.5f)); SceneNode* lightsBbsNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); BillboardSet* bbs; // Create billboard set for lights . bbs = mSceneMgr->createBillboardSet(); bbs->setMaterialName("Examples/Flare"); lightsBbsNode->attachObject(bbs); // add a blue spotlight Light* l = mSceneMgr->createLight(); Vector3 dir; l->setType(Light::LT_SPOTLIGHT); l->setPosition(-40, 180, -10); dir = -l->getPosition(); dir.normalise(); l->setDirection(dir); l->setDiffuseColour(0.0f, 0.0f, 0.5f); bbs->createBillboard(l->getPosition())->setColour(l->getDiffuseColour()); // add a green spotlight. l = mSceneMgr->createLight(); l->setType(Light::LT_SPOTLIGHT); l->setPosition(0, 150, -100); dir = -l->getPosition(); dir.normalise(); l->setDirection(dir); l->setDiffuseColour(0.0f, 0.5f, 0.0f); bbs->createBillboard(l->getPosition())->setColour(l->getDiffuseColour()); // create a floor mesh resource MeshManager::getSingleton().createPlane("floor", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Plane(Vector3::UNIT_Y, -1), 250, 250, 25, 25, true, 1, 15, 15, Vector3::UNIT_Z); // add a floor to our scene using the floor mesh we created Entity* floor = mSceneMgr->createEntity("Floor", "floor"); floor->setMaterialName("Examples/Rockwall"); floor->setCastShadows(false); mSceneMgr->getRootSceneNode()->attachObject(floor); tweakSneakAnim(); SceneNode* sn = NULL; Entity * ent = NULL; AnimationState* as = NULL; for (unsigned int i = 0; i < NUM_MODELS; i++) { // create scene nodes for the models at regular angular intervals sn = mSceneMgr->getRootSceneNode()->createChildSceneNode(); sn->yaw(Radian(Math::TWO_PI * (float)i / (float)NUM_MODELS)); sn->translate(0, 0, -20, Node::TS_LOCAL); mModelNodes.push_back(sn); // create and attach a jaiqua entity ent = mSceneMgr->createEntity("Jaiqua" + StringConverter::toString(i + 1), "jaiqua.mesh"); sn->attachObject(ent); // enable the entity's sneaking animation at a random speed and loop it manually since translation is involved as = ent->getAnimationState("Sneak"); as->setEnabled(true); as->setLoop(false); mAnimSpeeds.push_back(Math::RangeRandom(0.5, 1.5)); mAnimStates.push_back(as); } StringVector names; names.push_back("Skinning"); String value = "Software"; Pass * pass = ent->getSubEntity(0)->getMaterial()->getBestTechnique()->getPass(0); if (pass->hasVertexProgram() && pass->getVertexProgram()->isSkeletalAnimationIncluded()) { value = "Hardware"; } }
void OgreSample14App::createLights() { mSceneMgr->setAmbientLight(ColourValue(0.1f, 0.1f, 0.1f)); NameValuePairList params; params["numberOfChains"] = "2"; params["maxElements"] = "80"; RibbonTrail * trail = (RibbonTrail*)mSceneMgr->createMovableObject("RibbonTrail",¶ms); mSceneMgr->getRootSceneNode()->attachObject(trail); trail->setMaterialName("Examples/LightRibbonTrail"); trail->setTrailLength(400); SceneNode* node; Animation* anim; NodeAnimationTrack* track; Light* light; BillboardSet* bbs; // create a light node node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(50, 30, 0)); // create a 14 second animation with spline interpolation anim = mSceneMgr->createAnimation("Path1", 14); anim->setInterpolationMode(Animation::IM_SPLINE); track = anim->createNodeTrack(1, node); // create a node track for our animation // enter keyframes for our track to define a path for the light to follow track->createNodeKeyFrame(0)->setTranslate(Vector3(50, 30, 0)); track->createNodeKeyFrame(2)->setTranslate(Vector3(100, -30, 0)); track->createNodeKeyFrame(4)->setTranslate(Vector3(120, -80, 150)); track->createNodeKeyFrame(6)->setTranslate(Vector3(30, -80, 50)); track->createNodeKeyFrame(8)->setTranslate(Vector3(-50, 30, -50)); track->createNodeKeyFrame(10)->setTranslate(Vector3(-150, -20, -100)); track->createNodeKeyFrame(12)->setTranslate(Vector3(-50, -30, 0)); track->createNodeKeyFrame(14)->setTranslate(Vector3(50, 30, 0)); // create an animation state from the animation and enable it mYellowLightAnimState = mSceneMgr->createAnimationState("Path1"); mYellowLightAnimState->setEnabled(true); // set initial settings for the ribbon trail and add the light node trail->setInitialColour(0, 1.0f, 0.8f, 0); trail->setColourChange(0, 0.5f, 0.5f, 0.5f, 0.5f); trail->setInitialWidth(0, 5); trail->addNode(node); // attach a light with the same colour to the light node light = mSceneMgr->createLight(); light->setDiffuseColour(trail->getInitialColour(0)); node->attachObject(light); // attach a flare with the same colour to the light node bbs = mSceneMgr->createBillboardSet(1); bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(0)); bbs->setMaterialName("Examples/Flare"); node->attachObject(bbs); // create a second light node node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-50, 100, 0)); // create a 10 second animation with spline interpolation anim = mSceneMgr->createAnimation("Path2", 10); anim->setInterpolationMode(Animation::IM_SPLINE); track = anim->createNodeTrack(1, node); // create a node track for our animation // enter keyframes for our track to define a path for the light to follow track->createNodeKeyFrame(0)->setTranslate(Vector3(-50, 100, 0)); track->createNodeKeyFrame(2)->setTranslate(Vector3(-100, 150, -30)); track->createNodeKeyFrame(4)->setTranslate(Vector3(-200, 0, 40)); track->createNodeKeyFrame(6)->setTranslate(Vector3(0, -150, 70)); track->createNodeKeyFrame(8)->setTranslate(Vector3(50, 0, 30)); track->createNodeKeyFrame(10)->setTranslate(Vector3(-50, 100, 0)); // create an animation state from the animation and enable it mGreenLightAnimState = mSceneMgr->createAnimationState("Path2"); mGreenLightAnimState->setEnabled(true); trail->setInitialColour(1,0.0f,1.0f,0.4f); trail->setColourChange(1,0.5f,0.5f,0.5f,0.5f); trail->addNode(node); // attach a light with the same colour to the light node light = mSceneMgr->createLight(); light->setDiffuseColour(trail->getInitialColour(1)); node->attachObject(light); // attach a flare with the same colour to the light node bbs = mSceneMgr->createBillboardSet(1); bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(1)); bbs->setMaterialName("Examples/Flare"); node->attachObject(bbs); }
void OgreSample18App::createScene() { mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE); mCurrentShadowTechnique = SHADOWTYPE_STENCIL_ADDITIVE; // Set ambient light off mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0)); // Fixed light, dim mSunLight = mSceneMgr->createLight("SunLight"); mSunLight->setType(Light::LT_SPOTLIGHT); mSunLight->setPosition(1500,1750,1300); mSunLight->setSpotlightRange(Degree(30), Degree(50)); Ogre::Vector3 dir; dir = -mSunLight->getPosition(); dir.normalise(); mSunLight->setDirection(dir); mSunLight->setDiffuseColour(0.35, 0.35, 0.38); mSunLight->setSpecularColour(0.9, 0.9, 1); // Point light, movable, reddish mLight = mSceneMgr->createLight("Light2"); mLight->setDiffuseColour(mMinLightColour); mLight->setSpecularColour(1, 1, 1); mLight->setAttenuation(8000,1,0.0005,0); // Create light node mLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode( "MovingLightNode"); mLightNode->attachObject(mLight); // create billboard set BillboardSet* bbs = mSceneMgr->createBillboardSet("lightbbs", 1); bbs->setMaterialName("Examples/Flare"); Billboard* bb = bbs->createBillboard(0,0,0,mMinLightColour); // attach mLightNode->attachObject(bbs); ControllerFunctionRealPtr func = ControllerFunctionRealPtr(new WaveformControllerFunction(Ogre::WFT_SINE,0.75f,0.5f)); ControllerManager& contMgr = ControllerManager::getSingleton(); ControllerValueRealPtr val = ControllerValueRealPtr(new LightWibbler(mLight,bb,mMinLightColour,mMaxLightColour,mMinFlareSize,mMaxFlareSize)); mController = contMgr.createController(contMgr.getFrameTimeSource(),val,func); mLightNode->setPosition(Vector3(300,1750,-700)); Animation* anim = mSceneMgr->createAnimation("LightTrack", 20); // Spline it for nice curves anim->setInterpolationMode(Animation::IM_SPLINE); // Create a track to animate the camera's node NodeAnimationTrack* track = anim->createNodeTrack(0, mLightNode); // Setup keyframes TransformKeyFrame* key = track->createNodeKeyFrame(0); // A startposition key->setTranslate(Vector3(300,750,-700)); key = track->createNodeKeyFrame(2);//B key->setTranslate(Vector3(150,800,-250)); key = track->createNodeKeyFrame(4);//C key->setTranslate(Vector3(-150,850,-100)); key = track->createNodeKeyFrame(6);//D key->setTranslate(Vector3(-400,700,-200)); key = track->createNodeKeyFrame(8);//E key->setTranslate(Vector3(-200,700,-400)); key = track->createNodeKeyFrame(10);//F key->setTranslate(Vector3(-100,850,-200)); key = track->createNodeKeyFrame(12);//G key->setTranslate(Vector3(-100,575,180)); key = track->createNodeKeyFrame(14);//H key->setTranslate(Vector3(0,750,300)); key = track->createNodeKeyFrame(16);//I key->setTranslate(Vector3(100,850,100)); key = track->createNodeKeyFrame(18);//J key->setTranslate(Vector3(250,800,0)); key = track->createNodeKeyFrame(20);//K == A key->setTranslate(Vector3(300,750,-700)); // Create a new animation state to track this mAnimState = mSceneMgr->createAnimationState("LightTrack"); mAnimState->setEnabled(true); mLightNode->setAutoTracking(true,mSceneMgr->getRootSceneNode()); MeshPtr pAthene = MeshManager::getSingleton().load("athene.mesh", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); unsigned short src, dest; if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest)) { pAthene->buildTangentVectors(VES_TANGENT, src, dest); } SceneNode* node; node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); mAthene = mSceneMgr->createEntity( "athene", "athene.mesh" ); mAthene->setMaterialName(BASIC_ATHENE_MATERIAL); node->attachObject( mAthene ); node->yaw(Degree(90)); Entity* pEnt; // Columns for (int x = -2; x <= 2; ++x) { for (int z = -2; z <= 2; ++z) { if (x != 0 || z != 0) { StringUtil::StrStreamType str; str << "col" << x << "_" << z; node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); pEnt = mSceneMgr->createEntity( str.str(), "column.mesh" ); pEnt->setMaterialName(BASIC_ROCKWALL_MATERIAL); pColumns.push_back(pEnt); node->attachObject( pEnt ); node->translate(x*300,0, z*300); } } } // Skybox mSceneMgr->setSkyBox(true, "Examples/StormySkyBox"); // Floor plane (use POSM plane def) mPlane = new MovablePlane("*mPlane"); mPlane->normal = Vector3::UNIT_Y; mPlane->d = 107; MeshManager::getSingleton().createPlane("Myplane", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, *mPlane, 1500,1500,50,50,true,1,5,5,Vector3::UNIT_Z); pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); pPlaneEnt->setMaterialName(BASIC_ROCKWALL_MATERIAL); pPlaneEnt->setCastShadows(false); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_HWRENDER_TO_TEXTURE)) { mSceneMgr->setShadowTextureSettings(1024,2); } else { mSceneMgr->setShadowTextureSettings(512,2); } mSceneMgr->setShadowColour(ColourValue(0.5f,0.5f,0.5f)); //handles; resetMaterials(); materialChanged(0); configureLights(ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE); }