Exemplo n.º 1
0
Arquivo: main.c Projeto: ErikHK/tsbk03
/////////////////////////////////////////
//		M A I N
//
int main(int argc, char **argv)
{
	srand(time(NULL));
	mouse_x = 0;
	old_mouse_x = 0;
	mouse_y = 0;
	old_mouse_y = 0;

	m_angle = -300*M_PI; //FOULHACK!


	glutInit(&argc, argv);


	initKeymapManager();
	glutPassiveMotionFunc(mouse);

	//glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GL_MULTISAMPLE);
	glutInitWindowSize(800, 600);
	glutInitContextVersion(3, 2); // Might not be needed in Linux
	glutCreateWindow("Farm Escape");
	glutDisplayFunc(DisplayWindow);

	create_floor(&f);
	//create_plank(&p, SetVector(4,4,0), SetVector(0,5,0));
	create_fence(&ff, 14, SetVector(0,0,0));
	//f.model = generate_terrain(32);
	create_ball(&ball, SetVector(5,0,0));
	create_wall(&wall, SetVector(0,10,0), SetVector(2,5,2));

	create_joint(&legbase_joint[0], SetVector(-2.2, 3.8, .7), 
	"legjoint0", "legcurrpos0", "legbonepos0", 0);
	create_joint(&legbase_joint[1], SetVector(-2.2, 3.8, -.7),
	"legjoint1", "legcurrpos1", "legbonepos1", 0);
	create_joint(&legbase_joint[2], SetVector(.2, 3.9, -.7),
	"legjoint2", "legcurrpos2", "legbonepos2", 0);
	create_joint(&legbase_joint[3], SetVector(.2, 3.9, .7),
	"legjoint3", "legcurrpos3", "legbonepos3", 0);

	create_joint(&thigh_joint[0], SetVector(-2.3, 1.8, .4),
	NULL, NULL, NULL, 0);
	create_joint(&thigh_joint[1], SetVector(-2.3, 1.8, -.4),
	NULL, NULL, NULL, 0);
	create_joint(&thigh_joint[2], SetVector(.1, 2, -.4),
	NULL, NULL, NULL, 0);
	create_joint(&thigh_joint[3], SetVector(.1, 2.0, .4),
	NULL, NULL, NULL, 0);

	create_joint(&knee_joint[0], SetVector(-2.6, .9, .4),
	NULL, NULL, NULL, 0);
	create_joint(&knee_joint[1], SetVector(-2.6, .9, -.4),
	NULL, NULL, NULL, 0);
	create_joint(&knee_joint[2], SetVector(.4, .9, -.4),
	NULL, NULL, NULL, 0);
	create_joint(&knee_joint[3], SetVector(.4, .9, .4),
	NULL, NULL, NULL, 0);
	create_joint(&foot_joint[0], SetVector(-2.75, 0, .4),
	NULL, NULL, NULL, 0);
	create_joint(&foot_joint[1], SetVector(-2.75, 0, -.4),
	NULL, NULL, NULL, 0);
	create_joint(&foot_joint[2], SetVector(.34, 0, -.4),
	NULL, NULL, NULL, 0);
	create_joint(&foot_joint[3], SetVector(.34, 0, .4),
	NULL, NULL, NULL, 0);


	//BODY JOINTS
	create_joint(&body_joint[0], SetVector(-1.8, 3.6, 0),
	"bodyjoint", "bodycurrpos", "bodybonepos", 0);
	create_joint(&body_joint[1], SetVector(-1, 3.3, 0),
	NULL, NULL, NULL, 0);
	create_joint(&body_joint[2], SetVector(.14, 3.9, 0),
	NULL, NULL, NULL, 0);


	//TAIL JOINTS
	create_joint(&tail_joint[0], SetVector(.7+.3, 3.75, 0),
	"tailjoint", "tailcurrpos", "tailbonepos", 0);
	create_joint(&tail_joint[1], SetVector(2.2, 3.8, 0),
	NULL, NULL, NULL, 0);
	create_joint(&tail_joint[2], SetVector(3.0, 3.75, 0),
	NULL, NULL, NULL, 0);
	create_joint(&tail_joint[3], SetVector(3.9, 3.65, 0),
	NULL, NULL, NULL, 0);

	//HEAD JOINTS
	create_joint(&head_joint[0], SetVector(-2.9, 3.2, 0),
	"headjoint", "headcurrpos", "headbonepos", 0);
	create_joint(&head_joint[1], SetVector(-3.85, 4, 0),
	NULL, NULL, NULL, 0);
	create_joint(&head_joint[2], SetVector(-4.7, 3, 0),
	NULL, NULL, NULL, 0);

	//EAR JOINTS
	//create_joint(&left_ear_joint[0], SetVector(-2.9, 3.2, -.4),
	//"leftearjoint", "leftearcurrpos", "leftearbonepos", 0);
	create_joint(&left_ear_joint[0], SetVector(-2.9, 3.2, .6),
	NULL, NULL, NULL, 0);
	create_joint(&right_ear_joint[0], SetVector(-2.9, 3.2, -.6),
	NULL, NULL, NULL, 0);
	//create_joint(&left_ear_joint[1], SetVector(-2.9, 3.2, .6),
	//NULL, NULL, NULL, 0);
	//create_joint(&right_ear_joint[1], SetVector(-2.9, 3.2, -.6),
	//NULL, NULL, NULL, 0);

	//create_joint(&right_ear_joint[0], SetVector(-2.9, 3.2, -.6),
	//"rightearjoint", "rightearcurrpos", "rightearbonepos", 0);

	//create_joint(&right_ear_joint[1], SetVector(-2.9, 3.2, -.8),
	//"rightearjoint", "rightearcurrpos", "rightearbonepos", 0);


	//SET CHILDREN!
	body_joint[0].child[0] = &body_joint[1];
	body_joint[1].child[0] = &body_joint[2];
	body_joint[2].child[0] = &tail_joint[0];
	body_joint[2].child[1] = &legbase_joint[2];
	body_joint[2].child[2] = &legbase_joint[3];

	tail_joint[0].child[0] = &tail_joint[1];
	tail_joint[1].child[0] = &tail_joint[2];
	tail_joint[2].child[0] = &tail_joint[3];
	tail_joint[3].child[0] = NULL;

	head_joint[0].child[0] = &head_joint[1];
	head_joint[1].child[0] = &head_joint[2];
	head_joint[2].child[0] = NULL;
	//head_joint[2].child[0] = &right_ear_joint[1];
	head_joint[2].child[1] = &left_ear_joint[0];
	head_joint[2].child[2] = &right_ear_joint[0];

	//left_ear_joint[0].child[0] = &left_ear_joint[1];
	//right_ear_joint[0].child[0] = &right_ear_joint[1];

	//left_ear_joint[1].child[0] = NULL;
	//right_ear_joint[1].child[0] = NULL;

	//head_joint[0].child = &legbase_joint[0];
	int i;
        for(i=0;i<4;i++)
	{
	  legbase_joint[i].child[0] = &thigh_joint[i];
	  thigh_joint[i].child[0] = &knee_joint[i];
	  knee_joint[i].child[0] = &foot_joint[i];
	  foot_joint[i].child[0] = NULL;
	}

	//SET PARENTS
	legbase_joint[2].parent = &body_joint[2];
	legbase_joint[3].parent = &body_joint[2];

	//left_ear_joint[1].parent = &left_ear_joint[0];
	left_ear_joint[0].parent = &head_joint[2];

	//right_ear_joint[1].parent = &right_ear_joint[0];
	right_ear_joint[0].parent = &head_joint[2];


	create_cow(&cow);
	create_farmer(&farmer, SetVector(0,0,0));

	create_ragdoll(&ragdoll);

	g_shader = loadShaders("shader.vert" , "shader.frag");
	glUseProgram(g_shader);

	// Set up depth buffer
	glEnable(GL_DEPTH_TEST);

	//glEnable (GL_BLEND);
	//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// initiering
//#ifdef WIN32
//	glewInit();
//#endif

	//glutSetCursor(0);

	//terr = generate_terrain(512);


	glutTimerFunc(20, &OnTimer, 0);

	glutMainLoop();
	exit(0);
}
Exemplo n.º 2
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;
}