Ejemplo n.º 1
0
void tst_QPainterPath::testArcMoveTo()
{
    QFETCH(QRectF, rect);
    QFETCH(qreal, angle);

    QPainterPath path;
    path.arcMoveTo(rect, angle);
    path.arcTo(rect, angle, 30);
    path.arcTo(rect, angle + 30, 30);

    QPointF pos = path.elementAt(0);

    QVERIFY((path.elementCount()-1) % 3 == 0);

    qreal x_radius = rect.width() / 2.0;
    qreal y_radius = rect.height() / 2.0;

    QPointF shouldBe = rect.center()
                       + QPointF(x_radius * cos(ANGLE(angle)), -y_radius * sin(ANGLE(angle)));

    qreal iw = 1 / rect.width();
    qreal ih = 1 / rect.height();

    QVERIFY(pathFuzzyCompare(pos.x() * iw, shouldBe.x() * iw));
    QVERIFY(pathFuzzyCompare(pos.y() * ih, shouldBe.y() * ih));
}
Ejemplo n.º 2
0
//computes the angles from one point to the next
void Optimizer_Context::fill_angle()
{
    /*

        When computing the angles from one point to the next,
        the angle stored on each point is the INCOMING angle for that point.
        For the outgoing angle, use the value from the next point.
        The first point's angle is computed based on the last_known_point.

                                   angle
                |---->|           |---->|

                *    [P     P     P     P     P     P     ...]

                |                       |
        last_known_point           stored here

    */

    points[0].angle = ANGLE(last_known_point.point,
                                   points[0].point);

    for(size_t i = 1; i < points.size(); i++)
    {
        points[i].angle = ANGLE(points[i - 1].point,
                                points[i].point);
    }
}
Ejemplo n.º 3
0
static void get_data(int client_fd)
{
  time_t now, midnight;
  struct tm *local;
  time_t elapsed;
  float hangle, mangle, sangle;

  now = time(0);

  local = localtime(&now);

  local->tm_hour = 0;
  local->tm_min  = 0;
  local->tm_sec  = 0;

  midnight = mktime(local);

  elapsed = now - midnight;

  hangle = (float) -ANGLE(elapsed, 12 * 60 * 60);
  mangle = (float) -ANGLE(elapsed, 60 * 60);
  sangle = (float) -ANGLE(elapsed, 60);

  CapSetData(hours, &hangle);
  CapSetData(minutes, &mangle);
  CapSetData(seconds, &sangle);

  return;
}
Ejemplo n.º 4
0
/**
 * @brief Set the vector value using cartesian coordinates
 *
 *    @param v Vector to set.
 *    @param x X value for vector.
 *    @param y Y value for vector.
 */
void vect_cset( Vector2d* v, const double x, const double y )
{
   v->x     = x;
   v->y     = y;
   v->mod   = MOD(x,y);
   v->angle = ANGLE(x,y);
}
Ejemplo n.º 5
0
/**
 * @brief Adds a polar 2d vector to the current vector.
 *
 *    @param v Vector to add x and y to.
 *    @param m Module of vector to add.
 *    @param a Angle of vector to add.
 */
void vect_padd( Vector2d* v, const double m, const double a )
{
   v->x    += m*cos(a);
   v->y    += m*sin(a);
   v->mod   = MOD(v->x,v->y);
   v->angle = ANGLE(v->x,v->y);
}
Ejemplo n.º 6
0
/**
 * @brief Adds x and y to the current vector
 *
 *    @param v Vector to add x and y to.
 *    @param x X value to add to vector.
 *    @param y Y value to add to vector.
 */
void vect_cadd( Vector2d* v, const double x, const double y )
{
   v->x    += x;
   v->y    += y;
   v->mod   = MOD(v->x,v->y);
   v->angle = ANGLE(v->x,v->y);
}
Ejemplo n.º 7
0
/**
 * @brief Updates the position of a voice.
 *
 *    @param v Voice to update.
 *    @param x New X position for the voice.
 *    @param y New Y position for the voice.
 *    @return 0 on success.
 */
static int sound_mix_updatePosVoice( alVoice *v, double x, double y )
{
   double angle, dist;
   double px, py;
   double d;
   int idist;

   /* Get relative position. */
   px = x - sound_pos[0];
   py = y - sound_pos[1];

   /* Exact calculations. */
   angle = sound_pos[2] - ANGLE(px,py)/M_PI*180.;
   dist = MOD(px,py);

   /* Need to make sure distance doesn't overflow. */
   d = CLAMP( 0., 1., (dist - 50.) / 2500. );
   d = 255. * sqrt(d);
   idist = MIN( (int)d, 255);

   /* Panning also gets modulated at low distance. */
   if (idist < 10)
      angle *= d/10.;

   /* Try to play the song. */
   if (Mix_SetPosition( v->u.mix.channel, (Sint16)angle, (Uint8)idist) < 0) {
      WARN("Unable to set sound position: %s", Mix_GetError());
      return -1;
   }

   return 0;
}
Ejemplo n.º 8
0
/**
 * @brief Get the direction pointed to by two vectors (from ref to v).
 *
 *    @param ref Reference vector.
 *    @param v Vector to get angle from reference vector.
 *    @return Angle between ref and v.
 */
double vect_angle( const Vector2d* ref, const Vector2d* v )
{
   double x,y;

   x = v->x - ref->x;
   y = v->y - ref->y;

   return ANGLE( x, y );
}
Ejemplo n.º 9
0
// does "snap to grid" for given angle
void Snap( ANGLE &angDest, ANGLE angStep)
{
  /* Watch out for unsigned-signed mixing!
   All sub-expressions and arguments must be unsigned for this to work correctly!
   Unfortunately, ANGLE is not an unsigned type by default, so we must cast it.
   Also, angStep must be a divisor of ANGLE_180!
   */
  ASSERT(ANGLE_180%angStep == 0);   // don't test with ANGLE_360 ,since it is 0!
  angDest = ANGLE( ((UWORD(angDest)+UWORD(angStep)/2U)/UWORD(angStep))*UWORD(angStep) );
}
Ejemplo n.º 10
0
//-------------------------------
//
//-------------------------------
Quaternion Vector3::GetQuaternion()
{
	Vector3	vDummy;
	vDummy.x = x;
	vDummy.y = y;
	vDummy.z = z;

	if( x == 0 && y == 0 )
	{
		Quaternion qRot;
		qRot.SetRotationZ( ANGLE( 0 ) );
		return qRot;
	} //if

	vDummy.Normalize();
	vDummy *= -1;

	Matrix44	matWorld;
	matWorld.SetWorld( vInit, vDummy, vUp );

	return matWorld.GetQuaternion();
} //Vector3::GetQuaternion
Ejemplo n.º 11
0
void Game(void)
{
    int x, y, z, a;
    char msg0[80];
    char msg1[80];
    char msg2[80];
    char msg3[80];

    qdgdfa_stop_sound(music);

    GameStartup();

    x = 16384 + 64;
    z = 16384 + 64;
    y = 16384;
    a = ANGLE(0);

    if (_level == 0)
        strcpy(msg0, "LEVEL: CUSTOM");
    else
        sprintf(msg0, "LEVEL: %d", _level);

    sprintf(msg1, "AREA: %s", _area_name);
    sprintf(msg2, "PUMPS: %d / CONSOLES: %d", _num_pumps, _num_consoles);
    sprintf(msg3, "TOTAL SINKING ESTIMATED: %02d:%02d", _left_minutes, _left_seconds);

    SetMessage(msg0, msg1, msg2, msg3, 10);

    GameCore(x, y, z, a);

    GameShutdown();

    qdgdfa_reset();

    music = qdgdfa_load_sound("sound/holst.wav");
    qdgdfa_play_sound(music, 1);
}
Ejemplo n.º 12
0
 *
 * @todo TODO config pulse accumulator to fire its own RPM interrupt to give the wheel more
 * resoloution. Such as fire on every 10x.
 *
 * @author Sean Keys
 */
#define DECODER_IMPLEMENTATION_C
#define LT1_360_8_C

#include "../inc/freeEMS.h"
#include "../inc/interrupts.h"
#include "inc/GM-LT1-CAS-360and8.h"
#include "../inc/decoderInterface.h"
#include "../inc/utils.h"

const unsigned short eventAngles[] = {ANGLE(  0), ANGLE( 86), ANGLE(130), ANGLE(176),
                                      ANGLE(180), ANGLE(266), ANGLE(280), ANGLE(356),
                                      ANGLE(360), ANGLE(446), ANGLE(470), ANGLE(536),
                                      ANGLE(540), ANGLE(626), ANGLE(660), ANGLE(716)
                                     };
const unsigned char eventValidForCrankSync[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // This is wrong, but will never be used on this decoder anyway.
const unsigned char windowCounts[] = {4,86,44,46,4,86,14,76,4,86,24,66,4,86,34,56};
unsigned char lastAccumulatorCount = 0xFF; /* set to bogus number */
unsigned char lastPARegisterReading = 0xFF;
unsigned char windowState = 0;
unsigned char lastNumberOfRealEvents = 0;
unsigned char accumulatorRegisterCount = 0;
signed char cumulativeBastardTeeth = 0;


// Rolling tolerance to cumulative noise issues feature.
Ejemplo n.º 13
0
/**
 * @brief Runge-Kutta method of updating a solid based on its acceleration.
 *
 * Runge-Kutta 4 method
 *
 *   d^2 x(t) / d t^2 = a, a = constant (acceleration)
 *   x'(0) = v, x(0) = p
 *   x'' = f( t, x, x' ) = ( x' , a )
 *
 *   x_{n+1} = x_n + h/6 (k1 + 2*k2 + 3*k3 + k4)
 *    h = (b-a)/2
 *    k1 = f(t_n, X_n ), X_n = (x_n, x'_n)
 *    k2 = f(t_n + h/2, X_n + h/2*k1)
 *    k3 = f(t_n + h/2, X_n + h/2*k2)
 *    k4 = f(t_n + h, X_n + h*k3)
 *
 *   x_{n+1} = x_n + h/6*(6x'_n + 3*h*a, 4*a)
 *
 *
 * Main advantage comes thanks to the fact that Naev is on a 2d plane.
 *  Therefore RK chops it up in chunks and actually creates a tiny curve
 *  instead of approximating the curve for a tiny straight line.
 */
#define RK4_MIN_H 0.01 /**< Minimal pass we want. */
static void solid_update_rk4 (Solid *obj, const double dt)
{
   int i, N; /* for iteration, and pass calculation */
   double h, px,py, vx,vy; /* pass, and position/velocity values */
   double ix,iy, tx,ty, ax,ay, th; /* initial and temporary cartesian vector values */
   double vmod, vang;
   int vint;
   int limit; /* limit speed? */

   /* Initial positions and velocity. */
   px = obj->pos.x;
   py = obj->pos.y;
   vx = obj->vel.x;
   vy = obj->vel.y;
   limit = (obj->speed_max >= 0.);

   /* Initial RK parameters. */
   if (dt > RK4_MIN_H)
      N = (int)(dt / RK4_MIN_H);
   else
      N = 1;
   vmod = MOD( vx, vy );
   vint = (int) vmod/100.;
   if (N < vint)
      N = vint;
   h = dt / (double)N; /* step */

   /* Movement Quantity Theorem:  m*a = \sum f */
   th = obj->thrust  / obj->mass;

   for (i=0; i < N; i++) { /* iterations */

      /* Calculate acceleration for the frame. */
      ax = th*cos(obj->dir);
      ay = th*sin(obj->dir);

      /* Limit the speed. */
      if (limit) {
         vmod = MOD( vx, vy );
         if (vmod > obj->speed_max) {
            /* We limit by applying a force against it. */
            vang  = ANGLE( vx, vy ) + M_PI;
            vmod  = 3. * (vmod - obj->speed_max);

            /* Update accel. */
            ax += vmod * cos(vang);
            ay += vmod * sin(vang);
         }
      }

      /* x component */
      tx = ix = vx;
      tx += 2.*ix + h*tx;
      tx += 2.*ix + h*tx;
      tx += ix + h*tx;
      tx *= h/6.;

      px += tx;
      vx += ax * h;

      /* y component */
      ty = iy = vy;
      ty += 2.*(iy + h/2.*ty);
      ty += 2.*(iy + h/2.*ty);
      ty += iy + h*ty;
      ty *= h/6.;

      py += ty;
      vy += ay * h;

      /* rotation. */
      obj->dir += obj->dir_vel*h;
   }
   vect_cset( &obj->vel, vx, vy );
   vect_cset( &obj->pos, px, py );

   /* Sanity check. */
   if (obj->dir >= 2.*M_PI)
      obj->dir -= 2.*M_PI;
   else if (obj->dir < 0.)
      obj->dir += 2.*M_PI;
}
Ejemplo n.º 14
0
//---カメラを正面にセット
void CrBattleCharacter::SetCameraFront(int camera /* = 0*/)
{
	SetCameraAngle(ANGLE(180),5.0f,camera);
}
Ejemplo n.º 15
0
 * @ingroup interruptHandlers
 * @ingroup enginePositionRPMDecoders
 *
 * @brief For evenly spaced teeth on the camshaft with a single second input.
 *
 * This is suitable for engines such as the Yamaha R1 with 8 teeth on the crank
 * and equally for something with 16 on the cam. Sync is provided by the second
 * input allowing a sequential and/or COP/CNP setup to be used.
 *
 * @see EvenTeeth-Both-Nand1.c
 *
 * @author Fred Cooke
 */


#define DECODER_IMPLEMENTATION_C
#define DECODER_MAX_CODE_TIME    100 // To be optimised (shortened)!
#define NUMBER_OF_REAL_EVENTS     16
#define NUMBER_OF_VIRTUAL_EVENTS  16

#include "../inc/freeEMS.h"
#include "../inc/utils.h"
#include "../inc/interrupts.h"
#include "../inc/decoderInterface.h"

const unsigned short eventAngles[] = {ANGLE(0), ANGLE(45), ANGLE(90), ANGLE(135), ANGLE(180), ANGLE(225), ANGLE(270), ANGLE(315), ANGLE(360), ANGLE(405), ANGLE(450), ANGLE(495), ANGLE(540), ANGLE(585), ANGLE(630), ANGLE(675)};
const unsigned char eventValidForCrankSync[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; // Unused for now, but correct anyway.

// Bring in the actual code.
#include "code/EvenTeeth-Both-Xand1.c"
#include "../inc/utils.h"
#include "../inc/interrupts.h"
#include "../inc/decoderInterface.h"

unsigned char camTeethSeen = 0;
unsigned char previousCrankTeethSeen = 0;
unsigned char crankTeethSinceLastCamTooth = 0;
unsigned char PTITCurrentState;
unsigned char secondaryPTITCurrentState;
unsigned long thisEventTimeStamp;
unsigned short edgeTimeStamp;
unsigned long thisInterEventPeriod;
unsigned short thisTicksPerDegree;
unsigned short ratioBetweenThisAndLast;

const unsigned short eventAngles[] = {ANGLE(  0), ANGLE( 30), ANGLE( 60), ANGLE( 90),
                                      ANGLE(120), ANGLE(150), ANGLE(180), ANGLE(210),
                                      ANGLE(240), ANGLE(270), ANGLE(300), ANGLE(330),
                                      ANGLE(360), ANGLE(390), ANGLE(420), ANGLE(450),
                                      ANGLE(480), ANGLE(510), ANGLE(540), ANGLE(570),
                                      ANGLE(600), ANGLE(630), ANGLE(660), ANGLE(690)};
const unsigned char eventValidForCrankSync[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};

void decoderInitPreliminary(){
	// Set PT0 and PT1 to only capture on rising edges
	TCTL4 = 0x05;
}

void perDecoderReset(){
	camTeethSeen = 0;
	previousCrankTeethSeen = 0;
Ejemplo n.º 17
0
void CrBattleCharacter::BeginMovingCameraFront(int camera /*= 0*/)
{
	BeginMovingCameraAngle(ANGLE(180),5.0f,camera);
}
Ejemplo n.º 18
0
Archivo: weapon.c Proyecto: zid/naev
/**
 * @brief Creates a new weapon.
 *
 *    @param outfit Outfit which spawned the weapon.
 *    @param dir Direction the shooter is facing.
 *    @param pos Position of the shooter.
 *    @param vel Velocity of the shooter.
 *    @param parent Shooter ID.
 *    @param target Target ID of the shooter.
 *    @return A pointer to the newly created weapon.
 */
static Weapon* weapon_create( const Outfit* outfit,
      const double dir, const Vector2d* pos, const Vector2d* vel,
      const unsigned int parent, const unsigned int target )
{
   Vector2d v;
   double mass, rdir;
   Pilot *pilot_target;
   double x,y, t, dist;
   Weapon* w;

   /* Create basic features */
   w = malloc(sizeof(Weapon));
   memset(w, 0, sizeof(Weapon));
   w->faction = pilot_get(parent)->faction; /* non-changeable */
   w->parent = parent; /* non-changeable */
   w->target = target; /* non-changeable */
   w->outfit = outfit; /* non-changeable */
   w->update = weapon_update;
   w->status = WEAPON_STATUS_OK;
   w->strength = 1.;

   switch (outfit->type) {

      /* Bolts treated together */
      case OUTFIT_TYPE_BOLT:
      case OUTFIT_TYPE_TURRET_BOLT:
         /* Only difference is the direction of fire */
         if ((outfit->type == OUTFIT_TYPE_TURRET_BOLT) && (w->parent!=w->target) &&
               (w->target != 0)) { /* Must have valid target */

            pilot_target = pilot_get(w->target);
            if (pilot_target == NULL)
               rdir = dir;

            else {
               /* Get the distance */
               dist = vect_dist( pos, &pilot_target->solid->pos );

               /* Aim. */
               if (dist > outfit->u.blt.range*1.2) {
                  x = pilot_target->solid->pos.x - pos->x;
                  y = pilot_target->solid->pos.y - pos->y;
               }
               else {
                  /* Try to predict where the enemy will be. */
                  /* Time for shots to reach that distance */
                  t = dist / (w->outfit->u.blt.speed + VMOD(*vel));

                  /* Position is calculated on where it should be */
                  x = (pilot_target->solid->pos.x + pilot_target->solid->vel.x*t)
                     - (pos->x + vel->x*t);
                  y = (pilot_target->solid->pos.y + pilot_target->solid->vel.y*t)
                     - (pos->y + vel->y*t);
               }

               /* Set angle to face. */
               rdir = ANGLE(x, y);
            }
         }
         else /* fire straight */
            rdir = dir;

         rdir += RNG_2SIGMA() * outfit->u.blt.accuracy/2. * 1./180.*M_PI;
         if (rdir < 0.)
            rdir += 2.*M_PI;
         else if (rdir >= 2.*M_PI)
            rdir -= 2.*M_PI;

         mass = 1; /* Lasers are presumed to have unitary mass */
         vectcpy( &v, vel );
         vect_cadd( &v, outfit->u.blt.speed*cos(rdir), outfit->u.blt.speed*sin(rdir));
         w->timer = outfit->u.blt.range / outfit->u.blt.speed;
         w->falloff = w->timer - outfit->u.blt.falloff / outfit->u.blt.speed;
         w->solid = solid_create( mass, rdir, pos, &v );
         w->voice = sound_playPos( w->outfit->u.blt.sound,
               w->solid->pos.x,
               w->solid->pos.y,
               w->solid->vel.x,
               w->solid->vel.y);
         break;

      /* Beam weapons are treated together. */
      case OUTFIT_TYPE_BEAM:
      case OUTFIT_TYPE_TURRET_BEAM:
         if ((outfit->type == OUTFIT_TYPE_TURRET_BEAM) && (w->parent!=w->target)) {
            pilot_target = pilot_get(target);
            rdir = (pilot_target == NULL) ? dir :
                  vect_angle(pos, &pilot_target->solid->pos);
         }
         else
            rdir = dir;
         if (rdir < 0.)
            rdir += 2.*M_PI;
         else if (rdir >= 2.*M_PI)
            rdir -= 2.*M_PI;
         mass = 1.; /**< Needs a mass. */
         w->solid = solid_create( mass, rdir, pos, NULL );
         w->think = think_beam;
         w->timer = outfit->u.bem.duration;
         w->voice = sound_playPos( w->outfit->u.bem.sound,
               w->solid->pos.x,
               w->solid->pos.y,
               w->solid->vel.x,
               w->solid->vel.y);
         break;

      /* Treat seekers together. */
      case OUTFIT_TYPE_AMMO:
      case OUTFIT_TYPE_TURRET_AMMO:
         if (w->outfit->type == OUTFIT_TYPE_TURRET_AMMO) {
            pilot_target = pilot_get(w->target);
            if (pilot_target == NULL)
               rdir = dir;

            else {
               /* Get the distance */
               dist = vect_dist( pos, &pilot_target->solid->pos );

               /* Aim. */
               /* Try to predict where the enemy will be. */
               /* Time for shots to reach that distance */
               if (outfit->u.amm.thrust == 0.)
                  t = dist / (w->outfit->u.amm.speed + VMOD(*vel));
               else
                  t = dist / w->outfit->u.amm.speed;

               /* Position is calculated on where it should be */
               x = (pilot_target->solid->pos.x + pilot_target->solid->vel.x*t)
                  - (pos->x + vel->x*t);
               y = (pilot_target->solid->pos.y + pilot_target->solid->vel.y*t)
                  - (pos->y + vel->y*t);

               /* Set angle to face. */
               rdir = ANGLE(x, y);
            }
         }
         else {
            rdir = dir;
         }
         if (outfit->u.amm.accuracy != 0.) {
            rdir += RNG_2SIGMA() * outfit->u.amm.accuracy/2. * 1./180.*M_PI;
            if ((rdir > 2.*M_PI) || (rdir < 0.))
               rdir = fmod(rdir, 2.*M_PI);
         }
         if (rdir < 0.)
            rdir += 2.*M_PI;
         else if (rdir >= 2.*M_PI)
            rdir -= 2.*M_PI;

         /* If thrust is 0. we assume it starts out at speed. */
         vectcpy( &v, vel );
         if (outfit->u.amm.thrust == 0.)
            vect_cadd( &v, cos(rdir) * w->outfit->u.amm.speed,
                  sin(rdir) * w->outfit->u.amm.speed );

         /* Set up ammo details. */
         mass        = w->outfit->mass;
         w->lockon   = outfit->u.amm.lockon;
         w->timer    = outfit->u.amm.duration;
         w->solid    = solid_create( mass, rdir, pos, &v );
         if (w->outfit->u.amm.thrust != 0.)
            weapon_setThrust( w, w->outfit->u.amm.thrust * mass );

         /* Handle seekers. */
         if (w->outfit->u.amm.ai > 0) {
            w->think = think_seeker; /* AI is the same atm. */

            /* If they are seeking a pilot, increment lockon counter. */
            pilot_target = pilot_get(target);
            if (pilot_target != NULL)
               pilot_target->lockons++;
         }

         /* Play sound. */
         w->voice    = sound_playPos(w->outfit->u.amm.sound,
               w->solid->pos.x,
               w->solid->pos.y,
               w->solid->vel.x,
               w->solid->vel.y);
         break;

      /* just dump it where the player is */
      default:
         WARN("Weapon of type '%s' has no create implemented yet!",
               w->outfit->name);
         w->solid = solid_create( 1., dir, pos, vel );
         break;
   }

   /* Set life to timer. */
   w->life = w->timer;

   return w;
}
Ejemplo n.º 19
0
/**
 * @brief Updates the lockons on the pilot's launchers
 *
 *    @param p Pilot being updated.
 *    @param o Slot being updated.
 *    @param t Pilot that is currently the target of p (or NULL if not applicable).
 *    @param a Angle to update if necessary. Should be initialized to -1 before the loop.
 *    @param dt Current delta tick.
 */
void pilot_lockUpdateSlot( Pilot *p, PilotOutfitSlot *o, Pilot *t, double *a, double dt )
{
   double max, old;
   double x,y, ang, arc;
   int locked;

   /* No target. */
   if (t == NULL)
      return;

   /* Nota  seeker. */
   if (!outfit_isSeeker(o->outfit))
      return;

   /* Check arc. */
   arc = o->outfit->u.lau.arc;
   if (arc > 0.) {

      /* We use an external variable to set and update the angle if necessary. */
      if (*a < 0.) {
         x     = t->solid->pos.x - p->solid->pos.x;
         y     = t->solid->pos.y - p->solid->pos.y;
         ang   = ANGLE( x, y );
         *a    = fabs( angle_diff( ang, p->solid->dir ) );
      }

      /* Decay if not in arc. */
      if (*a > arc) {
         /* Limit decay to the lockon time for this launcher. */
         max = o->outfit->u.lau.lockon;

         /* When a lock is lost, immediately gain half the lock timer.
          * This is meant as an incentive for the aggressor not to lose the lock,
          * and for the target to try and break the lock. */
         old = o->u.ammo.lockon_timer;
         o->u.ammo.lockon_timer += dt;
         if ((old <= 0.) && (o->u.ammo.lockon_timer > 0.))
            o->u.ammo.lockon_timer += o->outfit->u.lau.lockon / 2.;

         /* Cap at max. */
         if (o->u.ammo.lockon_timer > max)
            o->u.ammo.lockon_timer = max;

         /* Out of arc. */
         o->u.ammo.in_arc = 0;
         return;
      }
   }

   /* In arc. */
   o->u.ammo.in_arc = 1;
   locked = (o->u.ammo.lockon_timer < 0.);

   /* Lower timer. When the timer reaches zero, the lock is established. */
   max = -o->outfit->u.lau.lockon/3.;
   if (o->u.ammo.lockon_timer > max) {
      /* Compensate for enemy hide factor. */
      o->u.ammo.lockon_timer -= dt * (o->outfit->u.lau.ew_target2 / t->ew_hide);

      /* Cap at -max/3. */
      if (o->u.ammo.lockon_timer < max)
         o->u.ammo.lockon_timer = max;

      /* Trigger lockon hook. */
      if (!locked && (o->u.ammo.lockon_timer < 0.))
         pilot_runHook( p, PILOT_HOOK_LOCKON );
   }
}
Ejemplo n.º 20
0
void
fequinoxsolstice(int year, double UTCoffset, double *equinoxdays, double *solsticedays)
{
	double dec, prevdec, L;
	int h, d, prevangle, angle;
	int found = 0;

	double decleft, decright, decmiddle;
	int dial, s;

	int *cumdays;
	cumdays = cumdaytab[isleap(year)];

	/*
	 * Find the first equinox, somewhere in March:
	 * It happens when the returned value "dec" goes from
	 * [350 ... 360> -> [0 ... 10]
	 */
	for (d = 18; d < 31; d++) {
		/* printf("Comparing day %d to %d.\n", d, d+1); */
		sunpos(year, 3, d, UTCoffset, 0, 0, 0, 0.0, 0.0, &L, &decleft);
		sunpos(year, 3, d + 1, UTCoffset, 0, 0, 0, 0.0, 0.0,
		    &L, &decright);
		/* printf("Found %g and %g.\n", decleft, decright); */
		if (SIGN(decleft) == SIGN(decright))
			continue;

		dial = SECSPERDAY;
		s = SECSPERDAY / 2;
		while (s > 0) {
			/* printf("Obtaining %d (%02d:%02d)\n",
			    dial, SHOUR(dial), SMIN(dial)); */
			sunpos(year, 3, d, UTCoffset,
			    SHOUR(dial), SMIN(dial), SSEC(dial),
			    0.0, 0.0, &L, &decmiddle);
			/* printf("Found %g\n", decmiddle); */
			if (SIGN(decleft) == SIGN(decmiddle)) {
				decleft = decmiddle;
				dial += s;
			} else {
				decright = decmiddle;
				dial -= s;
			}
			/*
			 printf("New boundaries: %g - %g\n", decleft, decright);
			*/

			s /= 2;
		}
		equinoxdays[0] = 1 + cumdays[3] + d + (dial / FSECSPERDAY);
		break;
	}

	/* Find the second equinox, somewhere in September:
	 * It happens when the returned value "dec" goes from
	 * [10 ... 0] -> <360 ... 350]
	 */
	for (d = 18; d < 31; d++) {
		/* printf("Comparing day %d to %d.\n", d, d+1); */
		sunpos(year, 9, d, UTCoffset, 0, 0, 0, 0.0, 0.0, &L, &decleft);
		sunpos(year, 9, d + 1, UTCoffset, 0, 0, 0, 0.0, 0.0,
		    &L, &decright);
		/* printf("Found %g and %g.\n", decleft, decright); */
		if (SIGN(decleft) == SIGN(decright))
			continue;

		dial = SECSPERDAY;
		s = SECSPERDAY / 2;
		while (s > 0) {
			/* printf("Obtaining %d (%02d:%02d)\n",
			    dial, SHOUR(dial), SMIN(dial)); */
			sunpos(year, 9, d, UTCoffset,
			    SHOUR(dial), SMIN(dial), SSEC(dial),
			    0.0, 0.0, &L, &decmiddle);
			/* printf("Found %g\n", decmiddle); */
			if (SIGN(decleft) == SIGN(decmiddle)) {
				decleft = decmiddle;
				dial += s;
			} else {
				decright = decmiddle;
				dial -= s;
			}
			/*
			printf("New boundaries: %g - %g\n", decleft, decright);
			*/

			s /= 2;
		}
		equinoxdays[1] = 1 + cumdays[9] + d + (dial / FSECSPERDAY);
		break;
	}

	/*
	 * Find the first solstice, somewhere in June:
	 * It happens when the returned value "dec" peaks
	 * [40 ... 45] -> [45 ... 40]
	 */
	found = 0;
	prevdec = 0;
	prevangle = 1;
	for (d = 18; d < 31; d++) {
		for (h = 0; h < 4 * HOURSPERDAY; h++) {
			sunpos(year, 6, d, UTCoffset, HOUR(h), MIN(h), SEC(h),
			    0.0, 0.0, &L, &dec);
			angle = ANGLE(prevdec, dec);
			if (prevangle != angle) {
#ifdef NOTDEF
				DEBUG2(year, 6, d, HOUR(h), MIN(h),
				    prevdec, dec, prevangle, angle);
#endif
				solsticedays[0] = 1 + cumdays[6] + d +
				    ((h / 4.0) / 24.0);
				found = 1;
				break;
			}
			prevdec = dec;
			prevangle = angle;
		}
		if (found)
			break;
	}

	/*
	 * Find the second solstice, somewhere in December:
	 * It happens when the returned value "dec" peaks
	 * [315 ... 310] -> [310 ... 315]
	 */
	found = 0;
	prevdec = 360;
	prevangle = -1;
	for (d = 18; d < 31; d++) {
		for (h = 0; h < 4 * HOURSPERDAY; h++) {
			sunpos(year, 12, d, UTCoffset, HOUR(h), MIN(h), SEC(h),
			    0.0, 0.0, &L, &dec);
			angle = ANGLE(prevdec, dec);
			if (prevangle != angle) {
#ifdef NOTDEF
				DEBUG2(year, 12, d, HOUR(h), MIN(h),
				    prevdec, dec, prevangle, angle);
#endif
				solsticedays[1] = 1 + cumdays[12] + d +
				    ((h / 4.0) / 24.0);
				found = 1;
				break;
			}
			prevdec = dec;
			prevangle = angle;
		}
		if (found)
			break;
	}

	return;
}
Ejemplo n.º 21
0
CRBATTLE_API int crbatTest(void)
{
	D3DTLVERTEX ver[4];

	ver[0].sx = 50.0f;ver[0].sy = 50.0f;ver[0].sz = 0.0f;
	ver[0].tu = 0.0f;ver[0].tv = 0.0f;

	ver[1].sx = 110.0f;ver[1].sy = 50.0f;ver[1].sz = 0.0f;
	ver[1].tu = 1.0f;ver[1].tv = 0.0f;

	ver[2].sx = 50.0f;ver[2].sy = 410.0f;ver[2].sz = 0.0f;
	ver[2].tu = 0.0f;ver[2].tv = 1.0f;

	ver[3].sx = 110.0f;ver[3].sy = 410.0f;ver[3].sz = 0.0f;
	ver[3].tu = 1.0f;ver[3].tv = 1.0f;
	for(int a = 0;a < 4;a ++){
		ver[a].dcColor = RGBA_MAKE(255,255,255 / (a + 1),255);
		ver[a].dvRHW = RGBA_MAKE(255,0,0,0);
	}

//	int x,y;
	float sx = 6,sy = -5,sz = 3;
	eiD3DMatrix matWorld,matProjection;
	float AddWorld = 0.0f,Angle = ANGLE(90),rotate;
	eistr s[100];


	int debug_time = GetTickCount(),frame;

	ei->Get();

	pViewport->SetRect(32,32,256 + 32,256 + 32);
	pViewport->SetRect(32,32,640 - 64,256);
//	pViewport->SetRect(0,0,640,480);
	pViewport->Set();
	eid3d->SetAmbientLight(RGBA_MAKE(255,255,255,255));

	frame = 0;

	crbaseClearScreen();
	crbatShowStatus();
//	crbatSetViewMode(BATTLE_VIEWMODE_DOUBLE);
//	crbatSetViewMode(BATTLE_VIEWMODE_HALF);
	crbatSetCamera(
		1,
		-5.0f,4.0f,-5.0f,
		15.0f,0.0f,15.0f,
		0.0f);

	while(!ei->Input[0].Button[0] && !ei->Escape){
		ei->Get();

		if(ei->Input[0].Button[1]){
			sz += (float)(1.0 * AddWorld);
		}
		if(ei->Input[0].Button[2]){
			sz -= (float)(1.0 * AddWorld);
		}

		if(ei->Input[0].Left){
			Angle += (float)(0.5f * AddWorld);
		} else if(ei->Input[0].Right){
			Angle -= (float)(0.5f * AddWorld);
		}
		if(Angle > PI * 2.0f)
			Angle = 0.0f;
		if(Angle < 0.0f)
			Angle = PI * 2.0f;
		rotate = 0.0f;

		if(ei->Input[0].Up){
			sx += (float)(cos(Angle) * 1.0f * AddWorld);
			sy += (float)(sin(Angle) * 1.0f * AddWorld);
		} else if(ei->Input[0].Down){
			sx -= (float)(cos(Angle) * 1.0f * AddWorld);
			sy -= (float)(sin(Angle) * 1.0f * AddWorld);
		}

		crbatSetCamera(
			0,
			sx,sy,sz,
			(float)(sx + (cos(Angle) * 10.0f)),
			(float)(sy + (sin(Angle) * 10.0f)),
			(float)0.0f,
			rotate);
		crbatSetCamera(
			1,
			sx,sy,sz,
			(float)(sx + (cos(Angle) * 10.0f)),
			(float)(sy + (sin(Angle) * 10.0f)),
			(float)0.0f,
			rotate);

		et->Reset();
//---デバッグ計測用--------------------
		if(GetTickCount() - debug_time >= 1000){
			debug_time= GetTickCount();
			sprintf(s,"%d",frame);
			SetWindowText(ew->hwnd,s);
			frame = 0;
		}
		frame ++;
//		sprintf(s,"%f",BattleView[0].Angle);
//		SetWindowText(ew->hwnd,s);
//-------------------------------------
		crbatClearDrawingList();
		crbatAddDrawingListAll();
/*		crbatAddDrawingList(&pBtChara[0]);
		crbatAddDrawingList(&pBtChara[1]);
		crbatAddDrawingList(&pBtChara[2]);
		crbatAddDrawingList(&pBtChara[5]);
		crbatAddDrawingList(&pBtChara[6]);*/
		crbatDrawScene();

//		{
//			RECT rect = {32,32,640 - 32,256 + 32};
//			ew->lpCell[1]->SetClipingRect(&rect);
//			crbatPut3DCell(&BattleCharaCell[0],128.0f,0.0f,128.0f,0.50f);
//			crbatPut3DCell(&BattleCharaCell[20],68.0f,0.0f,198.0f,0.50f);
//			crbatPut3DCell(&BattleCharaCell[40],228.0f,0.0f,32.0f,0.50f);
//			SetRect(&rect,0,0,640,480);
//			ew->lpCell[1]->SetClipingRect(&rect);
//		}
		//---フリップ
//		ew->Flip();
		ew->Refresh();
		if(!eiGetFullScreen()){
//			et->Wait(1);
		}

		//---進める時間
		AddWorld = (float)et->Get() / 100.0f;

	}

	return 1;
}