Example #1
0
void
setupworld ( world_t *world )
{
	int i;
	entity_t *e;
	vector2d_t angle,dir,verts[2];
	
	world->time = SDL_GetTicks();
	
	if(!world->playerentity)
	{
		if(!spawnplayer( world ))
			return;
	}
	for(i=0;i<world->numentities;i++)
	{
		e = &world->entities[i];
		
		if(e->think && world->time > e->nextthink)
		{
			void (*think)(world_t *w, struct entity_s *e);
			think = e->think;
			e->think = NULL;
			think(world,e);
		}
		
		/* don't need to add transparent stuff to the world */
		if(!e->texture)
			continue;
		if(e->follow)
			setfollowangle(world,e,&angle);
		else
			vectorcopy(&angle,&e->angle);

		vectorrot90( &angle, &dir );
		vectorscale( &dir, e->texture->width/2, &dir );
		vectorsubtract( &e->pos, &dir, &verts[0]);
		vectoradd( &e->pos, &dir, &verts[1]);
		
		addsprite(world->raycaster,verts,e->texture->height,e->vpos,
				SURFACE_NONE,e->texture);
	}

	/* copy over player view pos to raycaster */
	world->raycaster->currentplatform = world->playerentity->currentplatform;
	vectorcopy(&world->raycaster->viewpos,&world->playerentity->pos);
	vectorcopy(&world->raycaster->viewdir,&world->playerentity->angle);
	world->raycaster->eyelevel = world->playerentity->vpos+VIEW_HEIGHT;
}
Example #2
0
void	ft_impact(t_draw_suite *val, t_ray *ray, t_tool *t)
{
	val->impact->o = vectoradd(ray->o,
	vectorscale(val->curobject->dist, ray->d));
	find_normal(val->impact, val->curobject);
	vectornorm(val->impact->d);
	init_color(t, val->curobject->color, val->final_color);
	val->curlight = t->l_lights;
	while (val->curlight)
	{
		val->lightray->o = vectorcopy(val->curlight->o);
		val->lightray->d = vectorsub(val->impact->o, val->lightray->o);
		vectornorm(val->lightray->d);
		if ((val->curobject2 = intersection(t->l_objects,
						val->lightray)) && val->curobject2 == val->curobject)
			ft_impact2(val);
		val->curlight = val->curlight->next;
	}
}
Example #3
0
void	ft_impact2(t_draw_suite *val)
{
	val->invlight = vectorscale(-1, val->lightray->d);
	val->kdiff = vectordot(val->invlight, val->impact->d)
		* MAX((val->curlight->dist -
		val->curobject->dist) / val->curlight->dist, 0);
	if (val->kdiff >= 0)
	{
		update_color(val->kdiff * 1,
		val->curlight->color, val->final_color, val->curobject->color);
		val->reflectray = rotation(val->impact->d, val->invlight);
		vectornorm(val->reflectray);
		val->kspec = vectordot(val->invlight, val->reflectray);
		if (val->kspec >= 0)
			update_color(pow(val->kspec, 20)
			* MAX((val->curlight->dist -
			val->curobject->dist) / val->curlight->dist, 0)
			* val->curobject->shiny, val->curlight->color,
			val->final_color, val->curobject->color);
	}
}
Example #4
0
void tt2tb(pulsar *psr,int npsr)
{
  int i, p,k;
  longdouble mjd_tt, mjd_teph;
  double deltaT=0.0, obsTerm, earthVel[3];
  double deltaTDot, obsTermDot, earthVelDot[3];
  int first=1;
  const char *CVS_verNum = "$Revision: 1.11 $";

  if (displayCVSversion == 1) CVSdisplayVersion("tt2tdb.C","tt2tdb()",CVS_verNum);

  init_ifte();
  for (p=0;p<npsr;p++)
  {
    for (i=0;i<psr[p].nobs;i++)
    {
      if (psr[p].obsn[i].clockCorr==0 && strcmp(psr[p].obsn[i].telID,"STL")!=0)
	psr[p].obsn[i].correctionTT_TB = 0.0;
      else
      {
	if (strcmp(psr[p].obsn[i].telID,"STL")==0)
	  mjd_tt = psr[p].obsn[i].sat;
	else
	  mjd_tt = psr[p].obsn[i].sat + getCorrectionTT(psr[p].obsn+i)/SECDAY;
	/* Evaluate the time ephemeris and its derivative */
	if (psr[p].timeEphemeris == IF99_TIMEEPH)
	  {
	    deltaT = IF_deltaT(mjd_tt);
	  }
	if (psr[p].timeEphemeris == FB90_TIMEEPH)
	  {
	    deltaT = FB_deltaT(mjd_tt) - IFTE_TEPH0; /* FB code returns Teph-TDB not TT-TDB */
	  }
	/* Get term involving observatory position (if known) */

	/*	for (k=0;k<3;k++)
		varray[k] = -psr[p].obsn[i].earthMoonBary_earth[k+3];
		vectorsum(earthVel, 
		psr[p].obsn[i].earthMoonBary_ssb+3,
		varray);   */
	for (k=0;k<3;k++)
	  earthVel[k] = psr[p].obsn[i].earth_ssb[k+3];
	obsTerm = dotproduct(earthVel, psr[p].obsn[i].observatory_earth)
	  /  (1.0-IFTE_LC) ;
	/* both vectors were meant to be defined in Ephemeris units ...
	 This correction is neglible but worth doing so we can test with K=2*/
	if (psr[p].units == SI_UNITS)
	  obsTerm /= (double)(IFTE_K*IFTE_K); // both were in SI 
	else
	  obsTerm /= (double)IFTE_K;  // obs_earth was in SI
	//	printf("obsTerm = %g\n",(double)obsTerm);
	/* Compute Teph : Irwin & Fukushima (1999) eq 13*/	
	/* Note, DeltaT(Teph0) ~ -2x10^-14 s so is neglected */
	psr[p].obsn[i].correctionTT_Teph = IFTE_TEPH0 + obsTerm
	  + deltaT / (1.0-IFTE_LC);
	/* Compute TCB or TDB as requested */
	if (psr[p].units == TDB_UNITS)
	  {
	    psr[p].obsn[i].correctionTT_TB = 
	      psr[p].obsn[i].correctionTT_Teph - (1? 0.0 : IFTE_TEPH0); 
	  }
	else
	  {
	    psr[p].obsn[i].correctionTT_TB = 
	      IFTE_KM1 * (double)(mjd_tt-IFTE_MJD0)*86400.0/* linear drift term */
	      + IFTE_K * (psr[p].obsn[i].correctionTT_Teph-(longdouble)IFTE_TEPH0);
	  }
	/* Compute dTB/dTT for correct frequency transfer if needed */
	if (psr[p].dilateFreq==1)
	{
	  if (first==1)
	    {
	      //	      init_ifte();
	      first=0;

	    }
	  mjd_teph = mjd_tt + psr[p].obsn[i].correctionTT_Teph/86400.0;

	  deltaTDot = IFTE_DeltaTDot(2400000.0+(int)mjd_teph, 
				     0.5+(mjd_teph-(int)mjd_teph));
	  // XXX seems deltaTDot is coming out too big
	  IFTE_get_vEDot(2400000.0+(int)mjd_teph, 
			 0.5+(mjd_teph-(int)mjd_teph), earthVelDot);
	  vectorscale(earthVelDot, 1.0/86400.0);
	  obsTermDot = 
	    (dotproduct(earthVelDot, psr[p].obsn[i].observatory_earth)
	     + dotproduct(earthVel, psr[p].obsn[i].siteVel))
	    /  (1.0-IFTE_LC) ;
	  if (psr[p].units == SI_UNITS)
	    obsTerm /= (double) (IFTE_K*IFTE_K); // both were in SI 
	  else
	    obsTerm /= (double)IFTE_K;  // obs_earth was in SI
	  
	  if (psr[p].units == TDB_UNITS)	    
	    psr[p].obsn[i].einsteinRate = 
	      1.0 + obsTermDot + deltaTDot/(1.0-IFTE_LC);
	  else
	    {
	      psr[p].obsn[i].einsteinRate = 
		IFTE_K * (1.0 + obsTermDot + deltaTDot/(1.0-IFTE_LC));
	      //	  obsTermDot = 
	      //	    (dotproduct(earthVelDot, psr[p].obsn[i].observatory_earth)
	      //	     + dotproduct(earthVel, psr[p].obsn[i].siteVel))
	      //	    /  (1.0-IFTE_LC) ;

							   
	    }
// 	  if (!first) printf("%g %g %g %g %g Einstein\n", (double)mjd_tt,
// 		 deltaT, deltaTDot, obsTerm, obsTermDot);
//	  if (!first)
//	    printf("ER-1 %lg\n", psr[p].obsn[i].einsteinRate-1.0);
	}	  
      }
    }
  }
  IFTE_close_file();
}
Example #5
0
/* root of the monster's thinking - make a decision about
 * what to do
 */
void
monster_think ( world_t *world, entity_t *ent )
{
	vector2d_t dir;
	float dist;

	ent->wishdir.x = ent->wishdir.y = 0.0f;
	
	ent->think = monster_think;
	ent->nextthink = world->time + MONSTER_WIT;
	
	if(!world->playerentity)
	{
		ent->texture = ent->frames[MONSTERFRAME_STAND];
		ent->shoottime = -1;
		return;
	}
	if(!pointcanseepoint(world->raycaster,
			&world->playerentity->pos,world->playerentity->vpos+VIEW_HEIGHT,
			&ent->pos,ent->vpos+MONSTER_MUZZLEHEIGHT))
	{
		ent->texture = ent->frames[MONSTERFRAME_STAND];
		ent->nextthink = world->time + MONSTER_WIT*5;	/* monster is not very alert in the absence of
					   the player */
		ent->shoottime = -1;
		return;
	}
	vectorsubtract(&world->playerentity->pos,&ent->pos,&dir);
	dist = vectorlength(&dir);
	vectorscale(&dir,1.0f/dist,&dir);

	if(dist > MONSTER_SHOOTRANGE)
	{
		if((world->time/276)%2)
		{
			ent->texture = ent->frames[MONSTERFRAME_WALK1];
		} else
		{
			ent->texture = ent->frames[MONSTERFRAME_WALK2];
		}
		vectorcopy(&ent->wishdir,&dir);
		ent->shoottime = -1;		/* if we back off and re-approach
						 * the monster still has to take aim
						 */
		return;
	} else if(ent->shoottime > 0 && world->time > ent->shoottime )
	{
		ent->texture = ent->frames[MONSTERFRAME_FIRE];
		ent->shoottime = world->time + MONSTER_RELOADTIME;
		ent->think = monster_aimpose;				/* return to aim pose */
		ent->nextthink = world->time + MONSTER_FIRETIME;
		return;
	} else
	{
		if(ent->shoottime < 0)
		{
			ent->texture = ent->frames[MONSTERFRAME_AIM];
			ent->shoottime = world->time + MONSTER_AIMTIME;
		}
	}
}