Beispiel #1
0
void Camera::update(float elapsedTime,const Vector2f& mousePosition,bool buttonPressed) {
	/*
	if ( !gEngine->isConsoleActive() ) {
	*/
		if( GetAsyncKeyState('W') & 0x8000 ) {
			move(10.0f*elapsedTime);
		}
		if( GetAsyncKeyState('S') & 0x8000 ) {
			move(-10.0f*elapsedTime);
		}
		if( GetAsyncKeyState('A') & 0x8000 ) {
			strafe(-10.0f*elapsedTime);
		}
		if( GetAsyncKeyState('D') & 0x8000 ) {
			strafe(10.0f*elapsedTime);
		}
		
		if ( buttonPressed ) {		
			// Make each pixel correspond to a quarter of a degree.
			float dx = DEGTORAD(0.25f*(mousePosition.x - m_LastMousePosition.x));
			float dy = DEGTORAD(0.25f*(mousePosition.y - m_LastMousePosition.y));
			setPitch(dy);
			setYAngle(dx);		
		}
		m_LastMousePosition.x = mousePosition.x;
		m_LastMousePosition.y = mousePosition.y;
	//}
}
Beispiel #2
0
	void Camera::update()
	{
		float delta = 0.01f * _eye.z;
		//
		if (::GetAsyncKeyState('W') & 0x8000f)
		{
			walk(4.0f * delta);
		}
		if (::GetAsyncKeyState('S') & 0x8000f)
		{
			walk(-4.0f * delta);
		}
		if (::GetAsyncKeyState('A') & 0x8000f)
		{
			strafe(-4.0f * delta);
		}
		if (::GetAsyncKeyState('D') & 0x8000f)
		{
			strafe(4.0f * delta);
		}
		if (::GetAsyncKeyState('R') & 0x8000f)
		{
			fly(4.0f * delta);
		}
		if (::GetAsyncKeyState('F') & 0x8000f)
		{
			fly(-4.0f * delta);
		}
// 		if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000f)
// 		{
// 			yaw(-4.0f * delta);
// 		}
	}
Beispiel #3
0
void Camera::cameraInput(float deltaTime)
{
	float speed = 0.001f;
	if (GetAsyncKeyState('W') & 0x8000)
	{
		moveForward(speed);
	}
	if (GetAsyncKeyState('A') & 0x8000)
	{
		strafe(-speed); 
	}
	if (GetAsyncKeyState('S') & 0x8000)
	{
		moveForward(-speed); 
	}
	if (GetAsyncKeyState('D') & 0x8000)
	{
		strafe(speed); 
	}
	if (GetAsyncKeyState('X') & 0x8000)
	{
		moveVertically(-speed);
	}
	if (GetAsyncKeyState(VK_SPACE) & 0x8000)
	{
		moveVertically(speed);
	}


}
Beispiel #4
0
void CCamera::ProcInput(GameInput *gameInput)
{ 
	float fDelta = 0.005f;
	
	float x = gameInput->m_CurMState.pos.x - gameInput->m_OldMState.pos.x;
	float y = gameInput->m_CurMState.pos.y - gameInput->m_OldMState.pos.y;

	pitch(y * fDelta * 0.5);
	yaw(x * fDelta * 0.5);

	if(KEYDOWN('W'))
	{
		walk(5000.0f * fDelta);
	}
	if(KEYDOWN('S'))
	{
		walk(-5000.0f * fDelta);
	}
	if(KEYDOWN('A'))
	{
		strafe(-5000.0f * fDelta);
	}
	if(KEYDOWN('D'))
	{
		strafe(5000.0f * fDelta);
	}

	return;
}
void OnUpdate(float dt)
{
	XINPUT_STATE inputState = { 0, };
	if (XInputGetState(0, &inputState) == ERROR_SUCCESS)
	{
		if (inputState.Gamepad.sThumbLX < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE &&
			inputState.Gamepad.sThumbLX > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
			inputState.Gamepad.sThumbLX = 0;
		if (inputState.Gamepad.sThumbLY < XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE &&
			inputState.Gamepad.sThumbLY > -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
			inputState.Gamepad.sThumbLY = 0;
		if (inputState.Gamepad.sThumbRX < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
			inputState.Gamepad.sThumbRX > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
			inputState.Gamepad.sThumbRX = 0;
		if (inputState.Gamepad.sThumbRY < XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE &&
			inputState.Gamepad.sThumbRY > -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE)
			inputState.Gamepad.sThumbRY = 0;

		if (inputState.Gamepad.sThumbLY > 0) walk(30 * dt);
		else if (inputState.Gamepad.sThumbLY < 0) walk(-30 * dt);
		if (inputState.Gamepad.sThumbLX > 0) strafe(30 * dt);
		else if (inputState.Gamepad.sThumbLX < 0) strafe(-30 * dt);

		if (inputState.Gamepad.sThumbRY > 0) pitch(0.5f * dt);
		else if (inputState.Gamepad.sThumbRY < 0) pitch(-0.5f * dt);
		if (inputState.Gamepad.sThumbRX > 0) yaw(0.5f * dt);
		else if (inputState.Gamepad.sThumbRX < 0) yaw(-0.5f * dt);
	}
}
Beispiel #6
0
void strafeLeft(){
	setLiftPower(127);
	delay(500);
	setLiftPower(0);
	strafe(127, left);
	delay(750);
	strafe(0, left);
}
Beispiel #7
0
void strafeRight(){
	setLiftPower(127);
	delay(500);
	setLiftPower(0);
	strafe(127, right);
	delay(750);
	strafe(0, right);
}
Beispiel #8
0
void Camera::update(float timeDelta)
{
	if(EventDispatcher::Get()->keys[KEY_UP]) walk(10.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_DOWN]) walk(-10.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_LEFT]) strafe(-10.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_RIGHT]) strafe(10.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_N]) yaw(-1.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_M]) yaw(1.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_W]) pitch(-1.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_S]) pitch(1.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_Q]) roll(-1.0f * timeDelta);
	if(EventDispatcher::Get()->keys[KEY_E]) roll(1.0f * timeDelta);
}
void OnUpdate(float dt)
{
	if (IsKeyDown('W')) walk(30 * dt);
	else if (IsKeyDown('S')) walk(-30 * dt);
	if (IsKeyDown('A')) strafe(30 * dt);
	else if (IsKeyDown('D')) strafe(-30 * dt);

	float calcedX = GetMouseX() - lastMouseX, calcedY = GetMouseY() - lastMouseY;
	lastMouseX = GetMouseX();
	lastMouseY = GetMouseY();
	if (calcedY < 0) pitch(0.5f * dt * abs(calcedY));
	else if (calcedY > 0) pitch(-0.5f * dt * abs(calcedY));
	if (calcedX > 0) yaw(0.5f * dt * abs(calcedX));
	else if (calcedX < 0) yaw(-0.5f * dt * abs(calcedX));
}
void autoRamp(bool useLift)
{
	travelDistance(200, dBackward);
	gyroTurn(30, 15, dRight);
	goalRelease();
	wait1Msec(100);
	backward(15);
	wait1Msec(1500);
	stopMotors();
	int iCRate = servoChangeRate[goalCapture];	// Save change rate
	servoChangeRate[goalCapture] = 0; 					// Max Speed
	servo[goalCapture] = CATCHDOWN;					    // Set servo position
	wait1Msec(50);
	servoChangeRate[goalCapture] = iCRate;			// Reset the servo
	wait1Msec(100);
	travelDistance(10, dBackward);
	strafe(75);
	wait1Msec(500);
	stopMotors();
	travelDistance(100, dForward);
	gyroTurn(30, 2, dLeft);
	travelDistance(150, dForward);
	gyroTurn(20, 100, dRight);
	goalMed(useLift);
}
void getTube(eTube tube, int kickstandP)
{
	if(kickstandP == 1)
	{
		strafe(1/*not real*/);
		wait1Msec(1/*not real*/);
		travelDistance(1/*not real*/);
		gyroTurn(50,90,dRight);
		travelDistance(1/*not real*/);
		chooseTube(tube);

	}
	else if(kickstandP == 2)
	{
		chooseTube(tube);
	}

	else if(kickstandP == 3)
	{
		chooseTube(tube);
	}

	else
	{

	}
}
void autoFloor(bool useLift)
{
	int irValue = getIRReading();
	strafeDist(40, 100, dRight);
	displayCenteredTextLine(1, "IR = %i", irValue);
	if (irValue == 2)
	{
		strategyA(useLift);
	}
	else
	{
		irValue = getIRReading();
		if (irValue == 2)
		{
			strategyA(useLift);
		}

		else
		{
			gyroTurn(10, 5, dRight);
			int irValue1 = getIRReading();
			gyroTurn(10, 10, dLeft);
			int irValue2 = getIRReading();
			eraseDisplay();
			displayCenteredTextLine(2, "IR1 = %i", irValue1);
			displayCenteredTextLine(3, "IR2 = %i", irValue2);
			if (irValue1 == 2 || irValue2 == 2)
			{
				gyroTurn(10, 5, dRight);
				strategyA(useLift);
			}
			else
			{
				strafeDist(40, 75, dRight);
				gyroTurn(50, 30, dLeft);
				resetEncoders();
				while (irValue != 6)
				{
					irValue = getIRReading();
					strafe(100);
					int enc = abs(nMotorEncoder[leftBack]);
					displayCenteredTextLine(3, "distance=%i", enc);
					wait1Msec(1);
				}
				stopMotors();
				int enc = abs(nMotorEncoder[leftBack]);
				displayCenteredTextLine(1, "enc = %i", enc);
				if (enc < 1500)
				{
					strategyB(useLift);
				}
				else
				{
					strategyC(useLift);
				}
			}
		}
	}
}
task strafeButtoncontrol()
{

	//The following controls the strafe wheel
	if(vexRT[Btn8R] == 1)
	{
		strafe(127);
	}

	else if(vexRT[Btn8L] == 1)//Btn 8l goes left
	{
		strafe(-127);
	}
	else
	{
		strafe(0);
	}
}
void strategyX() //use if in position 3, from ramp
{
	displayCenteredTextLine(1, "strategy X"); //display whch strategy it chose
	strafe(50); //strafe right at half power
	wait1Msec(timeX1); //keep going for a certain amount of time
	stopMotors(); //stop
	travelDistance(distanceX1, dForward); //travel forward a certain distance
	gyroTurn(30, 80, dLeft); //turn left 80 degrees
	travelDistance(distanceX2, dForward); //travel forward a certain distance
}
task strafeTiltcontrol()						//TILT code
{
	int STRFthreshold=50;				//Threshold value obtained empirically. 36 works best
	while(1==1)
	{

		if((vexRT[AccelX] < (-1 * STRFthreshold))) //controller tilted LEFT beyond threshold (NEGATIVE value)
		{
			strafe(-127);		//LEFT
		}
		else if((vexRT[AccelX] > (STRFthreshold))) //controller tilted RIGHT beyond threshold (POSITIVE value)
		{
			strafe(127);			//RIGHT
		}
		else
		{
			strafe(0);
		}
	}
}
Beispiel #16
0
void	main_key(const bool *keys, t_ray *ray)
{
  if (keys[BKS_A] || keys[BKS_E])
    strafe(((keys[BKS_A]) ? 1 : 0), ray);
  if (keys[BKS_Z] || keys[BKS_S])
    move_player(((keys[BKS_Z]) ? 1 : 0), ray);
  if (keys[BKS_Q] || keys[BKS_D])
    rotate_player(((keys[BKS_Q]) ? 1 : 0), ray);
  if (keys[BKS_M])
    main_slowmo(ray);

}
Beispiel #17
0
int		key_hook(t_mega *all)
{
	if (all->hook.up)
		move_up_down(all, UP);
	if (all->hook.down)
		move_up_down(all, DOWN);
	if (all->hook.right)
		turn(all, -all->cam.rotspeed);
	if (all->hook.left)
		turn(all, all->cam.rotspeed);
	if (all->hook.strafe_left)
		strafe(all, LEFT);
	if (all->hook.strafe_right)
		strafe(all, RIGHT);
	if (all->hook.shoot)
		weapon_shoot(all);
	if (all->hook.minimap_enable)
		show_minimap(all);
	if (all->hook.action)
		do_something(all);
	return (1);
}
Beispiel #18
0
//-----------------------------------------------------------------------------
//! @brief   TODO enter a description
//! @remark
//-----------------------------------------------------------------------------
void Camera::update( float elapsedTime, double time, const Input& input )
{
    const InputState* inputState = input.getInput(0);
    if (inputState)
    {
		InputActions::ActionType fowardAction;
		InputActions::ActionType backwardAction;
		InputActions::ActionType moveLeftAction;
		InputActions::ActionType moveRightAction;
		InputActions::ActionType yawLeftAction;
		InputActions::ActionType yawRightAction;
		InputActions::ActionType pitchUpAction;
		InputActions::ActionType pitchDownAction;
		InputActions::ActionType rollLeftAction;
		InputActions::ActionType rollRightAction;
		InputSystem::getInputActionFromName(moveForward.getHash(), fowardAction);
		InputSystem::getInputActionFromName(moveBackWards.getHash(), backwardAction);
		InputSystem::getInputActionFromName(moveLeft.getHash(), moveLeftAction);
		InputSystem::getInputActionFromName(moveRight.getHash(), moveRightAction);
		InputSystem::getInputActionFromName(yawLeft.getHash(), yawLeftAction);
		InputSystem::getInputActionFromName(yawRight.getHash(), yawRightAction);
		InputSystem::getInputActionFromName(pitchUp.getHash(), pitchUpAction);
		InputSystem::getInputActionFromName(pitchDown.getHash(), pitchDownAction);
		InputSystem::getInputActionFromName(rollLeft.getHash(), rollLeftAction);
		InputSystem::getInputActionFromName(rollRight.getHash(), rollRightAction);

        float moveAlongDirectionFactor = inputState->getActionValue(fowardAction) - inputState->getActionValue(backwardAction);
        moveAlongDirection(moveAlongDirectionFactor * m_movementSpeed * elapsedTime );//Move forwared, backward
        float strafeFactor = inputState->getActionValue(moveLeftAction) - inputState->getActionValue(moveRightAction);
        strafe(strafeFactor   * m_movementSpeed * elapsedTime);//Move left/right
        float yawFactor = inputState->getActionValue(yawLeftAction) - inputState->getActionValue(yawRightAction);
        yaw(yawFactor * m_rotationSpeed * elapsedTime);
        float pitchFactor = inputState->getActionValue(pitchUpAction) - inputState->getActionValue(pitchDownAction);
        pitch(pitchFactor * m_rotationSpeed * elapsedTime); 
        float zAxisDelta = inputState->getActionValue(rollLeftAction) - inputState->getActionValue(rollRightAction);
        roll(zAxisDelta * m_rotationSpeed * 0.05f);
    }

    //Use the varibles to avoid a warning and allows us to use them in the code above without change
    time = 0.0;
    elapsedTime = 0.0f;
}
task main()
{
	disableDiagnosticsDisplay();

	while(true) {
		getJoystickSettings(joystick);  // Update Buttons and Joysticks
  	wait1Msec(10);

		/*--------------------------
		controller one
		-------------------------*/
		/*-------------------------
		maping
		---------------------------
		up =
		down =
		left = strafe left
		right = strafe right
		joystick left = left motors
		joystick right = right motors
		A = catcher down
		B =	catcher up
		X =
		Y =
		L1 =
		L2 =
		R1 =
		R2 =
		---------------------------*/

		// If lift is too high slower the driver motors
		if(nMotorEncoder[liftRight] < GOVLIMIT) {
			GOVERNOR = 1;
		} else {
		  GOVERNOR = 2;
		}

		// Drive the robot from joystick 1
		if((abs(joystick.joy1_y1) >= deadZone) || (abs(joystick.joy1_y2) >= deadZone)) {
			setMotion(joystick.joy1_y1 / GOVERNOR, joystick.joy1_y2 / GOVERNOR);
		}
		/*else if(joystick.joy1_TopHat == 6) {
			strafe(50);
		}
		else if(joystick.joy1_TopHat == 2){
			strafe(-50);
		}*/
		else if(joy1Btn(JOY_BUTTON_LT)) {
		  strafe(-50);
		}
	  else if(joy1Btn(JOY_BUTTON_RT)) {
	  	strafe(50);
		}
	  else {
		  stopMotors();
		}

		if(joy1Btn(JOY_BUTTON_RB))
		{
		int iCRate = servoChangeRate[goalCapture];	// Save change rate
		servoChangeRate[goalCapture] = 0; 					// Max Speed
		servo[goalCapture] = CATCHDOWN;					// Set servo position
		wait1Msec(20);
		servoChangeRate[goalCapture] = iCRate;			// Reset the servo
		}
		else if(joy1Btn(JOY_BUTTON_LB))
		{
		int iCRate = servoChangeRate[goalCapture];	// Save change rate
		servoChangeRate[goalCapture] = 0; 					// Max Speed
		servo[goalCapture] = CATCHUP;					// Set servo position
		wait1Msec(20);
		servoChangeRate[goalCapture] = iCRate;			// Reset the servo
	}

	/*--------------------------
	controller two
	-------------------------*/
	/*-------------------------
	maping
	---------------------------
	up =
	down =
	left =
	right =
	joystick left =
	joystick right =
	A =
	B =
	X =
	Y =
	LB = big backward
	LT = big forward
	RB = small backward
	RT = small forward
	---------------------------*/
		// Raise/lower the lift
		if(abs(joystick.joy2_y2) > deadZone) {
			stopLiftTask(); //first, ensure that robot is not already moving the lift
			if((joystick.joy2_y2 <= 0) && TSreadState(LTOUCH)) {
				lift(0);// if touch sensor is active and driver says go down, stop the lift (don't burn out motor)
				nMotorEncoder[liftMotor] = 0; //The lift is down, so set lift encoder to 0
				} else {//If touch is NOT active or driver says go up
				lift(rescale(joystick.joy2_y2)); //Raise lift at a rescaled value of the joystick
			}
			} else { //No controls?
			lift(0); //Stop lift motors.
		}
		// Set the lift to preset heights
		/*if(joy2Btn(JOY_BUTTON_A)) {
			liftHeight(35);
		} else if(joy2Btn(JOY_BUTTON_B)) {
			liftHeight(65);
		}	else if(joy2Btn(JOY_BUTTON_Y)) {
			liftHeight(95);
		} else if(joy2Btn(JOY_BUTTON_X)) {
			liftHeight(115);
		} else if(joy2Btn(JOY_BUTTON_RT)) {
			liftHeight(0);
			nMotorEncoder[liftRight] = 0;
		}*/

		// Run the spinner to pick up balls
		if((abs(joystick.joy2_y1)) >= deadZone) {
			spin(rescale(joystick.joy2_y1));
		} else {
			spin(0);
		}
	}
}
Beispiel #20
0
void g1_human_class::think()
{
	i4_bool process_input = i4_T;

	if (playback_think())
	{
		process_input=i4_F;
	}


	g1_player_piece_class * stank = commander();
	if ((g1_current_controller->view.get_view_mode()!=G1_ACTION_MODE &&
		 g1_current_controller->view.get_view_mode()!=G1_FOLLOW_MODE))
	{
		process_input=i4_F;
	}

	if (!process_input) //are we controlling the stank?
	{
		g1_input.deque_time(g1_input_class::LEFT);
		g1_input.deque_time(g1_input_class::RIGHT);
		g1_input.deque_time(g1_input_class::UP);
		g1_input.deque_time(g1_input_class::DOWN);
		g1_input.deque_time(g1_input_class::STRAFE_LEFT);
		g1_input.deque_time(g1_input_class::STRAFE_RIGHT);
		g1_input.deque_time(g1_input_class::STRAFE_UP);
		g1_input.deque_time(g1_input_class::STRAFE_DOWN);
		g1_input.deque_time(g1_input_class::ZOOM_IN);
		g1_input.deque_time(g1_input_class::ZOOM_OUT);
		g1_input.deque_time(g1_input_class::ZOOM_LEFT);
		g1_input.deque_time(g1_input_class::ZOOM_RIGHT);

		g1_input.deque_time(g1_input_class::ZOOM_UP);
		g1_input.deque_time(g1_input_class::ZOOM_DOWN);
//	if (g1_current_controller->view.get_view_mode()==G1_STRATEGY_MODE)
//		{
//		g1_resources.startegy_camera_dist+=(strategy_up-strategy_down)*G1_HZ/1000.0f;
//		if (g1_resources.startegy_camera_dist<=0.1f) g1_resources.startegy_camera_dist=0.1f;
//		g1_resources.startegy_camera_angle+=(strategy_out-strategy_in)*G1_HZ/1000.0f;
//		if (g1_resources.startegy_camera_angle<=0.1f) g1_resources.startegy_camera_angle=0.1f;
//		}
	}
	else
	{
		//keys are buffered in the order pressed, so do a reversed comparison
		if (memcmp(g1_input.grab_cheat_keys(),"DOG",3)==0)
		{
			g1_input.clear_cheat_keys();
			if (stank)
			{
				stank->toggle_stank_flag(g1_player_piece_class::ST_GODMODE);
			}
		}

		//This would actually belong the receive_event() function of
		//the border frame class, but it needs to be executed regardless
		//of wheter an event is outstanding.
		if (g1_border.get())
		{
			i4_float heh;
			i4_float cx=g1_border->last_mouse_x();
			i4_float lx=g1_border->prev_mouse_x();
			i4_float cy=g1_border->last_mouse_y();
			i4_float ly=g1_border->prev_mouse_y();
			if (cy<7)
			{
				heh=-0.2f;
			}
			else if (cy>(g1_border->height()-7))
			{
				heh=0.2f;
			}
			else
			{
				heh = ((cy - ly)*0.01f);
			}
			mouse_look_increment_y += heh;

			//if (mev->x<5)
			//  heh=-1.0f;
			//else if (mev->x>(width()-5))
			//  heh=1.0f;
			//else
			//if (mev->x>20&&mev->x<(width()-20))
			//    heh = (((sw32)mev->x - (sw32)mev->lx)*0.01f);
			//else
			//  heh=0;

			if (cx<20)
			{
				heh=-0.1f;
			}
			else if (cx>(g1_border->width()-20))
			{
				heh=0.1f;
			}
			else
			{
				heh = ((cx - lx)*0.01f);
			}
			mouse_look_increment_x += heh;
			g1_border->clear_mouse_move();
		}
		g1_map_piece_class * whofor=controlled();


		sw32
		left_ms=g1_input.deque_time(g1_input_class::LEFT),
		right_ms=g1_input.deque_time(g1_input_class::RIGHT),
		up_ms=g1_input.deque_time(g1_input_class::UP),
		down_ms=g1_input.deque_time(g1_input_class::DOWN),
		sleft_ms=g1_input.deque_time(g1_input_class::STRAFE_LEFT),
		sright_ms=g1_input.deque_time(g1_input_class::STRAFE_RIGHT);
		sw32 sup_ms=g1_input.deque_time(g1_input_class::STRAFE_UP);
		sw32 sdown_ms=g1_input.deque_time(g1_input_class::STRAFE_DOWN);
		sw32 zoom_in=g1_input.deque_time(g1_input_class::ZOOM_IN),
			 zoom_out=g1_input.deque_time(g1_input_class::ZOOM_OUT),
			 zoom_left=g1_input.deque_time(g1_input_class::ZOOM_LEFT),
			 zoom_right=g1_input.deque_time(g1_input_class::ZOOM_RIGHT),
			 zoom_up=g1_input.deque_time(g1_input_class::ZOOM_UP),
			 zoom_down=g1_input.deque_time(g1_input_class::ZOOM_DOWN);

		look(mouse_look_increment_x, mouse_look_increment_y,whofor);
		mouse_look_increment_y = mouse_look_increment_x = 0;
		turn( g1_resources.player_turn_speed*(left_ms-right_ms)*G1_HZ/1000.0f, whofor );
		accelerate( (up_ms-down_ms)*G1_HZ/1000.0f,whofor);
		strafe( (sright_ms-sleft_ms)*G1_HZ/1000.0f,
			   (sup_ms-sdown_ms)*G1_HZ/1000.0f,whofor);
		if (g1_current_controller->view.get_view_mode()==G1_FOLLOW_MODE)
		{
			g1_resources.follow_camera_dist+=(zoom_out-zoom_in)*G1_HZ/1000.0f;
			if (g1_resources.follow_camera_dist<=0.5f)
			{
				g1_resources.follow_camera_dist=0.5f;
			}
			g1_resources.follow_camera_height+=(zoom_up-zoom_down)*G1_HZ/1000.0f;
			g1_resources.follow_camera_rotation+=(zoom_right-zoom_left)*G1_HZ/1000.0f;
		}

		//if (sright_ms>0)
		//  sright_ms=sright_ms+1;

		if (g1_input.button_1())
		{
			fire0(whofor);
		}
		if (g1_input.button_2())
		{
			fire1(whofor);
		}
		if (g1_input.button_3())
		{
			fire2(whofor);
		}
	}


	if (g1_input.key_pressed)
	{
		continue_game();
	}

	g1_input.key_pressed=i4_F;
}
void FloatingCamera::simulateSelf(GLdouble deltaTime)
{

    double pyrSpd = -5;
    double pyrRot = 3;
    Matrix4D newTransform = Matrix4D::createIdentity();

    //Create movement vector
    Vector3f dVec = {0,0,0};
    double dYaw = 0.0;
    double dPitch = 0.0;
    double dRoll = 0.0;

    if(mApp->gMoveForward)
    {
        dVec.z = -pyrSpd*deltaTime;
    }
    else if(mApp->gMoveBackward)
    {
        dVec.z = pyrSpd*deltaTime;
    }

    if(mApp->gMoveLeft)
    {
        dVec.x = -pyrSpd*deltaTime;
    }
    else if(mApp->gMoveRight)
    {
        dVec.x = pyrSpd*deltaTime;
    }

    if(mApp->gMoveUp)
    {
        dVec.y = pyrSpd*deltaTime;
    }
    else if(mApp->gMoveDown)
    {
        dVec.y = -pyrSpd*deltaTime;
    }

   if(mApp->gYawLeft)
    {
        dYaw = pyrRot*deltaTime;
    }
    else if(mApp->gYawRight)
    {
        dYaw = -pyrRot*deltaTime;
    }

    if(mApp->gPitchUp)
    {
        dPitch = pyrRot*deltaTime;
    }
    else if(mApp->gPitchDown)
    {
        dPitch = -pyrRot*deltaTime;
    }

    if(mApp->gRollLeft)
    {
        dRoll = pyrRot*deltaTime;
    }
    else if(mApp->gRollRight)
    {
        dRoll = -pyrRot*deltaTime;
    }

    if(mRechargeTime > 0)
    {
        mRechargeTime -= deltaTime;
    }

    if(mApp->gShoot)
    {
        if(mRechargeTime < 0)
        {
            //Shoot
             MatterNodePtr matterNode(new MatterNode(mApp, VP_RENDER_GEOMETRY, mApp->gBulletMaterial, false, mApp->gBulletFile.c_str()));
            // matterNode->setOffset(0.0f, 0.0f, 0.0f);
            matterNode->setTransform(getCameraMatrix().inverted());
            Vector3f force = mForward * mApp->gBulletForce;
            matterNode->setInitialForce(force);
            mApp->getSceneGraph()->getRoot()->addChild(matterNode);

            mRechargeTime = RECHARGE_TIME;
        }
    }

    yaw(dYaw);
    pitch(dPitch);
    roll(dRoll);

    walk(dVec.z);
    fly(dVec.y);
    strafe(dVec.x);
}
Beispiel #22
0
//--------------------------------------------------------------
// Name:        Evaluate()
// Class:       GeneralCombatWithMeleeWeapon
//
// Description: Returns True Or False, and is run every frame
//              that the behavior
//
// Parameters:  Actor &self
//
// Returns:     True or False
//--------------------------------------------------------------
BehaviorReturnCode_t GeneralCombatWithMeleeWeapon::Evaluate ( Actor &self )
{      
	Entity *currentEnemy;

	// Make sure our rotate and headwatch targets are up to date
	if ( _state != GENERAL_COMBAT_MELEE_ATTACK && _state != GENERAL_COMBAT_MELEE_CHANGE_POSTURE )
		setUpRotate( self );        
		
	faceEnemy( self );
	setHeadWatchTarget( self );


	currentEnemy = self.enemyManager->GetCurrentEnemy();

	if (currentEnemy && _maxDistanceToEngage && !self.WithinDistance( currentEnemy, _maxDistanceToEngage))
		{
		self.enemyManager->ClearCurrentEnemy();
		SetFailureReason( "My Current Enemy is farther away than my _maxDistanceToEngage\n" );
		return BEHAVIOR_FAILED; // I may have an enemy, but he's too far away.  Ignore him.
		}
 
	if ( _state == GENERAL_COMBAT_MELEE_FAILED )
		return BEHAVIOR_FAILED;

	if ( currentEnemy && !self.WithinDistance( currentEnemy , _meleeDistance ) && level.time > _nextRushAttemptTime )
		{
		setupRushEnemy( self );
		_state = GENERAL_COMBAT_MELEE_RUSH_ENEMY;      
		}

	switch ( _state )
		{
		case GENERAL_COMBAT_MELEE_SELECT_STATE:
			//setTorsoAnim( self ); // Breaks the initial attack anim
			selectState( self );
		break;

		case GENERAL_COMBAT_MELEE_RUSH_ENEMY:
			rushEnemy( self );
		break;

		case GENERAL_COMBAT_MELEE_STRAFE:
			setTorsoAnim( self );
			strafe(self);
			setTorsoAnim( self );
		break;

		case GENERAL_COMBAT_MELEE_ATTACK:      
			attack( self );
		break;

		case GENERAL_COMBAT_MELEE_BLOCK:
			block( self );
		break;

		case GENERAL_COMBAT_MELEE_CHANGE_POSTURE:
			changePosture(self);
		break;

		case GENERAL_COMBAT_MELEE_HOLD:
			setTorsoAnim( self );
			hold( self );
		break;

		case GENERAL_COMBAT_MELEE_FAILED:
			return BEHAVIOR_FAILED;
		}

	return BEHAVIOR_EVALUATING; 
}
void FlightController::run() {
    double yUpperLimit = 9300;
    double lowerLimit = 1500;
    double xUpperLimit = 8100;
    Route myRoute;
    myRoute.initRoute(true);

    ros::Rate loop_rate(LOOP_RATE);
    setStraightFlight(true);

    bool firstIteration = true;

    takeOff();

    bool turning = true;
    double amountTurned = 0;
    double turnStepSize = 30;

    hoverDuration(3);
    navData->resetRawRotation();
    hoverDuration(2);

    cmd.linear.z = 0.5;
    pub_control.publish(cmd);
    while (navData->getPosition().z < 1200)
        ros::Rate(LOOP_RATE).sleep();



    hoverDuration(1);

    Vector3 pos;
    double starting_orientation = navData->getRawRotation();
    //ROS_INFO("Start while");

    while (!dronePossision.positionLocked) {
        //ROS_INFO("in while");
        if (turning) {
            turnDegrees(turnStepSize);
            double orientation = navData->getRawRotation();
            amountTurned += angleDifference(starting_orientation,orientation);
            //ROS_INFO("AMOUNTTURNED: %f",amountTurned);
            starting_orientation = orientation;
            if (amountTurned >= 360)
                turning = false;
        } else {
            navData->resetRaw();
            flyForward(0.4);
            turning = true;
            amountTurned = 0;
        }

    }

    lookingForQR = false;

    cmd.linear.z = -0.5;
    pub_control.publish(cmd);
    while (navData->getPosition().z > 900)
        ros::Rate(LOOP_RATE).sleep();

    //ROS_INFO("end while");
    navData->resetToPosition(dronePossision.x * 10, dronePossision.y * 10, dronePossision.heading);

    int startWall = dronePossision.wallNumber;

    turnDegrees(-dronePossision.angle);

    if(startWall == 0) {
        while (navData->getPosition().y - 700 > lowerLimit) {
            flyBackward(0.7);
            navData->addToY(-700);

            hoverDuration(3);
        }

        strafe(1, 0.8);
        navData->addToX(1000);
        hoverDuration(2);

        while (navData->getPosition().y + 700 < yUpperLimit) {
            flyForward(0.5);
            navData->addToX(700);

            hoverDuration(3);
        }
    } else if(startWall == 2){
        while (navData->getPosition().y + 700 < yUpperLimit) {
            flyForward(0.5);
            navData->addToX(700);

            hoverDuration(3);
        }

        strafe(1, 0.8);
        navData->addToX(-1000);
        hoverDuration(2);

        while (navData->getPosition().y - 700 > lowerLimit) {
            flyBackward(0.7);
            navData->addToY(-700);

            hoverDuration(3);
        }
    } else if(startWall == 3) {
        while (navData->getPosition().x + 700 < xUpperLimit){
            flyBackward(0.7);
            navData->addToX(700);
            hoverDuration(3);
        }

        strafe(1, 0.8);
        navData->addToY(1000);
        hoverDuration(2);

        while (navData->getPosition().x - 700 > xUpperLimit){
            flyBackward(0.7);
            navData->addToX(-700);
            hoverDuration(3);
        }
    } else if(startWall == 1){
        while (navData->getPosition().x + 700 < xUpperLimit){
            flyBackward(0.7);
            navData->addToX(700);
            hoverDuration(3);
        }

        strafe(1, 0.8);
        navData->addToY(-1000);
        hoverDuration(2);

        while (navData->getPosition().x - 700 > xUpperLimit){
            flyBackward(0.7);
            navData->addToX(-700);
            hoverDuration(3);
        }
    }
   /* else if(dronePossision.wallNumber == 1){
        while (navData->getPosition().y - 1000 > 1500) {
            flyForward(0.7);
            navData->addToY(-1000);

            hoverDuration(3);
            cvHandler->swapCam(false);
            cvHandler->checkCubes();
            cvHandler->swapCam(true);
        }
    }*/




    /*double rotation = navData->getRotation();
    double target;
    int wallNumber = dronePossision.wallNumber;
    ROS_INFO("WALL NUMBER RECEIVED START: %d", wallNumber);
    switch(dronePossision.wallNumber) {
        case 0:
            target = 180;
            break;
        case 1:
            target = 270;
            break;
        case 2:
            target = 0;
            break;
        case 3:
            target = 90;
            break;
    }

    ROS_INFO("Target = %f", target);*/



    /*int i = 0;
    while(i < 4) {
        double difference = angleDifference(rotation, target);
        int direction = angleDirection(rotation, target);
        ROS_INFO("Difference = %f", difference);
        ROS_INFO("Direction = %f", direction);
        //turnDegrees(difference*direction);

        cmd.angular.z = 1;
        pub_control.publish(cmd);
        while(navData->getRotation() > 190 || navData->getRotation() < 170 )
            ros::Rate(50).sleep();

    //ROS_INFO("Difference = %f", difference);
    //ROS_INFO("Direction = %f", direction);
    //turnTowardsAngle(target, 0);

/*    lookingForQR = true;
    flyForward(0.7);
    cvHandler->swapCam(false);
    hoverDuration(3);
    cvHandler->checkCubes();
    cvHandler->swapCam(true);
    flyForward(0.7);
    cvHandler->swapCam(false);
    hoverDuration(3);
    cvHandler->checkCubes();
    cvHandler->swapCam(true);
    flyForward(0.7);
    cvHandler->swapCam(false);
    hoverDuration(3);
    cvHandler->checkCubes();
    cvHandler->swapCam(true);
    flyForward(0.7);
    cvHandler->swapCam(false);
    hoverDuration(3);
    cvHandler->checkCubes();
    cvHandler->swapCam(true);

    lookingForQR = true;
    strafe(0.7, -1);
    cvHandler->swapCam(false);
    hoverDuration(3);
    cvHandler->checkCubes();
    cvHandler->swapCam(true);
    strafe(0.7, -1);
    cvHandler->swapCam(false);
    hoverDuration(3);
    cvHandler->checkCubes();
    cvHandler->swapCam(true);
    strafe(0.7, -1);
    cvHandler->swapCam(false);
    hoverDuration(3);
    cvHandler->checkCubes();
    cvHandler->swapCam(true);
    strafe(0.7, -1);
    cvHandler->swapCam(false);
    hoverDuration(3);
    cvHandler->checkCubes();
    cvHandler->swapCam(true);

    if(target == 0)
        while(navData->getPosition().y +1000 < 9300) {
            flyForward(0.7);
            navData->addToY(1000);

                hoverDuration(4);
                cvHandler->swapCam(false);
                cvHandler->checkCubes();
                cvHandler->swapCam(true);
                if (navData->getRotation() != target) {
                    difference = angleDifference(rotation, target);
                    direction = angleDirection(rotation, target);
                    ROS_INFO("Difference = %f", difference);
                    ROS_INFO("Direction = %f", direction);
                    turnDegrees(difference * direction);
                }
            }
        else if (target == 180)
            while (navData->getPosition().y - 1000 > 1500) {
                flyForward(0.7);
                navData->addToY(-1000);

                hoverDuration(4);
                cvHandler->swapCam(false);
                cvHandler->checkCubes();
                cvHandler->swapCam(true);
                if (navData->getRotation() != target) {
                    difference = angleDifference(rotation, target);
                    direction = angleDirection(rotation, target);
                    ROS_INFO("Difference = %f", difference);
                    ROS_INFO("Direction = %f", direction);
                    turnDegrees(difference * direction);
                }
            }

        }
*/

    land();
    return;
}