Ogre::Plane plane; plane.normal = Ogre::Vector3::UNIT_Y; plane.d = 100; Ogre::MeshManager::getSingleton().createPlane("Myplane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 10, 10, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); pPlaneEnt->setMaterialName("Examples/Rockwall"); pPlaneEnt->setCastShadows(false); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);
2.开启阴影
mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE); //灯光 Ogre::Light* l = mSceneMgr->createLight("Light2"); Ogre::Vector3 dir(-1,-1,0); dir.normalise(); l->setType(Ogre::Light::LT_DIRECTIONAL); l->setPosition(Vector3(20,80,50)); l->setDirection(dir); l->setDiffuseColour(1, 1, 0.8); l->setSpecularColour(1, 1, 1); //平面网格 Ogre::Plane plane; plane.normal = Ogre::Vector3::UNIT_Y; plane.d = 100; Ogre::MeshManager::getSingleton().createPlane("Myplane", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane, 1500, 1500, 10, 10, true, 1, 5, 5, Ogre::Vector3::UNIT_Z); Ogre::Entity* pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" ); pPlaneEnt->setMaterialName("Examples/Rockwall"); pPlaneEnt->setCastShadows(false); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt); //天空盒 mSceneMgr->setSkyBox(true, "Examples/SpaceSkyBox", 50 ); /* Light* l = mSceneMgr->createLight("MainLight"); l->setPosition(20,80,50);*/ //飞机 Entity *ent = mSceneMgr->createEntity( "razor", "razor.mesh" ); mSceneMgr->getRootSceneNode()->attachObject( ent ); ent->setCastShadows(true);
3.节点动画
Animation* anim = mSceneMgr->createAnimation("LightTrack", 20); anim->setInterpolationMode(Animation::IM_SPLINE); NodeAnimationTrack* track = anim->createNodeTrack(0, mLightNode); TransformKeyFrame* key = track->createNodeKeyFrame(0); // A startposition key->setTranslate(Vector3(300,550,-300)); key = track->createNodeKeyFrame(2);//B key->setTranslate(Vector3(150,600,-250)); key = track->createNodeKeyFrame(4);//C key->setTranslate(Vector3(-150,650,-100)); key = track->createNodeKeyFrame(6);//D key->setTranslate(Vector3(-400,500,-200)); key = track->createNodeKeyFrame(8);//E key->setTranslate(Vector3(-200,500,-400)); key = track->createNodeKeyFrame(10);//F key->setTranslate(Vector3(-100,450,-200)); key = track->createNodeKeyFrame(12);//G key->setTranslate(Vector3(-100,400,180)); key = track->createNodeKeyFrame(14);//H key->setTranslate(Vector3(0,250,600)); key = track->createNodeKeyFrame(16);//I key->setTranslate(Vector3(100,650,100)); key = track->createNodeKeyFrame(18);//J key->setTranslate(Vector3(250,600,0)); key = track->createNodeKeyFrame(20);//K == A key->setTranslate(Vector3(300,550,-300)); mAnimState = mSceneMgr->createAnimationState("LightTrack"); mAnimState->setEnabled(true);
mAnimState->addTime(evt.timeSinceLastFrame);
4.控制广告牌大小
Real mMinFlareSize = 40; Real mMaxFlareSize = 80; class LightWibbler : public ControllerValue<Real> { protected: Billboard* mBillboard; Real mMinSize; Real mSizeRange; Real intensity; public: LightWibbler(Billboard* billboard, Real minSize, Real maxSize) { mBillboard = billboard; mMinSize = minSize; mSizeRange = maxSize-minSize; } virtual Real getValue (void) const { return intensity; } virtual void setValue (Real value) { intensity = value; ColourValue newColour; // set billboard size Real newSize = mMinSize + (intensity * mSizeRange); mBillboard->setDimensions(newSize, newSize); } };
ControllerFunctionRealPtr func = ControllerFunctionRealPtr(new WaveformControllerFunction(Ogre::WFT_SINE, 0.0, 0.5)); ControllerValueRealPtr val = ControllerValueRealPtr(new LightWibbler(bb,mMinFlareSize,mMaxFlareSize)); ControllerManager& contMgr=ControllerManager::getSingleton(); contMgr.createController(contMgr.getFrameTimeSource(),val,func);
4.设置绸带
NameValuePairList pairList; pairList["numberOfChains"] = "2"; pairList["maxElements"] = "80"; RibbonTrail* trail = static_cast<RibbonTrail*>(mSceneMgr->createMovableObject("1", "RibbonTrail", &pairList)); mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(trail); trail->setMaterialName("Examples/LightRibbonTrail"); trail->setTrailLength(400); trail->setInitialColour(0, 1.0, 0.8, 0); trail->setColourChange(0, 0.5, 0.5, 0.5, 0.5); trail->setInitialWidth(0, 5); trail->addNode(mLightNode);