Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1160 → Rev 1159

/demos/trunk/jumpball/ball.c
18,11 → 18,11
 
/**
------------
CVS : $Id: ball.c,v 1.3 2003-05-05 09:21:55 pj Exp $
CVS : $Id: ball.c,v 1.2 2003-05-01 19:43:16 pj Exp $
 
File: $File$
Revision: $Revision: 1.3 $
Last update: $Date: 2003-05-05 09:21:55 $
Revision: $Revision: 1.2 $
Last update: $Date: 2003-05-01 19:43:16 $
------------
**/
 
46,7 → 46,7
*/
 
/*--------------------------------------------------------------*/
/* SIMULATION OF JUMPING BALLS */
/* SIMULATION OF JUMPING BALLS */
/*--------------------------------------------------------------*/
 
#include "demo.h"
53,35 → 53,25
#include <kernel/func.h>
#include <stdlib.h>
 
#define R 8 /* dimension of a ball */
#define G 9.8 /* acceleration of gravity */
#define R 8 /* dimension of a ball */
#define G 9.8 /* acceleration of gravity */
 
static int ballexit = 0;
static int npc = 0; /* number of tasks created */
static int npc = 0; /* number of tasks created */
 
/*--------------------------------------------------------------*/
/* Delay function for jumping balls */
/* Periodic task for ball simulation */
/*--------------------------------------------------------------*/
 
void my_delay(void)
TASK palla(int i)
{
int xxx;
for (xxx=0; xxx<BALL_DELAY; xxx++);
}
 
/*--------------------------------------------------------------*/
/* Periodic task for ball simulation */
/*--------------------------------------------------------------*/
 
TASK palla(int i)
{
int x, y; /* coordinate grafiche pallina */
int ox, oy; /* vecchia posizione pallina */
int x0, y0; /* posizione iniziale X pallina */
float vx, vy; /* velocitÂ… della pallina */
int x, y; /* coordinate grafiche pallina */
int ox, oy; /* vecchia posizione pallina */
int x0, y0; /* posizione iniziale X pallina */
float vx, vy; /* velocitÂ… della pallina */
float vy0; /* velocita' pallina al primo rimbalzo */
float ty, tx; /* variabile temporale */
float dt; /* incremento temporale */
float ty, tx; /* variabile temporale */
float dt; /* incremento temporale */
 
y = oy = y0 = BALL_HEIGHT;
x = ox = x0 = BALL_XMIN;
98,17 → 88,17
x = x0 + vx * tx;
 
if (y < 0) {
y = 0;
y = 0;
 
if (vy == 0.0)
vy = vy0;
else if (vy < BALL_VYMIN)
vy = vy0 * (1.0 - myrand(50)/100.0);
else
vy = 0.9 * vy;
if (vy == 0.0)
vy = vy0;
else if (vy < BALL_VYMIN)
vy = vy0 * (1.0 - myrand(50)/100.0);
else
vy = 0.9 * vy;
 
ty = 0.0;
y0 = 0;
y0 = 0;
}
 
if (x > BALL_XMAX) {
127,21 → 117,23
 
mutex_lock(&mutex);
grx_disc(ox, oy, R, 0);
ox = x;
oy = BALL_Y - y;
ox = x;
oy = BALL_Y - y;
mutex_unlock(&mutex);
 
if (ballexit && i!=0xFFFF) {
npc--;
return 0;
}
if (ballexit && i!=0xFFFF) {
npc--;
return 0;
}
 
mutex_lock(&mutex);
grx_disc(ox, oy, R, i);
mutex_unlock(&mutex);
 
my_delay();
 
{
int xxx;
for (xxx=0; xxx<10000; xxx++);
}
ty += dt;
tx += dt;
task_endcycle();
213,7 → 205,7
 
 
/*--------------------------------------------------------------*/
/* MAIN process */
/* MAIN process */
/*--------------------------------------------------------------*/
 
void scenario_ball()
223,7 → 215,7
//grx_line(0,BALL_Y-BALL_HEIGHT-6,383,BALL_Y-BALL_HEIGHT-6,red);
 
grx_rect(BALL_XMIN-R-1, BALL_Y-BALL_HEIGHT-R-1,
BALL_XMAX+R+1, BALL_Y+R+1, rgb16(0,200,0));
BALL_XMAX+R+1, BALL_Y+R+1, rgb16(0,200,0));
}
 
void init_ball(void)