Пример #1
0
int main() {
  krpc::Client conn = krpc::connect("Angle of attack");
  krpc::services::SpaceCenter space_center(&conn);
  auto vessel = space_center.active_vessel();

  while (true) {
    auto d = vessel.direction(vessel.orbit().body().reference_frame());
    auto v = vessel.velocity(vessel.orbit().body().reference_frame());

    // Compute the dot product of d and v
    double dotProd =
      std::get<0>(d)*std::get<0>(v) +
      std::get<1>(d)*std::get<1>(v) +
      std::get<2>(d)*std::get<2>(v);

    // Compute the magnitude of v
    double vMag = sqrt(
      std::get<0>(v)*std::get<0>(v) +
      std::get<1>(v)*std::get<1>(v) +
      std::get<2>(v)*std::get<2>(v));
    // Note: don't need to magnitude of d as it is a unit vector

    // Compute the angle between the vectors
    double angle = 0;
    if (dotProd > 0)
      angle = fabs(acos(dotProd / vMag) * (180.0 / pi));

    std::cout << "Angle of attack = "
              << std::fixed << std::setprecision(1)
              << angle << " degrees" << std::endl;

    std::this_thread::sleep_for(std::chrono::seconds(1));
  }
}
Пример #2
0
//------------------------------------------------------------------------------
//!
bool
CameraManipulator::onPointerMove( const Event& ev )
{
   if( _mode == 0 ) return false;

   switch( _mode )
   {
      case 1:
      {
         float radP = CGM::degToRad( _grabPos.x - ev.position().x );
         float radS = CGM::degToRad( ev.position().y - _grabPos.y );
         radP *= _direction;
         if( _isLocked  )
         {
            orbit( radP*0.75f, radS*0.75f );
         }
         else
         {
            tilt( radP*0.25f, radS*0.25f );
         }
         return true;
      } break;
      case 2: forward( ev.position() );
         return true;
      case 3: pan( ev.position() );
         return true;
      default:;
   }
   return false;
}
Пример #3
0
int main()
{
/*
	int x = 3;
	print f(x);
	print f(x);

	char s[] = "><<<";
	print orbit(s);
	print orbit(s);
*/

	//read
	int i;
	char line[MAX_N];	
	scanf("%s", &line);

	//solve
	do {
		for (i = 0; i < strlen(line); i++)
			printf("%c ", line[i]);
		printf("\n");
	} while (orbit(line));
	printf("Finish\n");
	return 0;
}
Пример #4
0
QuadEdge::Edge* RegionalTerrain_3r::MakeVertexEdge(QuadEdge::Vertex *v,
        QuadEdge::Face *left,
        QuadEdge::Face *right,
        SharedPoint_3r vnew_pos) {

    // we need to pop all faces and edges on the ccw traveral from the left
    // face to the right face in v's orbit. the vertexedgeiterator will begin
    // at a random edge in the orbit, and we have no way of determining whether
    // we are inside or outside the left-to-right range on the first pass
    // through the edges. the iterator will give us the edges back in ccw order
    // however.

    // the strategy is to place all edges in v's orbit into a list and rotate
    // the list so that the leftmost edge to pop is the first element.
    std::list<QuadEdge::Edge*> rotated_orbit;

    // iterate through the orbit and track the leftmost edge insertion index.
    size_t right_idx = 0;
    size_t i = 0;
    QuadEdge::VertexEdgeIterator orbit(v);
    QuadEdge::Edge *e;
    while ((e = orbit.next()) != 0) {
        if (e->Right() == right) {
            right_idx = i;
        }
        rotated_orbit.push_back(e);
        ++i;
    }

    // move the left-right range to the beginning of list.
    std::rotate(begin(rotated_orbit),
                std::next(begin(rotated_orbit), right_idx),
                end(rotated_orbit));

    // pop faces and edges in left-right range.
    for (auto edge : rotated_orbit) {
        SigPopFace(edge->Right());
        if (edge->Right() == left) {
            break;
        }
        SigPopEdge(edge);
    }

    // make topological changes to QuadEdge cell, set new vertex position.
    QuadEdge::Edge* enew = terrain_->makeVertexEdge(v, left, right);
    QuadEdge::Vertex* vnew = enew->Dest();
    vnew->pos = vnew_pos;

    // we assume vnew_pos is already registered, so just push the vertex.
    SigPushVertex(vnew);

    // push all new edges and faces.
    QuadEdge::VertexEdgeIterator orbitnew(vnew);
    while ((e = orbitnew.next()) != 0) {
        SigPushEdge(e);
        SigPushFace(e->Left());
    }

    return enew;
}
Пример #5
0
void solar_system::add_moon (double moon_radius, double orbit_radius,
                             double inclin, double lon_asc, double offset)
{
    double n (k_ * std::sqrt(1.0 / std::pow(orbit_radius, 3)));
    body moon;
    moon.size = moon_radius;
    moon.trajectory = orbit(inclin, lon_asc, orbit_radius, n, offset);

    moons_.push_back(moon);
}
Пример #6
0
void solar_system::add_planet (double planet_radius, double orbit_radius,
                               double inclin, double lon_asc, double offset)
{
    double n (k_ * std::sqrt(1.0 / std::pow(orbit_radius, 3)));
    body planet;
    planet.size = planet_radius;
    planet.trajectory = orbit(inclin, lon_asc, orbit_radius, n, offset);

    planets_.push_back(planet);
}
Пример #7
0
void moon() 
{
	glPushMatrix();
	//glRotatef(-45.0, 0.0, 0.0, 1.0);
	glRotatef(2*time, 0.0, 0.0, 1.0);
	glTranslatef(0.6, 0.0, 0.0); // temporäre werte
	glColor3f(0.5, 0.5, 0.5);
	planet(0.1);
	glPopMatrix();
	
	orbit(0.6, 0.0, 0.0);
}
Пример #8
0
void mars() 
{
	glPushMatrix();
	//glRotatef(-30.0, 0.0, 0.0, 1.0);
	glRotatef(0.5*time, 0.0, 0.0, 1.0);
	glTranslatef(3.0, 0.0, 0.0); // temporäre werte
	glColor3f(1.0, 0.0, 0.0);
	planet(0.2);
	glPopMatrix();

	orbit(3.0, 0.0, 0.0);
}
Пример #9
0
void RegionalTerrain_3r::KillVertexEdge(QuadEdge::Edge *e) {
    QuadEdge::Face *left = e->Left();
    QuadEdge::Face *right = e->Right();
    QuadEdge::Vertex *v = e->Org();

    QuadEdge::VertexEdgeIterator orbit(e->Dest());
    QuadEdge::Edge *eold;
    while ((eold = orbit.next()) != 0) {
        SigPopEdge(eold);
        SigPopFace(eold->Left());
    }
    SigPopVertex(e->Dest());
    terrain_->killVertexEdge(e);

    // we need to pop all faces and edges on the ccw traveral from the left
    // face to the right face in v's orbit. the vertexedgeiterator will begin
    // at a random edge in the orbit, and we have no way of determining whether
    // we are inside or outside the left-to-right range on the first pass
    // through the edges. the iterator will give us the edges back in ccw order
    // however.

    // the strategy is to place all edges in v's orbit into a list and rotate
    // the list so that the leftmost edge to pop is the first element.
    std::list<QuadEdge::Edge*> rotated_orbit;

    // iterate through the orbit and track the leftmost edge insertion index.
    size_t right_idx = 0;
    size_t i = 0;
    QuadEdge::VertexEdgeIterator orbitnew(v);
    QuadEdge::Edge *enew;
    while ((enew = orbitnew.next()) != 0) {
        if (enew->Right() == right) {
            right_idx = i;
        }
        rotated_orbit.push_back(enew);
        ++i;
    }

    // move the left-right range to the beginning of list.
    std::rotate(begin(rotated_orbit),
                std::next(begin(rotated_orbit), right_idx),
                end(rotated_orbit));

    // push faces and edges in left-right range.
    for (auto edge : rotated_orbit) {
        SigPushFace(edge->Right());
        if (edge->Right() == left) {
            break;
        }
        SigPushEdge(edge);
    }
}
Пример #10
0
/////////////////////////////////////////////////////////////////////////////
// Test routine to output position and velocity information
void PrintPosVel(const cTle &tle)
{
   cOrbit       orbit(tle);
   cEci         eci;
   vector<cEci> Pos;

   // Calculate position, velocity
   // mpe = "minutes past epoch"
   for (int mpe = 0; mpe <= (360 * 4); mpe += 360)
   {
      // Get the position of the satellite at time "mpe"
      // The coordinates are placed into the local variable "eci".
      orbit.getPosition(mpe, &eci);
    
      // Push the coordinates object onto the end of the vector.
      Pos.push_back(eci);
   }

   // Print TLE data
   printf("%s\n",   tle.getName().c_str());
   printf("%s\n",   tle.getLine1().c_str());
   printf("%s\n\n", tle.getLine2().c_str());

   // Header
   printf("  TSINCE            X                Y                Z\n\n");

   // Iterate over each of the ECI position objects pushed onto the
   // position vector, above, printing the ECI position information
   // as we go.
   for (unsigned int i = 0; i < Pos.size(); i++)
   {
      printf("%8d.00  %16.8f %16.8f %16.8f\n",
               i * 360,
               Pos[i].getPos().m_x,
               Pos[i].getPos().m_y,
               Pos[i].getPos().m_z);
   }

   printf("\n                    XDOT             YDOT             ZDOT\n\n");

   // Iterate over each of the ECI position objects in the position
   // vector again, but this time print the velocity information.
   for (unsigned int i = 0; i < Pos.size(); i++)
   {
      printf("             %16.8f %16.8f %16.8f\n",
             Pos[i].getVel().m_x,
             Pos[i].getVel().m_y,
             Pos[i].getVel().m_z);
   }
}
Пример #11
0
void earth() 
{
	glPushMatrix();
	//glRotatef(45.0, 0.0, 0.0, 1.0);
	glRotatef(time, 0.0, 0.0, 1.0);
	glTranslatef(1.8, 0.0, 0.0); // temporäre werte
	glColor3f(0.0, 0.0, 1.0);
	planet(0.3);

	moon();
		
	glPopMatrix();

	orbit(1.8, 0.0, 0.0);		
}
Пример #12
0
void simple_isochrone_orbit_for_movie(void){
    IsochronePotential Iso(1000000.,3.64);
    Actions_Spherical AS(&Iso);
    VecDoub X ={2.67519,1.04903,-3.08583,175.546,-216.936,63.3228};
    Orbit orbit(&Iso);
    VecDoub QQ=X;double PPtmp = 0., fac = 0.;
    for(int i=0;i<250;i++){
        QQ=orbit.integrate(QQ, 0.004,0.004);
        VecDoub PP2 = AS.actions(QQ);
        VecDoub PP = AS.angles_and_freqs(QQ);
        if(PP[0]<PPtmp){PPtmp = PP[0];fac+=1.;}
        else PPtmp = PP[0];
        std::cout<<i*0.004<<" "<<QQ[0]<<" "<<QQ[1]<<" "<<PP2[0]<<" "<<PP2[1]<<" "<<PP[0]+fac*2*PI<<" "<<PP[1]<<std::endl;
    }
}
Пример #13
0
//----------------------------------------
void ofEasyCam::begin(ofRectangle rect) {
	//	orbit(ofMap(ofGetMouseX(), 0, ofGetWidth(), 180, -180), ofMap(ofGetMouseY(), 0, ofGetHeight(), 90, -90), orbitRadius, testNodes[targetIndex[1]]);
	
	if(ofGetMousePressed(0)) {
		ofVec2f mousePos(ofGetMouseX(), ofGetMouseY());
		if(oldMousePress) {
			vel -= (mousePos - pmouse) * speed;
		}
		pmouse = mousePos;
	}
	
	pos += vel;
	vel *= (1-drag);

	orbit(pos.x, pos.y, distance, (targetNode ? targetNode->getGlobalPosition() : targetPoint));
	
	
	oldMousePress = ofGetMousePressed(0);
	
	ofCamera::begin(rect);
}
Пример #14
0
void Camera::orbitRight(int scale)
{
   myTurnDir = TR;
   mHeading += mTurnRate*scale;
   orbit(mHeading, pitch());
}
Пример #15
0
void Camera::orbitLeft(int scale) 
{
   myTurnDir = TL;
   mHeading -= mTurnRate*scale;
   orbit(mHeading, pitch());
}
Пример #16
0
static void makemoves(void) {
	int i, hitme;
	char ch;
	while (TRUE) { /* command loop */
		hitme = FALSE;
		justin = 0;
		Time = 0.0;
		i = -1;
		while (TRUE)  { /* get a command */
			chew();
			skip(1);
			proutn("COMMAND> ");
			if (scan() == IHEOL) continue;
			for (i=0; i < 29; i++) // Abbreviations allowed for the first 29 commands, only.
				if (isit(commands[i]))
					break;
			if (i < 29) break;
			for (; i < NUMCOMMANDS; i++)
				if (strcmp(commands[i], citem) == 0) break;
			if (i < NUMCOMMANDS
#ifndef CLOAKING
			    && i != 26 // ignore the CLOAK command
#endif
#ifndef CAPTURE
			    && i != 27 // ignore the CAPTURE command
#endif
#ifndef SCORE
			    && i != 28 // ignore the SCORE command
#endif
#ifndef DEBUG
			    && i != 33 // ignore the DEBUG command
#endif
			   ) break;

			if (skill <= SFAIR)  {
				prout("UNRECOGNIZED COMMAND. LEGAL COMMANDS ARE:");
				listCommands(TRUE);
			}
			else prout("UNRECOGNIZED COMMAND.");
		}
		switch (i) { /* command switch */
			case 0:			// srscan
				srscan(1);
				break;
			case 1:			// lrscan
				lrscan();
				break;
			case 2:			// phasers
				phasers();
                if (ididit) {
#ifdef CLOAKING
                    if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) {
                        prout("The Romulan ship discovers you are breaking the Treaty of Algeron!");
                        ncviol++;
                        isviolreported = TRUE;
                    }
#endif
                    hitme = TRUE;
                }
				break;
			case 3:			// photons
				photon();
                if (ididit) {
#ifdef CLOAKING
                    if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) {
                        prout("The Romulan ship discovers you are breaking the Treaty of Algeron!");
                        ncviol++;
                        isviolreported = TRUE;
                    }
#endif
                    hitme = TRUE;
                }
				break;
			case 4:			// move
				warp(1);
				break;
			case 5:			// shields
				sheild(1);
				if (ididit) {
					attack(2);
					shldchg = 0;
				}
				break;
			case 6:			// dock
				dock();
				break;
			case 7:			// damages
				dreprt();
				break;
			case 8:			// chart
				chart(0);
				break;
			case 9:			// impulse
				impuls();
				break;
			case 10:		// rest
				waiting();
				if (ididit) hitme = TRUE;
				break;
			case 11:		// warp
				setwrp();
				break;
			case 12:		// status
				srscan(3);
				break;
			case 13:			// sensors
				sensor();
				break;
			case 14:			// orbit
				orbit();
				if (ididit) hitme = TRUE;
				break;
			case 15:			// transport "beam"
				beam();
				break;
			case 16:			// mine
				mine();
				if (ididit) hitme = TRUE;
				break;
			case 17:			// crystals
				usecrystals();
				break;
			case 18:			// shuttle
				shuttle();
				if (ididit) hitme = TRUE;
				break;
			case 19:			// Planet list
				preport();
				break;
			case 20:			// Status information
				srscan(2);
				break;
			case 21:			// Game Report 
				report(0);
				break;
			case 22:			// use COMPUTER!
				eta();
				break;
			case 23:
				listCommands(TRUE);
				break;
			case 24:		// Emergency exit
				clearscreen();	// Hide screen
				freeze(TRUE);	// forced save
				exit(1);		// And quick exit
				break;
			case 25:
				probe();		// Launch probe
				break;
#ifdef CLOAKING
			case 26:
				cloak();        // turn on/off cloaking
				if (iscloaking) {
					attack(2); // We will be seen while we cloak
					iscloaking = FALSE;
					iscloaked = TRUE;
				}
				break;
#endif
#ifdef CAPTURE
			case 27:
				capture();      // Attempt to get Klingon ship to surrender
				if (ididit) hitme = TRUE;
				break;
#endif
#ifdef SCORE
			case 28:
				score(1);    // get the score
				break;
#endif
			case 29:			// Abandon Ship
				abandn();
				break;
			case 30:			// Self Destruct
				dstrct();
				break;
			case 31:			// Save Game
				freeze(FALSE);
				if (skill > SGOOD)
					prout("WARNING--Frozen games produce no plaques!");
				break;
			case 32:			// Try a desparation measure
				deathray();
				if (ididit) hitme = TRUE;
				break;
#ifdef DEBUG
			case 33:			// What do we want for debug???
				debugme();
				break;
#endif
			case 34:		// Call for help
				help();
				break;
			case 35:
				alldone = 1;	// quit the game
#ifdef DEBUG
				if (idebug) score(0);
#endif
				break;
			case 36:
				helpme();	// get help
				break;
		}
		for (;;) {
			if (alldone) break;		// Game has ended
#ifdef DEBUG
			if (idebug) prout("2500");
#endif
			if (Time != 0.0) {
				events();
				if (alldone) break;		// Events did us in
			}
			if (d.galaxy[quadx][quady] == 1000) { // Galaxy went Nova!
				atover(0);
				continue;
			}
			if (nenhere == 0) movetho();
			if (hitme && justin==0) {
				attack(2);
				if (alldone) break;
				if (d.galaxy[quadx][quady] == 1000) {	// went NOVA! 
					atover(0);
					hitme = TRUE;
					continue;
				}
			}
			break;
		}
		if (alldone) break;
	}
}
void ZRUser01(float *myState, float *otherState, float time)
{
//BEGIN::PROC::ZRUser
float opulens[3] = {0.0, -0.6, 0.0};
float Laser[3] = {0.4, 0.0, 0.0};
float shield[3] = {0.0, 0.4, 0.0};
float disrupt[3] = {0.0,0.2,0.0};
float zero[3] = {0.0, 0.0, 0.0};
float difference[3];
float facing[3];
float Asteroid[3] = {0.0, -0.6, 0.0};
int recieved;


switch((int)time)
{
    case 0:
        SphereNumber = !!(myState[0] < 0) + 1;
        Station[0] = (SphereNumber == 1) ? 0.6 : -0.6; //station closer to where you started
        break;
    case 30:
        getUp = (otherState[1] <= 0);
        break;
    case 61:
    case 66:
        Spin = PisRevolving(otherState) ? 1 : 0;
        break;
    case 75: if(PinAsteroid(otherState) == 1) asteroid = 1;
}


Laser[0] = ((SphereNumber == 1) - (PotherHasLaser() == SphereNumber)) ? 0.4 : -0.4;

recieved = (int)PgetMessage();
switch(recieved)
{
    case 6:
        if(!(Station[0] < 0.0) && switchedStation++ < 3)
            Station[0] = -0.6;
        break;
    case 7:
        if(!(Station[0] > 0.0) && switchedStation++ < 3)
            Station[0] = 0.6;
        break;
    case 2:
    case 3:
        if(time < 45)
        asteroid = 1;
        break;
    case 4:
    case 5:
        if(time < 45)
        asteroid = 0;
        break;
}


if(time <= 120)
PsendMessage(4 - 2*asteroid + (Spin == 0));
else
PsendMessage((Station[0] < 0) + 6);

Asteroid[1] = asteroid ? -0.6 : 0.6;


switch(state)
{
    case 0:
        ZRSetPositionTarget(Laser);
        shoot(myState, opulens, 0);
        if(PhaveLaser() || PgetPhase() == 2)
            state = 1;
        break;
        
    case 1:
        if(!getUp) {
            shield[1] = .3;
            disrupt[1] = .3;
        }
        ZRSetPositionTarget(disrupt);
        shoot(myState, opulens, 0);
        if(PotherDisruptorUpgraded() || PdisruptorUpgraded())
            state = 2;
        if(PgetPhase() == 2)
            state = 3;
        break;
        
    case 2:
        ZRSetPositionTarget(shield);
        shoot(myState, opulens, 0);
        if(PotherHasShield() || PhaveShield() || PgetPhase() == 2)
            state = 3;
        break;
    case 3:
        if(PiceHits() < 15 && !asteroid)
            shoot(myState, opulens, (PgetPhase() > 1));
        if(!(PiceMelted()) && asteroid)
        {
            mathVecSubtract(difference, myState, opulens, 3);
            if(mathVecMagnitude(difference, 3) > .8)
                ZRSetPositionTarget(opulens);
            else if(!Spin)
                ZRSetVelocityTarget(zero);
            shoot(myState, opulens, (PgetPhase() > 1));
            return;
        }
        if(Spin){
            ZRSetPositionTarget(Asteroid);
            spin(myState);
        }
        else
            orbit(myState, Asteroid, Station[0] == -0.6);
        if((!Spin && (time + timeToMS(myState, Station) >= 165)) || (Spin && (time >= 156)))
            state = 4;
        break;
    default:
        leaveOrbit(myState, Asteroid, Station);
        mathVecSubtract(facing, otherState, myState, 3);
        mathVecNormalize(facing, 3);
        ZRSetAttitudeTarget(facing);
        if (acos(mathVecInner(&myState[6], facing, 3) / mathVecMagnitude(&myState[6], 3)) < (0.1))
            Ptractor();
        break;
}
//END::PROC::ZRUser
}
Пример #18
0
int main() {
  krpc::Client conn = krpc::connect("Sub-orbital flight");
  krpc::services::KRPC krpc(&conn);
  krpc::services::SpaceCenter space_center(&conn);

  auto vessel = space_center.active_vessel();

  vessel.auto_pilot().target_pitch_and_heading(90, 90);
  vessel.auto_pilot().engage();
  vessel.control().set_throttle(1);
  std::this_thread::sleep_for(std::chrono::seconds(1));

  std::cout << "Launch!" << std::endl;
  vessel.control().activate_next_stage();

  typedef krpc::services::KRPC::Expression Expr;

  {
    auto solid_fuel = vessel.resources().amount_call("SolidFuel");
    auto expr = Expr::less_than(
      conn, Expr::call(conn, solid_fuel), Expr::constant_float(conn, 0.1));
    auto event = krpc.add_event(expr);
    event.acquire();
    event.wait();
    event.release();
  }

  std::cout << "Booster separation" << std::endl;
  vessel.control().activate_next_stage();

  {
    auto mean_altitude = vessel.flight().mean_altitude_call();
    auto expr = Expr::greater_than(
      conn, Expr::call(conn, mean_altitude), Expr::constant_double(conn, 10000));
    auto event = krpc.add_event(expr);
    event.acquire();
    event.wait();
    event.release();
  }

  std::cout << "Gravity turn" << std::endl;
  vessel.auto_pilot().target_pitch_and_heading(60, 90);

  {
    auto apoapsis_altitude = vessel.orbit().apoapsis_altitude_call();
    auto expr = Expr::greater_than(
      conn, Expr::call(conn, apoapsis_altitude), Expr::constant_double(conn, 100000));
    auto event = krpc.add_event(expr);
    event.acquire();
    event.wait();
    event.release();
  }

  std::cout << "Launch stage separation" << std::endl;
  vessel.control().set_throttle(0);
  std::this_thread::sleep_for(std::chrono::seconds(1));
  vessel.control().activate_next_stage();
  vessel.auto_pilot().disengage();

  {
    auto srf_altitude = vessel.flight().surface_altitude_call();
    auto expr = Expr::less_than(
      conn, Expr::call(conn, srf_altitude), Expr::constant_double(conn, 1000));
    auto event = krpc.add_event(expr);
    event.acquire();
    event.wait();
    event.release();
  }

  vessel.control().activate_next_stage();

  while (vessel.flight(vessel.orbit().body().reference_frame()).vertical_speed() < -0.1) {
    std::cout << "Altitude = " << vessel.flight().surface_altitude() << " meters" << std::endl;
    std::this_thread::sleep_for(std::chrono::seconds(1));
  }
  std::cout << "Landed!" << std::endl;
}
Пример #19
0
int do_repair()
{
/* Repair if necessary (we are safe) */

    struct planet* l;
    int dx, dy;
    int dist;

    l = get_nearest_planet();
    dx = abs(me->p_x - l->pl_x);
    dy = abs(me->p_y - l->pl_y);

    if (me->p_damage > 0 || me->p_fuel < 2000) {
	if (me->p_war & l->pl_owner) {
	    if (l->pl_armies > 0) {
		if ((dx < PFIREDIST) && (dy < PFIREDIST)) {
		    if (debug)
			ERROR(1,( "%d) on top of hostile planet (%s)\n", me->p_no, l->pl_name));
		    return 0;	/* can't repair on top of hostile planets */
		}
		if ((int) (hypot((double) dx, (double) dy)) < PFIREDIST) {
		    if (debug)
		        ERROR(1,("%d) on top of hostile planet (%s)\n", 
				me->p_no, l->pl_name));
		    return 0;
		}
	    } 
	    me->p_desspeed = 0;
	}
	else { /* if friendly */
	    if ((l->pl_flags & PLREPAIR) &&
		!(me->p_flags & PFORBIT)) { /* oh, repair! */
		dist = (hypot((double) dx, (double) dy));

		if (debug)
		    ERROR(1,( "%d) locking on to planet %d\n",
			    me->p_no, l->pl_no));
		if (! cloaker) cloak_off();
		shield_down();
		me->p_desdir = getcourse(l->pl_x, l->pl_y);
		lock_planet(l->pl_no);
		me->p_desspeed = 4;
		if (dist-(ORBDIST/2) < (11500 * me->p_speed * me->p_speed) /
		    me->p_ship.s_decint) {
		    if (me->p_desspeed > 2) {
			set_speed(2);
		    }
		}

		if ((dist < ENTORBDIST) && (me->p_speed <= 2))  {
		    me->p_flags &= ~PFPLLOCK;
		    orbit();
		}
		return 1;
	    }
	    else {			/* not repair, so ignore it */
		me->p_desspeed = 0;
	    }
	}
	shield_down();
	if (me->p_speed == 0)
	    repair();
	if (debug)
	    ERROR(1,( "%d) repairing damage at %d\n",
		me->p_no,
		me->p_damage));
	return 1;
    }
    else {
	return 0;
    }
}
Пример #20
0
void ACamera::orbitRight(float scale)
{
   mTurnDir = TR;
   mHeading -= mTurnRate*scale;
   orbit(mHeading, pitch());
}
Пример #21
0
void Camera::orbitUp(int scale)
{
   myTurnDir = TU; 
   mPitch = min(BasicMath::PI/2.0-0.01, mPitch + mTurnRate*scale);
   orbit(heading(), mPitch);
}
Пример #22
0
void ACamera::orbitUp(float scale)
{
   mTurnDir = TU; 
   mPitch = std::min<float>(-0.1, mPitch + mTurnRate*scale);
   orbit(heading(), mPitch);
}
Пример #23
0
int main(int argc,char *argv[])
{
  int arg=0,satno=0,header=0,oneline=0,no,name=0,desig=0;
  char tlefile[LIM];
  char line0[LIM],line1[LIM],line2[LIM],nfd[32];
  FILE *file;
  orbit_t orb;
  float aodp,perigee,apogee,period;
  int info=0;
  double mjd;
  char *env;

  env=getenv("ST_TLEDIR");
  sprintf(tlefile,"%s/bulk.tle",env);

  // Decode options
  while ((arg=getopt(argc,argv,"c:i:aH1ftnd"))!=-1) {
    switch (arg) {
      
    case 'c':
      strcpy(tlefile,optarg);
      break;

    case '1':
      oneline=1;
      break;

    case 'f':
      oneline=2;
      break;

    case 'n':
      name=1;
      break;

    case 'd':
      desig=1;
      break;

    case 'i':
      satno=atoi(optarg);
      break;

    case 'a':
      info=1;
      break;

    case 'H':
      header=1;
      break;

    case 'h':
      usage();
      return 0;
      break;

    default:
      usage();
      return 0;
    }
  }

  if (oneline==0) {
    // Open file
    file=fopen(tlefile,"rb");
    if (file==NULL) 
      fatal_error("File open failed for reading \"%s\"",tlefile);

    while (fgetline(file,line1,LIM)>0) {
      // Find TLE line
      if (line1[0]=='1') {
	fgetline(file,line2,LIM);
	sscanf(line1+2,"%d",&no);
	if (satno==0 || satno==no) {
	  if (name==1 && desig==0) 
	    printf("%s\n",line0);
	  else if (name==0 && desig==1)
	    printf("%.8s\n",line1+9);
	  else
	    printf("%s\n%s\n%s\n",line0,line1,line2);
	}
      }
      strcpy(line0,line1);
    }

    /*
    // Loop over file
    while (fgetline(file,line0,LIM)>0) {
      // Read data lines
      if (line0[0]!='1' || line0[0]!='2') {
	fgetline(file,line1,LIM);
	fgetline(file,line2,LIM);
	sscanf(line1+2,"%d",&no);

	if (satno==0 || satno==no) {
	  if (name==1 && desig==0) 
	    printf("%s\n",line0);
	  else if (name==0 && desig==1)
	    printf("%.8s\n",line1+9);
	  else
	    printf("%s\n%s\n%s\n",line0,line1,line2);
	}
      } else if (line0[0]=='1') {
	fgetline(file,line2,LIM);
	sscanf(line1+2,"%d",&no);

	if (satno==0 || satno==no)
	  printf("%s\n%s\n",line0,line2);
      }
    }
    */
    fclose(file);
  } else if (oneline==1) {
    // Open file
    file=fopen(tlefile,"rb");
    if (file==NULL) 
      fatal_error("File open failed for reading \"%s\"",tlefile);
    
    if (info==0 && header==1)
      printf("SATNO YEAR DOY     INCL    ASCN     ARGP     MA       ECC      MM\n");
    if (info==1 && header==1)
      printf("SATNO SEMI     PERIGEE  APOGEE    PERIOD  ECC\n");
    
    // Loop over file
    while (read_twoline(file,satno,&orb)==0) {
      orbit(orb,&aodp,&perigee,&apogee,&period);
      mjd=doy2mjd(orb.ep_year,orb.ep_day);
      mjd2nfd(mjd,nfd);
      if (info==0) printf("%05d %10.4lf %8.4f %8.4f %8.4f %8.4f %8.6f %8.5f\n",orb.satno,mjd,DEG(orb.eqinc),DEG(orb.ascn),DEG(orb.argp),DEG(orb.mnan),orb.ecc,orb.rev);
      if (info==1) printf("%05d %6.0f x %6.0f x %6.2f %8.2f %8.6f %14.8lf\n",orb.satno,perigee,apogee,DEG(orb.eqinc),period,orb.ecc,mjd);
    }
    fclose(file);
  } else if (oneline==2) {
    // Open file
    file=fopen(tlefile,"rb");
    if (file==NULL) 
      fatal_error("File open failed for reading \"%s\"",tlefile);
    
    if (info==0 && header==1)
      printf("SATNO YEAR DOY     INCL    ASCN     ARGP     MA       ECC      MM\n");
    if (info==1 && header==1)
      printf("SATNO SEMI     PERIGEE  APOGEE    PERIOD  ECC\n");
    
    // Loop over file
    while (read_twoline(file,satno,&orb)==0) 
      print_orb(&orb);
    fclose(file);
  }

  return 0;
}
Пример #24
0
void ACamera::orbitDown(float scale)
{
   mTurnDir = TD; 
   mPitch = std::max<float>(-M_PI / 2.0 + 0.01, mPitch - mTurnRate*scale);
   orbit(heading(), mPitch);
}
Пример #25
0
int main(int argc,char *argv[])
{
  orbit_t orb;
  float aodp,perigee,apogee,period,dt=0.0;
  char line1[70],line2[70];
  int arg=0;
  double mjd,dh;

  // Initialize
  orb.satno=99999;
  orb.eqinc=0.0;
  orb.ascn=0.0;
  orb.argp=0.0;
  orb.mnan=0.0;
  orb.bstar=0.5e-4;
  orb.ep_day=1.000;
  orb.ep_year=2013;

  // Decode options
  while ((arg=getopt(argc,argv,"q:Q:i:I:w:t:m:n:hd:"))!=-1) {
    switch(arg) {
    case 'q':
      perigee=atof(optarg);
      break;

    case 'Q':
      apogee=atof(optarg);
      break;

    case 'I':
      orb.eqinc=atof(optarg)*D2R;
      break;

    case 'n':
      orb.ascn=atof(optarg)*D2R;
      break;

    case 'i':
      orb.satno=atoi(optarg);
      break;

    case 'w':
      orb.argp=atof(optarg)*D2R;
      break;

    case 'm':
      orb.mnan=atof(optarg)*D2R;
      break;

    case 't':
      mjd=nfd2mjd(optarg);
      break;

    case 'd':
      dt=atof(optarg);
      break;

    case 'h':
      usage();
      return 0;

    default:
      usage();
      return 0;
    }
  }

  orb.ep_day=mjd2doy(mjd+dt/86400.0,&orb.ep_year);

  perigee+=XKMPER;
  apogee+=XKMPER;
  aodp=0.5*(perigee+apogee)/XKMPER;
  orb.ecc=0.5*(apogee-perigee)/(aodp*XKMPER);
  orb.rev=XKE*pow(aodp,-1.5)*XMNPDA/(2.0*M_PI);
  if (orb.rev<10)
    orb.bstar=0.0;
  orbit(orb,&aodp,&perigee,&apogee,&period);

  format_tle(orb,line1,line2);
  printf("%s\n%s\n",line1,line2);

  return 0;
}
void ZRUser01(float *myState, float *otherState, float time)
{
//BEGIN::PROC::ZRUser
float opulens[3] = {0.0, -0.6, 0.0};
float Laser[3] = {0.4, 0.0, 0.0};
float shield[3] = {0.0, 0.4, 0.0};
float zero[3] = {0.0, 0.0, 0.0};
float difference[3];
float Asteroid[3] = {0.0, -0.6, 0.0};
float Station[3] = {0.0, 0.0, 0.0};


switch((int)time)
{
    case 0:
        SphereNumber = !!(myState[0] < 0) + 1;
        break;
    case 30:
        getShield = (otherState[1] <= 0);
        break;
    case 61:
        asteroid = (PinAsteroid(otherState) == 1) ? 1 : 0;
        break;
    case 90:
        asteroid = (PisRevolving(otherState) == 2 && !asteroid) ? 1 : asteroid;
        break;
}


Station[0] = (SphereNumber == 1) ? 0.6 : -0.6; //station closer to where you started
Asteroid[1] = asteroid ? -0.6 : 0.6;
Laser[0] = ((SphereNumber == 1) - (PotherHasLaser() == SphereNumber)) ? 0.4 : -0.4;


switch(state)
{
    case 0:
        ZRSetPositionTarget(Laser);
        shoot(myState, opulens, 0);
        if(PhaveLaser() || PgetPhase() == 2)
            state = 1;
        break;
        
    case 1:
        if(!getShield)
            shield[1] = .3;
        ZRSetPositionTarget(shield);
        shoot(myState, opulens, 0);
        if(PotherHasShield() || PhaveShield() || PgetPhase() == 2)
            state = 2;
        break;
        
    case 2:
        if(PiceHits() < 14 && !asteroid)
            shoot(myState, opulens, (PgetPhase() > 1));
        if(!(PiceMelted()) && asteroid)
        {
            mathVecSubtract(difference, myState, opulens, 3);
            if(mathVecMagnitude(difference, 3) > .8)
                ZRSetPositionTarget(opulens);
            else
                ZRSetVelocityTarget(zero);
            shoot(myState, opulens, (PgetPhase() > 1));
            return;
        }
        orbit(myState, Asteroid, Station[0] == -0.6);
        if(time + timeToMS(myState, Station) >= 165)
            state = 3;
        break;
        
    default:
        ZRSetPositionTarget(Station);
        break;
}
//END::PROC::ZRUser
}
Пример #27
0
void Camera::orbitDown(int scale)
{
   myTurnDir = TD; 
   mPitch = max(-BasicMath::PI/2.0+0.01, mPitch - mTurnRate*scale);
   orbit(heading(), mPitch);
}
Пример #28
0
void Camera::orbitUp(int scale)
{
   myTurnDir = TU; 
   mPitch = min(-0.1, mPitch + mTurnRate*scale);
   orbit(heading(), mPitch);
}
Пример #29
0
//----------------------------------------
void ofNode::orbit(float longitude, float latitude, float radius, ofNode& centerNode) {
    orbit(longitude, latitude, radius, centerNode.getGlobalPosition());
}
Пример #30
0
Orbit Orbit::NextOrbit()
{
    double d = ((double)(rand() % 1000) / 1000.0)+0.35;
    Orbit orbit(this->_distance*d);
    return orbit;
}