예제 #1
0
/**
 * @brief The worker thread function that accepts input keyboard commands.
 *
 * This is ok here - but later it might be a good idea to make a node which
 * posts keyboard events to a topic. Recycle common code if used by many!
 */
void KobukiManager::keyboardInputLoop()
{
  struct termios raw;
  memcpy(&raw, &original_terminal_state, sizeof(struct termios));

  raw.c_lflag &= ~(ICANON | ECHO);
  // Setting a new line, then end of file
  raw.c_cc[VEOL] = 1;
  raw.c_cc[VEOF] = 2;
  tcsetattr(key_file_descriptor, TCSANOW, &raw);

  puts("Reading from keyboard");
  puts("---------------------------");
  puts("Forward/back arrows : linear velocity incr/decr.");
  puts("Right/left arrows : angular velocity incr/decr.");
  puts("Spacebar : reset linear/angular velocities.");
  puts("q : quit.");
  char c;
  while (!quit_requested)
  {
    if (read(key_file_descriptor, &c, 1) < 0)
    {
      perror("read char failed():");
      exit(-1);
    }
    processKeyboardInput(c);
  }
}
bool BaseFrameListener::frameEnded(const FrameEvent &evt) {

	// grab the keyboard & mouse state
	app->getKeyboard()->capture();
	app->getMouse()->capture();

	processKeyboardInput(evt);
	processMouseInput(evt);

	if(! keepRendering)
	{
		//OGRE_APP.shutdown();
	}

	return keepRendering;
}
예제 #3
0
void PlayerCharacter::update(Ogre::Real elapsedTime, OIS::Keyboard *input) 
{

	processKeyboardInput(elapsedTime);
	processMouseInput(elapsedTime);

	//Get the position of the ground below the player
	Ogre::TerrainGroup* terrain = RenderManager::getSingletonPtr()->getTerrainManager()->getTerrainGroup();
		
	//Store the position to increase it, to guarantuee a hit on the terrain
	Ogre::Vector3 main_position = mMainNode_->getPosition();
	Ogre::Vector3 ray_cast_position = main_position;
	ray_cast_position.y += 1000.0f;

	// Setup the query ray
	Ogre::Ray queryRay(ray_cast_position, Ogre::Vector3::NEGATIVE_UNIT_Y);

	// Perform the scene query
	Ogre::TerrainGroup::RayResult result = terrain->rayIntersects(queryRay);

	if(result.hit) {
		mCurrentGroundPosition = result.position.y;
	}


	//Process jumping
	if(isJumping_)
	{
		// if we're jumping, add a vertical offset too, and apply gravity
		mMainNode_->translate(0, mCurrentDropVelocity * elapsedTime, 0, Ogre::Node::TS_LOCAL);
		mCurrentDropVelocity -= mDropVelocityIncrement * elapsedTime;
			
		Ogre::Vector3 pos = mMainNode_->getPosition();
		if (pos.y <= mCurrentGroundPosition)
		{
			// if we've hit the ground, change to landing state
			pos.y = mCurrentGroundPosition;
			mMainNode_->setPosition(pos);
			isJumping_ = false;
			mCurrentDropVelocity = 0.0f;
		}
	}

	//Upate the player height to the world if not jumping
	if(!isJumping_)
	{
		if(main_position.y <= mCurrentGroundPosition)
		{
			main_position.y = mCurrentGroundPosition;
			mMainNode_->setPosition(main_position);
			mCurrentDropVelocity = 0.0f;
		}
		else
		{
			mCurrentDropVelocity += mDropVelocityIncrement * elapsedTime;
			main_position.y = main_position.y - mCurrentDropVelocity;

			//Check if we are already below the ground
			if(main_position.y < mCurrentGroundPosition)
				main_position.y = mCurrentGroundPosition;
			mMainNode_->setPosition(main_position);
		}
	}

	if (isRunning_ && mBaseAnimID == ANIM_IDLE_BASE)
	{
		// start running if not already moving and the player wants to move
		setBaseAnimation(ANIM_WALK, true);
	}

	if(!isRunning_ && mBaseAnimID == ANIM_WALK)
	{
		setBaseAnimation(ANIM_IDLE_BASE);
	}

	updateAnimations(elapsedTime);
}
예제 #4
0
/**
 * @brief Callback function for remote keyboard inputs subscriber.
 */
void KeyOpCore::remoteKeyInputReceived(const kobuki_msgs::KeyboardInput& key)
{
  processKeyboardInput(key.pressedKey);
}