Exemplo n.º 1
0
	void Camera::update()
	{
		float delta = 0.01f * _eye.z;
		//
		if (::GetAsyncKeyState('W') & 0x8000f)
		{
			walk(4.0f * delta);
		}
		if (::GetAsyncKeyState('S') & 0x8000f)
		{
			walk(-4.0f * delta);
		}
		if (::GetAsyncKeyState('A') & 0x8000f)
		{
			strafe(-4.0f * delta);
		}
		if (::GetAsyncKeyState('D') & 0x8000f)
		{
			strafe(4.0f * delta);
		}
		if (::GetAsyncKeyState('R') & 0x8000f)
		{
			fly(4.0f * delta);
		}
		if (::GetAsyncKeyState('F') & 0x8000f)
		{
			fly(-4.0f * delta);
		}
// 		if (::GetAsyncKeyState(VK_LBUTTON) & 0x8000f)
// 		{
// 			yaw(-4.0f * delta);
// 		}
	}
Exemplo n.º 2
0
void Ship::flyTo(float& dt, Planet& p)
{

		if (getX() < p.getX())
		{
			fly(dt, L"prawo", 7000);
			//focus(p);
		}
		else if (getX() > p.getX())
		{
			fly(dt, L"lewo", 7000);
			//focus(p);
		}
		else if (getY() > p.getY())
		{
			fly(dt, L"gór", 7000);
			//focus(p);
		}
		else if (getY() < p.getY())
		{
			fly(dt, L"dół", 7000);
			//focus(p);
		}
	
}
Exemplo n.º 3
0
void moveships(void)
{
   register int n,i,p;
   int target;

   target = goodbogey(0);
   if (target != 0)
      for (n=0; amtable[n] < MAXSHIPS; n++)
         if (amtable[n] != player)
            shiplist[amtable[n]].course = intercept(amtable[n], target -1);
   target = goodbogey(JAPANESE);
   if (target != 0)
      for (n=0; japtable[n] < MAXSHIPS; n++)
         if (japtable[n] != player)
            shiplist[japtable[n]].course = intercept(japtable[n], target -1);
   for (n=0; n < MAXSHIPS; n++) {
      firedflack[n] = 0;
      firedguns[n] = 0;
      if (shiplist[n].torps && shiplist[n].hits && n != player && n != MIDWAY)
         drdc((shiplist[n].course = shiplist[shiplist[n].flagship].course), &shiplist[n].row, &shiplist[n].col);
   }
   if (player != MIDWAY)
      drdc(shiplist[player].course, &shiplist[player].row, &shiplist[player].col);
   if (automatic >= 0)
	   plotships();

   for (n=0; amtable[n] < MAXSHIPS; n++) {
      if (shiplist[amtable[n]].hits && shiplist[amtable[n]].torps) {
         for (i = 0; japtable[i] < MAXSHIPS; i++) {
            if (shiplist[japtable[i]].hits && shiplist[japtable[i]].torps) {
               if (range(shiplist[amtable[n]].row, shiplist[amtable[n]].col, shiplist[japtable[i]].row, shiplist[japtable[i]].col) < 25) {   /* within sight */
                  for (p=japtable[i]; p < MAXSHIPS && shiplist[p].flagship == japtable[i]; p++)
                     if (p != player)
                        fireguns(p, amtable[n]);
                  for (p=amtable[n]; p < MAXSHIPS && shiplist[p].flagship == amtable[n]; p++)
                     if (p != player)
                        fireguns(p, japtable[i]);
                  newbogey(japtable[i]);
                  newbogey(amtable[n]);
               }
            }
         }
      }
   }
   fly(american,0,1);
   fly(japanese,0,0);
   fly(amscouts,1,1);
   fly(japscouts,1,0);
   if (automatic >= 0)
	   plotplanes();
   steer(american,0,1);
   steer(japanese,0,0);
   steer(amscouts,1,1);
   steer(japscouts,1,0);
}
Exemplo n.º 4
0
Arquivo: main.cpp Projeto: CCJY/coliru
int main()
{
   
   std::cout << "Hello World" << std::endl; 
   fly(10);
   return 0;
}
Exemplo n.º 5
0
Arquivo: Hive.cpp Projeto: enree/flyZ
void Hive::addFly(int stupidity)
{
    if (m_flies.size() >= m_size * m_size * m_capacity)
    {
        QMessageBox::warning(NULL, "Sorry!", "Too many flies");
        return;
    }
    int placeOfBirth(rand() % (m_size * m_size));
    {
        QMutexLocker locker(&m_mutex);
        while (isCapacityExceed(placeOfBirth))
        {
            ++placeOfBirth;
            placeOfBirth %= (m_size * m_size);
        }
    }

    Fly* fly(new Fly(placeOfBirth, stupidity, this));
    m_flies.append(fly);

    increaseFliesCount(fly->position());

    connect(fly, SIGNAL(positionChanged(int,int)),
            this, SLOT(positionChanged(int,int)), Qt::QueuedConnection);
    connect(fly, SIGNAL(died(int)), this, SLOT(onDied(int)), Qt::QueuedConnection);

    m_futureFlies.append(QtConcurrent::run(fly, &Fly::live));
}
Exemplo n.º 6
0
int main( )
{
	struct airport a ;
	int i, pri, curtime, endtime ;
	double expectarrive, expectdepart ;
	struct plane temp ;

  system ( "cls" ) ;

    initairport ( &a );

	start ( &endtime, &expectarrive, &expectdepart ) ;

	for ( curtime = 1 ; curtime <= endtime ; curtime++ )
	{
		pri = randomnumber ( expectarrive ) ;

		for ( i = 1 ; i <= pri ; i++ )
		{
			newplane ( &a, curtime, ARRIVE ) ;
			if ( apfull ( a, 'l' ) )
				 refuse ( &a, ARRIVE ) ;
			else
				apaddqueue( &a, 'l' ) ;
		}

		pri = randomnumber ( expectdepart ) ;
		for ( i = 1 ; i <= pri ; i++ )
		{
			newplane ( &a, curtime, DEPART ) ;
			if ( apfull ( a, 't' ) )
			   refuse ( &a, DEPART ) ;
			else
			   apaddqueue ( &a, 't' ) ;
		}

		if (  ! ( apempty ( a, 'l' ) ) )
		{
			temp = apdelqueue ( &a, 'l' ) ;
			land ( &a, temp, curtime ) ;
		}
		else
		{
			if ( ! ( apempty ( a, 't' ) ) )
			{
				temp = apdelqueue ( &a, 't' ) ;
				fly ( &a, temp, curtime ) ;
			}
			else
				idle ( &a, curtime ) ;
		}
	}

	conclude ( &a, endtime ) ;

    return 0 ;
}
Exemplo n.º 7
0
task usercontrol()
{
	// Set the motors initially
	currentPreset = 0;
	fly(currentPreset);

	while(true)
	{
		// Flywheel Speed
		if(vexRT(Btn8U))
			currentPreset = 0;
		else if (vexRT(Btn8R))
			currentPreset = 1;
		else if (vexRT(Btn8D))
			currentPreset = 2;
		else if (vexRT(Btn8L))
			currentPreset = 3;

		// Set the flywheel speed
		fly(currentPreset);

		// Fit the input to an exponential curve
		// Squares are always positive, so a ternary operator is needed for negative numbers
		// The abs is just in case we decide to go with odd exponents or even roots (like 3/2)
		// We devide by 128 because the program can theoretically reach -128
		int verticalL = pow(abs(vexRT(Ch3))/128.0,2.7)*127.0 *((vexRT(Ch3)>0)?(1):(-1));
		int verticalR = pow(abs(vexRT(Ch2))/128.0,2.7)*127.0 *((vexRT(Ch2)>0)?(1):(-1));

		// Move Robot
		motor[LRW] = verticalL;
		motor[LFW] = motor[LRW];
		motor[RRW] = verticalR;
		motor[RFW] = motor[RRW];

		//Feeder control
		if(vexRT(Btn6U))
			motor[I1] = 127;
		else if(vexRT(Btn5U))
			motor[I1] = -127;
		else
	 	   motor[I1] = 0;
		motor[I2] = motor[I1];
	}
}
Exemplo n.º 8
0
int main(void)
{
    int i;
    init_genrand(time(NULL));
    printf("MT init complete...\n");
    for(i=0;i<N;i++)
    {
    	fly(0,rnd());
    	printf("Neutron#%i completed...\n",i);
	}
	printf("==Result: N+=%10lu N-=%10lu N0=%10lu\n",Np,Nm,N0);
	printf("==Result: W+=%10.2f W-=%10.2f W0=%10.2f\n",(float)Np/N,(float)Nm/N,(float)N0/N);
    return 0;
}
Exemplo n.º 9
0
Bird::Bird(QWidget *parent)
    : QWidget(parent)
{
    setMaximumSize(35,35);
    setMinimumSize(35,35);
    co=0;
    timer=new QTimer(this);
    src[0]=":/Images/bird1.png";
    src[1]=":/Images/bird2.png";
    src[2]=":/Images/bird3.png";
    this->rale=-31;
    connect(timer,SIGNAL(timeout()),this,SLOT(update()));
    connect(this,SIGNAL(fly()),this,SLOT(updateRale()));
    timer->start(200);

}
Exemplo n.º 10
0
//------------------------------------------------------
void ttBirds::update(){
    
   
    
    switch (condition) {
        case BIRD_FLY:{
            
            
            bird.body->ApplyForce(bird.body->GetMass() * -world->getWorld()->GetGravity(), bird.body->GetWorldCenter());
            fly();

            spriteRenderer->clear();
            spriteRenderer->update(ofGetElapsedTimeMillis());
            sprites[0]->animation.loops = -1;
            sprites[0]->animation.frame_duration  = 75;
            sprites[0]->animation.frame_duration /= ofClamp(fabs(bird.getVelocity().x), 1, 3);
            spriteRenderer->addCenteredTile(&sprites[0]->animation, sprites[0]->pos.x, sprites[0]->pos.y);
            killZone.setFromCenter(bird.getPosition(),50, 50);
        }
            break;
            
        case BIRD_ATTACK:{
            bird.setVelocity(0, 0);
            spriteRenderer->clear();
            spriteRenderer->update(ofGetElapsedTimeMillis());
            if (sprites[0]->animation.loops == -1) {
                sprites[0]->animation.loops = 2;
            }
            
            if(sprites[0]->animation.loops == 0){
                condition = BIRD_FLY;
            }
            spriteRenderer->addCenteredTile(&sprites[0]->animation, sprites[0]->pos.x, sprites[0]->pos.y);
            killZone.setFromCenter(bird.getPosition(), 0, 0);
            
        }
            break;
            
        case BIRD_DEAD:{
            
        }break;
    }
    
    getPos = bird.getPosition();
}
Exemplo n.º 11
0
int main()
{
    int t;
    scanf("%d", &t);
    while (t--) {
        int ans = INF, begin,end;
        scanf("%d %d %d %d",&a[1],&a[2],&a[3],&up);
        scanf("%d %d %d %d",&a[4],&a[5],&a[6],&down);
        scanf("%d %d %d",&a[7],&a[8],&a[9]);
        scanf("%d %d",&a[10],&a[0]);
        scanf("%d %d",&begin,&end);

        for(int i = 0 ; i <= 99 ; i++)
        {
            ans = min(ans , fly(begin,i) + walk(i, end));
        }
        printf("%d\n", ans == INF ? 0:ans);
    }
}
Exemplo n.º 12
0
void *run_airplane(void *parameters)
{
    thread_args_t *args;
    int airplane_id;

    args = (thread_args_t *) parameters;
    airplane_id = args->airplane_id;

    while(1) {
        request_landing(airplane_id);
        land(airplane_id);
        stop(airplane_id);
        request_start(airplane_id);
        start(airplane_id);
        fly(airplane_id);
    }

    return NULL;
}
Exemplo n.º 13
0
	void Munition::update(unsigned long elapsed_millis) {
	
		if( isActive ){
			
			fly();
			double elapsed_seconds = elapsed_millis / (double)1000;
			_physics.step( elapsed_seconds);
			actualizeTimer( elapsed_seconds );
			
			if ( isEndTimer() ) {

				endTimer();

			}
		
		}
		else {

			// the ball is inactive so don't update 

		}
	}
Exemplo n.º 14
0
void Steven::update( float delta )
{
	//keep speed 
	b2Body* body = getB2Body();
	b2Vec2 v = body->GetLinearVelocity();
	b2Vec2 impulse = skiSpeed(v);
	impulse *= body->GetMass();
	//b2Vec2 impulse = b2Vec2( (10 - v.x)*body->GetMass(), 0);
	body->ApplyLinearImpulse(impulse, body->GetWorldCenter());

	////compute distance to hill
	b2Vec2 rayStart = this->m_pB2Body->GetWorldCenter();
	b2Vec2 rayEnd = b2Vec2(rayStart.x, rayStart.y - 100);
	class RayCastCallback : public b2RayCastCallback
	{
		virtual float32 ReportFixture(b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction)
		{
			CCString* name = b2Helper::getBodyName(fixture->GetBody());
			if (name->compare("hill") == 0)
			{
				Steven* steven = Steven::sharedSteven();
				steven->mSkiHigh = (steven->m_pB2Body->GetWorldCenter().y - point.y) * G.PTM_RATIO - mRadius;
				return 0;
			}
			return 1;
		}
	} callback;
	G.world->RayCast(&callback,rayStart, rayEnd);

	//auto rotation in sky
	if (flying())
	{
		rotationBy(-30 * delta);
	}
	if (flying() && mStatus == StevenStatus::SS_Ski)
	{
		fly();
	}
}
Exemplo n.º 15
0
task main()
{
    while(true)
    {
        if(VexRT(Btn5U)) {
            leftTurn(1);
            wait10Msec(100);
        }
        if(VexRT(Btn6U)) {
            rightTurn(1);
            wait10Msec(100);
        }
        if(VexRT(Btn8U)) {
            move(2);
            wait10Msec(100);
        }
        if(VexRT(Btn8D)) {
            move(-2);
            wait10Msec(100);
        }

        if(VexRT(Btn7U)) {
            rightTurn(360);
        }


        if(vexRT(Btn8R)) {
            rightTurn(2);
            move(20);
            leftTurn(10);
            move(30);
            intake(true);
            fly(3);
            wait10Msec(1000);
            rest();
        }
    }
}
Exemplo n.º 16
0
/*! The viewer will be parented on the specified widget, 
  but with a Qt::Window flag to make it a top-level window
 */
TriangleMeshViewer::TriangleMeshViewer(QWidget* parent,const ParametersRender* param,const std::vector<const TriangleMesh*>& mesh,bool verbose)
  :QWidget(parent,Qt::Window)
  ,_verbose(verbose)
  ,parameters(param)
  ,camera_position(0.0f,-3.0f,0.0f)
  ,camera_forward(0.0f,1.0f,0.0f)
  ,camera_up(0.0f,0.0f,1.0f)
  ,camera_velocity(0.0f)
  ,camera_yaw_rate(0.0f)
  ,camera_pitch_rate(0.0f)
  ,camera_roll_rate(0.0f)
  ,object_tilt(30.0f*M_PI/180.0f)
  ,object_rotation(0.0f)
  ,object_spinrate(0.0f)
  ,keypressed_arrow_left(false)
  ,keypressed_arrow_right(false)
  ,keypressed_arrow_up(false)
  ,keypressed_arrow_down(false)
  ,keypressed_mouse_left(false)
  ,keypressed_mouse_right(false)
  ,fly_mode(false)
{
  QGridLayout*const grid=new QGridLayout();
  setLayout(grid);
  grid->setRowStretch(0,1);
  grid->setColumnStretch(0,1);

  //! \todo Is there any good reason not to enable multisampling by default ?
  QGLFormat gl_format;
  gl_format.setSampleBuffers(true);

  display=new TriangleMeshViewerDisplay(this,gl_format,param,mesh,_verbose);
  grid->addWidget(display,0,0);

  tilt_box=new QGroupBox("Tilt");
  tilt_box->setLayout(new QVBoxLayout());
  tilt_box->layout()->setAlignment(Qt::AlignCenter);
  tilt_slider=new QSlider(Qt::Vertical);
  tilt_box->layout()->addWidget(tilt_slider);
  tilt_slider->setRange(-80,80);
  tilt_slider->setSingleStep(10);
  tilt_slider->setValue(30);
  tilt_slider->setTickInterval(10);
  tilt_slider->setTickPosition(QSlider::TicksBothSides);
  tilt_slider->setTracking(true);
  grid->addWidget(tilt_box,0,1);

  spinrate_box=new QGroupBox("Spin Rate");
  spinrate_box->setLayout(new QHBoxLayout());
  spinrate_box->layout()->setAlignment(Qt::AlignCenter);
  spinrate_slider=new QSlider(Qt::Horizontal);
  spinrate_box->layout()->addWidget(spinrate_slider);
  spinrate_slider->setRange(-80,80);
  spinrate_slider->setSingleStep(10);
  spinrate_slider->setValue(0);
  spinrate_slider->setTickInterval(10);
  spinrate_slider->setTickPosition(QSlider::TicksBothSides);
  spinrate_slider->setTracking(true);
  grid->addWidget(spinrate_box,1,0);
  
  button_box=new QWidget();
  button_box->setLayout(new QVBoxLayout());
  grid->addWidget(button_box,1,1);

  QPushButton*const fly_button=new QPushButton("Fly");
  button_box->layout()->addWidget(fly_button);
  fly_button->setToolTip("While flying:\nEsc will return to normal view.\nMouse controls pitch and yaw.\nLeft and right mouse buttons (or left/right arrow keys) control roll.\nMouse wheel (or up/down arrow keys) control speed.");

  QPushButton*const reset_button=new QPushButton("Reset");
  button_box->layout()->addWidget(reset_button);
  reset_button->setToolTip("Press to restore initial default orientation.");

  statusbar=new QStatusBar();
  grid->addWidget(statusbar,2,0,1,2);

  //Calling setFocus() when switching to fly mode seems to avoid need for this, but do it anyway.
  tilt_slider->setFocusPolicy(Qt::NoFocus);
  spinrate_slider->setFocusPolicy(Qt::NoFocus);

  connect(
	  tilt_slider,SIGNAL(valueChanged(int)),
	  this,SLOT(set_tilt(int))
	  );
  connect(
	  spinrate_slider,SIGNAL(valueChanged(int)),
	  this,SLOT(set_spinrate(int))
	  );
  connect(
	  fly_button,SIGNAL(clicked()),
	  this,SLOT(fly())
	  );
  connect(
	  reset_button,SIGNAL(clicked()),
	  this,SLOT(reset())
	  );

  clock.reset(new QTime());
  clock->start();
  last_t=0;

  QTimer*const timer=new QTimer(this);  
  connect(timer,SIGNAL(timeout()),this,SLOT(tick()));
  timer->start(static_cast<int>(ceil(1000.0f/parameters->fps_target)));
  
  setMouseTracking(true);  // To get moves regardless of button state
  display->setMouseTracking(true);
  setFocus();
}
Exemplo n.º 17
0
 void Budgie::move()const{
   fly();
 }
Exemplo n.º 18
0
void rest()//all motors on robot stop
{
    freeze();
    fly(0);
    intake(false);
}
Exemplo n.º 19
0
void FloatingCamera::simulateSelf(GLdouble deltaTime)
{

    double pyrSpd = -5;
    double pyrRot = 3;
    Matrix4D newTransform = Matrix4D::createIdentity();

    //Create movement vector
    Vector3f dVec = {0,0,0};
    double dYaw = 0.0;
    double dPitch = 0.0;
    double dRoll = 0.0;

    if(mApp->gMoveForward)
    {
        dVec.z = -pyrSpd*deltaTime;
    }
    else if(mApp->gMoveBackward)
    {
        dVec.z = pyrSpd*deltaTime;
    }

    if(mApp->gMoveLeft)
    {
        dVec.x = -pyrSpd*deltaTime;
    }
    else if(mApp->gMoveRight)
    {
        dVec.x = pyrSpd*deltaTime;
    }

    if(mApp->gMoveUp)
    {
        dVec.y = pyrSpd*deltaTime;
    }
    else if(mApp->gMoveDown)
    {
        dVec.y = -pyrSpd*deltaTime;
    }

   if(mApp->gYawLeft)
    {
        dYaw = pyrRot*deltaTime;
    }
    else if(mApp->gYawRight)
    {
        dYaw = -pyrRot*deltaTime;
    }

    if(mApp->gPitchUp)
    {
        dPitch = pyrRot*deltaTime;
    }
    else if(mApp->gPitchDown)
    {
        dPitch = -pyrRot*deltaTime;
    }

    if(mApp->gRollLeft)
    {
        dRoll = pyrRot*deltaTime;
    }
    else if(mApp->gRollRight)
    {
        dRoll = -pyrRot*deltaTime;
    }

    if(mRechargeTime > 0)
    {
        mRechargeTime -= deltaTime;
    }

    if(mApp->gShoot)
    {
        if(mRechargeTime < 0)
        {
            //Shoot
             MatterNodePtr matterNode(new MatterNode(mApp, VP_RENDER_GEOMETRY, mApp->gBulletMaterial, false, mApp->gBulletFile.c_str()));
            // matterNode->setOffset(0.0f, 0.0f, 0.0f);
            matterNode->setTransform(getCameraMatrix().inverted());
            Vector3f force = mForward * mApp->gBulletForce;
            matterNode->setInitialForce(force);
            mApp->getSceneGraph()->getRoot()->addChild(matterNode);

            mRechargeTime = RECHARGE_TIME;
        }
    }

    yaw(dYaw);
    pitch(dPitch);
    roll(dRoll);

    walk(dVec.z);
    fly(dVec.y);
    strafe(dVec.x);
}
Exemplo n.º 20
0
void FlyingCreature::attack(Creature& other){
	fly();
	dealDamage(other);
	stopFly();

}
Exemplo n.º 21
0
int main()
{
    int fbfd = 0;
    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;
    long int screensize = 0;
    char *fbp = 0;
    int x = 0, y = 0;
    long int location = 0;

    #define background_red 235
    #define background_green 138
    #define background_blue 163

    void makeBackground(){
        for (y = 0; y < 236; y++)//maks 236
            for (x = 0; x < 800; x++) {//maks 800

                location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
                           (y+vinfo.yoffset) * finfo.line_length;

                if (vinfo.bits_per_pixel == 32) { // color information
                    *(fbp + location) = background_blue;        // blue
                    *(fbp + location + 1) = background_green;     // green
                    *(fbp + location + 2) = background_red;    // red
                    *(fbp + location + 3) = 0;      // No transparency
                } else { 
                    printf("can't write\n");
                }
            }
    }

    void drawBlock(int absis, int ordinat, int red, int green, int blue){
        for (y = ordinat; y < ordinat+10; y++)//maks 236
            for (x = absis; x < ordinat+10; x++) {//maks 800

                location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
                           (y+vinfo.yoffset) * finfo.line_length;

                if (vinfo.bits_per_pixel == 32) { // color information
                    *(fbp + location) = blue;        // blue
                    *(fbp + location + 1) = green;     // green
                    *(fbp + location + 2) = red;    // red
                    *(fbp + location + 3) = 0;      // No transparency
                } else  { 
                printf("can't write\n");
                }
            }
    }
    void eraseBlock(int absis, int ordinat){
        for (y = ordinat; y < ordinat+10; y++)//maks 236
            for (x = absis; x < ordinat+10; x++) {//maks 800

                location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
                           (y+vinfo.yoffset) * finfo.line_length;

                if (vinfo.bits_per_pixel == 32) { // color information
                    *(fbp + location) = background_blue;        // blue
                    *(fbp + location + 1) = background_green;     // green
                    *(fbp + location + 2) = background_red;    // red
                    *(fbp + location + 3) = 0;      // No transparency
                } else { 
                    printf("can't write\n");
                }
            }
    }

    void fly(int red, int green, int blue){
        for(int i = 0; i<10; i++){
            drawBlock(10*i,10*i,red,green,blue);
            printf("Heiho\n");
            sleep(1000);
            eraseBlock(10*i,10*i);
        }
    }
    

    // Open the file for reading and writing
    fbfd = open("/dev/fb0", O_RDWR);
    if (fbfd == -1) {
        perror("Error: cannot open framebuffer device");
        exit(1);
    }
    printf("The framebuffer device was opened successfully.\n");

    // Get fixed screen information
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo) == -1) {
        perror("Error reading fixed information");
        exit(2);
    }

    // Get variable screen information
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
        perror("Error reading variable information");
        exit(3);
    }

    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel);

    // Figure out the size of the screen in bytes
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
    printf("Screensize: %d", screensize);

    // Map the device to memory
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
    if ((int)fbp == -1) {
        perror("Error: failed to map framebuffer device to memory");
        exit(4);
    }
    printf("The framebuffer device was mapped to memory successfully.\n");

    makeBackground(0, 200, 255);
    drawBlock(0, 0, 200, 100, 0);
    fly(200,100,0);
    munmap(fbp, screensize);
    close(fbfd);
    return 0;
}
Exemplo n.º 22
0
int
main(int argc, char *argv[])
{
    SDL_Surface *screen;

    TPool *tpool;
    CIList *cil;
    CImage *ci;

    int i, ch;
    unsigned int rw, rh; // requested window size
    unsigned long int fcount, do_jpeg;
    double ticks_start, load_fade, aspect;

    /* Copyright notice */
    printf("\n  Continuous Imaging 'fly'\n  Copyright (C) 2008-2012  David Lowy & Tom Rathborne\n\n");

    /* Get options --jpeg / -j and --geometry / -g */
    static struct option longopts[] = {
        { "jpeg",       no_argument,        NULL, 'j' },
        { "geometry",   required_argument,  NULL, 'g' },
        { NULL,         0,                  NULL, 0 }
    };

    /* Defaults */
    do_jpeg = 0;
    rw = 0;
    rh = 0;

    while ((ch = getopt_long(argc, argv, "jg:", longopts, NULL)) != -1)
        switch(ch) {
            case 'j':
                do_jpeg = 1;
                break;
            case 'g':
                if (sscanf(optarg, "%ux%u", &rw, &rh) != 2) {
                    printf("Unhandled geometry '%s': format is WxH\n", optarg);
                    rw = 0;
                    rh = 0;
                }
                break;
            default:
                printf("Unrecognized option %c ignored\n", ch);
        }

    argc -= optind;
    argv += optind;

    /* Get SDL+GL screen */
    screen = init_sdl_gl(CI_BPC, CI_BITS, rw, rh);
    if(!screen) {
        fprintf(stderr, "Failed to init SDL GL context.\n");
        return (0);
    }

#ifndef CI_LINUX
    SDL_ShowCursor(SDL_DISABLE);
#endif
    SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);

    /* Set up JPEG if necessary */
    if (do_jpeg) jpeg_alloc(screen->w, screen->h);

    aspect = CI_ASPECT / ((double)screen->w / (double)screen->h);

    /* time entire program */
    ticks_start = SDL_GetTicks();

    /* Init texture pool */
    tpool = tp_create(65535, 800); // This was supposed to keep fewer textures in VRAM, but it just fills VRAM.

    /* create CI List */
    cil = cil_create(tpool, "thumb/%s.jpg", "image/%s.jpg");

    /* Load all dbs, make links */
    cil_load_scidb(cil, "cidb.db");

    /* Load image data and textures - and draw 'em! */
    for(i = 0; i < cil->rcount; i++) {
        ci = cil->list[i];
        assert(ci);
        assert(ci->subs);

        cil_ci_imgprep(cil, ci, 0); /* load images to N levels */
        ci_load_tx(ci, 0); /* load textures to N level */

        // Render
        load_fade = sqrt(1.0 - ((double) i / (double) cil->rcount));
        glLoadIdentity();
        glScalef(load_fade, load_fade / aspect, 1.0);
        // glRotatef(360.0 * ((double) i / (double) cil->rcount), 0.0, 0.0, 1.0);
        glTranslatef(-0.5, -0.5, 0.0);

        glClear(GL_COLOR_BUFFER_BIT);
        glColor4f(1.0, 1.0, 1.0, sqrt(load_fade));
        glBindTexture(GL_TEXTURE_2D, ci->tid);
        glCallList(cil->gl_list);
        SDL_GL_SwapBuffers();
    }

    for(i = 0; i < cil->rcount; i++) {
        ci = cil->list[i];
        assert(ci);
        assert(ci->subs);
        ci_mklist(ci, cil->gl_list);
    }

    printf("Startup took %.2fs.\n", (SDL_GetTicks() - ticks_start) / 1000.0);

    /* Main loop */
    ticks_start = SDL_GetTicks();

    SDL_WarpMouse(screen->w/2, screen->h/2);
    SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
    fcount = fly(screen, cil, do_jpeg);

    printf("Average FPS: %.2f\n", fcount * 1000.0 / (SDL_GetTicks() - ticks_start));

    printf("Cleaning up ...\n");

    cil_cleanup(cil);

    /* cleanup */
    cil_delete(cil);

    /* drop our data */
    tp_delete(tpool);

    /* JPEG cleanup */
    if (do_jpeg) jpeg_free();

    SDL_Quit();

    return (0);
}
Exemplo n.º 23
0
// Stop all motors on bot
void rest()
{
	freeze();
	fly(0);
	intake(false);
}
Exemplo n.º 24
0
void flight::run()
{
	fly();
}
Exemplo n.º 25
0
C_RESULT output_gtk_stage_transform( void *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
{
  static int frame = 0;
  static int mass = 0, x_center = -1, y_center = -1;
  unsigned char mask_buf[WIDTH*HEIGHT];
  uint8_t display_data[WIDTH*HEIGHT*3];
  int is_hover;
  static int width, height;
  static int is_face = 0;
  int camshift_error;
  static float this_hue_buf[WIDTH*HEIGHT];
  static float last_hue_buf[WIDTH*HEIGHT];
  int i;
  static camshift_frames = 0;
  FILE *fp;
  char filename[50];
  
  frame++;

  // GET FRAME FROM VIDEO FEED
  vp_os_mutex_lock(&video_update_lock);
  pixbuf_data      = (uint8_t*)in->buffers[0];
  vp_os_mutex_unlock(&video_update_lock);

  // Process frame for orange ball
  // UNCOMMENT TO DETECT BALL
  //process_frame_ball(pixbuf_data, mask_buf, &mass, &x_center, &y_center);
  
  // UNCOMMENT TO DETECT FACES
  if (is_face == 0) {
    //printf("Detecting face...\n");
    process_frame_face(pixbuf_data, &mass, &x_center, &y_center, &width, &height);
    if (mass > 8) {
      is_face = 1;
      rgb2hue(pixbuf_data, last_hue_buf);
      printf("DETECT!!! x,y = %d, %d\n", x_center, y_center);
    }
  } else {
    rgb2hue(pixbuf_data, this_hue_buf);
    camshift_error = camshift(last_hue_buf, this_hue_buf, &x_center, &y_center, width, height);
    printf("camshift x,y = %d, %d\n", x_center, y_center);

    // copy this buffer to last buffer
    for (i=0; i<WIDTH*HEIGHT; i++) {
      last_hue_buf[i] = this_hue_buf[i];
    }
    
    if (camshift_error) {
      printf("CAMSHIFT ERROR\n");
      is_face = 0;
      x_center = -1;
      y_center = -1;
    }
    camshift_frames++;
    // about two seconds
    if (camshift_frames > 30) {
      printf("!!check to see if we are still tracking\n");
      camshift_frames = 0;
      is_face = 0;
    }
  }
  
  // we did not use the mask, so make it all black
  clear_mask(mask_buf);

  // write pixbuf to file
  sprintf(filename, "/home/a/pixbuf/pixbuf_%d.ppm", frame);
  fp = fopen(filename, "w");
  // write header
  fprintf(fp, "P6\n320 240\n255\n");
  for (i=0; i<320*240*3; i++) {
    fprintf(fp, "%c", pixbuf_data[i]);
  }
  fclose(fp);
  
  fp = fopen("/home/a/meanshift_log.txt", "a");
  // write log
  // framenum, mass, centroid_x, centroid_y, width, height
  fprintf(fp, "%d %d %d %d %d %d\n", frame, mass, x_center, y_center, width, height);
  
  // Get mask display
  display_mask(mask_buf, display_data, x_center, y_center);
  
  // Fly drone
  is_hover = fly(x_center, y_center, mass);

  // Print status
  printf("Frame number: %d\n", frame);
  printf("Mass: %d; Centroid: (%d, %d)\n", mass, x_center, y_center);
  printf("Meanshift Width: %d; Height: %d\n", width, height);
  printf("\033[2J");

  gdk_threads_enter();
  // GdkPixbuf structures to store the displayed picture
  static GdkPixbuf *pixbuf = NULL;
  static GdkPixbuf *maskbuf = NULL;

  if (pixbuf != NULL) {
    g_object_unref(pixbuf);
    pixbuf=NULL;
  }

  // Create GdkPixbuf from color frame data
  pixbuf = gdk_pixbuf_new_from_data(pixbuf_data,
  				    GDK_COLORSPACE_RGB,
  				    FALSE,    // No alpha channel
  				    8,        // 8 bits per pixel
  				    320,      // Image width
				    240,
  				    320 * 3,  // new pixel every 3 bytes (3channel per pixel)
  				    NULL,     // Function pointers
  				    NULL);
  // Create the GdkPixbuf from color mask display buffer
  maskbuf = gdk_pixbuf_new_from_data(display_data,
  				    GDK_COLORSPACE_RGB,
  				    FALSE,    // No alpha channel
  				    8,        // 8 bits per pixel
  				    320,      // Image width
				    240,
  				    320 * 3,  // new pixel every 3 bytes (3channel per pixel)
  				    NULL,     // Function pointers
  				    NULL);
  gui_t *gui = get_gui();

 // Display the image
  if (gui && gui->cam) {
    gtk_image_set_from_pixbuf(GTK_IMAGE(gui->cam), pixbuf);
    // also display the pixbuf in a second window
    if (gui->mask_cam) {
      gtk_image_set_from_pixbuf(GTK_IMAGE(gui->mask_cam), maskbuf);
    }
  }
  gdk_threads_leave();
  
  return (SUCCESS);
}