Example #1
0
void templateAppInit( int width, int height ) {

	atexit( templateAppExit );

	GFX_start();
	
	init_physic_world();
	
	gContactAddedCallback = contact_added_callback;

	glViewport( 0.0f, 0.0f, width, height );

	GFX_set_matrix_mode( PROJECTION_MATRIX );
	GFX_load_identity();
	GFX_set_perspective( 45.0f,
						 ( float )width / ( float )height,
						 0.1f,
						 100.0f,
						 -90.0f );

	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

	while( i != obj->n_objmesh ) {

		OBJ_build_mesh( obj, i );
		
		OBJMESH *objmesh = &obj->objmesh[ i ];
				
		if( !strcmp( objmesh->name, "Cube" ) )
		{
			objmesh->rotation.x =
			objmesh->rotation.y =
			objmesh->rotation.z = 35.0f;
			
			add_rigid_body( objmesh, 1.0f );
		}

		else add_rigid_body( objmesh, 0.0f );		

		OBJ_free_mesh_vertex_data( obj, i ); 

		++i;
	}
	
	program = PROGRAM_create( ( char * )"default",
							  VERTEX_SHADER,
							  FRAGMENT_SHADER,
							  1,
							  0,
							  program_bind_attrib_location,
							  NULL );

	PROGRAM_draw( program );
}
void load_game(void)
{
    init_physic_world();
    gContactAddedCallback = contact_added_callback;
    obj = OBJ_load(OBJ_FILE, 1);
    unsigned int i = 0;
    while (i != obj->n_objmesh) {
	OBJMESH *objmesh = &obj->objmesh[i];
	OBJ_optimize_mesh(obj, i, 128);
	OBJ_build_mesh(obj, i);
	if (strstr(objmesh->name, "momo"))
	    add_rigid_body(objmesh, SPHERE, 2.0f, 0);
	else if (strstr(objmesh->name, "barrel"))
	    add_rigid_body(objmesh, CYLINDER, 1.0f, 0);
	else if (strstr(objmesh->name, "plank"))
	    add_rigid_body(objmesh, BOX, 1.0f, 0);
	else if (strstr(objmesh->name, "ground"))
	    add_rigid_body(objmesh, BOX, 0.0f, 0);
	else if (strstr(objmesh->name, "steel"))
	    add_rigid_body(objmesh, CYLINDER, 0.0f, 0);
	else if (strstr(objmesh->name, "banana")) {
	    add_rigid_body(objmesh, SPHERE, 1.0f, 1);
	    objmesh->btrigidbody->setCollisionFlags(objmesh->btrigidbody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
	    objmesh->btrigidbody->forceActivationState(ISLAND_SLEEPING);
	    ++banana;
	} else if (strstr(objmesh->name, "gameover")) {
	    objmesh->visible = 0;
	    gameover = objmesh;
	}
	OBJ_free_mesh_vertex_data(obj, i);
	++i;
    }
    i = 0;
    while (i != obj->n_texture) {
	OBJ_build_texture(obj, i, obj->texture_path, TEXTURE_MIPMAP | TEXTURE_16_BITS, TEXTURE_FILTER_2X, 0.0f);
	++i;
    }
    program = PROGRAM_create((char *)"default", VERTEX_SHADER, FRAGMENT_SHADER, 1, 0, program_bind_attrib_location, NULL);
    i = 0;
    while (i != obj->n_objmaterial) {
	OBJ_build_material(obj, i, NULL);
	++i;
    }
    PROGRAM_draw(program);
    glUniform1i(PROGRAM_get_uniform_location(program, (char *)"DIFFUSE"), 1);
    momo_index = 0;
    center.x = eye.x = 3.5f;
    get_next_momo();
}
Example #3
0
void templateAppInit(int width, int height) {

    atexit(templateAppExit);

    gfx = new GFX;

    init_physic_world();

    gContactAddedCallback = contact_added_callback;

    glViewport(0.0f, 0.0f, width, height);

    gfx->set_matrix_mode(PROJECTION_MATRIX);
    gfx->load_identity();
    // Adjust "Field of View Y" angle for devices which has an aspect
    // ratio which is wider than the origin iPhone (3:2).  Devices which
    // have a narrower aspect ratio (such as iPad) work fine, as is.
    const float iPhoneOriginalWidth =320.0f;
    const float iPhoneOriginalHeight=480.0f;
    const float originalFovy=45.0f;
    float fovy(originalFovy);
    if (height*iPhoneOriginalWidth > width*iPhoneOriginalHeight) {
        float   h = (iPhoneOriginalHeight*0.5f) / tanf(originalFovy*0.5f*DEG_TO_RAD);
        fovy = 2.0f * atan2f(((float)height)*0.5, h) * RAD_TO_DEG;
    }
    gfx->set_perspective(fovy,
                         (float)width / (float)height,
                           0.1f,
                         100.0f,
                         -90.0f);

    obj = new OBJ(OBJ_FILE, true);

    for (auto objmesh=obj->objmesh.begin();
         objmesh!=obj->objmesh.end(); ++objmesh) {

        objmesh->build();

        /* Test the current mesh name to verify it is the Cube.  If yes,
         * give it a rotation of 35 degrees on the XYZ axis; and then call the
         * add_rigid_body function using the mesh pointer and passing in a mass
         * of 1kg as a parameter.
         */
        if (!strcmp(objmesh->name, "Cube")) {
            objmesh->rotation->x =
            objmesh->rotation->y =
            objmesh->rotation->z = 35.0f;

            add_rigid_body(&(*objmesh), 1.0f);
        } else {
            /* If it's not the Cube, it must be the plane.  Add it as a new
             * rigid body using the mass of 0 since you want it to be a static
             * object.
             */
            add_rigid_body(&(*objmesh), 0.0f);
        }

        objmesh->free_vertex_data();
    }

    program = new PROGRAM((char *)"default",
                          VERTEX_SHADER,
                          FRAGMENT_SHADER,
                          true,
                          false,
                          program_bind_attrib_location,
                          NULL);

    program->draw();
}