void CSceneNodeAnimatorCameraFollowShip::animateNode( ISceneNode* node, u32 timeMs )
{
	ICameraSceneNode* camera = static_cast<ICameraSceneNode*>( node );
	IShip* ship = static_cast<IShip*>(Target);

	vector3df direction = (ship->getTarget() - ship->getPosition()).normalize();
	vector3df offset = direction * Distance;
	/*vector3df upoffset = ship->getUpVector();
	upoffset = upoffset.normalize() * 10;*/

	camera->setPosition( ship->getPosition() + offset/* + upoffset */);
	camera->setRotation( ship->getRotation() );
	camera->setUpVector( ship->getUpVector() );
	camera->setTarget( ship->getTarget() );


}
Application::Application():sock(true){
	//int16_t mRCYaw = mRCPitch = mRCRoll = 0; 
	mRCThrottle = 1250; 
	mRCPitch = 1500; 
	mRCYaw = 1500; 
	mRCRoll = 1500; 
	
	mRCThrottle = 2000; 
	mRCPitch = 1000; 
	mRCYaw = 1000; 
	mRCRoll = 1000; 
	
	irrDevice = createDevice(video::EDT_OPENGL, dimension2d<u32>(640, 480), 32, false, false, false, this);
	irrGUI = irrDevice->getGUIEnvironment();
	irrTimer = irrDevice->getTimer();
	irrScene = irrDevice->getSceneManager();
	irrDriver = irrDevice->getVideoDriver();

	irrDevice->getCursorControl()->setVisible(0);

	// load a map
	irrDevice->getFileSystem()->addFileArchive("map-20kdm2.pk3");
	scene::IAnimatedMesh* mesh = irrScene->getMesh("20kdm2.bsp");
	scene::ISceneNode* node = 0;

	if (mesh)
			node = irrScene->addOctreeSceneNode(mesh->getMesh(0), 0, -1, 1024);
	if (node)
			node->setPosition(core::vector3df(-1300,-144,-1249));
        
	// Initialize bullet
	CollisionConfiguration = new btDefaultCollisionConfiguration();
	BroadPhase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000));
	Dispatcher = new btCollisionDispatcher(CollisionConfiguration);
	Solver = new btSequentialImpulseConstraintSolver();
	World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);
	World->setGravity(btVector3(0, -9.82, 0)); 

	// Add camera
	ICameraSceneNode *Camera = irrScene->addCameraSceneNodeFPS(0, 100, 0.01);
	//ICameraSceneNode *Camera = irrScene->addCameraSceneNode();
	Camera->setPosition(vector3df(0, 0, 0));
	Camera->setRotation(vector3df(45, -30, 0)); 
	//Camera->setUpVector(vector3df(0, 0, 1.0)); 
	//Camera->setTarget(vector3df(1, 0, 0));
	
	// Preload textures
	irrDriver->getTexture("ice0.jpg");
	irrDriver->getTexture("rust0.jpg");

	// Create the initial scene
	irrScene->addLightSceneNode(0, core::vector3df(2, 5, -2), SColorf(4, 4, 4, 1));
	irrScene->addLightSceneNode(0, core::vector3df(2, -5, -2), SColorf(4, 4, 4, 1));
	CreateStartScene();

	// Main loop
	TimeStamp = irrTimer->getTime(), DeltaTime = 0;

	Copter *view = new Copter(this);
	activeQuad = view;

	sock.bind("127.0.0.1", 9002); 
}