Jump to content

Switching between CIGI and "manual" flight control


photo

Recommended Posts

Posted

Hello,

Is it possible to temporarily regain manual "flight" control during a CIGI session (through custom code/script)?

Use case: During a flight session, we may need to "flight with keyboard and mouse" to reckon the terrain, prepare the mission or simply debrief. In our current IG, with a key press, with toggle between network CIGI control and mouse control. Can a similar behavior be coded ?

Thanks.

Posted

Hi Amerio,

Yes, of course!
You need to make a "Player switcher": a switcher between the current Player (made by CIGIClient) and your PlayerSpectator (which can be controlled by keyboard/mouse).
Here is a sample code for this feature:

AppWorldLogic.h:

#include <UniginePlayers.h>
//...
class AppWorldLogic : public Unigine::WorldLogic {
private:
	Unigine::PlayerSpectatorPtr spectator; // your Player that can be controlled by keyboard/mouse
	Unigine::PlayerPtr default_player; // in your case, it is a Player created by CIGI Client
// ...
};


AppWorldLogic.cpp:

#include <UnigineApp.h>
#include <UnigineConsole.h>
#include <UnigineGame.h>

using namespace Unigine;

int AppWorldLogic::init() 
{
	// create and set up your Player
	spectator = PlayerSpectator::create();
	spectator->setZFar(200000.0f);		// set far clip plane (200 km, for example)
	spectator->setMinVelocity(50.0f);	// set camera speed when you use WSAD/QE keys (50 m/s)
	spectator->setMaxVelocity(500.0f);	// set camera speed when you hold SHIFT key (500 m/s)
	
	// ...
	return 1;
}

int AppWorldLogic::update()
{
	// switch the camera by press the SPACE button
	if (App::get()->clearKeyState(' ') && !Console::get()->getActivity())
	{
		PlayerPtr current_player = Game::get()->getPlayer();
		if (!current_player || current_player != spectator)
		{
			// switch to manual camera
			default_player = current_player; // save current CIGI camera
			spectator->setWorldTransform(current_player->getWorldTransform()); // make position and rotation of our camera the same as the CIGI camera
			Game::get()->setPlayer(spectator->getPlayer()); // set to our camera
		}
		else
			// switch to automatic CIGI camera
			Game::get()->setPlayer(default_player);
	}
	
	return 1;
}

 

Best regards,
Alexander

  • Like 1
Posted

Hi, thanks a lot for the code snippet !

(I had to modify it a bit because VS2015 could not find the '!=' operator PlayerPtr, though.)

×
×
  • Create New...