Exemple #1
0
void gl_M4_Id(M4 *a)
{
	int i,j;
	for(i=0;i<4;i++)
	for(j=0;j<4;j++) 
	if (i==j) a->m[i][j]=int2sll(1); else a->m[i][j]=int2sll(0);
}
Exemple #2
0
int Matrix_Inv(GLfloat *r,GLfloat *m,int n)
{
	 int i,j,k,l;
	 GLfloat max,tmp,t;

	 /* identitée dans r */
	 for(i=0;i<n*n;i++) r[i]=int2sll(0);
	 for(i=0;i<n;i++) r[i*n+i]=int2sll(1);
	 
	 for(j=0;j<n;j++) {
			
			/* recherche du nombre de plus grand module sur la colonne j */
			max=m[j*n+j];
			k=j;
			for(i=j+1;i<n;i++)
				if (sllvalue(sll_abs(m[i*n+j]))>sllvalue(sll_abs(max))) {
					 k=i;
					 max=m[i*n+j];
				}

      /* non intersible matrix */
      if (sllvalue(max)==sllvalue(int2sll(0))) return 1;

			
			/* permutation des lignes j et k */
			if (k!=j) {
				 for(i=0;i<n;i++) {
						tmp=m[j*n+i];
						m[j*n+i]=m[k*n+i];
						m[k*n+i]=tmp;
						
						tmp=r[j*n+i];
						r[j*n+i]=r[k*n+i];
						r[k*n+i]=tmp;
				 }
			}
			
			/* multiplication de la ligne j par 1/max */
			max=slldiv(int2sll(1), max);
			for(i=0;i<n;i++) {
				tmp=m[j*n+i];
				 m[j*n+i]=sllmul(tmp, max);
				tmp=r[j*n+i];
				 r[j*n+i]=sllmul(tmp, max);
			}
			
			
			for(l=0;l<n;l++) if (l!=j) {
				 t=m[l*n+j];
				 for(i=0;i<n;i++) {
						tmp=m[l*n+i];
						m[l*n+i]=sllsub(tmp, sllmul(m[j*n+i],t));
						tmp=r[l*n+i];
						r[l*n+i]=sllsub(tmp, sllmul(r[j*n+i],t));
				 }
			}
	 }

	 return 0;
}
Exemple #3
0
int gl_M4_IsId(M4 *a)
{
	int i,j;
	for(i=0;i<4;i++)
    for(j=0;j<4;j++) {
      if (i==j) { 
        if (sllvalue(a->m[i][j]) != sllvalue(int2sll(1))) return 0;
      } else if (sllvalue(a->m[i][j]) != sllvalue(int2sll(0))) return 0;
    }
  return 1;
}
Exemple #4
0
void glLightModeli(int pname,int param)
{
  GLParam p[6];
  int i;

  p[0].op=OP_LightModel;
  p[1].i=pname;
  p[2].f=int2sll(param);
  for(i=0;i<4;i++) p[3+i].f=int2sll(0);

  gl_add_op(p);
}
Exemple #5
0
/* inversion of an orthogonal matrix of type Y=M.X+P */ 
void gl_M4_InvOrtho(M4 *a,M4 b)
{
	int i,j;
	GLfloat s;
	for(i=0;i<3;i++)
	for(j=0;j<3;j++) a->m[i][j]=b.m[j][i];
	a->m[3][0]=int2sll(0); a->m[3][1]=int2sll(0); a->m[3][2]=int2sll(0); a->m[3][3]=int2sll(1);
	for(i=0;i<3;i++) {
		s=int2sll(0);
		for(j=0;j<3;j++) s=sllsub(s, sllmul(b.m[j][i],b.m[j][3]));
		a->m[i][3]=s;
	}
}
Exemple #6
0
void Firework_Initialize(int width, int height) {
  Firework_GRAVITY = slldiv(CONST_8, int2sll(100));
  Firework_baselineYSpeed = slldiv(int2sll(-25), CONST_10);
  Firework_maxYSpeed = CONST_3; // This gets negated later
  Firework_xDampen = slldiv(int2sll(99), int2sll(100));
  Firework_aDampen = slldiv(CONST_1, int2sll(100));
  
  screen_width = width;
  screen_height = height;

  for (int i = 0; i < FIREWORKS; i++) {
    Firework_Start(&prv_fireworks[i]);
  }
}
Exemple #7
0
void glTexParameteri(int target,int pname,int param)
{
  GLParam p[8];
  
  p[0].op=OP_TexParameter;
  p[1].i=target;
  p[2].i=pname;
  p[3].i=param;
  p[4].f=int2sll(0);
  p[5].f=int2sll(0);
  p[6].f=int2sll(0);
  p[7].f=int2sll(0);

  gl_add_op(p);
}
// Calculates the distance between two GPS lat/lon coordinates
// returns units: KM
// From: http://www.movable-type.co.uk/scripts/latlong.html
sll DistanceBetweenSLL(sll lat1, sll lon1, sll lat2, sll lon2) {  
  sll R = int2sll(6371); // kilometres
  sll lat1_rad = slldeg2rad(lat1);
  sll lon1_rad = slldeg2rad(lon1);
  sll lat2_rad = slldeg2rad(lat2);
  sll lon2_rad = slldeg2rad(lon2);
  sll dist_lat = sllsub(lat2_rad, lat1_rad);
  sll dist_lon = sllsub(lon2_rad, lon1_rad);

  dist_lat = slldiv2(dist_lat);
  dist_lon = slldiv2(dist_lon);

  dist_lat = sllsin(dist_lat);
  dist_lon = sllsin(dist_lon);

  sll a = sllmul(dist_lat, dist_lat);
  sll b = sllmul(dist_lon, dist_lon);
  sll c = sllmul(sllcos(lat1_rad), sllcos(lat2_rad));
  sll d = slladd(a, sllmul(b,c));

  sll d_sqrt = sllsqrt(d);
  sll d_sqrt_1 = sllsqrt(sllsub(CONST_1,d));

  sll result = sllmul2(sllatan2(d_sqrt, d_sqrt_1));

  return sllmul(R,result);
}
Exemple #9
0
int gl_V3_Norm(V3 *a)
{
	GLfloat n;
	n=sllsqrt(slladd(slladd(sllmul(a->X,a->X), sllmul(a->Y,a->Y)), sllmul(a->Z,a->Z)));
	if (sllvalue(n)==sllvalue(int2sll(0))) return 1;
	a->X=slldiv(a->X, n);
	a->Y=slldiv(a->Y, n);
	a->Z=slldiv(a->Z, n);
	return 0;
}
Exemple #10
0
void gl_M4_Mul(M4 *c,M4 *a,M4 *b)
{
  int i,j,k;
  GLfloat s;
  for(i=0;i<4;i++)
    for(j=0;j<4;j++) {
      s=int2sll(0);
      for(k=0;k<4;k++) s=slladd(s,sllmul(a->m[i][k],b->m[k][j]));
      c->m[i][j]=s;
    }
}
Exemple #11
0
void glColor4f(GLfloat r,GLfloat g,GLfloat b,GLfloat a)
{
  GLParam p[8];

  p[0].op=OP_Color;
  p[1].f=r;
  p[2].f=g;
  p[3].f=b;
  p[4].f=a;
  /* direct convertion to integer to go faster if no shading */
  p[5].ui = (unsigned int) (sll2int(
			  	slladd(
			  		sllmul(r,int2sll(ZB_POINT_RED_MAX - ZB_POINT_RED_MIN)),
                            		int2sll(ZB_POINT_RED_MIN)
				      )
			           )
		 	   );
  p[6].ui = (unsigned int) (sll2int(
			  	slladd(
					sllmul(g, int2sll(ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN)),
                            		int2sll(ZB_POINT_GREEN_MIN)
				      )
				   )
		            );
  p[7].ui = (unsigned int) (sll2int(
			  	slladd(
					sllmul(b, int2sll(ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN)), 
                            		int2sll(ZB_POINT_BLUE_MIN)
				      )
				   )
		            );
  gl_add_op(p);
}
Exemple #12
0
void glColor4fv(GLfloat *v)
{
  GLParam p[8];

  p[0].op=OP_Color;
  p[1].f=v[0];
  p[2].f=v[1];
  p[3].f=v[2];
  p[4].f=v[3];
  /* direct convertion to integer to go faster if no shading */
  p[5].ui = (unsigned int) (sll2int(
			  	slladd(
			  		sllmul(v[0], int2sll(ZB_POINT_RED_MAX - ZB_POINT_RED_MIN)), 
                            		int2sll(ZB_POINT_RED_MIN)
				      )
				    )
		  	   );
  p[6].ui = (unsigned int) (sll2int(
			  	slladd(
					sllmul(v[1], int2sll(ZB_POINT_GREEN_MAX - ZB_POINT_GREEN_MIN)), 
                            		int2sll(ZB_POINT_GREEN_MIN)
				      )
				   )
		           );
  p[7].ui = (unsigned int) (sll2int(
			  	slladd(
					sllmul(v[2], int2sll(ZB_POINT_BLUE_MAX - ZB_POINT_BLUE_MIN)), 
                            		int2sll(ZB_POINT_BLUE_MIN)
				      )
				    )
		            );
  gl_add_op(p);
}
Exemple #13
0
void glLightf(int light,int type,GLfloat v)
{
  GLParam p[7];
  int i;

  p[0].op=OP_Light;
  p[1].i=light;
  p[2].i=type;
  p[3].f=v;
  for(i=0;i<3;i++) p[4+i].f=int2sll(0);

  gl_add_op(p);
}
Exemple #14
0
void Firework_Move(FireworkStruct* firework) {
  for (int loop = 0; loop < FIREWORK_PARTICLES; loop++) {
    // Once the firework is ready to launch start moving the particles
    if (firework->framesUntilLaunch <= 0) {
      firework->x[loop] = slladd(firework->x[loop], firework->xSpeed[loop]);
      firework->y[loop] = slladd(firework->y[loop], firework->ySpeed[loop]);
      firework->ySpeed[loop] = slladd(firework->ySpeed[loop], Firework_GRAVITY);
    }
  }
  firework->framesUntilLaunch--;

  // Once a fireworks speed turns positive (i.e. at top of arc) - blow it up!
  if (firework->ySpeed[0] > CONST_0) {
    for (int loop = 0; loop < FIREWORK_PARTICLES; loop++) {
      // Set a random x and y speed beteen -4 and + 4
      firework->xSpeed[loop] = slladd(int2sll(-4), rand_sll(CONST_8));
      firework->ySpeed[loop] = slladd(int2sll(-4), rand_sll(CONST_8));
    }

    firework->hasExploded = true;
  }
}
Exemple #15
0
void glMaterialf(int mode,int type,GLfloat v)
{
  GLParam p[7];
  int i;

  p[0].op=OP_Material;
  p[1].i=mode;
  p[2].i=type;
  p[3].f=v;
  for(i=0;i<3;i++) p[4+i].f=int2sll(0);

  gl_add_op(p);
}
Exemple #16
0
void Firework_Update(GBitmap *bitmap) {
  static int darken_count = 0;
  if (darken_count++ >= 4) {
    darken_count = 0;
    graphics_darken(bitmap);
  }
  // Draw fireworks
  for (int i = 0; i < FIREWORKS; i++) {
    FireworkStruct* firework = &prv_fireworks[i];
    GColor color;
    if (firework->hasExploded) {
      color = GColorFromRGB(
          sll2int(sllmul(int2sll(firework->red), firework->alpha)),
          sll2int(sllmul(int2sll(firework->green), firework->alpha)),
          sll2int(sllmul(int2sll(firework->blue), firework->alpha)));

      for (int p = 0; p < FIREWORK_PARTICLES; p++) {
        int xpos = sll2int(firework->x[p]);
        int ypos = sll2int(firework->y[p]);
        graphics_draw_pixel_color(bitmap, (GPoint){xpos, ypos}, color);
        graphics_draw_pixel_color(bitmap, (GPoint){xpos + 1, ypos}, color);
        graphics_draw_pixel_color(bitmap, (GPoint){xpos + 1, ypos + 1}, color);
        graphics_draw_pixel_color(bitmap, (GPoint){xpos, ypos + 1}, color);
      }

      Firework_Explode(&prv_fireworks[i]);
    } else {
      color = GColorFromRGB(255, 255, 0);
      int xpos = sll2int(firework->x[0]);
      int ypos = sll2int(firework->y[0]);
      graphics_draw_pixel_color(bitmap, (GPoint){xpos, ypos}, color);
      graphics_draw_pixel_color(bitmap, (GPoint){xpos + 1, ypos}, color);
      graphics_draw_pixel_color(bitmap, (GPoint){xpos + 1, ypos + 1}, color);
      graphics_draw_pixel_color(bitmap, (GPoint){xpos, ypos + 1}, color);

      Firework_Move(&prv_fireworks[i]);
    }
  }
}
Exemple #17
0
void Firework_Start(FireworkStruct* firework) {
  // Pick an initial x location and  random x/y speeds
  sll xLoc = int2sll(10 + (rand() % (screen_width - 20)));
  sll yLoc = int2sll(screen_height); // start at the bottom of the screen
  sll xSpeedVal = slladd(int2sll(-2), rand_sll(CONST_4));
  sll ySpeedVal = sllsub(Firework_baselineYSpeed, rand_sll(Firework_maxYSpeed));

  // Set initial x/y location and speeds
  for (int loop = 0; loop < FIREWORK_PARTICLES; loop++) {
    firework->x[loop] = xLoc;
    firework->y[loop] = yLoc;
    firework->xSpeed[loop] = xSpeedVal;
    firework->ySpeed[loop] = ySpeedVal;
  }

  // Max out at 170 for more vibrant colors
  firework->red   = ((rand() % 4) * 85);
  firework->green = ((rand() % 4) * 85);
  firework->blue  = ((rand() % 4) * 85);
  
  // Instead of white, black or gray, do GColorFolly
  if (firework->red == firework->green  && firework->green && firework->blue) {
    firework->red = 255;
    firework->blue = 85;
  } else if (firework->red == 0 && firework->green == 0 && firework->blue == 85) {
    // Oxford blue too dark, do Cyan
    firework->green = 255;
    firework->blue =  255;
  }

  firework->alpha = CONST_1;

  firework->framesUntilLaunch = (rand() % 100);

  firework->hasExploded = false;
}
Exemple #18
0
/* c=c*a */
void gl_M4_MulLeft(M4 *c,M4 *b)
{
  int i,j,k;
  GLfloat s;
  M4 a;

  /*memcpy(&a, c, 16*sizeof(GLfloat));
  */
  a=*c;

  for(i=0;i<4;i++)
    for(j=0;j<4;j++) {
      s=int2sll(0);
      for(k=0;k<4;k++) s=slladd(s,sllmul(a.m[i][k],b->m[k][j]));
      c->m[i][j]=s;
    }
}
Exemple #19
0
void glMaterialfv(int mode,int type,GLfloat *v)
{
  GLParam p[7];
  int i,n;

  assert(mode == GL_FRONT  || mode == GL_BACK || mode==GL_FRONT_AND_BACK);

  p[0].op=OP_Material;
  p[1].i=mode;
  p[2].i=type;
  n=4;
  if (type == GL_SHININESS) n=1;
  for(i=0;i<4;i++) p[3+i].f=v[i];
  for(i=n;i<4;i++) p[3+i].f=int2sll(0);

  gl_add_op(p);
}
Exemple #20
0
void glVertex3f(GLfloat x,GLfloat y,GLfloat z) 
{
  glVertex4f(x,y,z,int2sll(1));
}
Exemple #21
0
void phase2_process(void)
{
    sll inc=dbl2sll(0.0022);

    phase2_ship_x=128; phase2_ship_y=147;
    phase2_shoot.x=0; phase2_shoot.y=0; phase2_shoot.state=100;
    phase2_bad.x=0; phase2_bad.y=300; phase2_bad.state=105;
    phase2_global_x=0; phase2_global_y=0;

    music_play_fade(MUSIC_LEVEL);
    init_frame_time();

    theend=0;
    while (!theend)
    {
	getKey();
	if (hit1_pressed)
		if (phase2_shoot.state>=25)
		{

			sll angle=sllsub(mode7_angle,sllmul(inc,int2sll((128-phase2_ship_x)<<1)));
			sll multi=int2sll((256-phase2_ship_y)/24);
			phase2_shoot.dx=sllmul(sllrotl(sllcos(angle),3),SLL_CONST_PI);
			phase2_shoot.dy=sllmul(sllrotl(sllsin(angle),3),SLL_CONST_PI);
			phase2_shoot.x=slladd(mode7_x,sllmul(phase2_shoot.dx,multi));
			phase2_shoot.y=slladd(mode7_y,sllmul(phase2_shoot.dy,multi));
			angle=sllsub(mode7_angle,sllmul(inc,int2sll((128-phase2_ship_x)<<2)));
			phase2_shoot.dx=sllmul(sllrotl(sllcos(angle),3),SLL_CONST_PI);
			phase2_shoot.dy=sllmul(sllrotl(sllsin(angle),3),SLL_CONST_PI);
			phase2_shoot.alt=(phase2_ship_y-128)>>2;
			phase2_shoot.state=24;
			play_sound(SND_SHIP_LASER);
		}

	if (left_pressed)
		phase2_ship_x-=8;
	else if (right_pressed)
		phase2_ship_x+=8;
	else if (phase2_ship_x<128)
		phase2_ship_x+=4;
	else if (phase2_ship_x>128)
		phase2_ship_x-=4;

	if (phase2_ship_x>=192)
		phase2_ship_x-=8;
	else if (phase2_ship_x<=64)
		phase2_ship_x+=8;

	if (up_pressed)
	{
		if (mode7_z<512)
		{
			mode7_z += 32;
			phase2_ship_y-=8;
		}
	}
	else if (down_pressed)
	{
		if (mode7_z>256)
		{
			mode7_z -= 32;
			phase2_ship_y+=8;
		}

	}
	else
	if (mode7_z>400)
	{
		mode7_z-=16;
		phase2_ship_y+=4;
	}
	else
	if (mode7_z<368)
	{
		mode7_z+=16;
		phase2_ship_y-=4;
	}

	mode7_process(sllsub(mode7_angle,sllmul(inc,int2sll((128-phase2_ship_x)>>1))));
	phase2_global_x= sll2int(mode7_x);
	phase2_global_y= sll2int(mode7_y);

	phase2_draw();
	delay_frame_time();
    }
sll slldeg2rad(sll deg) {
  return (slldiv(sllmul(deg,CONST_PI), int2sll(180)));
}
Exemple #23
0
void glColor3f(GLfloat x,GLfloat y,GLfloat z) 
{
  glColor4f(x,y,z,int2sll(1));
}
Exemple #24
0
void glColor3fv(GLfloat *v) 
{
  glColor4f(v[0],v[1],v[2],int2sll(1));
}
Exemple #25
0
void glTexCoord2f(GLfloat s,GLfloat t)
{
  glTexCoord4f(s,t,int2sll(0),int2sll(1));
}
Exemple #26
0
void glTexCoord2fv(GLfloat *v)
{
  glTexCoord4f(v[0],v[1],int2sll(0),int2sll(1));
}
Exemple #27
0
void glVertex2f(GLfloat x,GLfloat y) 
{
  glVertex4f(x,y,int2sll(0),int2sll(1));
}
Exemple #28
0
sll rand_sll(sll max_val) {
  sll max_scale = int2sll(1000);
  int max_val_int = sll2int(sllmul(max_val, max_scale));
  return slldiv(int2sll(rand() % (max_val_int + 1)), max_scale);
}
Exemple #29
0
void glVertex3fv(GLfloat *v) 
{
  glVertex4f(v[0],v[1],v[2],int2sll(1));
}
Exemple #30
0
void glopFrustum(GLContext *c,GLParam *p)
{
  GLfloat *r;
  M4 m;
  GLfloat left=p[1].f;
  GLfloat right=p[2].f;
  GLfloat bottom=p[3].f;
  GLfloat top=p[4].f;
  GLfloat near=p[5].f;
  GLfloat farp=p[6].f;
  GLfloat x,y,A,B,C,D,tmp2=int2sll(2);

  x = slldiv(sllmul(tmp2,near), sllsub(right,left));
  y = slldiv(sllmul(tmp2,near), sllsub(top,bottom));
  A = slldiv(slladd(right,left), sllsub(right,left));
  B = slldiv(slladd(top,bottom), sllsub(top,bottom));
  C = slldiv(sllneg(slladd(farp,near)), sllsub(farp,near));
  D = slldiv(sllneg(sllmul(sllmul(tmp2,farp),near)), sllsub(farp,near));

  r=&m.m[0][0];
  r[0]= x; r[1]=int2sll(0);  r[2]=A;            r[3]=int2sll(0);
  r[4]= int2sll(0); r[5]=y;  r[6]=B;            r[7]=int2sll(0);
  r[8]= int2sll(0); r[9]=int2sll(0);  r[10]=C;           r[11]=D;
  r[12]=int2sll(0); r[13]=int2sll(0); r[14]=int2sll(-1); r[15]=int2sll(0);

  gl_M4_MulLeft(c->matrix_stack_ptr[c->matrix_mode],&m);

  gl_matrix_update(c);
}