コード例 #1
0
ファイル: camera.cpp プロジェクト: sythaeryn/pndrpg
void	initCamera()
{
	if (ConfigFile->getVar("HMDEnable").asBool())
	{
		std::vector<NL3D::CStereoDeviceInfo> devices;
		IStereoDisplay::listDevices(devices);
		for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
		{
			std::stringstream name;
			name << std::string("[") << it->Serial << "] [" << IStereoDisplay::getLibraryName(it->Library) << " - " << it->Manufacturer << " - " << it->ProductName << "]";
			nlinfo("Stereo Display: %s", name.str().c_str());
		}
		CStereoDeviceInfo *deviceInfo = NULL;
		std::string hmdDeviceCfg = ConfigFile->getVar("HMDDevice").asString();
		if (hmdDeviceCfg == std::string("Auto")
			&& devices.begin() != devices.end())
		{
			for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
			{
				if (it->AllowAuto)
				{
					deviceInfo = &devices[0];
				}
			}
		}
		else
		{
			std::string hmdDeviceId = ConfigFile->getVar("HMDDeviceId").asString();
			for (std::vector<NL3D::CStereoDeviceInfo>::iterator it(devices.begin()), end(devices.end()); it != end; ++it)
			{
				std::stringstream name;
				name << IStereoDisplay::getLibraryName(it->Library) << " - " << it->Manufacturer << " - " << it->ProductName;
				if (name.str() == hmdDeviceCfg)
					deviceInfo = &(*it);
				if (hmdDeviceId == it->Serial)
					break;
			}
		}
		if (deviceInfo)
		{
			nlinfo("Create VR stereo display device");
			StereoDisplay = IStereoDisplay::createDevice(*deviceInfo);
			if (StereoDisplay)
			{
				if (deviceInfo->Class == CStereoDeviceInfo::StereoHMD)
				{
					nlinfo("Stereo display device is a HMD");
					StereoHMD = static_cast<IStereoHMD *>(StereoDisplay);
					StereoHMD->setScale(3.0f); // snowballs is about 4 units per meter
				}
				StereoDisplay->setDriver(Driver); // move after driver creation, move stereodisplay before driver creation
				StereoDisplay->attachToDisplay();
			}
		}
	}
	IStereoDisplay::releaseUnusedLibraries();

	// Set up directly the camera
	Camera = Scene->getCam();
	Camera.setTransformMode (UTransformable::DirectMatrix);
	Camera.setPerspective((float)Pi/2.f, 
		ConfigFile->getVar("ScreenWidth").asFloat() / ConfigFile->getVar("ScreenHeight").asFloat(), 
		0.1f, 1000.f);
	Camera.lookAt (CVector(ConfigFile->getVar("StartPoint").asFloat(0),
							ConfigFile->getVar("StartPoint").asFloat(1),
							ConfigFile->getVar("StartPoint").asFloat(2)),
							CVectorD (0,0,0));

	CamCollisionEntity = VisualCollisionManager->createEntity();
	CamCollisionEntity->setCeilMode(true);

	// Create the snowing particle system
	Snow = Scene->createInstance("snow.ps");
	// And setup it
	Snow.setTransformMode (UTransformable::DirectMatrix);

	//
	// Setup the sky scene
	//

	// -- -- not sure what the sky has to do with the camera

	SkyScene = Driver->createScene(false);

	SkyCamera = SkyScene->getCam ();
	SkyCamera.setTransformMode (UTransformable::DirectMatrix);
	// Set the very same frustum as the main camera
	SkyCamera.setFrustum (Camera.getFrustum ());

	Sky = SkyScene->createInstance("sky.shape");
	Sky.setTransformMode (UTransformable::DirectMatrix);
	Sky.setMatrix(CMatrix::Identity);
}
コード例 #2
0
ファイル: scene_parser.cpp プロジェクト: AzyxWare/ryzom
//-----------------------------------------------
// updateCamera :
// Update the camera (position, target, roll, fov)
//-----------------------------------------------
void CSceneParser::updateCamera(double timeInSec)
{
	// If there is a play list for the camera.
	if(_PlayList)
	{
		// Get the Id of the animation in the slot 0.
		uint idAnim = _PlayList->getAnimation(0);
		if(idAnim != UPlayList::empty)
		{
			UAnimation *animation = _AnimationSet->getAnimation(idAnim);
			if(animation)
			{
				// Get Camera informations from the animation (Pos, Target, Roll).
				UTrack* trackRollCam	= animation->getTrackByName("Camera.roll");
				UTrack* trackFovCam		= animation->getTrackByName("Camera.fov");
				UTrack* trackPosCam		= animation->getTrackByName("Camera.PathPos");
				UTrack* trackPosTarget	= animation->getTrackByName("Camera.Target.PathPos");
				if(trackPosCam && trackPosTarget)
				{
					float rollCam = 0.f;
					CVector posCam;
					CVector posTarget;
					float difTime = (float)(timeInSec-_TimeStart);

					if(trackRollCam)
						trackRollCam->interpolate(difTime, rollCam);
					trackPosCam->interpolate(difTime, posCam);
					trackPosTarget->interpolate(difTime, posTarget);

					// Update camera transformations.
					UCamera cam = Scene->getCam();
					if(cam)
					{
						cam->setTransformMode(UTransformable::RotQuat);
						cam->lookAt(posCam, posTarget, rollCam);
						if(trackFovCam)
						{
							float fov;
							trackFovCam->interpolate(difTime, fov);
							CFrustum	fr= cam->getFrustum();
							// change only the fov
							cam->setPerspective(fov, fr.getAspectRatio(), fr.Near, fr.Far);
						}
					}

					// Update camera transformations for the Root.
					cam = SceneRoot->getCam();
					if(cam)
					{
						cam->setTransformMode(UTransformable::RotQuat);
						cam->lookAt(posCam, posTarget, rollCam);
						if(trackFovCam)
						{
							float fov;
							trackFovCam->interpolate(difTime, fov);
							CFrustum	fr= cam->getFrustum();
							// change only the fov
							cam->setPerspective(fov, fr.getAspectRatio(), fr.Near, fr.Far);
						}
					}
				}
			}
		}
	}
}// updateCamera //