Ejemplo n.º 1
0
void rgluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,
                GLdouble centerx, GLdouble centery, GLdouble centerz,
                GLdouble upx, GLdouble upy, GLdouble upz)
{
    GLdouble m[16];
    GLdouble x[3], y[3], z[3];
    GLdouble mag;

    z[0] = eyex - centerx;
    z[1] = eyey - centery;
    z[2] = eyez - centerz;
    mag = fsqrt(z[0]*z[0] + z[1]*z[1] + z[2]*z[2]);
    if (mag)
    {
        z[0] /= mag;
        z[1] /= mag;
        z[2] /= mag;
    }

    y[0] = upx;
    y[1] = upy;
    y[2] = upz;

    x[0] =  y[1]*z[2] - y[2]*z[1];
    x[1] = -y[0]*z[2] + y[2]*z[0];
    x[2] =  y[0]*z[1] - y[1]*z[0];

    y[0] =  z[1]*x[2] - z[2]*x[1];
    y[1] = -z[0]*x[2] + z[2]*x[0];
    y[2] =  z[0]*x[1] - z[1]*x[0];

    mag = fsqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
    if (mag)
    {
        x[0] /= mag;
        x[1] /= mag;
        x[2] /= mag;
    }

    mag = fsqrt(y[0]*y[0] + y[1]*y[1] + y[2]*y[2]);
    if (mag)
    {
        y[0] /= mag;
        y[1] /= mag;
        y[2] /= mag;
    }

#define M(row,col) m[(col<<2)+row]
    M(0,0) = x[0];  M(0,1) = x[1];  M(0,2) = x[2];  M(0,3) = 0.0;
    M(1,0) = y[0];  M(1,1) = y[1];  M(1,2) = y[2];  M(1,3) = 0.0;
    M(2,0) = z[0];  M(2,1) = z[1];  M(2,2) = z[2];  M(2,3) = 0.0;
    M(3,0) = 0.0;   M(3,1) = 0.0;   M(3,2) = 0.0;  M(3,3) = 1.0;
#undef M

    glMultMatrixd(m);
    glTranslated(-eyex, -eyey, -eyez);
}
Ejemplo n.º 2
0
int main(int argc, char*argv[]){
  uint32_t i;
  uint32_t result;
  uint32_t out;
  int k=0;
  int del = 0;
  int table[128];

  i=0;
  while(i<128){
    table[i]=0;
    i++;
  }

  k=0;
  i = (127 << 23) + (0 << 14);
  while(k < 16384*1024){
    result=fsqrt_s(i);
    out = fsqrt(i,0);
    del = out - result;
    table[del+64] = table[del+64]+1;
    k++;
    i++;
  }
      
  printtable(table);
  return 0;

}
Ejemplo n.º 3
0
void getRotatePoint(Ship *ship, vector *point, real32 *distance)
{
    Node *slavenode;
    Ship *slave;
    udword count;
    vector dist;

    dbgAssertOrIgnore(ship->flags & SOF_Slaveable);     //ship should be slaveable
    dbgAssertOrIgnore(ship->slaveinfo->slaves.num >= 5);    //need enough for a pie plate!

    slavenode = ship->slaveinfo->slaves.head;
    point->x = ship->posinfo.position.x;
    point->y = ship->posinfo.position.y;
    point->z = ship->posinfo.position.z;

    count = 0;
    while (count < 5)
    {
        slave = (Ship *) listGetStructOfNode(slavenode);
        vecAdd(*point, *point, slave->posinfo.position);
        slavenode = slavenode->next;
        count++;
    }
    point->x /= 6.0f;
    point->y /= 6.0f;
    point->z /= 6.0f;

    vecSub(dist,ship->posinfo.position, *point);
    *distance = vecMagnitudeSquared(dist);
    *distance = fsqrt(*distance);
}
Ejemplo n.º 4
0
void V_Normalize(float *a) {
	float s = (a[0] * a[0] + a[1] * a[1] + a[2] * a[2]);
	float len = 1.0f / fsqrt(s);
	a[0] *= len;
	a[1] *= len;
	a[2] *= len;
}
Ejemplo n.º 5
0
void print_fsqrt( uint32_t a ) {
    uint32_t b = fsqrt( a );
    float af = getFloat(a);
    float bf = getFloat(b);
    printf("実装したfsqrt\n");
    printf("小数表示 fsqrt( %f ) = %f\n", af, bf );
    printf("10進数表示 fsqrt( %d ) = %d\n", a, b );
    printf("16進数表示 fsqrt( %x ) = %x\n", a, b );
}
Ejemplo n.º 6
0
/*-----------------------------------------------------------------------------
    Name        : vecNormalize
    Description : normalizes a vector (makes it a unit vector)
    Inputs      : vector
    Outputs     : vector is normalized
    Return      :
----------------------------------------------------------------------------*/
void vecNormalize(vector *a)
{
    real32 mag = fsqrt(vecMagnitudeSquared(*a));
    real32 oneOverMag = 1.0f / mag;

    a->x *= oneOverMag;
    a->y *= oneOverMag;
    a->z *= oneOverMag;
}
Ejemplo n.º 7
0
/*-----------------------------------------------------------------------------
    Name        : vecCopyAndNormalize
    Description : copies a source vector to destination vector, and then
                  normalizes the destination vector
    Inputs      : src, dst
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void vecCopyAndNormalize(vector *src,vector *dst)
{
    real32 mag = fsqrt(vecMagnitudeSquared(*src));
    real32 oneOverMag = 1.0f / mag;

    dst->x = src->x * oneOverMag;
    dst->y = src->y * oneOverMag;
    dst->z = src->z * oneOverMag;
}
Ejemplo n.º 8
0
int plugin_tex_doit(int stype, Cast *cast, float *texvec, float *dxt, float *dyt, float *result)
{
	float val = 0.0;
	float a = 1.0;
	float p[3];
	float tv[3];
	int i;
	int res = TEX_INT;

	tv[0]=(texvec[0]+1.0)/2.0;
	tv[1]=(texvec[1]+1.0)/2.0;
	tv[2]=(texvec[2]+1.0)/2.0;

	p[0] = cast->txtscale * tv[0];
	p[1] = cast->txtscale * tv[1];
	p[2] = cast->txtscale * tv[2];
	
	for (i=0; i<cast->depth; i++) {
		val += a * hnoise(1.0, p[0], p[1], p[2]);
		
		p[0] *= 2.0;
		p[1] *= 2.0;
		p[2] *= 2.0;
		a *= 0.5;
	}
	
	/* always return this value */
	result[0] = CLAMP (val+cast->offset, 0.0, 1.0) * pow (fabs(sqrt(tv[0]*tv[0]+tv[1]*tv[1]+tv[2]*tv[2])), cast->falloff);
	
	if(stype==1) {
		/*
		 * this is r, g, b, a:
		 */
		result[1]= 0.5*result[0];
		result[2]= 1.0-val;
		result[3]= fsqrt(fabs(result[0]));
		result[4]= 1.0;

		res |= TEX_RGB;
	}
	if(stype==2) {
		/*
		 * This value is the displacement of the actual normal in 
		 * the Material calculation. 
		 */
		result[5]+= val;
		result[6]+= 1.0-val;
		result[7]= 0.0;

		res |= TEX_NOR;
	}
	
	return res;
}
Ejemplo n.º 9
0
void gensqrt_s(void)
{
#ifdef INTERPRET_SQRT_S
   gencallinterp((native_type)cached_interpreter_table.SQRT_S, 0);
#else
   gencheck_cop1_unusable();
#ifdef __x86_64__
   mov_xreg64_m64rel(RAX, (unsigned long long *)(&reg_cop1_simple[dst->f.cf.fs]));
   fld_preg64_dword(RAX);
   fsqrt();
   mov_xreg64_m64rel(RAX, (unsigned long long *)(&reg_cop1_simple[dst->f.cf.fd]));
   fstp_preg64_dword(RAX);
#else
   mov_eax_memoffs32((unsigned int *)(&reg_cop1_simple[dst->f.cf.fs]));
   fld_preg32_dword(EAX);
   fsqrt();
   mov_eax_memoffs32((unsigned int *)(&reg_cop1_simple[dst->f.cf.fd]));
   fstp_preg32_dword(EAX);
#endif
#endif
}
Ejemplo n.º 10
0
float Gipps::accel(const LaneObject* v, float pos, float speed, float){
	float s = pos - v->getFrontPosition();
	float dv = v->getSpeed() - speed;
    float v0Local = vns_MIN(v0*malphaV0,speedLimit);
    float TLocal = DT*malphaT;

    float vp = v->getSpeed() - dv;
    // safe speed
    float vSafe = -b * TLocal + fsqrt(b * b * TLocal * TLocal + vp * vp + 2 * b * vns_MAX(s - s0, 0.0));
    float vNew = vns_MIN(vSafe, vns_MIN(v->getSpeed() + a * TLocal, v0Local));
    return (vNew - v->getSpeed()) / TLocal;
}
Ejemplo n.º 11
0
Archivo: v3.cpp Proyecto: anqanq000/vvv
void loadhook(float x=0.0f,float y=0.0f)
   {
   FILE *file;

   if ((file=fopen(CONFIG,"rb"))==NULL) reloadhook();
   else
      {
      VOLREN->get_tfunc()->load(file);

      load(file);
      reloadhook();

      VOLREN->get_histo()->load(file);
      reloadhook();

      VOLREN->get_tfunc()->get_escale(&GUI_re_scale,&GUI_ge_scale,&GUI_be_scale);
      VOLREN->get_tfunc()->get_ascale(&GUI_ra_scale,&GUI_ga_scale,&GUI_ba_scale);

      GUI_re_scale=fsqrt(GUI_re_scale);
      GUI_ge_scale=fsqrt(GUI_ge_scale);
      GUI_be_scale=fsqrt(GUI_be_scale);

      GUI_ra_scale=fsqrt(GUI_ra_scale);
      GUI_ga_scale=fsqrt(GUI_ga_scale);
      GUI_ba_scale=fsqrt(GUI_ba_scale);

      fclose(file);
      }
   }
Ejemplo n.º 12
0
void gensqrt_s()
{
#ifdef INTERPRET_SQRT_S
   gencallinterp((u32)SQRT_S, 0);
#else
   gencheck_cop1_unusable();
   mov_eax_memoffs32((u32 *)(&reg_cop1_simple[dst->f.cf.fs]));
   fld_preg32_dword(EAX);
   fsqrt();
   mov_eax_memoffs32((u32 *)(&reg_cop1_simple[dst->f.cf.fd]));
   fstp_preg32_dword(EAX);
#endif
}
Ejemplo n.º 13
0
void gensqrt_s(void)
{
#ifdef INTERPRET_SQRT_S
   gencallinterp((unsigned int)cached_interpreter_table.SQRT_S, 0);
#else
   gencheck_cop1_unusable();
   mov_eax_memoffs32((unsigned int *)(&reg_cop1_simple[dst->f.cf.fs]));
   fld_preg32_dword(EAX);
   fsqrt();
   mov_eax_memoffs32((unsigned int *)(&reg_cop1_simple[dst->f.cf.fd]));
   fstp_preg32_dword(EAX);
#endif
}
Ejemplo n.º 14
0
void gensqrt_d()
{
#ifdef INTERPRET_SQRT_D
   gencallinterp((unsigned long)SQRT_D, 0);
#else
   gencheck_cop1_unusable();
   mov_eax_memoffs32((unsigned long *)(&reg_cop1_double[dst->f.cf.fs]));
   fld_preg32_qword(EAX);
   fsqrt();
   mov_eax_memoffs32((unsigned long *)(&reg_cop1_double[dst->f.cf.fd]));
   fstp_preg32_qword(EAX);
#endif
}
Ejemplo n.º 15
0
/*-----------------------------------------------------------------------------
    Name        : vecCapMinVector
    Description : limits a vector's minimum magnitude from growing below a maximum
                  magnitude
    Inputs      : vectorToCap, minMagnitude
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void vecCapMinVector(vector *vectorToCap,real32 minMagnitude)
{
    real32 actualMag = fsqrt(vecMagnitudeSquared(*vectorToCap));
    real32 ratio;

    if (actualMag < minMagnitude)
    {
        ratio = minMagnitude / actualMag;
        vectorToCap->x *= ratio;
        vectorToCap->y *= ratio;
        vectorToCap->z *= ratio;
    }
}
Ejemplo n.º 16
0
void gensqrt_d(usf_state_t * state)
{
#ifdef INTERPRET_SQRT_D
   gencallinterp(state, (unsigned int)state->current_instruction_table.SQRT_D, 0);
#else
   gencheck_cop1_unusable(state);
   mov_eax_memoffs32(state, (unsigned int *)(&state->reg_cop1_double[state->dst->f.cf.fs]));
   fld_preg32_qword(state, EAX);
   fsqrt(state);
   mov_eax_memoffs32(state, (unsigned int *)(&state->reg_cop1_double[state->dst->f.cf.fd]));
   fstp_preg32_qword(state, EAX);
#endif
}
Ejemplo n.º 17
0
inline f32 distToLine(f32  cx, f32 cy, f32 ax, f32 ay, f32 bx, f32 by)
{ 
	f32 r_numerator = (cx-ax)*(bx-ax) + (cy-ay)*(by-ay);
	f32 r_denomenator = (bx-ax)*(bx-ax) + (by-ay)*(by-ay);
	f32 r = r_numerator / r_denomenator;

    f32 px = ax + r*(bx-ax);
    f32 py = ay + r*(by-ay);

    f32 s =  ((ay-cy)*(bx-ax)-(ax-cx)*(by-ay) ) / r_denomenator;

	f32 distanceLine = fabs(s)*fsqrt(r_denomenator);
	return distanceLine;
}	
Ejemplo n.º 18
0
void gensqrt_s(void)
{
#if defined(COUNT_INSTR)
    inc_m32rel(&instr_count[123]);
#endif
#ifdef INTERPRET_SQRT_S
    gencallinterp((unsigned long long)cached_interpreter_table.SQRT_S, 0);
#else
    gencheck_cop1_unusable();
    mov_xreg64_m64rel(RAX, (unsigned long long *)(&reg_cop1_simple[dst->f.cf.fs]));
    fld_preg64_dword(RAX);
    fsqrt();
    mov_xreg64_m64rel(RAX, (unsigned long long *)(&reg_cop1_simple[dst->f.cf.fd]));
    fstp_preg64_dword(RAX);
#endif
}
Ejemplo n.º 19
0
//fires the bursts for the ship
bool doBurstFire(Ship *ship)
{
    HeavyCorvetteSpec *spec = (HeavyCorvetteSpec *)ship->ShipSpecifics;
    GunInfo *gunInfo = ship->gunInfo;
    sdword numGuns = gunInfo->numGuns;
    //Gun *gun;
    sdword done;
    vector trajectory,heading;
    real32 range,one_over_range;
    SpaceObjRotImpTarg dummyTarg;

    vecSub(trajectory,spec->burstFireVector,ship->posinfo.position);
    range = vecMagnitudeSquared(trajectory);
    range = fsqrt(range);
    one_over_range = 1.0f/range;
    vecScalarMultiply(trajectory,trajectory,one_over_range);

    dummyTarg.objtype = OBJ_ShipType;
    dummyTarg.posinfo.position = spec->burstFireVector;
    dummyTarg.collInfo.collPosition = spec->burstFireVector;
    dummyTarg.currentLOD = ship->currentLOD;
    dummyTarg.collMyBlob = ship->collMyBlob;
    vecSet(dummyTarg.posinfo.velocity,0.0f,0.0f,0.0f);

    //track target even more precisely
    vecSub(heading,spec->burstFireVector,ship->posinfo.position);
    vecNormalize(&heading);
    aitrackHeadingWithFlags(ship,&heading,0.9999f,AITRACKHEADING_IGNOREUPVEC);

    //set special information that needs to be 'transmitted'
    //to the code in gunshoot.

    //fix later
    spec->bulletLifeTime = range*oneOverburstSpeed;



    bitSet(ship->specialFlags,SPECIAL_BurstFiring);
    done = gunShootGunsAtTarget(ship,&dummyTarg,0.0f,&trajectory);
    bitClear(ship->specialFlags,SPECIAL_BurstFiring);
    if(done == TRUE)
    {
        spec->cooldown = TRUE;
        spec->burstChargeState2 = burstCoolDownTime;
    }
    return done;
}
Ejemplo n.º 20
0
int check_float( float a, float b ) {
  uint32_t a_int = getUint32_t( a );
  uint32_t b_int = getUint32_t( b );
  float normal_f = (float)sqrt( a );
  uint32_t sqrt  = getUint32_t( normal_f );
  uint32_t f_sqrt = fsqrt( a_int );
  if ( sqrt != f_sqrt ) {
    printf("数字 : %f\n", a);
    printf("通常 %x\n", sqrt );
    printf("自作 %x\n", f_sqrt );
  }
  uint32_t inv   = getUint32_t( (float)(1.0 / a ) );
  uint32_t f_inv  = finv( a_int );
  uint32_t div   = getUint32_t( (float)(1.0 / b ) );
  uint32_t f_div  = finv( b_int );
  return sqrt == f_sqrt && inv == f_inv && div == f_div; 
}
int main(void) {
  
  union data_32bit a;
  union data_32bit result;

  int select_flag;
  char select_buf[10];
  printf("select import form :\n");
  printf("float -> 0\n");
  printf("32bit -> 1 (others)\n");
  gets(select_buf);
  sscanf(select_buf, "%d\n", &select_flag);

  if (select_flag == 0) {
    printf("a.fl32 : "); scanf("%f", &a.fl32);
  } else {
    char a_str[35];
    printf("詰めて入力しても可\n");
    printf("- --exp--- -------fraction--------\n");
    printf("a(32bit) :\n");
    gets(a_str);
    a.uint32 = str_to_uint32(delete_space(a_str));
  }
    
  printf("\n");

  printf("-- a --\n");
  print_data(a);
  
  printf("\n");

  result.uint32 = fsqrt(a.uint32);
  
  printf("-- fsqrt(result) --\n");
  print_data(result);

  printf("\n");

  union data_32bit test;

  printf("-- correct answer --\n");
  test.fl32 = sqrtf(a.fl32);
  print_data(test);

  return(0);
}
Ejemplo n.º 22
0
void Matrix::rotate(float angle, const Vector & axis) {
	float vx = axis.x, vy = axis.y, vz = axis.z;
	float rcos = fcos(angle * DEG2RAD);
	float rsin = fsin(angle * DEG2RAD);
	float invrcos = (1.0f - rcos);
	float mag = fsqrt(vx*vx + vy*vy + vz*vz);
	float xx, yy, zz, xy, yz, zx;

	if (mag < 1.0e-6) {
		// Rotation vector is too small to be significant
		return;
	}

	// Normalize the rotation vector
	vx /= mag;
	vy /= mag;  
	vz /= mag;

	xx = vx * vx;
	yy = vy * vy;
	zz = vz * vz;
	xy = (vx * vy * invrcos);
	yz = (vy * vz * invrcos);
	zx = (vz * vx * invrcos);

	// Generate the rotation matrix
	Matrix mr; mr.identity();

	// Hehe
	mr.matrix[0][0] = xx + rcos * (1.0f - xx);
	mr.matrix[2][1] = yz - vx * rsin;
	mr.matrix[1][2] = yz + vx * rsin;

	mr.matrix[1][1] = yy + rcos * (1.0f - yy);
	mr.matrix[2][0] = zx + vy * rsin;
	mr.matrix[0][2] = zx - vy * rsin;

	mr.matrix[2][2] = zz + rcos * (1.0f - zz);
	mr.matrix[1][0] = xy - vz * rsin;
	mr.matrix[0][1] = xy + vz * rsin;

	// Multiply it onto us
	*this = *this * mr;
}
Ejemplo n.º 23
0
void tutDrawLinePulse(sdword x0, sdword y0, sdword x1, sdword y1, ubyte pulsevalue, sdword segsize)
{
    real32 x0f = (real32)x0;
    real32 y0f = (real32)y0;
    real32 x1f = (real32)x1;
    real32 y1f = (real32)y1;

    real32 diffx = (x1f - x0f);
    real32 diffy = (y1f - y0f);
    sdword segment;
    real32 segments;
    bool blendon;

    segments = fsqrt(diffx*diffx + diffy*diffy) / (real32)segsize;

    diffx /= segments;
    diffy /= segments;

    if (glCapFeatureExists(GL_LINE_SMOOTH))
    {
        blendon = (bool)glIsEnabled(GL_BLEND);
        if (!blendon) glEnable(GL_BLEND);
        glEnable(GL_LINE_SMOOTH);
    }
    glBegin(GL_LINES);
    for(segment = 0; segment <= segments; segment++)
    {
        glColor3ub(pulsevalue, pulsevalue, pulsevalue);
        glVertex2f(primScreenToGLX((sdword)x0f), primScreenToGLY((sdword)y0f));
        x0f += diffx;
        y0f += diffy;
        glVertex2f(primScreenToGLX((sdword)x0f), primScreenToGLY((sdword)y0f));
        pulsevalue += 25;
    }
    glEnd();
    if (glCapFeatureExists(GL_LINE_SMOOTH))
    {
        glDisable(GL_LINE_SMOOTH);
        if (!blendon) glDisable(GL_BLEND);
    }
}
Ejemplo n.º 24
0
void
fakephong_highlight_texture (pvr_ptr_t highlight, unsigned int xsize,
			     unsigned int ysize, float hardness)
{
  uint8 *tmphilight;
  unsigned int x, y;
  float norm[3] = {0.0, 0.0, 1.0};
  const float xscale = (float) (xsize - 1) / 2.0f;
  const float yscale = (float) (ysize - 1) / 2.0f;
  
  tmphilight = malloc (xsize * ysize);
  
  /* We need a way to map 2D texture coordinates to points on a unit hemisphere,
     such that interpolating linearly along the texture approximates travelling
     smoothly along a great circle around the hemisphere.  Not sure how best to
     do this.  Maybe a parabolic texture?
     Using x, y coords unaltered and choosing z on the surface of the sphere. 
     Only the circular part of the texture is used.  */
  
  for (y = 0; y < ysize; y++)
    for (x = 0; x < xsize; x++)
      {
        float reflection[3];
	float dot;
	
	reflection[0] = (x - xscale) / xscale;
	reflection[1] = (y - yscale) / yscale;
	reflection[2] = fsqrt (1.0 - reflection[0] * reflection[0]
			       - reflection[1] * reflection[1]);
	
	dot = vec_dot (reflection, norm);
	
	tmphilight[y * ysize + x] = 255.0 * powf (dot, hardness);
      }
  
  assert (highlight != 0);

  pvr_txr_load_ex (tmphilight, highlight, xsize, ysize, PVR_TXRLOAD_8BPP);
  
  free (tmphilight);
}
Ejemplo n.º 25
0
void printSqrt (uint32_t in)
{
  union uint32_f a, c;
  char aa[33],cc[33];
  a.i = in;
  if (fpclassify (a.f) != FP_NORMAL)
    return;
  c.i = fsqrt (a.i);
  if (fpclassify (c.f) != FP_NORMAL)
    return;
  for (int t = 0; t < 32;++t)
    {
      aa[31 - t] = a.i & (1 << t) ? '1' : '0';
      cc[31 - t] = c.i & (1 << t) ? '1' : '0';
    }
  aa[32] = '\0';
  cc[32] = '\0';
  // 非正規化数とかはやらない
  if (isnormal (a.f))
    {
      if (!isnan (c.f))
	printf ("%s\t%s\n",aa,cc);
    }    
}
Ejemplo n.º 26
0
void wkTradeInit(void)
{
    sdword index;
    Node *objnode = universe.ShipList.head;
    Ship *ship;
    real32 mass;

    index = 0;

    while (objnode != NULL)
    {
        ship = (Ship *)listGetStructOfNode(objnode);
        dbgAssertOrIgnore(ship->objtype == OBJ_ShipType);

        wkTradeShips[index].ship = ship;
        mass = ship->staticinfo->staticheader.mass / WK_MASS_SCALE;


        wkTradeShips[index].x = 0.0f;
        wkTradeShips[index].y = 0.0f;
        wkTradeShips[index].vx = 0.0f;
        wkTradeShips[index].vy = 0.0f;
        wkTradeShips[index].ang = 0.0f;
        wkTradeShips[index].vang = 0.0f;
        wkTradeShips[index].vangacc = WK_ANGULAR_ACC / fsqrt(mass);
        wkTradeShips[index].vangmax = WK_ANGULAR_MAXVEL / fsqrt(fsqrt(mass));
        wkTradeShips[index].acc = WK_LINEAR_ACC / fsqrt(mass);
        wkTradeShips[index].maxvel = WK_LINEAR_MAXVEL;
        wkTradeShips[index].revacc = WK_LINEAR_REVACC / fsqrt(mass);
        wkTradeShips[index].strafeacc = WK_STRAFE_ACC / fsqrt(mass);
        wkTradeShips[index].controlthrust = 0;
        wkTradeShips[index].controlrot = 0;
        wkTradeShips[index].controlstrafe = 0;
        wkTradeShips[index].controlfire = 0;

        index++;
        objnode = objnode->next;
    }
    wkTradeShips[index].ship = NULL;

}
Ejemplo n.º 27
0
static void do_emu(struct info * info)
{
	unsigned short code;
	temp_real tmp;
	char * address;

	if (I387.cwd & I387.swd & 0x3f)
		I387.swd |= 0x8000;
	else
		I387.swd &= 0x7fff;
	ORIG_EIP = EIP;
/* 0x0007 means user code space */
	if (CS != 0x000F) {
		printk("math_emulate: %04x:%08x\n\r",CS,EIP);
		panic("Math emulation needed in kernel");
	}
	code = get_fs_word((unsigned short *) EIP);
	bswapw(code);
	code &= 0x7ff;
	I387.fip = EIP;
	*(unsigned short *) &I387.fcs = CS;
	*(1+(unsigned short *) &I387.fcs) = code;
	EIP += 2;
	switch (code) {
		case 0x1d0: /* fnop */
			return;
		case 0x1d1: case 0x1d2: case 0x1d3:
		case 0x1d4: case 0x1d5: case 0x1d6: case 0x1d7:
			math_abort(info,SIGILL);
		case 0x1e0:
			ST(0).exponent ^= 0x8000;
			return;
		case 0x1e1:
			ST(0).exponent &= 0x7fff;
			return;
		case 0x1e2: case 0x1e3:
			math_abort(info,SIGILL);
		case 0x1e4:
			ftst(PST(0));
			return;
		case 0x1e5:
			printk("fxam not implemented\n\r");
			math_abort(info,SIGILL);
		case 0x1e6: case 0x1e7:
			math_abort(info,SIGILL);
		case 0x1e8:
			fpush();
			ST(0) = CONST1;
			return;
		case 0x1e9:
			fpush();
			ST(0) = CONSTL2T;
			return;
		case 0x1ea:
			fpush();
			ST(0) = CONSTL2E;
			return;
		case 0x1eb:
			fpush();
			ST(0) = CONSTPI;
			return;
		case 0x1ec:
			fpush();
			ST(0) = CONSTLG2;
			return;
		case 0x1ed:
			fpush();
			ST(0) = CONSTLN2;
			return;
		case 0x1ee:
			fpush();
			ST(0) = CONSTZ;
			return;
		case 0x1ef:
			math_abort(info,SIGILL);
		case 0x1fa:
			fsqrt(PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1f0: case 0x1f1: case 0x1f2: case 0x1f3:
		case 0x1f4: case 0x1f5: case 0x1f6: case 0x1f7:
		case 0x1f8: case 0x1f9: case 0x1fb: case 0x1fd:
		case 0x1fe: case 0x1ff:
			printk("%04x fxxx not implemented\n\r",code + 0xd800);
			math_abort(info,SIGILL);
		case 0x1fc:
			frndint(PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x2e9:
			fucom(PST(1),PST(0));
			fpop(); fpop();
			return;
		case 0x3d0: case 0x3d1:
			return;
		case 0x3e2:
			I387.swd &= 0x7f00;
			return;
		case 0x3e3:
			I387.cwd = 0x037f;
			I387.swd = 0x0000;
			I387.twd = 0x0000;
			return;
		case 0x3e4:
			return;
		case 0x6d9:
			fcom(PST(1),PST(0));
			fpop(); fpop();
			return;
		case 0x7e0:
			*(short *) &EAX = I387.swd;
			return;
	}
	switch (code >> 3) {
		case 0x18:
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x19:
			fmul(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1a:
			fcom(PST(code & 7),PST(0));
			return;
		case 0x1b:
			fcom(PST(code & 7),PST(0));
			fpop();
			return;
		case 0x1c:
			real_to_real(&ST(code & 7),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(0),&tmp,&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1d:
			ST(0).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1e:
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x1f:
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x38:
			fpush();
			ST(0) = ST((code+1) & 7);
			return;
		case 0x39:
			fxchg(&ST(0),&ST(code & 7));
			return;
		case 0x3b:
			ST(code & 7) = ST(0);
			fpop();
			return;
		case 0x98:
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x99:
			fmul(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x9a:
			fcom(PST(code & 7),PST(0));
			return;
		case 0x9b:
			fcom(PST(code & 7),PST(0));
			fpop();
			return;			
		case 0x9c:
			ST(code & 7).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x9d:
			real_to_real(&ST(0),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(code & 7),&tmp,&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x9e:
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0x9f:
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			return;
		case 0xb8:
			printk("ffree not implemented\n\r");
			math_abort(info,SIGILL);
		case 0xb9:
			fxchg(&ST(0),&ST(code & 7));
			return;
		case 0xba:
			ST(code & 7) = ST(0);
			return;
		case 0xbb:
			ST(code & 7) = ST(0);
			fpop();
			return;
		case 0xbc:
			fucom(PST(code & 7),PST(0));
			return;
		case 0xbd:
			fucom(PST(code & 7),PST(0));
			fpop();
			return;
		case 0xd8:
			fadd(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xd9:
			fmul(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xda:
			fcom(PST(code & 7),PST(0));
			fpop();
			return;
		case 0xdc:
			ST(code & 7).exponent ^= 0x8000;
			fadd(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xdd:
			real_to_real(&ST(0),&tmp);
			tmp.exponent ^= 0x8000;
			fadd(PST(code & 7),&tmp,&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xde:
			fdiv(PST(0),PST(code & 7),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xdf:
			fdiv(PST(code & 7),PST(0),&tmp);
			real_to_real(&tmp,&ST(code & 7));
			fpop();
			return;
		case 0xf8:
			printk("ffree not implemented\n\r");
			math_abort(info,SIGILL);
			fpop();
			return;
		case 0xf9:
			fxchg(&ST(0),&ST(code & 7));
			return;
		case 0xfa:
		case 0xfb:
			ST(code & 7) = ST(0);
			fpop();
			return;
	}
	switch ((code>>3) & 0xe7) {
		case 0x22:
			put_short_real(PST(0),info,code);
			return;
		case 0x23:
			put_short_real(PST(0),info,code);
			fpop();
			return;
		case 0x24:
			address = ea(info,code);
			for (code = 0 ; code < 7 ; code++) {
				((long *) & I387)[code] =
				   get_fs_long((unsigned long *) address);
				address += 4;
			}
			return;
		case 0x25:
			address = ea(info,code);
			*(unsigned short *) &I387.cwd =
				get_fs_word((unsigned short *) address);
			return;
		case 0x26:
			address = ea(info,code);
			verify_area(address,28);
			for (code = 0 ; code < 7 ; code++) {
				put_fs_long( ((long *) & I387)[code],
					(unsigned long *) address);
				address += 4;
			}
			return;
		case 0x27:
			address = ea(info,code);
			verify_area(address,2);
			put_fs_word(I387.cwd,(short *) address);
			return;
		case 0x62:
			put_long_int(PST(0),info,code);
			return;
		case 0x63:
			put_long_int(PST(0),info,code);
			fpop();
			return;
		case 0x65:
			fpush();
			get_temp_real(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return;
		case 0x67:
			put_temp_real(PST(0),info,code);
			fpop();
			return;
		case 0xa2:
			put_long_real(PST(0),info,code);
			return;
		case 0xa3:
			put_long_real(PST(0),info,code);
			fpop();
			return;
		case 0xa4:
			address = ea(info,code);
			for (code = 0 ; code < 27 ; code++) {
				((long *) & I387)[code] =
				   get_fs_long((unsigned long *) address);
				address += 4;
			}
			return;
		case 0xa6:
			address = ea(info,code);
			verify_area(address,108);
			for (code = 0 ; code < 27 ; code++) {
				put_fs_long( ((long *) & I387)[code],
					(unsigned long *) address);
				address += 4;
			}
			I387.cwd = 0x037f;
			I387.swd = 0x0000;
			I387.twd = 0x0000;
			return;
		case 0xa7:
			address = ea(info,code);
			verify_area(address,2);
			put_fs_word(I387.swd,(short *) address);
			return;
		case 0xe2:
			put_short_int(PST(0),info,code);
			return;
		case 0xe3:
			put_short_int(PST(0),info,code);
			fpop();
			return;
		case 0xe4:
			fpush();
			get_BCD(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return;
		case 0xe5:
			fpush();
			get_longlong_int(&tmp,info,code);
			real_to_real(&tmp,&ST(0));
			return;
		case 0xe6:
			put_BCD(PST(0),info,code);
			fpop();
			return;
		case 0xe7:
			put_longlong_int(PST(0),info,code);
			fpop();
			return;
	}
	switch (code >> 9) {
		case 0:
			get_short_real(&tmp,info,code);
			break;
		case 1:
			get_long_int(&tmp,info,code);
			break;
		case 2:
			get_long_real(&tmp,info,code);
			break;
		case 4:
			get_short_int(&tmp,info,code);
	}
	switch ((code>>3) & 0x27) {
		case 0:
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 1:
			fmul(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 2:
			fcom(&tmp,PST(0));
			return;
		case 3:
			fcom(&tmp,PST(0));
			fpop();
			return;
		case 4:
			tmp.exponent ^= 0x8000;
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 5:
			ST(0).exponent ^= 0x8000;
			fadd(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 6:
			fdiv(PST(0),&tmp,&tmp);
			real_to_real(&tmp,&ST(0));
			return;
		case 7:
			fdiv(&tmp,PST(0),&tmp);
			real_to_real(&tmp,&ST(0));
			return;
	}
	if ((code & 0x138) == 0x100) {
			fpush();
			real_to_real(&tmp,&ST(0));
			return;
	}
	printk("Unknown math-insns: %04x:%08x %04x\n\r",CS,EIP,code);
	math_abort(info,SIGFPE);
}
Ejemplo n.º 28
0
void test_mode_7 ()
{
    MODE_7_PARAMS params;
    BITMAP *tile, *sprite, *buffer;
    PALETTE pal;
    int quit = FALSE;
    fixed angle = itofix (0);
    fixed x = 0, y = 0;
    fixed dx = 0, dy = 0;
    fixed speed = 0;
    int i, j, r2;

    params.space_z = itofix (50);
    params.scale_x = ftofix (200.0);
    params.scale_y = ftofix (200.0);
    params.obj_scale_x = ftofix (50.0);
    params.obj_scale_y = ftofix (50.0);
    params.horizon = 20;

    // to avoid flicker the program makes use of a double-buffering system
    buffer = create_bitmap (screen->w, screen->h);
    // create a 64x64 tile bitmap and draw something on it.
    tile = create_bitmap (64, 64);
    for (i = 0; i < 32; i++)
    {
        for (j = i; j < 32; j++)
        {
            putpixel (tile, i, j, i);
            putpixel (tile, i, 63-j, i);
            putpixel (tile, 63-i, j, i);
            putpixel (tile, 63-i, 63-j, i);
            putpixel (tile, j, i, i);
            putpixel (tile, j, 63-i, i);
            putpixel (tile, 63-j, i, i);
            putpixel (tile, 63-j, 63-i, i);
        }
    }
    text_mode (-1);

    // Create another bitmap and draw something to it.
    // This bitmap contains the object.
    sprite = create_bitmap (64, 64);
    clear (sprite);
    for (i = 0; i < 64; i++)
    {
        for (j = 0; j < 64; j++)
        {
            r2 = (32 - i) * (32 - i) + (32 - j) * (32 - j);
            if (r2 < 30 * 30)
            {
                r2 = (24 - i) * (24 - i) + (24 - j) * (24 - j);
                putpixel (sprite, i, j, 127 - fixtoi(fsqrt(itofix(r2))));
            }
        }
    }

    // create a palette
    // colors for the tiles
    for (i = 0; i < 64; i++)
    {
        pal[i].r = i;
        pal[i].g = i;
        pal[i].b = 0;
    }
    // colors for the object
    for (i = 0; i < 32; i++)
    {
        pal[i+64].r = 0;
        pal[i+64].g = 0;
        pal[i+64].b = 2 * i;
        pal[i+96].r = 2 * i;
        pal[i+96].g = 2 * i;
        pal[i+96].b = 63;
    }
    set_palette (pal);

    while (!quit)
    {
        // act on keyboard input
        if (key[KEY_ESC]) quit = TRUE;
        if (key[KEY_UP] && speed < itofix (5))
            speed += ftofix (0.1);
        if (key[KEY_DOWN] && speed > itofix (-5))
            speed -= ftofix (0.1);
        if (key[KEY_LEFT])
            angle = (angle - itofix (3)) & 0xFFFFFF;
        if (key[KEY_RIGHT])
            angle = (angle + itofix (3)) & 0xFFFFFF;
        if (key[KEY_Z])
            params.space_z += itofix(5);
        if (key[KEY_X])
            params.space_z -= itofix(5);
        if (key[KEY_Q])
            params.scale_x = fmul (params.scale_x, ftofix (1.5));
        if (key[KEY_W])
            params.scale_x = fdiv (params.scale_x, ftofix (1.5));
        if (key[KEY_E])
            params.scale_y = fmul (params.scale_y, ftofix (1.5));
        if (key[KEY_R])
            params.scale_y = fdiv (params.scale_y, ftofix (1.5));
        if (key[KEY_H])
            params.horizon++;
        if (key[KEY_J])
            params.horizon--;

        dx = fmul (speed, fcos (angle));
        dy = fmul (speed, fsin (angle));

        x += dx;
        y += dy;

        mode_7 (buffer, tile, angle, x, y, params);
        draw_object (buffer, sprite, angle, x, y, params);
        vsync();
        blit (buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);

    }
    destroy_bitmap (tile);
    destroy_bitmap (sprite);
    destroy_bitmap (buffer);
}
Ejemplo n.º 29
0
address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {

  // rbx,: methodOop
  // rcx: scratrch
  // rsi: sender sp

  if (!InlineIntrinsics) return NULL; // Generate a vanilla entry

  address entry_point = __ pc();

  // These don't need a safepoint check because they aren't virtually
  // callable. We won't enter these intrinsics from compiled code.
  // If in the future we added an intrinsic which was virtually callable
  // we'd have to worry about how to safepoint so that this code is used.

  // mathematical functions inlined by compiler
  // (interpreter must provide identical implementation
  // in order to avoid monotonicity bugs when switching
  // from interpreter to compiler in the middle of some
  // computation)
  //
  // stack: [ ret adr ] <-- rsp
  //        [ lo(arg) ]
  //        [ hi(arg) ]
  //

  // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
  //       native methods. Interpreter::method_kind(...) does a check for
  //       native methods first before checking for intrinsic methods and
  //       thus will never select this entry point. Make sure it is not
  //       called accidentally since the SharedRuntime entry points will
  //       not work for JDK 1.2.
  //
  // We no longer need to check for JDK 1.2 since it's EOL'ed.
  // The following check existed in pre 1.6 implementation,
  //    if (Universe::is_jdk12x_version()) {
  //      __ should_not_reach_here();
  //    }
  // Universe::is_jdk12x_version() always returns false since
  // the JDK version is not yet determined when this method is called.
  // This method is called during interpreter_init() whereas
  // JDK version is only determined when universe2_init() is called.

  // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
  //       java methods.  Interpreter::method_kind(...) will select
  //       this entry point for the corresponding methods in JDK 1.3.
  // get argument
  __ fld_d(Address(rsp, 1*wordSize));
  switch (kind) {
    case Interpreter::java_lang_math_sin :
        __ trigfunc('s');
        break;
    case Interpreter::java_lang_math_cos :
        __ trigfunc('c');
        break;
    case Interpreter::java_lang_math_tan :
        __ trigfunc('t');
        break;
    case Interpreter::java_lang_math_sqrt:
        __ fsqrt();
        break;
    case Interpreter::java_lang_math_abs:
        __ fabs();
        break;
    case Interpreter::java_lang_math_log:
        __ flog();
        // Store to stack to convert 80bit precision back to 64bits
        __ push_fTOS();
        __ pop_fTOS();
        break;
    case Interpreter::java_lang_math_log10:
        __ flog10();
        // Store to stack to convert 80bit precision back to 64bits
        __ push_fTOS();
        __ pop_fTOS();
        break;
    default                              :
        ShouldNotReachHere();
  }

  // return double result in xmm0 for interpreter and compilers.
  if (UseSSE >= 2) {
    __ subptr(rsp, 2*wordSize);
    __ fstp_d(Address(rsp, 0));
    __ movdbl(xmm0, Address(rsp, 0));
    __ addptr(rsp, 2*wordSize);
  }

  // done, result in FPU ST(0) or XMM0
  __ pop(rdi);                               // get return address
  __ mov(rsp, rsi);                          // set sp to sender sp
  __ jmp(rdi);

  return entry_point;
}
Ejemplo n.º 30
0
void cSkeleton<_DataType>::FlagNonUniformGradient()
{
	int				i, j, k, l, m, n, Idx, loc[8];
	int				NumNonunifromVoxels, IsNonuniform;
	float			AveVec_f[3], DotProduct_f, Tempf;


	printf ("\n");
	printf ("Flag NonUniform Gradient() ... \n");
	fflush(stdout);

	for (k=1; k<Depth_mi-1; k++) {
		for (j=1; j<Height_mi-1; j++) {
			for (i=1; i<Width_mi-1; i++) {

				loc[0] = Index (i, j, k);
				if (VoxelFlags_muc[loc[0]]==FLAG_EMPTY || 
					VoxelFlags_muc[loc[0]]==FLAG_NONUNIFORM) continue;
				if (Distance_mi[loc[0]]<=1) continue;
				
				for (m=0; m<3; m++) AveVec_f[m] = 0.0;
				
				Idx = 0;
				for (n=k; n<=k+1; n++) {
					for (m=j; m<=j+1; m++) {
						for (l=i; l<=i+1; l++) {
							loc[Idx] = Index (l, m, n);
							AveVec_f[0] += GVFDistance_mf[loc[Idx]*3 + 0];
							AveVec_f[1] += GVFDistance_mf[loc[Idx]*3 + 1];
							AveVec_f[2] += GVFDistance_mf[loc[Idx]*3 + 2];
							Idx++;
						}
					}
				}
				for (l=0; l<3; l++) AveVec_f[l] /= 8.0;
				// When the vector length is zero, then mark the voxels as nonuniform voxels
				Tempf = fsqrt (AveVec_f[0]*AveVec_f[0] + AveVec_f[1]*AveVec_f[1] + AveVec_f[2]*AveVec_f[2]);
				if (Tempf<1e-6) {
					for (m=0; m<8; m++) VoxelFlags_muc[loc[m]] = FLAG_NONUNIFORM;
					continue;
				}
				
				IsNonuniform = false;
				for (m=0; m<8; m++) {
					DotProduct_f = 0;
					for (l=0; l<3; l++) {
						DotProduct_f += AveVec_f[l]*GVFDistance_mf[loc[m]*3 + l];
					}
					if (DotProduct_f<=0) {
						IsNonuniform = true;
						break;
					}
				}
				
				
				if (IsNonuniform) {
					for (m=0; m<8; m++) VoxelFlags_muc[loc[m]] = FLAG_NONUNIFORM;
				}

			}
		}
	}

	NumNonunifromVoxels = 0;
	for (i=0; i<WHD_mi; i++) {
		if (VoxelFlags_muc[i]==FLAG_NONUNIFORM) NumNonunifromVoxels++;

	}
	
	printf ("Num. Nonuniform Voxels = %d\n", NumNonunifromVoxels);
	printf ("Num. Segmented Voxels = %d\n", NumSegmentedVoxels_mi);
	printf ("Num. Nonuniform / NumSegmented = %f %%\n", (float)NumNonunifromVoxels/NumSegmentedVoxels_mi*100.0);
	printf ("Num. Nonuniform / Total Num. Voxels = %f %%\n", (double)NumNonunifromVoxels/WHD_mi*100.0);
	fflush (stdout);
}