예제 #1
0
static int
light_ponctual(t_detail *detail, t_color *color, t_light *light, double *vector)
{
  t_light	*tmp;
  double	l[NB_DIMENSION];
  double	r[NB_DIMENSION];
  double	theta[3];
  int	it;

  tmp = light;
  it = 0;
  if (detail == NULL || color == NULL || light == NULL || vector == NULL)
    return (0);
  while (tmp != NULL)
    {
      get_vector_light(tmp, detail, l);
      if (tmp->type != AMBIENT)
	{
	  theta[0] = calc_angle(l, detail->normal);
	  inverse_vector(l);
	  get_vector_reflechie(l, detail->normal, r);
	  inverse_vector(l);
	  theta[1] = calc_angle(r, l);
	  if ((theta[2] = shadow_management(detail, color, l)))
	    light_apply(tmp, detail, theta, color);
	  ++it;
	}
      tmp = tmp->next;
    }
  color[2].red = ABS(CAST(color[2].red / (log(it) + 1.0F)));
  color[2].green = ABS(CAST(color[2].green / (log(it) + 1.0F)));
  color[2].blue = ABS(CAST(color[2].blue / (log(it) + 1.0F)));
  return (EXIT_SUCCESS);
}
예제 #2
0
// UpdateViewCursor
void
RotateBoxState::UpdateViewCursor(BView* view, BPoint current) const
{
	BPoint origin(fParent->Origin());
	fParent->TransformFromCanvas(origin);
	fParent->TransformFromCanvas(current);
	BPoint from = origin + BPoint(sinf(22.5 * 180.0 / M_PI) * 50.0,
								  -cosf(22.5 * 180.0 / M_PI) * 50.0);

	float rotation = calc_angle(origin, from, current) + 180.0;

	if (rotation < 45.0) {
		_SetViewCursor(view, kRotateLCursor);
	} else if (rotation < 90.0) {
		_SetViewCursor(view, kRotateLTCursor);
	} else if (rotation < 135.0) {
		_SetViewCursor(view, kRotateTCursor);
	} else if (rotation < 180.0) {
		_SetViewCursor(view, kRotateRTCursor);
	} else if (rotation < 225.0) {
		_SetViewCursor(view, kRotateRCursor);
	} else if (rotation < 270.0) {
		_SetViewCursor(view, kRotateRBCursor);
	} else if (rotation < 315.0) {
		_SetViewCursor(view, kRotateBCursor);
	} else {
		_SetViewCursor(view, kRotateLBCursor);
	}
}
예제 #3
0
	bool motion(){
		float x0, y0, z0; // предыдущие координаты
		float x1, y1, z1; // текущие координаты
		float x2, y2, z2; // следующие координаты
		float delta; // координаты для расчета расстояния
		float angle; // угол направления относительно текущего положения

		//-------------x0--------------//-//-------------y0--------------//-//-------------z0--------------//
		x0 = this->prev_position.get_x(); y0 = this->prev_position.get_y(); z0 = this->prev_position.get_z();

		//---------x1-------------//-//---------y1-------------//-//---------z1-------------//
		x1 = this->position.get_x(); y1 = this->position.get_y(); z1 = this->position.get_z();


		angle = calc_angle((x1>=x0) ? x1-x0 : x0-x1,(y1>=y0) ? y1-y0 : y0-y1);

		x2 = (((2-k*pow(t,2.0)/m)*x1 + (b*t/(2*m) - 1)*x0) / (1 + b*t/(2*m)))*cos(angle*PI/180);
		y2 = (((2-k*pow(t,2.0)/m)*y1 + (b*t/(2*m) - 1)*y0) / (1 + b*t/(2*m)))*sin(angle*PI/180);
		z2 = 0.0;

		delta = sqrt(pow(x2, 2.0) + pow(y2, 2.0)) - sqrt(pow(x1, 2.0) + pow(y1, 2.0));

		this->move(x2, y2, z2);

		if (delta > 0 && delta < 0.0005) return false; // условие для прекращения движения

		return true;
	}
예제 #4
0
파일: tp_main.c 프로젝트: flyingsnow/TPP
void gesture_swipe(SDL_Event event) 
{	
	float angle;
	uint32_t now, touch_time;
	Gesture_Event *p_gesture_data = &gesture_data;

	if(pos_move_x == 0 && pos_move_y == 0) {
		return;
	}
	
	int16_t distance_x = event.button.x - pos_start_x;
	int16_t distance_y = event.button.y - pos_start_y;
	
	uint16_t s_distance = sqrt(distance_x * distance_x + distance_y * distance_y);
	now = SDL_GetTicks();
	touch_time = now - touch_start_time;
	
	if(touch_time < MIN_SWIPE_TIME && s_distance > MIN_DRAG_DIST) {
		_gesture = GESTURE_SWIPE;
		angle = calc_angle(pos_start_x, pos_start_y, pos_move_x, pos_move_y);
		p_gesture_data->distance = distance;
		p_gesture_data->distance_x = distance_x;
		p_gesture_data->distance_y = distance_y;
		p_gesture_data->angle = angle;
		triggle_event(_gesture, &gesture_data);
	}

}
예제 #5
0
static int
light_calcul(t_detail *detail, t_color *color, double *l, t_light *tmp)
{
  double	r[NB_DIMENSION];
  double	theta[3];

  if (detail == NULL || color == NULL)
    return (EXIT_FAILURE);
  theta[0] = calc_angle(detail->normal, l);
  inverse_vector(l);
  get_vector_reflechie(l, detail->normal, r);
  inverse_vector(l);
  theta[1] = calc_angle(r, l);
  theta[2] = shadow_management(detail, color, l);
  light_apply(tmp, detail, theta, color);
  return (EXIT_SUCCESS);
}
예제 #6
0
// DragTo
void
RotateBoxState::DragTo(BPoint current, uint32 modifiers)
{
	double angle = calc_angle(fParent->Origin(), fOrigin, current);

	double newAngle = fOldAngle + angle;

	if (modifiers & B_SHIFT_KEY) {
		if (newAngle < 0.0)
			newAngle -= 22.5;
		else
			newAngle += 22.5;
		newAngle = 45.0 * ((int32)newAngle / 45);
	}

	fParent->RotateBy(newAngle - fParent->LocalRotation());
}
예제 #7
0
파일: cone.c 프로젝트: Ankirama/Epitech
/*
** brief : color without ambiance luminosity
** @our struct light
** @p : our vector P
** @color : cone's color
*/
static void	_normal_cone(t_light *l, t_vector *p,
			     t_cone *cone, t_color **color)
{
  double	angle;
  t_vector	*vn;
  t_color	*tmp;

  vn = create_vector(p->x, p->y, (-1.0) * cone->angle * p->z);
  angle = calc_angle(p, l->coord, vn, cone->pn);
  free(vn);
  if (!(angle < 0))
    {
      tmp = _calc(angle, cone, l);
      add_colors(color, tmp);
      free(tmp);
    }
}
예제 #8
0
ShipPart2::ShipPart2(Ship *creator, SpaceSprite *osprite,
double oangle, Vector2 orelpos, Vector2 opivot, double omass)
:
SpaceObject(creator, creator->pos, oangle, osprite),
mother(creator)
{
	STACKTRACE;
	layer = LAYER_SHIPS;
	set_depth(DEPTH_SHOTS);

	// angle relative to the mother ship (sprite angle = mother angle + rel. angle)
	offset_angle = oangle;

	// the point relative to center of this sprite, rotation is around this point
	// The pi/2 rotation is needed, since the vectors are declared along y as if angle=0 there,
	// instead angle=0 along x.
	pivot_point = rotate(opivot, PI/2);

	// position of the pivot point relative to mothership central position
	offset_pos = rotate(orelpos, PI/2);

	// just here so that you can override this, if needed.
	ship_rotations = 64;

	// mass, should be non-zero to allow for collisions; the bigger the mass, the less
	// it'll "move" out of position due to collisions
	//	mass = omass;
	mass = ship->mass;			 // might be better ?

	// ok, override earlier settings now
	calc_angle();
	calc_pos(mother->pos);

	collide_flag_anyone = mother->collide_flag_anyone;
	//collide_flag_anyone = ALL_LAYERS;
	//collide_flag_anyone = 1<<LAYER_SHIPS - 1<<LAYER_SHOTS;
	//collide_flag_sameteam = mother->collide_flag_sameteam;
	collide_flag_sameteam = 0;
	collide_flag_sameship = 0;

	hascollided = 0;
	change_pos = 0;
	change_vel = 0;
}
예제 #9
0
void ShipPart::calculate_manager(Vector2 refpos, Vector2 refvel)
{
	STACKTRACE;

	if (!(mother && mother->exists())) {
		mother = 0;
		state = 0;
		return;
	}

	calc_angle();				 // update (angle) using mother settings
	calc_pos(refpos);			 // update (pos) using manager settings
	vel = refvel;

	//sprite_index = get_index(angle);

	SpaceObject::calculate();

}
inline real min_angle(const Point2D &point1, const Point2D &point2, const Point2D &point3) {
    real angle0 = calc_angle(point1, point2, point3), angle1 = calc_angle(point2, point3, point1), angle2 = calc_angle(point3, point1, point2);
    return std::min(angle0, std::min(angle1, angle2));
}
예제 #11
0
int force_calc_bon(t_frame pframe, t_files fpkg)
{
  int     i,j,k,l,N,ci,cj,nqi,id1,id2,id3,id4;
  vector  *x,*v,dx,dy;
  t_vector distx,disty;
  double  dr,r,r2,r6,r12,ir,ir2,ir6,ir12,E=0.0,rc2;
  double  ar21,ar22,air21,air22,air11,air12,ang;
  double  C6ij,C12ij,FORCE,f,df,kc,ddr,fij;
  double  q2,dfq,fq,fe,phi,cosval,cosv2,dV;
  int     ist,isl,ds,m;

  distx=&dx; disty=&dy;
  for(i=0;i<pframe->nr_umols;i++){
    for(j=0;j<pframe->nr_mols[i];j++){
      // BONDED
      for(k=0;k<pframe->mol[pframe->mol_seq[i]]->nr_b;k++){
        id1  = j*pframe->mol[pframe->mol_seq[i]]->nr_t + pframe->mol[pframe->mol_seq[i]]->b_seq[2*k  ]+pframe->n_start[i];
        id2  = j*pframe->mol[pframe->mol_seq[i]]->nr_t + pframe->mol[pframe->mol_seq[i]]->b_seq[2*k+1]+pframe->n_start[i];
        r2   = pbc_dx(pframe,id1,id2,dx);
        dr   = r2*InvSqrt(r2);
        // BEGIN HARMONIC
        kc   = pframe->mol[pframe->mol_seq[i]]->k_bond[2*k];
        ddr  = dr-pframe->mol[pframe->mol_seq[i]]->k_bond[2*k+1];
        df   = kc*ddr;
        dV   = 0.5*df*ddr;
        // END HARMONIC
        E   += dV;
        df  *= InvSqrt(r2);
        for (m=XX; m<=ZZ; m++) {
          fij=-df*dx[m];
          pframe->f[id1][m]+=fij;
          pframe->f[id2][m]-=fij;
        }
      }

      // ANGLES
      for(k=0;k<pframe->mol[pframe->mol_seq[i]]->nr_a;k++){
        id1   = j*pframe->mol[pframe->mol_seq[i]]->nr_t + pframe->mol[pframe->mol_seq[i]]->a_seq[2*k  ]+pframe->n_start[i];
        id2   = j*pframe->mol[pframe->mol_seq[i]]->nr_t + pframe->mol[pframe->mol_seq[i]]->a_seq[2*k+1]+pframe->n_start[i];
        id3   = j*pframe->mol[pframe->mol_seq[i]]->nr_t + pframe->mol[pframe->mol_seq[i]]->a_seq[2*k+2]+pframe->n_start[i];
        ar21  = pbc_dx(pframe,id1,id2,dx);
        ar22  = pbc_dx(pframe,id3,id2,dy);
        phi   = calc_angle(dx,dy,&cosval);
        cosv2 = cosval*cosval;

        // BEGIN HARMONIC
        kc    = pframe->mol[pframe->mol_seq[i]]->k_angle[2*k];
        ddr   = phi-pframe->mol[pframe->mol_seq[i]]->k_angle[2*k+1]*DEG2RAD;
        df    = kc*ddr;
        dV    = 0.5*df*ddr;
        // END HARMONIC
        E    += dV;

        if(cosv2<1){
          double st,sth;
          double cik,cii,ckk;
          double nrkj2,nrij2;
          vector f_i,f_j,f_k;

          st    = -df*InvSqrt(1.0 - cosv2);
          sth   = st*cosval;
          nrkj2 = iprod(dy,dy);
          nrij2 = iprod(dx,dx);
          cik   = st*InvSqrt(nrkj2*nrij2);
          cii   = sth/nrij2;	
          ckk   = sth/nrkj2;	
      
          for (m=XX; (m<=ZZ); m++) {	
	    f_i[m]=-(cik*dy[m]-cii*dx[m]);
	    f_k[m]=-(cik*dx[m]-ckk*dy[m]);
	    f_j[m]=-f_i[m]-f_k[m];
	    pframe->f[id1][m]+=f_i[m];
	    pframe->f[id2][m]+=f_j[m];
	    pframe->f[id3][m]+=f_k[m];
          }
        }
      }
      // PROPER DIHEDRALS
      E += pdihs(pframe,i,j);

      // IMPROPER DIHEDRALS
      E += idihs(pframe,i,j);
    }
  }
  pframe->E[2]  = E;
  pframe->E[0] += E;

  return 0;
}
예제 #12
0
void sgangle_plot(char *fn,char *afile,char *dfile, 
		  char *d1file, char *d2file,
		  atom_id index1[], int gnx1, char *grpn1,
		  atom_id index2[], int gnx2, char *grpn2,
		  t_topology *top,int ePBC)
{
  FILE         
    *sg_angle,           /* xvgr file with angles */
    *sg_distance = NULL, /* xvgr file with distances */
    *sg_distance1 = NULL,/* xvgr file with distance between plane and atom */
    *sg_distance2 = NULL;/* xvgr file with distance between plane and atom2 */
  real
    t,                   /* time */
    angle,               /* cosine of angle between two groups */
    distance,            /* distance between two groups. */
    distance1,           /* distance between plane and one of two atoms */
    distance2;           /* same for second of two atoms */
  int        status,natoms,teller=0;
  rvec       *x0;   /* coordinates, and coordinates corrected for pb */
  matrix     box;        
  char       buf[256];   /* for xvgr title */

  if ((natoms = read_first_x(&status,fn,&t,&x0,box)) == 0)
    gmx_fatal(FARGS,"Could not read coordinates from statusfile\n");

  sprintf(buf,"Angle between %s and %s",grpn1,grpn2);
  sg_angle = xvgropen(afile,buf,"Time (ps)","Angle (degrees)");

  if (dfile) {
    sprintf(buf,"Distance between %s and %s",grpn1,grpn2);
    sg_distance = xvgropen(dfile,buf,"Time (ps)","Distance (nm)");
  }

  if (d1file) {
    sprintf(buf,"Distance between plane and first atom of vector");
    sg_distance1 = xvgropen(d1file,buf,"Time (ps)","Distance (nm)");
  }

  if (d2file) {
    sprintf(buf,"Distance between plane and second atom of vector");
    sg_distance2 = xvgropen(d2file,buf,"Time (ps","Distance (nm)");
  }

  do 
    {
      teller++;

      rm_pbc(&(top->idef),ePBC,natoms,box,x0,x0);
      
      calc_angle(ePBC,box,x0,index1,index2,gnx1,gnx2,&angle,
		 &distance,&distance1,&distance2);
      
      fprintf(sg_angle,"%12g  %12g  %12g\n",t,angle,acos(angle)*180.0/M_PI);
      if (dfile)
	fprintf(sg_distance,"%12g  %12g\n",t,distance);
      if (d1file)
	fprintf(sg_distance1,"%12g  %12g\n",t,distance1);
      if (d2file)
	fprintf(sg_distance2,"%12g  %12g\n",t,distance1);

    } while (read_next_x(status,&t,natoms,x0,box));
  
  fprintf(stderr,"\n");
  close_trj(status);
  fclose(sg_angle);
  if (dfile)
    fclose(sg_distance);
  if (d1file)
    fclose(sg_distance1);
  if (d2file)
    fclose(sg_distance2);

  sfree(x0);
}
예제 #13
0
void Game::logic()
{
	o_player.logic_input();
	o_player.move();
	o_player.shot( o_bulets, o_particles );
	o_player.check_collision(o_bulets, o_enemies);

	for ( int n = 0; n < (signed)o_bulets.size(); n++ )
	{
		o_bulets[n]->move();
	}

	MOUSE_ANGLE = calc_angle(o_player.get_box(),o_player.get_mouse());
	float angle = MOUSE_ANGLE;
	bool right = true;
	for ( int n = 0; n < (signed)o_particles.size(); n++ )
	{
		o_particles[n]->move(&o_player);	
		if ( right == true )
		{
			if ( MOUSE_ANGLE++ > angle + (o_particles.size() / 2 ) )
			{
				right = false;
				MOUSE_ANGLE = angle;
			}
		}
		else {
			MOUSE_ANGLE--;}

	}

	if ( rand() % 50 == 10 )
	{
		o_enemies.push_back( new Enemy( i_enemiesLevel ) ); 
	}

	for ( int n = 0; n < ( signed ) o_enemies.size(); n++ )
	{
		o_enemies[n]->move(o_player);
		o_enemies[n]->check_collision(o_bulets, o_particles);
	}

	for ( int n = 0; n < ( signed ) o_enemies.size(); n++ )
	{
		if ( o_enemies[n]->b_die == true )
		{
			o_enemies.erase(o_enemies.begin()+n);
		}
	}

	for ( int n = 0; n < (signed)o_bulets.size(); n++ )
	{
		if ( o_bulets[n]->b_die == true )
		{
			o_bulets.erase(o_bulets.begin()+n);
		}
	}

	for ( int n = 0; n < (signed)o_particles.size(); n++ )
	{
		if ( o_particles[n]->b_die == true )
		{
			o_particles.erase(o_particles.begin()+n);
		}
	}

	i_enemiesLevel+=(float)0.05;
	if ( i_enemiesLevel > 660 )
	{
		i_enemiesLevel = 660;
	}

}
예제 #14
0
// Returns the angle between atoms i, j, and k in degrees.
// Atom j is the central atom.
double Molecule::angle(int i, int j, int k)
{
  return calc_angle(i,j,k);
}
예제 #15
0
bool survey_environment( char_data * ch )
{
   list < environment_data * >::iterator env;
   double dist, angle, eta;
   int dir = -1, iMes;
   bool found = false;

   if( !ch->has_pcflag( PCFLAG_ONMAP ) )
      return false;

   ch->print( "&WAn imp appears with an ear-splitting BANG!\r\n" );

   for( env = envlist.begin(  ); env != envlist.end(  ); ++env )
   {
      environment_data *en = *env;

      if( ch->wmap != en->wmap )
         continue;

      dist = ( int )distance( ch->mx, ch->my, en->mx, en->my );

      if( dist > 300 )
         continue;

      found = true;

      angle = calc_angle( ch->mx, ch->my, en->mx, en->my, &dist );

      if( angle == -1 )
         dir = -1;
      else if( angle >= 360 )
         dir = DIR_NORTH;
      else if( angle >= 315 )
         dir = DIR_NORTHWEST;
      else if( angle >= 270 )
         dir = DIR_WEST;
      else if( angle >= 225 )
         dir = DIR_SOUTHWEST;
      else if( angle >= 180 )
         dir = DIR_SOUTH;
      else if( angle >= 135 )
         dir = DIR_SOUTHEAST;
      else if( angle >= 90 )
         dir = DIR_EAST;
      else if( angle >= 45 )
         dir = DIR_NORTHEAST;
      else if( angle >= 0 )
         dir = DIR_NORTH;

      if( dist > 200 )
         iMes = 0;
      else if( dist > 150 )
         iMes = 1;
      else if( dist > 100 )
         iMes = 2;
      else if( dist > 75 )
         iMes = 3;
      else if( dist > 50 )
         iMes = 4;
      else if( dist > 25 )
         iMes = 5;
      else if( dist > 15 )
         iMes = 6;
      else if( dist > 10 )
         iMes = 7;
      else if( dist > 5 )
         iMes = 8;
      else if( dist > 1 )
         iMes = 9;
      else
         iMes = 10;

      eta = dist * 10;
      if( dir == -1 )
         ch->printf( "&GAn %s bound &R%s&G within the immediate vicinity.\r\n", dir_name[en->direction], env_name[en->type] );
      else
         ch->printf( "&GA &R%s&G %s in the general %sern direction.\r\n", env_name[en->type], env_distances[iMes], dir_name[dir] );
      if( eta / 60 > 0 )
         ch->printf( "&GThis %s is about %d minutes away from you.\r\n", env_name[en->type], ( int )( eta / 60 ) );
      else
         ch->printf( "&GThis %s should be in the vicinity now.\r\n", env_name[en->type] );
   }

   if( !found )
   {
      ch->print( "&GNo environmental affects to report!\r\n" );
      ch->print( "&WThe imp vanishes with an ear-splitting BANG!\r\n" );
      return false;
   }

   ch->print( "&WThe imp vanishes with an ear-splitting BANG!\r\n" );
   return true;
}