之前的教學中,我們已經學會加入實體,及旋轉及放大縮小的調整。現在來談談攝影機、燈光與影子。



void BasicTutorial2::createCamera(void)
{
// create the camera
mCamera = mSceneMgr->createCamera("PlayerCam");
// set its position, direction 

mCamera->setPosition(Ogre::Vector3(0,10,500));
mCamera->lookAt(Ogre::Vector3(0,0,0));
// set the near clip distance
mCamera->setNearClipDistance(5);

mCameraMan = new OgreBites::SdkCameraMan(mCamera); // create a default camera controller
}在BaseApplication 更改createCamera的参數




--------------------------------------------------------------------------------




void BasicTutorial2::createViewports(void)
{
// Create one viewport, entire window
Ogre::Viewport* vp = mWindow->addViewport(mCamera);
vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
// Alter the camera aspect ratio to match the viewport
mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->;getActualHeight()));
}更改createViewports的設定


Ogre所支援的陰影


1.Modulative Texture Shadows (Ogre::SHADOWTYPE_TEXTURE_MODULATIVE) 最省計算資源,產生一個黑白的陰影投射。
2.Modulative Stencil Shadows (Ogre::SHADOWTYPE_STENCIL_MODULATIVE) 這項技術將陰影體積當作一個模組,渲染所有不透明的物件。跟Additive Stencil Shadows比起來較為稀疏。
3.Additive Stencil Shadows (Ogre::SHADOWTYPE_STENCIL_ADDITIVE)這項技術將每到光,當作獨立的添加在場景上。這將會對顯示卡造成負擔,因為當增加而外的光通過場景時,就必須在做計算。

void BasicTutorial2::createScene(void)
{
mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE)
//設定AmbientLight,設定使用SHADOWTYPE_STENCIL_ADDITIVE


Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh");
entNinja->setCastShadows(true);
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);
//載入實體,設定投射陰影


Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
//須要一個平面讓投影呈現
//定義平面,在(0,0,0)的位置 以y+為法向量,場景幾何物件與之距離為0


Ogre::MeshManager::getSingleton().createPlane("ground", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
plane, 1500, 1500, 20, 20, true, 1, 5, 5, Ogre::Vector3::UNIT_Z);
//大小1500x1500,新增一個叫做ground的mesh 


Ogre::Entity* entGround = mSceneMgr->createEntity("GroundEntity", "ground");
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entGround);
//告訴場景經理,不要投影那些用來投影陰影的物件


entGround->setMaterialName("Examples/Rockwall");
entGround->setCastShadows(false);
//在平面上貼上Rockwall的材質


Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
pointLight->setType(Ogre::Light::LT_POINT);
pointLight->setPosition(Ogre::Vector3(0, 150, 250));
//新增一個點光源,可以調整位置,或將它與場景節點結合,隨物件移動。 


pointLight->setDiffuseColour(1.0, 0.0, 0.0);
pointLight->setSpecularColour(1.0, 0.0, 0.0);
//設定光線顏色跟反射顏色

Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight");
directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0));
directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0));
//設定平行光源,光線顏色、反色顏色


directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 )); 
//因為平行光從很遠的地方照射過來,所以不用設定位置,只要設定照射方向


Ogre::Light* spotLight = mSceneMgr->createLight("spotLight");
spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
spotLight->setDiffuseColour(0, 0, 1.0);
spotLight->setSpecularColour(0, 0, 1.0);
//新增一個聚光燈,設定光線顏色、反色顏色


spotLight->setDirection(-1, -1, 0);
spotLight->setPosition(Ogre::Vector3(300, 300, 0));
//要設定燈的位置及照射方向 


spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));
//可以設定光線直射區域及光暈大小。



}

arrow
arrow
    全站熱搜

    hoshili770205 發表在 痞客邦 留言(0) 人氣()