ogre 光源

ogre 光源
我们接着研究ogre的光源与影子。
void TutorialApplication::createCamera()
{
	mCamera = mSceneMgr->createCamera("PlayerCam");
	mCamera->setPosition(Ogre::Vector3(0,300,500));
	mCamera->lookAt(Ogre::Vector3(0,0,0));
	mCamera->setNearClipDistance(5);   //过近则不渲染
	//mCamera->setFarClipDistance(100);//因为我们要使用 stencil shadows这个不能设置

	mCameraMan = new OgreBites::SdkCameraMan(mCamera);
}
void TutorialApplication::createViewports()
{
	Ogre::Viewport* vp = mWindow->addViewport(mCamera);
	vp->setBackgroundColour(Ogre::ColourValue(0,0,0));
	mCamera->setAspectRatio(Ogre::Real(vp->getActualWidth())/Ogre::Real(vp->getActualHeight()));
}


//---------------------------------------------------------------------------
void TutorialApplication::createScene(void)
{
    Ogre::Entity* ninjaEnity = mSceneMgr->createEntity("ninja.mesh");
	ninjaEnity->setCastShadows(true);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ninjaEnity);

	Ogre::Plane plane(Ogre::Vector3::UNIT_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);

	Ogre::Entity* groundEntity = mSceneMgr->createEntity("ground");
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);
	groundEntity->setCastShadows(false);
	groundEntity->setMaterialName("Examples/Rockwall");

	mSceneMgr->setAmbientLight(Ogre::ColourValue(0,0,0));
	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);

	Ogre::Light* spotLight = mSceneMgr->createLight("SpotLight");
	spotLight->setDiffuseColour(0,0,1.0);
	spotLight->setSpecularColour(0,0,1.0);

	spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
	spotLight->setDirection(-1,-1,0);
	spotLight->setPosition(Ogre::Vector3(200,200,0));
	spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));

	Ogre::Light* directionalLight = mSceneMgr->createLight("DirectionalLight");
	directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
	directionalLight->setDiffuseColour(Ogre::ColourValue(.4, 0, 0));
	directionalLight->setSpecularColour(Ogre::ColourValue(.4, 0, 0));
	directionalLight->setDirection(Ogre::Vector3(0, -1, 1));

	Ogre::Light* pointLight = mSceneMgr->createLight("PointLight");
	pointLight->setType(Ogre::Light::LT_POINT);
	pointLight->setDiffuseColour(.3, .3, .3);
	pointLight->setSpecularColour(.3, .3, .3);
	pointLight->setPosition(Ogre::Vector3(0, 150, 250));
}

Ogre::Light::LT_POINT   点光源
Ogre::Light::LT_SPOTLIGHT  聚光灯
Ogre::Light::LT_DIRECTIONAL 方向光,比如太阳光

你可能感兴趣的:(ogre)