void 
Spacetime::reversePhysics_analytic(matrix<double> u)
{
	matrix<double> state_1 = getState();
	matrix<double> C_1 = computeC_analytic();
	matrix<double> G_1 = computeG_analytic();
	matrix<double> MInv_1 = !computeM_analytic();

	matrix<double> thetaDotDot_1 = -1.0 * (MInv_1 * (u - C_1 - G_1));
	
	matrix<double> stateDot_1(4,1);
	stateDot_1(0,0) = state_1(2,0);
	stateDot_1(1,0) = state_1(3,0);
	stateDot_1(2,0) = thetaDotDot_1(0,0);
	stateDot_1(3,0) = thetaDotDot_1(1,0);
	
	setState(state_1 + stateDot_1*deltaT/2.0);
	
	matrix<double> state_2 = getState();
	matrix<double> C_2 = computeC_analytic();
	matrix<double> G_2 = computeG_analytic();
	matrix<double> MInv_2 = !computeM_analytic();

	matrix<double> thetaDotDot_2 = -1.0 * (MInv_2 * (u - C_2 - G_2));
	
	matrix<double> stateDot_2(4,1);
	stateDot_2(0,0) = state_2(2,0);
	stateDot_2(1,0) = state_2(3,0);
	stateDot_2(2,0) = thetaDotDot_2(0,0);
	stateDot_2(3,0) = thetaDotDot_2(1,0);
	
	setState(state_1 + stateDot_2*deltaT);
}
void 
Spacetime::stepPhysics_analytic(matrix<double> u)
{
	matrix<double> state_1 = getState();
	matrix<double> C_1 = computeC_analytic();
	matrix<double> G_1 = computeG_analytic();
	matrix<double> MInv_1 = !computeM_analytic();

	matrix<double> damping = G_1;//(MInv_1 * (u - C_1 - G_1));
	damping(0,0) *= abs(state_1(2,0));
	damping(1,0) *= abs(state_1(3,0));

	matrix<double> thetaDotDot_1 =  (MInv_1 * (u/*+damping*/ - C_1 - G_1));
	
	matrix<double> stateDot_1(4,1);
	stateDot_1(0,0) = state_1(2,0);
	stateDot_1(1,0) = state_1(3,0);
	stateDot_1(2,0) = thetaDotDot_1(0,0);
	stateDot_1(3,0) = thetaDotDot_1(1,0);
	
	setState(state_1 + stateDot_1*deltaT/2.0);
	
	matrix<double> state_2 = getState();
	matrix<double> C_2 = computeC_analytic();
	matrix<double> G_2 = computeG_analytic();
	matrix<double> MInv_2 = !computeM_analytic();
	
	damping = G_2;
	damping(0,0) *= abs(state_2(2,0));
	damping(1,0) *= abs(state_2(3,0));

	matrix<double> thetaDotDot_2 = (MInv_2 * (u/*+damping*/ - C_2 - G_2));
	
	matrix<double> stateDot_2(4,1);
	stateDot_2(0,0) = state_2(2,0);
	stateDot_2(1,0) = state_2(3,0);
	stateDot_2(2,0) = thetaDotDot_2(0,0);
	stateDot_2(3,0) = thetaDotDot_2(1,0);
	
	setState(state_1 + stateDot_2*deltaT);
}
Example #3
0
int main(void) {
	while (1) {
		state = 0;
		int setTime = 15;
		numPlayers = 2;
		initScreen();
		clearScreen();
		initCharBuffer();
		clean_up();
		initKeyboard();
		initState0();
		initAI();


		//Bypass the menu system for testing
		if (IORD(keys,0) == 8) {
			initPlayer(pOne, MARIO, "pOne", 50, 100, HUMAN);
			initPlayer(pTwo, LUIGI, "pTwo", 50, 100, COMPUTER);
			state = 2;
		} else {
			while (state == 0) {
				decode_scancode(ps2, &decode_mode, buf, &ascii);
				state_0(decode_mode, buf[0]);
			};
			initState1(pOne);
			if(aOn)file_handle = initAudio(fname);
			if(aOn)alt_irq_register(AUDIO_0_IRQ, &ab, (alt_isr_func) write_fifo);
			if(aOn)		alt_up_audio_enable_write_interrupt(ab->audio);
			while (state == 1) {
				decode_scancode(ps2, &decode_mode, buf, &ascii);
				state_1(decode_mode, buf[0], ascii);
				if(aOn)loop_audio(file_handle, fname, ab);
			};
		}

		//clean_up();
		clearCharBuffer();
		clearScreen();

		//enable keyboard IRQ
		void* keyboard_control_register_ptr = (void*) (KEYBOARD_BASE + 4);
		alt_irq_register(KEYBOARD_IRQ, keyboard_control_register_ptr,
				keyboard_ISR);
		alt_up_ps2_enable_read_interrupt(ps2);

		//Draw field and UI to both buffers
		initField();

		updateField();
		drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name);
		drawGas(p[pOne].gas);
		drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		drawBullet(p[pOne].bulletType);
		//drawWindIndicator(1);
		updateScreen();

		updateField();
		drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name);
		drawGas(p[pOne].gas);
		drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp);
		drawBullet(p[pOne].bulletType);
		//drawWindIndicator(1);

		float time;
		alt_timestamp_start();


		int start_timer_flag = 1;
		//printf("NUM PLAYERA %i\n", numPlayers);
		int i;
		while (state == 2) {
			int fallFlag = 1;

			//Checks to see if any players are falling
			while (fallFlag == 1) {
				fallFlag = 0;
				for (i = 0; i < numPlayers; i++) {
					if (p[i].alive) {
						if (p[i].y + TANK_HEIGHT >= SCREEN_HEIGHT-1) {
							p[i].hp = 0;
							p[i].alive = DEAD;
						}
						checkPlayerFalling(i);
						if (p[i].isFalling) {
							undrawPlayer(i);
							updatePlayer(i);
							fallFlag = 1;
						}
					}
				}
				if (fallFlag == 1) {
					updateScreen();
				}
			}

			if(start_timer_flag){
				start_time = (float) alt_timestamp() / (float) alt_timestamp_freq();
				start_timer_flag = 0;
			}
			time = (float) alt_timestamp() / (float) alt_timestamp_freq()-start_time;
			if (time >= setTime) {
				setPlayerTurn();
			}
			if (p[turn].type == HUMAN) {
				runGame();

			} else {
				p[turn].deg = 0;
				aiMain(turn);
				setPlayerTurn();
			}
			printTimer(setTime - time);
			int deadCount = 0;
			for (i = 0; i < numPlayers; i++) {
				if (p[i].alive == DEAD)
					deadCount++;
			}
			if (deadCount == numPlayers - 1) {
				usleep(500000);
				state = 3;
			}
		}

		alt_up_ps2_disable_read_interrupt(ps2);
		if(aOn)alt_up_audio_disable_write_interrupt(ab->audio);

		GameOverScreen();
	}
}