Exemple #1
0
int main(int argc, char** argv)
{
    init_gfx();
    init_2d();
    
    world = dWorldCreate();

    dBodyID ball = dBodyCreate(world);
    dBodySetPosition(ball, 0, 0, 0);

    for (;;) {
        Uint8* chars = SDL_GetKeyState(NULL);

        if (chars[SDLK_LEFT]) {
            dBodyAddForce(ball, -force, 0, 0);
        }
        if (chars[SDLK_RIGHT]) {
            dBodyAddForce(ball, +force, 0, 0);
        }
        if (chars[SDLK_UP]) {
            dBodyAddForce(ball, 0, +force, 0);
        }
        if (chars[SDLK_DOWN]) {
            dBodyAddForce(ball, 0, -force, 0);
        }

        const dReal* pos = dBodyGetPosition(ball);
        glTranslatef(pos[0], pos[1], pos[2]);
        draw_circle();

        dWorldQuickStep(world, 0.01);
        step();
    }
}
Exemple #2
0
int main(int argc, char** argv)
{
    init_gfx();
    init_2d();
 
    // create world and set gravity   
    world = dWorldCreate();
    dWorldSetGravity(world, 0, -5, 0);
    
    // create a body for our ball
    dBodyID body = dBodyCreate(world);
    dBodySetPosition(body, 0, 0, 0);

    for (;;) {  // infinite loop

        // get the position and move there in OpenGL
        const dReal* pos = dBodyGetPosition(body);
        glTranslatef(pos[0], pos[1], pos[2]);
        
        draw_circle();

        // integrate all bodies
        dWorldQuickStep(world, 0.01);

        // redraw screen
        step();
    }
}
int main (void)
{
	int array[N][M];
	int i, j, k;
	
	init_2d(array, N, M);
	
	for (i = 0; i < N; i++)
		for (j = 0; j < M; j++) {
			scanf("%d", &k);
			array[i][j] += k;
		}
		
	for (i = 0; i < N; i++) {
		for (j = 0; j < M; j++)
			printf("%d ", array[i][j]);
		printf("\n");
	}
	
	return 0;
}
Exemple #4
0
int main(int argc, char** argv)
{
    init_gfx();
    init_2d();

    world = dWorldCreate();

    dBodyID ball = dBodyCreate(world);
    dBodySetPosition(ball, 0, 0, 0);

    for (;;) {
        Uint8* chars = SDL_GetKeyState(NULL);
        const dReal* pos = dBodyGetPosition(ball);
        const dReal* q = dBodyGetQuaternion(ball);
        double angle = get_q_angle(q);
        const dReal* axis = get_q_axis(q);

        if (chars[SDLK_LEFT]) {
            dBodyAddForceAtPos(ball, -force, 0, 0,
                               pos[0], pos[1]+1, pos[2]);
        }
        if (chars[SDLK_RIGHT]) {
            dBodyAddForceAtPos(ball, force, 0, 0,
                               pos[0], pos[1]+1, pos[2]);
        }
        if (chars[SDLK_UP]) {
            dBodyAddForce(ball, 0, +force, 0);
        }
        if (chars[SDLK_DOWN]) {
            dBodyAddForce(ball, 0, -force, 0);
        }

        glTranslatef(pos[0], pos[1], pos[2]);
        glRotatef(angle * 180 / M_PI, axis[0], axis[1], axis[2]);
        draw_circle();

        dWorldQuickStep(world, 0.01);
        step();
    }
}