void debug_help()
{
	int s, i;

	dc_printf( "Available functions:\n\n" );

	s = scroll_times;
	for (i=0; i<Num_debug_commands; i++ ) {
		dc_printf( " %s - %s\n", Debug_command[i]->name, Debug_command[i]->help );

		if ( scroll_times - s > DROWS - 3 ) {
			int k;
			dc_printf( "       Press a key...B for back\n" );
			debug_draw();
			k = key_getch();
			s = scroll_times;
			if ( k == KEY_B ) {
				i -= ((DROWS-3)*2);
				if ( i <= 0 ) {
					i = -1;
				}
			}
		}
		debug_draw();
	}
	dc_printf( "\n" );

	dc_printf( "Typing '? function_name' will give the current status.\n" );
	dc_printf( "Typing 'function_name ?' will give help on the function.\n" );
	dc_printf( "Typing ? or help will give you help.\n");
	dc_printf( "F3 selects last command line.\n" );
}
Example #2
0
int main(int argc, char* argv[])
{
	bool rv;
	cv::Mat capture_img, canvas_img;

	rv = init_video(0);
	//rv = init_image("source.png");
	//rv = init_movie("source.m4v");
	if (rv == false) return -1;

	while(true) {
		capture(capture_img);
		process(capture_img);

		capture_img.copyTo(canvas_img);
		debug_draw(canvas_img);
		cv::imshow("result", canvas_img);

		int c = cv::waitKey(1);
		if (c == 27) {
			break;
		}
	}

	finish();

	cv::destroyAllWindows();

	return 0;
}
Example #3
0
// The start of the Application
int Raycasting::start(const std::vector<std::string> &args)
{
	//Remove the need to send physic world to every object. Instead send just the description.

	//Fix having two fixtures working weirdly.
	quit = false;

	int window_x_size = 640;
	int window_y_size = 480;
	// Set the window
	DisplayWindowDescription desc;
	desc.set_title("ClanLib Raycasting Example");
	desc.set_size(Size(window_x_size, window_y_size), true);
	desc.set_allow_resize(false);

	DisplayWindow window(desc);
	
	// Connect the Window close event
	Slot slot_quit = window.sig_window_close().connect(this, &Raycasting::on_window_close);

	// Connect a keyboard handler to on_key_up()
	Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &Raycasting::on_input_up);

	// Create the canvas
	Canvas canvas(window);

	//Setup physic world
	PhysicsWorldDescription phys_desc;
	phys_desc.set_gravity(0.0f,10.0f);
	phys_desc.set_sleep(true);
	phys_desc.set_physic_scale(100);
	phys_desc.set_timestep(1.0f/200.0f);

	PhysicsWorld phys_world(phys_desc);

	//Get the Physics Context
	PhysicsContext pc = phys_world.get_pc();

	//Setup ground body
	BodyDescription ground_desc(phys_world);
	ground_desc.set_position(Vec2f((float)window_x_size/2.0f,(float)window_y_size));
	ground_desc.set_type(body_static);

	Body ground(pc, ground_desc);
	//Setup ground fixture
	PolygonShape ground_shape(phys_world);
	ground_shape.set_as_box((float)window_x_size/2,20.0f);

	FixtureDescription fixture_desc(phys_world);
	fixture_desc.set_shape(ground_shape);
	
	Fixture ground_fixture(pc, ground, fixture_desc);

	//Setup box body
	BodyDescription box_desc(phys_world);
	box_desc.set_position(Vec2f(10.0f,10.0f));
	box_desc.set_type(body_dynamic);
	box_desc.set_linear_velocity(Vec2f(100.0f,0.0f));
	Body box(pc, box_desc);

	box_desc.set_position(Vec2f((float)window_x_size-50.0f,100.0f));
	box_desc.set_linear_velocity(Vec2f(-80.0f,0.0f));
	Body box2(pc, box_desc);

	//Setup box fixture
	PolygonShape box_shape(phys_world);
	box_shape.set_as_box(30.0f, 30.0f);

	FixtureDescription fixture_desc2(phys_world);
	fixture_desc2.set_shape(box_shape);
	fixture_desc2.set_restitution(0.6f);
	fixture_desc2.set_friction(0.0005f);

	Fixture box_fixture(pc, box, fixture_desc2);
	Fixture box_fixture2(pc, box2, fixture_desc2);

	Vec2f ground_pos = ground.get_position();

	unsigned int last_time = System::get_time();
	
	//Setup debug draw.
	PhysicsDebugDraw debug_draw(phys_world);
	debug_draw.set_flags(f_shape|f_aabb);

	GraphicContext gc = canvas.get_gc();
	PhysicsQueryAssistant qa = phys_world.get_qa();

	clan::Font font(canvas, "Tahoma", 12);

	// Set raycast points
	Pointf p1(300,500);
	Pointf p2(100,100);

	// Set query rect;
	Rectf rect1(400.0f, 380.0f, Sizef(50.0f,50.0f));

	// Run until someone presses escape
	while (!quit)
	{
		unsigned int current_time = System::get_time();
		float time_delta_ms = static_cast<float> (current_time - last_time);
		last_time = current_time;

		canvas.clear();
		
		//Raycast
		
		font.draw_text(canvas, 10,20, "Raycasting...");
		
		qa.raycast_first(p1, p2);
		if(qa.has_query_result())
		{
			font.draw_text(canvas, 100,20, "Found object !");
			canvas.draw_line(p1,p2, Colorf::green);
		}
		else canvas.draw_line(p1, p2, Colorf::red);
		
		//Raycast

		//Query
		
		font.draw_text(canvas, 10,35, "Querying...");

		qa.query_any(rect1);

		if(qa.has_query_result())
		{
			font.draw_text(canvas, 100,35, "Found object !");
			canvas.draw_box(rect1, Colorf::green);

		}
		else canvas.draw_box(rect1, Colorf::red);
		//Query

		phys_world.step();
		debug_draw.draw(canvas);
		
		canvas.flush();
		window.flip(1);

		// This call processes user input and other events
		KeepAlive::process(0);

		System::sleep(10);
	}

	return 0;
}
void debug_console( void (*_func)() )
{
	int done = 0;

	scanner_init();

	while( key_inkey() ) {
		os_poll();
	}

	if ( !debug_inited ) {
		debug_init();
	}

	debug_draw();

	while (!done) {
		// poll the os
		os_poll();

		int k = key_inkey();
		switch( k ) {

		case KEY_SHIFTED+KEY_ENTER:
		case KEY_ESC:
			done=1; break;

		case KEY_BACKSP:
			if ( command_line_pos > 0 ) {
				command_line[--command_line_pos] = 0;
			}
			break;

		case KEY_F3:
			if ( last_oldcommand > -1 ) {
				strcpy_s( command_line, oldcommand_line[last_oldcommand] );
				command_line_pos = strlen(command_line);
				command_line[command_line_pos] = 0;
			}
			break;

		case KEY_UP:
			command_scroll--;
			if (command_scroll<0) {
				command_scroll = last_oldcommand;
			}

			if ( command_scroll > -1 ) {
				strcpy_s( command_line, oldcommand_line[command_scroll] );
				command_line_pos = strlen(command_line);
				command_line[command_line_pos] = 0;
			}
			break;

		case KEY_DOWN:
			command_scroll++;
			if (command_scroll>last_oldcommand) {
				command_scroll = 0;
			}
			if (command_scroll>last_oldcommand) {
				command_scroll = -1;
			}
			if ( command_scroll > -1 ) {
				strcpy_s( command_line, oldcommand_line[command_scroll] );
				command_line_pos = strlen(command_line);
				command_line[command_line_pos] = 0;
			}
			break;

		case KEY_ENTER: {
			debug_output( '\n' );
			debug_draw();

			debug_do_command(command_line);

			int i, found = 0;
			for (i=0; i<=last_oldcommand; i++ ) {
				if (!stricmp( oldcommand_line[i], command_line )) {
					found = 1;
				}
			}
			if ( !found ) {
				if ( last_oldcommand < DEBUG_HISTORY-1 ) {
					last_oldcommand++;
					strcpy_s( oldcommand_line[last_oldcommand], command_line);
				} else {
					int iLoop;
					for (iLoop=0; iLoop<last_oldcommand; iLoop++ ) {
						strcpy_s( oldcommand_line[iLoop], oldcommand_line[iLoop+1] );
					}
					strcpy_s( oldcommand_line[last_oldcommand], command_line);
				}
			}

			debug_output( '\n' );
			command_line_pos = 0;
			command_line[command_line_pos] = 0;

			command_scroll = 0;

			} 
			break;
		default: {
				ubyte c = (ubyte)key_to_ascii(k);
				if ( c != 255 ) {
					command_line[command_line_pos++] = c;
					command_line[command_line_pos] = 0;
				}
			}
		}

		strcpy_s( debug_text[debug_y], ">" );
		strcat_s( debug_text[debug_y], command_line );
		debug_draw();

		if ( _func ) {
			_func();
		}
	}

	while( key_inkey() ) {
		os_poll();
	}
}
Example #5
0
// The start of the Application
int Collision::start(const std::vector<std::string> &args)
{
	//Remove the need to send physic world to every object. Instead send just the description.

	//Fix having two fixtures working weirdly.
	quit = false;

	// Set the window
	DisplayWindowDescription desc;
	desc.set_title("ClanLib Collision Example");
	desc.set_size(Size(window_x_size, window_y_size), true);
	desc.set_allow_resize(false);

	DisplayWindow window(desc);
	
	// Connect the Window close event
	window.sig_window_close().connect(this, &Collision::on_window_close);

	// Connect a keyboard handler to on_key_up()
	window.get_ic().get_keyboard().sig_key_up().connect(this, &Collision::on_input_up);

	// Create the canvas
	Canvas canvas(window);

	//Setup physic world
	PhysicsWorldDescription phys_desc;
	phys_desc.set_gravity(0.0f,10.0f);
	phys_desc.set_sleep(true);
	phys_desc.set_physic_scale(100);
	phys_desc.set_timestep(1.0f/60.0f);
	phys_desc.set_velocity_iterations(8);
	phys_desc.set_position_iterations(3);

	PhysicsWorld phys_world(phys_desc);

	//Setup ground body
	Body ground = create_ground_body(phys_world);

	unsigned int last_time = System::get_time();

	//Setup outline body
	Body outline_body = create_outline_body(phys_world);
	outline_body.set_position(Vec2f(200.0f,200.0f));

	//Setup debug draw.
	PhysicsDebugDraw debug_draw(phys_world);
	debug_draw.set_flags(f_shape);

	GraphicContext gc = canvas.get_gc();
	
	// Run until someone presses escape
	while (!quit)
	{
		unsigned int current_time = System::get_time();
		float time_delta_ms = static_cast<float> (current_time - last_time);
		last_time = current_time;

		canvas.clear();
		
		phys_world.step();
		debug_draw.draw(canvas);

		canvas.flush();
		window.flip(1);
		
		// This call processes user input and other events
		KeepAlive::process(0);

		System::sleep(10);
	}

	return 0;
}
Example #6
0
// The start of the Application
int Joints::start(const std::vector<std::string> &args)
{
	//Remove the need to send physic world to every object. Instead send just the description.

	//Fix having two fixtures working weirdly.
	quit = false;

	// Set the window
	DisplayWindowDescription desc;
	desc.set_title("ClanLib Joints Example");
	desc.set_size(Size(window_x_size, window_y_size), true);
	desc.set_allow_resize(false);

	DisplayWindow window(desc);
	
	// Connect the Window close event
	Slot slot_quit = window.sig_window_close().connect(this, &Joints::on_window_close);

	// Connect a keyboard handler to on_key_up()
	Slot slot_input_up = (window.get_ic().get_keyboard()).sig_key_up().connect(this, &Joints::on_input_up);

	// Create the canvas
	Canvas canvas(window);

	//Setup physic world
	PhysicsWorldDescription phys_desc;
	phys_desc.set_gravity(0.0f,10.0f);
	phys_desc.set_sleep(true);
	phys_desc.set_physic_scale(100);

	PhysicsWorld phys_world(phys_desc);

	//Setup ground body
	Body ground = create_ground_body(phys_world);

	unsigned int last_time = System::get_time();

	//Setup debug draw.
	PhysicsDebugDraw debug_draw(phys_world);
	debug_draw.set_flags(f_shape|f_aabb|f_joint);

	GraphicContext gc = canvas.get_gc();
	//Setup joints

	const int number_of_joints = 3;
	std::vector<Body> bodies_A(number_of_joints);
	std::vector<Body> bodies_B(number_of_joints);
	std::vector<std::shared_ptr<Joint>> Joints(number_of_joints);
	

	for(int i=0; i<number_of_joints; i++)
	{
		bodies_A[i] = create_box_body(phys_world);
		bodies_A[i].set_position(Vec2f(80.0f+80.0f*i,280.0f));

		bodies_B[i] = create_box_body(phys_world);
		bodies_B[i].set_position(Vec2f(80.0f+80.0f*i,440.0f));

		Joints[i] = create_joint(phys_world, bodies_A[i], bodies_B[i], i);
	}

	// Run until someone presses escape
	while (!quit)
	{
		unsigned int current_time = System::get_time();
		float time_delta_ms = static_cast<float> (current_time - last_time);
		last_time = current_time;

		canvas.clear();
		
		phys_world.step();
		debug_draw.draw(canvas);

		canvas.flush();
		window.flip(1);

		// This call processes user input and other events
		KeepAlive::process(0);

		System::sleep(10);
	}

	return 0;
}
Example #7
0
void DrawDebug(void)
{
	if (settings->enable_debug_keys)
	{
		// handle debug keys
		if (justpushed(DEBUG_GOD_KEY))
		{
			game.debug.god ^= 1;
			sound(SND_MENU_SELECT);
		}
		
		if (justpushed(DEBUG_SAVE_KEY))
		{
			game_save(settings->last_save_slot);
			sound(SND_SWITCH_WEAPON);
			console.Print("Game saved.");
		}
		
		if (justpushed(F6KEY))
		{
			game.debug.DrawBoundingBoxes ^= 1;
			sound(SND_COMPUTER_BEEP);
		}
		
		if (justpushed(F9KEY))
		{
			AddXP(1);
		}
		
		if (inputs[DEBUG_FLY_KEY])
		{
			player->yinertia = -0x880;
			if (!player->hurt_time) player->hurt_time = 20;		// make invincible
		}
	}
	
	/*if (game.debug.debugmode)
	{
		//debug("%d fps", game.debug.fps);
		
		if (game.debug.god)
		{
			//debug("<GOD MODE>");
			player->weapons[player->curWeapon].level = 2;
			player->weapons[player->curWeapon].xp = player->weapons[player->curWeapon].max_xp[2];
			player->weapons[player->curWeapon].ammo = player->weapons[player->curWeapon].maxammo;
			player->hp = player->maxHealth;
		}
		
		debug("%d,%d", (player->x>>CSF)/TILE_W, (player->y>>CSF)/TILE_H);
		debug("[%c%c%c%c]", player->blockl?'l':' ', player->blockr?'r':' ', player->blocku?'u':' ', player->blockd?'d':' ');
		//debug("%d", player->xinertia);
		//debug("%d", player->yinertia);*/
		/*
		debug("Have Puppy: %d", game.flags[274]);
		debug("Kakeru: %d", game.flags[275]);
		debug("Runner Gone: %d", game.flags[276]);
		debug("No Shinobu: %d", game.flags[277]);
		debug("Door Open: %d", game.flags[278]);
		debug("Mick: %d", game.flags[279]);
		debug("Gave 1st: %d", game.flags[590]);
		debug("Gave 2nd: %d", game.flags[591]);
		debug("Gave 3rd: %d", game.flags[592]);
		debug("Gave 4th: %d", game.flags[593]);
		debug("Gave 5th: %d", game.flags[594]);
		debug("-");
		{
			int i;
			for(i=0;i<player->ninventory;i++)
				debug("%d", player->inventory[i]);
		}
		*/
	//}
	
	debug_draw();
	DrawDebugMarks();
}