Exemple #1
0
// this is actually render
void updateSky()
{
	CMatrix skyCameraMatrix;
	skyCameraMatrix.identity();
	// 
	skyCameraMatrix= Camera.getMatrix();
	skyCameraMatrix.setPos(CVector::Null);
	SkyCamera.setMatrix(skyCameraMatrix);

	SkyScene->render();
	// Must clear ZBuffer For incoming rendering.
	Driver->clearZBuffer();

	if (!StereoHMD) // Cloudscape not supported (fix Viewport please)
		Clouds->render();
}
Exemple #2
0
void updateCamera()
{
	if (StereoHMD)
	{
		NLMISC::CQuat hmdOrient = StereoHMD->getOrientation();
		NLMISC::CMatrix camMatrix = Camera.getMatrix();
		NLMISC::CMatrix hmdMatrix;
		hmdMatrix.setRot(hmdOrient);
		NLMISC::CMatrix posMatrix; // minimal head modeling, will be changed in the future
		posMatrix.translate(StereoHMD->getEyePosition());
		Camera.setMatrix((camMatrix * hmdMatrix) * posMatrix);
	}
	// Set the new position of the snow emitter
	CMatrix	mat = CMatrix::Identity;
	mat.setPos (Camera.getMatrix().getPos()/*+CVector (0.0f, 0.0f, -10.0f)*/);
	Snow.setMatrix(mat);
}
	virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */)
	{
		NL3D::UInstance inst = Scene->createInstance("wind.ps");
		if (!inst.empty())
		{
			inst.setPos(MainCam.getPos());
		}
	}
Exemple #4
0
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);
}
Exemple #5
0
namespace SBCLIENT {

//
// Variables
//

// The camera for the whole scene
UCamera					Camera = NULL;
// The collision entity use to snap the camera on the ground
UVisualCollisionEntity	*CamCollisionEntity = NULL;

// The particle system for the snowing effect
static UInstance			Snow = NULL;

// The sky 3D objects
UScene				*SkyScene = NULL;
UCamera				SkyCamera = NULL;
static UInstance			Sky = NULL;

static UCloudScape			*Clouds = NULL;

IStereoDisplay *StereoDisplay = NULL;
IStereoHMD *StereoHMD = NULL;

//
// Functions
//

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);
}

void releaseCamera()
{
	SkyScene->deleteInstance(Sky);
	Driver->deleteScene(SkyScene);
	Scene->deleteInstance(Snow);
	VisualCollisionManager->deleteEntity(CamCollisionEntity);

	if (StereoHMD)
	{
		delete StereoHMD;
		StereoHMD = NULL;
		StereoDisplay = NULL;
	}
	delete StereoDisplay;
	StereoDisplay = NULL;
	IStereoDisplay::releaseAllLibraries();
}

void updateCamera()
{
	if (StereoHMD)
	{
		NLMISC::CQuat hmdOrient = StereoHMD->getOrientation();
		NLMISC::CMatrix camMatrix = Camera.getMatrix();
		NLMISC::CMatrix hmdMatrix;
		hmdMatrix.setRot(hmdOrient);
		NLMISC::CMatrix posMatrix; // minimal head modeling, will be changed in the future
		posMatrix.translate(StereoHMD->getEyePosition());
		Camera.setMatrix((camMatrix * hmdMatrix) * posMatrix);
	}
	// Set the new position of the snow emitter
	CMatrix	mat = CMatrix::Identity;
	mat.setPos (Camera.getMatrix().getPos()/*+CVector (0.0f, 0.0f, -10.0f)*/);
	Snow.setMatrix(mat);
}

void initSky()
{
	// -- -- or what the clouds have to do with the sky

	SCloudScapeSetup css;
	Clouds = Scene->createCloudScape ();
	Clouds->init (&css);
	Clouds->setQuality (160);
	Clouds->setNbCloudToUpdateIn80ms (1);
}

void releaseSky()
{
	Scene->deleteCloudScape(Clouds);
}

// -- -- random note: update and render makes more sense than animate and update
void animateSky(double dt)
{
	if (!StereoHMD) Clouds->anim(dt);
	SkyScene->animate(AnimationTime);
}

// this is actually render
void updateSky()
{
	CMatrix skyCameraMatrix;
	skyCameraMatrix.identity();
	// 
	skyCameraMatrix= Camera.getMatrix();
	skyCameraMatrix.setPos(CVector::Null);
	SkyCamera.setMatrix(skyCameraMatrix);

	SkyScene->render();
	// Must clear ZBuffer For incoming rendering.
	Driver->clearZBuffer();

	if (!StereoHMD) // Cloudscape not supported (fix Viewport please)
		Clouds->render();
}

} /* namespace SBCLIENT */
Exemple #6
0
//-----------------------------------------------
// aiMode :
// Manage the Fly Mode.
//-----------------------------------------------
void CUserControls::aiMode()
{
	CInterfaceManager *IM = CInterfaceManager::getInstance ();

	// Left Click and Dbl Click
	bool dblClickLeft = false;
	if(EventsListener.isMouseButtonPushed(leftButton))
	{
		_LeftClickStart = T1;
	}
	if( EventsListener.isMouseButtonReleased (leftButton) )
	{
		if(T1 <= _LeftClickEnd + CWidgetManager::getInstance()->getUserDblClickDelay())
		{
			dblClickLeft = true;
		}
		_LeftClickEnd = T1;
	}

	// Right Click and Dbl Click
	bool dblClickRight = false;
	if(EventsListener.isMouseButtonPushed(rightButton))
	{
		_RightClickStart = T1;
	}
	if( EventsListener.isMouseButtonReleased (rightButton) )
	{
		if(T1 <= _RightClickEnd + CWidgetManager::getInstance()->getUserDblClickDelay())
		{
			dblClickRight = true;
		}
		_RightClickEnd = T1;
	}

	if (EventsListener.isMouseButtonReleased (rightButton))
	{
		// Short Right Click -> Check Action
		if((T1-_RightClickStart) <= _TimeLongClick)
		{
			if(ClientCfg.SelectWithRClick)
				execActionCursorPos(true,dblClickRight);

			// Launch Context Menu
			if (!R2::isEditionCurrent()) // context menu managed in a different fashion for R2ED
			{
				IM->launchContextMenuInGame("ui:interface:game_context_menu");
			}
		}
		else
		{
			EventsListener.enableMouseSmoothing(false);
		}

		// Give back the mouse handling to the interface.
		CWidgetManager::getInstance()->enableMouseHandling(true);
	}
	else if (EventsListener.isMouseButtonDown (rightButton))
	{
		if((T1-_RightClickStart) > _TimeLongClick)
		{
			CWidgetManager::getInstance()->enableMouseHandling(false);
			EventsListener.enableMouseSmoothing(true);
			// Get the cursor instance and hide.
			CViewPointer *cursor = static_cast< CViewPointer* >( CWidgetManager::getInstance()->getPointer() );
			if(cursor)
			{
				// Freelook mode.
				SetMouseFreeLook ();
			}

			if (EventsListener.isMouseAngleX())
			{
				// Rotate the body.
				CMatrix m;
				m.identity();
				m.rotateZ(-EventsListener.getMouseAngleX ());
				View.view((m * View.view()).normed());
			}

			if (EventsListener.isMouseAngleY())
			{
				CMatrix m;
				// Get the rotation axis.
				CVector v = View.view() ^ CVector(0,0,1);
				// Transform to a Quaternion
				CQuat quat(v, EventsListener.getMouseAngleY ());

				// Get the rotation matrix.
				m.identity();
				m.setRot(quat);
				// Create a front vector from the view.
				CVector front = View.view();
				front.z = 0;
				front.normalize();
				// Set the new view.
				v = (m * View.view()).normed();
				if(v*front > 0)
					View.view(v);
			}
		}
	}
	else
	{
		// Freelook mode.
		SetMouseCursor ();

		// Is the left click activated.
		if (EventsListener.isMouseButtonReleased (leftButton))
			execActionCursorPos(true,dblClickLeft);
	}


	// Turn the camera to the left.
	if(Actions.valide("turn_left"))
	{
		CMatrix camMatrix = MainCam.getMatrix();
		camMatrix.rotateZ(DT*ClientCfg.RotKeySpeedMax);
		View.view(camMatrix.getJ());
	}
	// Turn the camera to the right.
	if(Actions.valide("turn_right"))
	{
		CMatrix camMatrix = MainCam.getMatrix();
		camMatrix.rotateZ(-DT*ClientCfg.RotKeySpeedMax);
		View.view(camMatrix.getJ());
	}

	// look up
	if (Actions.valide("look_up"))
	{
		CMatrix camMatrix = MainCam.getMatrix();
		// Avoid gimbal lock
		float	angle= DT*ClientCfg.RotKeySpeedMax;
		float	curAngle= asinf(camMatrix.getJ().z);
		if(curAngle+angle > float(0.95*Pi/2))
			angle= float(0.95*Pi/2) - curAngle;
		// rotate
		camMatrix.rotateX(angle);
		View.view(camMatrix.getJ());
	}
	// look down
	if (Actions.valide("look_down"))
	{
		CMatrix camMatrix = MainCam.getMatrix();
		// Avoid gimbal lock
		float	angle= -DT*ClientCfg.RotKeySpeedMax;
		float	curAngle= asinf(camMatrix.getJ().z);
		if(curAngle+angle < float(-0.95*Pi/2))
			angle= float(-0.95*Pi/2) - curAngle;
		// rotate
		camMatrix.rotateX(angle);
		View.view(camMatrix.getJ());
	}

	// Move up
	float accel = 0;
	if (Actions.valide("camera_up"))
		accel += ClientCfg.FlyAccel;
	// Move down
	if (Actions.valide("camera_down"))
		accel -= ClientCfg.FlyAccel;
	updateVelocity (DT, accel, ClientCfg.FlyAccel, ClientCfg.Fly, _FlyVerticalVelocity);

	// Action "Foraward" is valide -> Autowalk false, forward true.
	accel = 0;
	if(Actions.valide("forward"))
		accel += ClientCfg.FlyAccel;
	// Action "backward" is valide -> Autowalk false, backward true.
	if(Actions.valide("backward"))
		accel -= ClientCfg.FlyAccel;
	updateVelocity (DT, accel, ClientCfg.FlyAccel, ClientCfg.Fly, _FlyFrontVelocity);

	// Action "strafe_left" is valide -> strafeLeft true.
	accel = 0;
	if(Actions.valide("strafe_left"))
		accel -= ClientCfg.FlyAccel;
	// Action "strafe_right" is valide -> strafeRight true.
	if(Actions.valide("strafe_right"))
		accel += ClientCfg.FlyAccel;
	updateVelocity (DT, accel, ClientCfg.FlyAccel, ClientCfg.Fly, _FlyLateralVelocity);

	// Set the view.
	const CMatrix &camMatrix = MainCam.getMatrix();
	View.viewPos(View.viewPos() + camMatrix.getI()*(_FlyLateralVelocity*DT) + camMatrix.getJ()*(_FlyFrontVelocity*DT) + camMatrix.getK()*(_FlyVerticalVelocity*DT));
}// aiMode //
Exemple #7
0
//-----------------------------------------------
// 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 //
Exemple #8
0
	void CObjectViewer::init(nlWindow wnd, uint16 w, uint16 h)
	{
		//H_AUTO2
		nldebug("CObjectViewer::init");

		// load and set remap extensions from config
		//Modules::config().configRemapExtensions();

		// load and set search paths from config
		//Modules::config().configSearchPaths();

		// set background color from config
		Modules::config().setAndCallback("BackgroundColor", CConfigCallback(this, &CObjectViewer::cfcbBackgroundColor));	

		// set graphics driver from config
		Modules::config().setAndCallback("GraphicsDriver",CConfigCallback(this,&CObjectViewer::cfcbGraphicsDriver));

		// create the driver
		nlassert(!_Driver);

		_Driver = UDriver::createDriver(NULL, _Direct3D, NULL);
		nlassert(_Driver);

		// initialize the window with config file values
		_Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32));

		_Light = ULight::createLight();

		// set mode of the light
		_Light->setMode(ULight::DirectionalLight);

		// set position of the light
		_Light->setPosition(CVector(-20.f, 30.f, 10.f));

		// white light
		_Light->setAmbiant(CRGBA(255, 255, 255));

		// set and enable the light
		_Driver->setLight(0, *_Light);
		_Driver->enableLight(0);

		// Create a scene
		_Scene = _Driver->createScene(true);

		_PlayListManager = _Scene->createPlayListManager();

		_Scene->enableLightingSystem(true);

		// create the camera
		UCamera camera = _Scene->getCam();

		camera.setTransformMode (UTransformable::DirectMatrix);

		setSizeViewport(w, h);

		// camera will look at entities
		updateCamera(0,0,0);

		NLMISC::CVector hotSpot=NLMISC::CVector(0,0,0);

		_MouseListener = _Driver->create3dMouseListener();
		_MouseListener->setMatrix(Modules::objView().getScene()->getCam().getMatrix());
		_MouseListener->setFrustrum(Modules::objView().getScene()->getCam().getFrustum());
		_MouseListener->setHotSpot(hotSpot);
		_MouseListener->setMouseMode(U3dMouseListener::edit3d);
	}