inline double		resolv_hole_e(t_rt *s, t_hole_cube *cube)
{
  return (QUARTIC(s->ray.new_eye.x) + QUARTIC(s->ray.new_eye.y) +
	  QUARTIC(s->ray.new_eye.z) -
	  (5 * (CARRE(s->ray.new_eye.x) + CARRE(s->ray.new_eye.y) +
		CARRE(s->ray.new_eye.z))) + cube->rad);
}
Beispiel #2
0
/**
* \fn void speedBombReaction(Worms* pWorms, int centerX, int centerY, int radius
* \brief Applies speed and dammage according to the position of the worms to the center of the explosion.
*
* \param[in] pWorms, pointer to the worms.
* \param[in] centerX, X coordinate of the center of the cercle of the explosion.
* \param[in] centerY, Y coordinate of the center of the cercle of the explosion.
* \param[in] radius, radius of the explosion.
* \returns void
*/
void speedBombReaction(Worms* pWorms, int centerX, int centerY, int radius)
{
	int middleX = pWorms->wormsObject->objectBox.x + pWorms->wormsObject->objectBox.w / 2;
	int middleY = pWorms->wormsObject->objectBox.y + pWorms->wormsObject->objectBox.h / 2;
	float signeX = 1.0, signeY = 1.0, distanceX = 0, distanceY = 0;
	if (middleX < centerX)
	{
		signeX = -1.0;
		if (middleY > centerY)
		{
			signeY = -1.0;
		}
	}
	//calcul de la distance par rapport au centre
	distanceX = MY_ABS((middleX - centerX)) / (float)radius;
	distanceY = MY_ABS((middleY - centerY)) / (float)radius;
	double decrease = sqrt(CARRE(distanceX) + CARRE(distanceY));
	if (decrease <= 0.35)
	{
		pWorms->wormsObject->Xspeed = (float)(vitesseX * BombFactor * signeX*1.0 / 0.35);
		pWorms->wormsObject->Yspeed = (float)(vitesseY * BombFactor * signeY*1.0 / 0.35);
		pWorms->vie -= (int)(MAXDAMAGE * 1.0 / 0.35);
	}
	else
	{
		pWorms->wormsObject->Xspeed = (float)(vitesseX * BombFactor * signeX * 1.0 / decrease);
		pWorms->wormsObject->Yspeed = (float)(vitesseY * BombFactor * signeY * 1.0 / decrease);
		pWorms->vie -= (int)(MAXDAMAGE * 1.0 / decrease);
	}
	wormsDead(pWorms, 0);
}
Beispiel #3
0
Cube::Cube(double mass, glm::dvec3 scaling){
  _collisionShape = new CubeShape(this);

  vertices.push_back(scaling * glm::dvec3(-1., 1., 1.));
  vertices.push_back(scaling * glm::dvec3(-1., 1., -1.));
  vertices.push_back(scaling * glm::dvec3(1., 1., -1.));
  vertices.push_back(scaling * glm::dvec3(1., 1., 1.));

  vertices.push_back(scaling * glm::dvec3(-1., -1., 1.));
  vertices.push_back(scaling * glm::dvec3(-1., -1., -1.));
  vertices.push_back(scaling * glm::dvec3(1., -1., -1.));
  vertices.push_back(scaling * glm::dvec3(1., -1., 1.));

  // matrice d'inertie pour un parallélépipède
  current.inertiaTensor =
        { { CARRE(scaling.y) + CARRE(scaling.z), 0                            , 0                             },
          { 0                            , CARRE(scaling.x) + CARRE(scaling.z), 0                             },
          { 0                            , 0                            , CARRE(scaling.x) + CARRE(scaling.y) }
        };

  current.scaling = scaling;
  current.mass = mass;
  current.inverseMass = 1. / mass;

  current.inertiaTensor = (mass / 12.) * current.inertiaTensor;
  current.inverseInertiaTensor = glm::inverse(current.inertiaTensor);

  current.recalculate();
}
inline double		resolv_hole_c(t_rt *s)
{
  return ((6 * ((CARRE(s->ray.vct->x) * CARRE(s->ray.new_eye.x)) +
		(CARRE(s->ray.vct->y) * CARRE(s->ray.new_eye.y)) +
		(CARRE(s->ray.vct->z) * CARRE(s->ray.new_eye.z)))) -
	  (5 * (CARRE(s->ray.vct->x) + CARRE(s->ray.vct->y) +
		CARRE(s->ray.vct->z))));
}
Beispiel #5
0
/* *********************************************************************** */
static int calcul_nrj_dpz(Sound *s, Tcl_Interp *interp, int start,int longueur)
{
  int J,JJ,m,i,j,trame,dpz,sens;
  double nrj;
  
  max_nrj = max_dpz = 0;
  min_nrj = min_dpz = MAX_ENTIER;

  Snack_ProgressCallback(s->cmdPtr, interp, "Computing pitch", 0.0);

  for (trame=i=0; i<longueur; i += cst_step_hamming,trame++) {
    J = minimum(s->length,(i+cst_length_hamming));
    JJ = J-1;
    if (s->length < i + start + cst_length_hamming) {
      Snack_GetSoundData(s, i+start, Signal, s->length - i + start);
      for (j = s->length - i + start; j < cst_length_hamming; j++) {
	Signal[j] = 0.0f;
      }
    } else {
      Snack_GetSoundData(s, i+start, Signal, cst_length_hamming);
    }    

    /* ---- nrj ---- */
    for (nrj=0.0,j=0; j<J-i; j++) 
      nrj += CARRE((double) Signal[j]);  
    
    m = Nrj[trame] = (short) (10 * log10(nrj));
    
    if (m > max_nrj) max_nrj = m;
    if (m < min_nrj) min_nrj = m;
    
    /* ---- dpz ---- */
    for (dpz=0,j=0; j<J-i; j++) {
      while ( (j<J-i) && (abs((int)Signal[j]) > EPSILON) ) j++; /* looking just close to zero values */
      if (j<J-i) dpz ++;
      sens = ( ((j-1) >= 0) && (Signal[j-1] > Signal[j])); 
      if (sens) while ( (j<JJ-i) && (Signal[j] > Signal[j+1]) ) j++;
      else while ( (j<JJ-i) && (Signal[j] <= Signal[j+1]) ) j++;      
    }
    m = Dpz[trame] = dpz;
    
    if (m > max_dpz) max_dpz = m;
    if (m < min_dpz) min_dpz = m;

    if ((trame % 300) == 299) {
      int res = Snack_ProgressCallback(s->cmdPtr, interp, "Computing pitch",
				       0.05 * (double) i / longueur);
      if (res != TCL_OK) {
	return TCL_ERROR;
      }
    }  
  }

  seuil_nrj = min_nrj + (SEUIL_NRJ*(max_nrj-min_nrj))/100;   
  seuil_dpz = min_dpz + (SEUIL_DPZ*(max_dpz-min_dpz))/100;  
 
  if (debug) printf("dpz <%d,%d>, nrj <%d,%d> => Seuil nrj: %d, Seuil dpz: %d\n",min_dpz,max_dpz,min_nrj,max_nrj,seuil_nrj,seuil_dpz);

  return trame;
  }
/**
* \fn void setSurfaceRelativeCoordinates(SDL_Surface* pSurface, int relativeTime, float Xspeed, float Yspeed)
* \brief Process relatives coordinates for gravity and jump functions.
*
* \param[in] pSurface, pointer to the surface to move.
* \param[in] relativeTime, relative time to use to generate coordinates.
* \param[in] Xspeed, speed along the X axis.
* \param[in] Yspeed, speed along the Y axis.
* \returns void
*/
void setSurfaceRelativeCoordinates(SDL_Surface* pSurface, int relativeTime, float Xspeed, float Yspeed)
{
	float relativeX = 0.0, relativeY = 0.0;
	const double g = 9.81;

	relativeX = (float)(Xspeed * relativeTime);
	relativeY = (float)(Yspeed * relativeTime - (float)(g*CARRE(relativeTime) / 2000));

	pSurface->clip_rect.x += (int)relativeX;
	pSurface->clip_rect.y -= (int)relativeY;
}
Beispiel #7
0
int	inter_indice_sphere(t_camera *camera, t_object *object,
			     double *vector, double *indice)
{
  double	pos[NB_DIMENSION];
  double	u[NB_DIMENSION];

  if (modif_position(camera->position, object, pos, INVERSE_ROTATION) ||
      modif_vector(object->rotation, vector, u, INVERSE_ROTATION))
    return (EXIT_FAILURE);
  indice[A] = CARRE(u[X]) + CARRE(u[Y]) + CARRE(u[Z]);
  indice[B] = 2.000 * ((pos[X] * u[X]) + (pos[Y] * u[Y]) + (pos[Z] * u[Z]));
  indice[C] = CARRE(pos[X]) + CARRE(pos[Y]) + CARRE(pos[Z]) -
    CARRE(((t_sphere *)object->son)->radius);
  indice[DELTA] = CARRE(indice[B]) - (4.000 * indice[A] * indice[C]);
  return (EXIT_SUCCESS);
}
Beispiel #8
0
int	inter_indice_cone(t_camera *camera, t_object *object,
			     double *vector, double *indice)
{
  double	pos[NB_DIMENSION];
  double	u[NB_DIMENSION];
  double	radian;
  double	opening;

  radian = (((t_cone *)object->son)->angle * M_PI) / 180.000;
  opening = CARRE(tan(radian));
  if (!opening)
    opening += EPSILON;
  if (modif_position(camera->position, object, pos, INVERSE_ROTATION) ||
      modif_vector(object->rotation, vector, u, INVERSE_ROTATION))
    return (EXIT_FAILURE);
  indice[A] = CARRE(u[X]) + CARRE(u[Y]) - (CARRE(u[Z]) / opening);
  indice[B] = 2.000 *
    ((pos[X] * u[X]) + (pos[Y] * u[Y]) - (pos[Z] * (u[Z]) / opening));
  indice[C] = CARRE(pos[X]) + CARRE(pos[Y]) - (CARRE(pos[Z]) / opening);
  indice[DELTA] = CARRE(indice[B]) - (4.000 * indice[A] * indice[C]);
  return (EXIT_SUCCESS);
}
Beispiel #9
0
int	inter_indice_tore(t_camera *camera, t_object *object,
				  double *vector, double *indice)
{
  double	r;
  double	R;
  double	pos[NB_DIMENSION];
  double	u[NB_DIMENSION];

  r = (double)((t_tore *)object->son)->radius[MIN];
  R = (double)((t_tore *)object->son)->radius[MAX];
  if (modif_position(camera->position, object, pos, INVERSE_ROTATION) ||
      modif_vector(object->rotation, vector, u, INVERSE_ROTATION))
    return (EXIT_FAILURE);
  indice[A] = CARRE(CARRE(u[X]) + CARRE(u[Y]) + CARRE(u[Z]));
  indice[B] = 2.0 * (CARRE(u[X]) + CARRE(u[Y]) + CARRE(u[Z])) * \
    (2.0 * (u[X] * pos[X] + u[Y] * pos[Y] + u[Z] * pos[Z]));
  indice[C] = 2.0 * (CARRE(u[X]) + CARRE(u[Y]) + CARRE(u[Z])) *		\
    (CARRE(pos[X]) + CARRE(pos[Y]) + CARRE(pos[Z]) + CARRE(R) -		\
     CARRE(r)) + CARRE(2.0 * (u[X] * pos[X] + u[Y] * pos[Y]		\
			      + u[Z] * pos[Z])) - 4.0 * CARRE(R) *	\
    (CARRE(u[X]) + CARRE(u[Z]));
  indice[D] = 2.0 * (2.0 * (u[X] * pos[X] + u[Y] * pos[Y] + u[Z] * pos[Z])) * \
    (CARRE(pos[X]) + CARRE(pos[Y]) + CARRE(pos[Z]) + CARRE(R) - CARRE(r)) - \
    (4.0 * CARRE(R) * 2.0 * (u[X] * pos[X] + u[Z] * pos[Z]));
  indice[E] = CARRE(CARRE(pos[X]) + CARRE(pos[Y]) + CARRE(pos[Z]) \
		    + CARRE(R) - CARRE(r))			  \
    - (4.0 * CARRE(R) * (CARRE(pos[X]) + CARRE(pos[Z])));
  return (EXIT_SUCCESS);
}