コード例 #1
0
ファイル: fold.c プロジェクト: coyizumi/cs111
/*
 * Fold the contents of standard input to fit within WIDTH columns (or bytes)
 * and write to standard output.
 *
 * If sflag is set, split the line at the last space character on the line.
 * This flag necessitates storing the line in a buffer until the current
 * column > width, or a newline or EOF is read.
 *
 * The buffer can grow larger than WIDTH due to backspaces and carriage
 * returns embedded in the input stream.
 */
void
fold(int width)
{
	static wchar_t *buf;
	static int buf_max;
	int col, i, indx, space;
	wint_t ch;

	col = indx = 0;
	while ((ch = getwchar()) != WEOF) {
		if (ch == '\n') {
			wprintf(L"%.*ls\n", indx, buf);
			col = indx = 0;
			continue;
		}
		if ((col = newpos(col, ch)) > width) {
			if (sflag) {
				i = indx;
				while (--i >= 0 && !iswblank(buf[i]))
					;
				space = i;
			}
			if (sflag && space != -1) {
				space++;
				wprintf(L"%.*ls\n", space, buf);
				wmemmove(buf, buf + space, indx - space);
				indx -= space;
				col = 0;
				for (i = 0; i < indx; i++)
					col = newpos(col, buf[i]);
			} else {
				wprintf(L"%.*ls\n", indx, buf);
				col = indx = 0;
			}
			col = newpos(col, ch);
		}
		if (indx + 1 > buf_max) {
			buf_max += LINE_MAX;
			buf = realloc(buf, sizeof(*buf) * buf_max);
			if (buf == NULL)
				err(1, "realloc()");
		}
		buf[indx++] = ch;
	}

	if (indx != 0)
		wprintf(L"%.*ls", indx, buf);
}
コード例 #2
0
ファイル: guides.cpp プロジェクト: wdmchaft/DoonSketch
void GuidelinePropertiesDialog::_onApply()
{
    double deg_angle = _spin_angle.get_value();
    if (!_mode)
        deg_angle += _oldangle;
    Geom::Point normal;
    if ( deg_angle == 90. || deg_angle == 270. || deg_angle == -90. || deg_angle == -270.) {
        normal = Geom::Point(1.,0.);
    } else if ( deg_angle == 0. || deg_angle == 180. || deg_angle == -180.) {
        normal = Geom::Point(0.,1.);
    } else {
        double rad_angle = Geom::deg_to_rad( deg_angle );
        normal = Geom::rot90(Geom::Point::polar(rad_angle, 1.0));
    }
    sp_guide_set_normal(*_guide, normal, true);

    SPUnit const &unit = *sp_unit_selector_get_unit(SP_UNIT_SELECTOR(_unit_selector->gobj()));
    gdouble const raw_dist_x = _spin_button_x.get_value();
    gdouble const points_x = sp_units_get_pixels(raw_dist_x, unit);
    gdouble const raw_dist_y = _spin_button_y.get_value();
    gdouble const points_y = sp_units_get_pixels(raw_dist_y, unit);
    Geom::Point newpos(points_x, points_y);
    if (!_mode)
        newpos += _oldpos;

    sp_guide_moveto(*_guide, newpos, true);

    sp_document_done(SP_OBJECT_DOCUMENT(_guide), SP_VERB_NONE, 
                     _("Set guide properties"));
}
コード例 #3
0
ファイル: CGUIPanel.cpp プロジェクト: jivibounty/irrlicht
void CGUIPanel::moveInnerPane()
{
	core::dimension2d<s32> dim = InnerPane->getAbsolutePosition().getSize();
	core::position2d<s32> newpos(-HScrollBar->getPos(), -VScrollBar->getPos());
	core::rect<s32> r(newpos, newpos + dim);
	InnerPane->setRelativePosition(r);
}
コード例 #4
0
ファイル: ParticleSet.cpp プロジェクト: digideskio/qmcpack
bool ParticleSet::makeMoveWithDrift(const Walker_t& awalker
                                    , const ParticlePos_t& drift , const ParticlePos_t& deltaR
                                    , const vector<RealType>& dt)
{
  if (UseBoundBox)
  {
    for (int iat=0; iat<deltaR.size(); ++iat)
    {
      SingleParticlePos_t displ(dt[iat]*deltaR[iat]+drift[iat]);
      if (Lattice.outOfBound(Lattice.toUnit(displ)))
        return false;
      SingleParticlePos_t newpos(awalker.R[iat]+displ);
      if (!Lattice.isValid(Lattice.toUnit(newpos)))
        return false;
      R[iat]=newpos;
    }
  }
  else
  {
    for (int iat=0; iat<deltaR.size(); ++iat)
      R[iat]=awalker.R[iat]+dt[iat]*deltaR[iat]+drift[iat];
  }
  for (int i=0; i< DistTables.size(); i++)
    DistTables[i]->evaluate(*this);
  if (SK)
    SK->UpdateAllPart();
  //every move is valid
  return true;
}
コード例 #5
0
ファイル: enemy.cpp プロジェクト: henderjm/Graphics
void move(mat4 & e, vec3 & pos) {
	//e_position -= vec3(getPosition().v[0],0,getPosition().v[2]) * getDelta() * e_speed;

	if(e_isAlive) {
		e = scale(e, vec3(1.5,1.5,1.5));
		e_direction = vec3(getPosition() - e_cs.center);
		e_direction = normalise(e_direction);
		e_rotation.v[1] = std::acos(e_direction.v[2]);
		if(e_direction.v[0] > 0)
			e_rotation.v[1] =-e_rotation.v[1];
		e = rotate_x_deg(e, e_rotation.v[0]);
		e = rotate_y_deg(e, (-e_rotation.v[1] * (180/M_PI)));
		e = rotate_z_deg(e, e_rotation.v[2]);
	}
	if(e_isAlive) {
		vec3 newpos(e_cs.center);
		newpos += e_direction * e_speed;
//		newpos.v[1] -= 0.3;
		setE_Position(newpos);
		e = translate(e,getE_Position());
		
	}
//	e_position =  getPosition() - e_position;
//	temp -= getPosition() * getDelta() * e_speed;//vec3(getPosition().v[0],0,getPosition().v[2]);// * getDelta() * e_speed;

}
コード例 #6
0
ファイル: subs.c プロジェクト: ajinkya93/netbsd-src
int
readc(void)
{
	char    c;

	if (tflag) {
		cline();
		newpos();
	}
	buflush();
	if (read(0, &c, 1) != 1)
		errexit("readc");
#ifdef WHY_IS_THIS_HARDWIRED_IN_HERE
	if (c == '\177')
		getout(0);
#endif
	if (c == '\033' || c == '\015')
		return ('\n');
	if (cflag)
		return (c);
	if (c == '\014')
		return ('R');
	if (c >= 'a' && c <= 'z')
		return (c & 0137);
	return (c);
}
コード例 #7
0
void PlayerInst::use_move(GameState* gs, const GameAction& action) {
	perf_timer_begin(FUNCNAME);
	int dx = action.action_x;
	int dy = action.action_y;

	float mag = effective_stats().movespeed;

	float ddx = dx * mag;
	float ddy = dy * mag;

	EnemyInst* target = NULL;
//Enemy hitting test for melee
	gs->object_radius_test(this, (GameInst**)&target, 1, &enemy_colfilter,
			x + ddx * 2, y + ddy * 2);

//Smaller radius enemy pushing test, can intercept enemy radius but not too far
	EnemyInst* alreadyhitting[5] = { 0, 0, 0, 0, 0 };
	gs->object_radius_test(this, (GameInst**)alreadyhitting, 5,
			&enemy_colfilter, x, y, radius);
	bool already = false;
	for (int i = 0; i < 5; i++) {
		if (alreadyhitting[i]) {
			if (ddx < 0 == ((alreadyhitting[i]->x - x + ddx * 2) < 0)) {
				ddx = 0;
			}
			if (ddy < 0 == ((alreadyhitting[i]->y - y + ddy * 2) < 0)) {
				ddy = 0;
			}
			already = true;
		}
	}

	Pos newpos(round(rx + ddx), round(ry + ddy));

	if (!gs->tile_radius_test(newpos.x, newpos.y, radius)) {
		vx = ddx;
		vy = ddy;
	} else if (!gs->tile_radius_test(newpos.x, y, radius)) {
		vx = ddx;
	} else if (!gs->tile_radius_test(x, newpos.y, radius)) {
		vy = ddy;
	} else if (ddx != 0 && ddy != 0) {
		//Alternatives in opposite directions for x & y
		Pos newpos_alt1(round(vx + ddx), round(vy - ddy));
		Pos newpos_alt2(round(vx - ddx), round(vy + ddy));
		if (!gs->tile_radius_test(newpos_alt1.x, newpos_alt1.y, radius)) {
			vx += ddx;
			vy -= ddy;
		} else if (!gs->tile_radius_test(newpos_alt2.x, newpos_alt2.y,
				radius)) {
			vx -= ddx;
			vy += ddy;
		}

	}

	event_log("Player id: %d using move for turn %d, vx=%f, vy=%f\n", id, gs->frame(), vx, vy);
	perf_timer_end(FUNCNAME);
}
コード例 #8
0
ファイル: ui.cpp プロジェクト: jgke/putkijuoksu
// handle input
void input(Level &level, Player &player) {
    SDL_Event ev;
    GLCoord newpos(player.pos);
    const Uint8 *keystate = SDL_GetKeyboardState(NULL);
    float speed = 0.1;
    if(keystate[SDL_SCANCODE_LSHIFT] || keystate[SDL_SCANCODE_RSHIFT])
        speed = 0.5;

    if(keystate[SDL_SCANCODE_W])
        move(newpos, GLCoord(0, speed, 0), player.cameraDirection);
    if(keystate[SDL_SCANCODE_A])
        move(newpos, GLCoord(-speed, 0, 0), player.cameraDirection);
    if(keystate[SDL_SCANCODE_S])
        move(newpos, GLCoord(0, -speed, 0), player.cameraDirection);
    if(keystate[SDL_SCANCODE_D])
        move(newpos, GLCoord(speed, 0, 0), player.cameraDirection);

    if(keystate[SDL_SCANCODE_LEFT])
        player.cameraDirection -= GLCoord(0, 0, 5);
    if(keystate[SDL_SCANCODE_RIGHT])
        player.cameraDirection += GLCoord(0, 0, 5);
    if(player.cameraDirection.z < 0)
        player.cameraDirection.z += 360;
    if(player.cameraDirection.z >= 360)
        player.cameraDirection.z -= 360;
    if(player.collisions) {
        newpos = check_collisions(level, player.pos, newpos);
    }
    player.pos = newpos;
    while(SDL_PollEvent(&ev)) {
        switch(ev.type) {
        case SDL_KEYDOWN:
            switch(ev.key.keysym.sym) {
            case SDLK_c:
                if(player.collisions) {
                    player.pos.z = 50;
                    glDisable(GL_FOG);
                }
                else {
                    player.pos.z = 0.5;
                    glEnable(GL_FOG);
                }
                player.collisions = !player.collisions;
                break;
            case SDLK_p:
                place(level, player.pos, player.cameraTarget - player.pos);
                break;
            case SDLK_x:
                dig(level, player.pos, player.cameraTarget - player.pos);
                break;
            case SDLK_q:
                clean_ui();
                exit(0);
            }
            break;
        }
    }
}
コード例 #9
0
ファイル: ghostflame.cpp プロジェクト: leyyin/supertux
void
Ghostflame::active_update(float elapsed_time)
{
  angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
  Vector newpos(start_position.x + cos(angle) * radius,
                start_position.y + sin(angle) * radius);
  movement = newpos - get_pos();

}
コード例 #10
0
ファイル: subs.c プロジェクト: ajinkya93/netbsd-src
void
fixtty(struct termios *t)
{
	if (tflag)
		newpos();
	buflush();
	if (tcsetattr(0, TCSADRAIN, t) < 0)
		errexit("fixtty");
}
コード例 #11
0
ファイル: iceflame.cpp プロジェクト: CRS-ECHO51/supertux
void
Iceflame::active_update(float elapsed_time)
{
  angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
  Vector newpos(start_position.x + cos(angle) * radius,
                start_position.y + sin(angle) * radius);
  movement = newpos - get_pos();

  if (sprite->get_action() == "fade" && sprite->animation_done()) remove_me();
}
コード例 #12
0
ファイル: SettingBoxIG.cpp プロジェクト: martres/bomberman
void	SettingBoxIG::eventRotOcu(void *data)
{
  glm::vec3 *rotation;
  rotation = (glm::vec3 *)data;
  glm::vec3 newpos(0, 0, -10);
  newpos = this->posSauv;
  newpos = glm::rotateY(newpos, rotation->y);
  this->_position = newpos;
  this->rot = (glm::vec3 *)data;
}
コード例 #13
0
void
Flame::active_update(float elapsed_time)
{
  angle = fmodf(angle + elapsed_time * speed, 2*M_PI);
  Vector newpos(start_position.x + cos(angle) * radius,
                start_position.y + sin(angle) * radius);
  movement = newpos - get_pos();

  sound_source->set_position(get_pos());
}
コード例 #14
0
ファイル: worm.c プロジェクト: jyin0813/OpenBSD-src
void
prize(void)
{
	int value;

	value = rnd(9) + 1;
	newpos(&goody);
	waddch(tv, value+'0');
	wrefresh(tv);
}
コード例 #15
0
ファイル: gameengine.cpp プロジェクト: MrHase/fm
MyML GameEngine::invert(MyML &pos)
{

    MyML newpos("x=0;y=0");
    newpos.A("x", STR(GE_WIDTH-INT(pos.A("x"))));
    newpos.A("y", STR(GE_HEIGHT-INT(pos.A("y"))));

    //MyML newpos("x=@%s|0;y=@%s|1",vector<MyML>(),{STR(GE_WIDTH-INT(pos.A("x"))),STR(GE_HEIGHT-INT(pos.A("y")))});
    return newpos;
}
コード例 #16
0
  NonLocalECPComponent::RealType 
  NonLocalECPComponent::evaluate(ParticleSet& W, TrialWaveFunction& psi,int iat, vector<NonLocalData>& Txy) {
    RealType esum=0.0;

    //int iel=0;
    for(int nn=myTable->M[iat],iel=0; nn<myTable->M[iat+1]; nn++,iel++){

      register RealType r(myTable->r(nn));
      if(r>Rmax) continue;

      register RealType rinv(myTable->rinv(nn));
      register PosType  dr(myTable->dr(nn));

      int txyCounter=Txy.size();
      // Compute ratio of wave functions
      for (int j=0; j < nknot ; j++){ 
        PosType deltar(r*rrotsgrid_m[j]-dr);
        PosType newpos(W.makeMove(iel,deltar)); 
        psiratio[j]=psi.ratio(W,iel)*sgridweight_m[j];
        W.rejectMove(iel);
        //psi.rejectMove(iel);
        //first, add a new NonLocalData with ratio
        Txy.push_back(NonLocalData(iel,psiratio[j],deltar));
      }
      // Compute radial potential
      for(int ip=0;ip< nchannel; ip++){
        vrad[ip]=nlpp_m[ip]->splint(r)*wgt_angpp_m[ip];
      }

      // Compute spherical harmonics on grid
      for (int j=0, jl=0; j<nknot ; j++){ 
        RealType zz=dot(dr,rrotsgrid_m[j])*rinv;
        // Forming the Legendre polynomials
        lpol[0]=1.0;
        RealType lpolprev=0.0;
        for (int l=0 ; l< lmax ; l++){
          //Not a big difference
          //lpol[l+1]=(2*l+1)*zz*lpol[l]-l*lpolprev;
          //lpol[l+1]/=(l+1);
          lpol[l+1]=Lfactor1[l]*zz*lpol[l]-l*lpolprev; 
          lpol[l+1]*=Lfactor2[l]; 
          lpolprev=lpol[l];
        }

        //for(int l=0; l <nchannel; l++,jl++) Amat[jl]=lpol[ angpp_m[l] ]; 
        RealType lsum=0;
        for(int l=0; l <nchannel; l++) lsum += vrad[l]*lpol[ angpp_m[l] ]; 
        esum += Txy[txyCounter++].Weight *= lsum;
      } 
     //BLAS::gemv(nknot, nchannel, &Amat[0], &psiratio[0], &wvec[0]);
     //esum += BLAS::dot(nchannel, &vrad[0], &wvec[0]);
    }   /* end loop over electron */
    return esum;

  }
コード例 #17
0
ファイル: ParticleSet.cpp プロジェクト: digideskio/qmcpack
/** move the iat-th particle by displ
 *
 * @param iat the particle that is moved on a sphere
 * @param displ displacement from the current position
 */
void
ParticleSet::makeMoveOnSphere(Index_t iat, const SingleParticlePos_t& displ)
{
  activePtcl=iat;
  activePos=R[iat]; //save the current position
  SingleParticlePos_t newpos(activePos+displ);
  for (int i=0; i< DistTables.size(); ++i)
    DistTables[i]->moveOnSphere(*this,newpos,iat);
  R[iat]=newpos;
  if (SK && SK->DoUpdate)
    SK->makeMove(iat,R[iat]);
}
コード例 #18
0
ファイル: flame.cpp プロジェクト: brmbrmcar/supertux
void
Flame::active_update(float elapsed_time)
{
  angle = fmodf(angle + elapsed_time * speed, math::TAU);
  if (!Editor::is_active()) {
    Vector newpos(start_position.x + cosf(angle) * radius,
                  start_position.y + sinf(angle) * radius);
    movement = newpos - get_pos();
    sound_source->set_position(get_pos());
  }

  if (sprite->get_action() == "fade" && sprite->animation_done()) remove_me();
}
コード例 #19
0
ファイル: ParticleSet.cpp プロジェクト: digideskio/qmcpack
/** move a particle iat
 * @param iat the index of the particle to be moved
 * @param displ the displacement of the iath-particle position
 * @return the proposed position
 *
 * Update activePtcl index and activePos position for the proposed move.
 * Evaluate the related distance table data DistanceTableData::Temp.
 */
bool
ParticleSet::makeMoveAndCheck(Index_t iat, const SingleParticlePos_t& displ)
{
  myTimers[0]->start();
  activePtcl=iat;
  //SingleParticlePos_t red_displ(Lattice.toUnit(displ));
  if (UseBoundBox)
  {
    if (Lattice.outOfBound(Lattice.toUnit(displ)))
      return false;
    activePos=R[iat]; //save the current position
    SingleParticlePos_t newpos(activePos+displ);
    newRedPos=Lattice.toUnit(newpos);
    if (Lattice.isValid(newRedPos))
    {
      for (int i=0; i< DistTables.size(); ++i)
        DistTables[i]->move(*this,newpos,iat);
      R[iat]=newpos;
      if (SK && SK->DoUpdate)
        SK->makeMove(iat,newpos);
      myTimers[0]->stop();
      return true;
    }
    //out of bound
    myTimers[0]->stop();
    return false;
  }
  else
  {
    activePos=R[iat]; //save the current position
    SingleParticlePos_t newpos(activePos+displ);
    for (int i=0; i< DistTables.size(); ++i)
      DistTables[i]->move(*this,newpos,iat);
    R[iat]=newpos;
    myTimers[0]->stop();
    return true;
  }
}
コード例 #20
0
ファイル: fancy.c プロジェクト: ajinkya93/netbsd-src
void
refresh(void)
{
	int     i, r, c;

	r = curr;		/* save current position */
	c = curc;

	for (i = 12; i > 6; i--)/* fix positions 12-7 */
		if (board[i] != oldb[i]) {
			fixpos(oldb[i], board[i], 13, 1 + (12 - i) * 4, -1);
			oldb[i] = board[i];
		}
	if (board[0] != oldb[0]) {	/* fix red men on bar */
		fixpos(oldb[0], board[0], 13, 25, -1);
		oldb[0] = board[0];
	}
	for (i = 6; i > 0; i--)	/* fix positions 6-1 */
		if (board[i] != oldb[i]) {
			fixpos(oldb[i], board[i], 13, 29 + (6 - i) * 4, -1);
			oldb[i] = board[i];
		}
	i = -(off[0] < 0 ? off[0] + 15 : off[0]);	/* fix white's home */
	if (oldw != i) {
		fixpos(oldw, i, 13, 54, -1);
		oldw = i;
	}
	for (i = 13; i < 19; i++)	/* fix positions 13-18 */
		if (board[i] != oldb[i]) {
			fixpos(oldb[i], board[i], 3, 1 + (i - 13) * 4, 1);
			oldb[i] = board[i];
		}
	if (board[25] != oldb[25]) {	/* fix white men on bar */
		fixpos(oldb[25], board[25], 3, 25, 1);
		oldb[25] = board[25];
	}
	for (i = 19; i < 25; i++)	/* fix positions 19-24 */
		if (board[i] != oldb[i]) {
			fixpos(oldb[i], board[i], 3, 29 + (i - 19) * 4, 1);
			oldb[i] = board[i];
		}
	i = (off[1] < 0 ? off[1] + 15 : off[1]);	/* fix red's home */
	if (oldr != i) {
		fixpos(oldr, i, 3, 54, 1);
		oldr = i;
	}
	curmove(r, c);		/* return to saved position */
	newpos();
	buflush();
}
コード例 #21
0
ファイル: ParticleSet.cpp プロジェクト: digideskio/qmcpack
/** move a particle iat
 * @param iat the index of the particle to be moved
 * @param displ the displacement of the iath-particle position
 * @return the proposed position
 *
 * Update activePtcl index and activePos position for the proposed move.
 * Evaluate the related distance table data DistanceTableData::Temp.
 */
ParticleSet::SingleParticlePos_t
ParticleSet::makeMove(Index_t iat, const SingleParticlePos_t& displ)
{
  activePtcl=iat;
  activePos=R[iat]; //save the current position
  SingleParticlePos_t newpos(activePos+displ);
  for (int i=0; i< DistTables.size(); ++i)
    DistTables[i]->move(*this,newpos,iat);
  R[iat]=newpos;
  //Do not change SK: 2007-05-18
  //Change SK only if DoUpdate is true: 2008-09-12
  if (SK && SK->DoUpdate)
    SK->makeMove(iat,newpos);
  return newpos;
}
コード例 #22
0
/**
 * Utility to place detector in space, according to data file
 */
void LoadILLReflectometry::placeDetector(double distance /* meter */,
                                         double angle /* degree */) {
  const double deg2rad = M_PI / 180.0;
  std::string componentName("uniq_detector");
  V3D pos = m_loader.getComponentPosition(m_localWorkspace, componentName);
  //      double r, theta, phi;
  //      pos.getSpherical(r, theta, phi);

  double angle_rad = angle * deg2rad;
  V3D newpos(distance * sin(angle_rad), pos.Y(), distance * cos(angle_rad));
  m_loader.moveComponent(m_localWorkspace, componentName, newpos);

  // Apply a local rotation to stay perpendicular to the beam
  const V3D axis(0.0, 1.0, 0.0);
  Quat rotation(angle, axis);
  m_loader.rotateComponent(m_localWorkspace, componentName, rotation);
}
コード例 #23
0
ファイル: warp.cpp プロジェクト: aaronaskew/synfig
synfig::Layer::Handle
Warp::hit_check(synfig::Context context, const synfig::Point &p)const
{
	Point src_tl=param_src_tl.get(Point());
	Point src_br=param_src_br.get(Point());
	bool clip=param_clip.get(bool());
	
	Point newpos(transform_forward(p));

	if(clip)
	{
		Rect rect(src_tl,src_br);
		if(!rect.is_inside(newpos))
			return 0;
	}

	return context.hit_check(newpos);
}
コード例 #24
0
ファイル: k_mnu.cpp プロジェクト: jschwartzenberg/kicker
QMouseEvent PanelKMenu::translateMouseEvent( QMouseEvent* e )
{
    QRect side = sideImageRect();

    if ( !side.contains( e->pos() ) )
        return *e;

    QPoint newpos( e->pos() );
    QApplication::isRightToLeft() ?
        newpos.setX( newpos.x() - side.width() ) :
        newpos.setX( newpos.x() + side.width() );
    QPoint newglobal( e->globalPos() );
    QApplication::isRightToLeft() ?
        newglobal.setX( newpos.x() - side.width() ) :
        newglobal.setX( newpos.x() + side.width() );

    return QMouseEvent( e->type(), newpos, newglobal, e->button(), e->state() );
}
コード例 #25
0
ファイル: twenty2.c プロジェクト: febinstephen/k-r-solutions
main()
{
	int pos,c;
	pos = 0;
	while ((c == getchar()) != EOF ) {
		line[pos] = c;
		if (c == '\n') {
			printl(pos);
			pos = 0;
		} else if (++pos >= MAXCOLM) {
			pos = findblk(pos);
			printl(pos);
			pos = newpos(pos);
		} else if (c == '\t') {
	               //pos = exptab(pos);
		}
	}
}
コード例 #26
0
ファイル: lx1_22.c プロジェクト: charlesyoungwin/cPractice
int main(){
    int c, pos;

    pos = 0;
    while( (c = getchar()) != EOF){
        line[pos] = c;
        if( c == '\t')
            pos = exptab(pos);
        else if( c == '\n'){
            printl(pos);
            pos = 0;
        } else if(++pos >= MAXCOL){
            pos = findblnk(pos);
            printl(pos);
            pos = newpos(pos);
        }
    }
}
コード例 #27
0
ファイル: analogpad.cpp プロジェクト: zzilla/robocam
void AnalogPad::mousePressEvent(QMouseEvent *event)
{
    // Scale pad position to range [-1, 1]
    qreal xx = qreal(event->pos().x()) / m_Position.x() - 1;
    qreal yy = qreal(event->pos().y()) / m_Position.y() - 1;

    // Calculate the distance from the center
    qreal dist = sqrt(pow(xx, 2) + pow(yy, 2));

    // Return if outside the pad area
    if(dist>0.9) return;

    m_MouseDown = true;
    m_TouchPosition = event->pos();
    
    // Calculate unit vectors
    xx /= dist;
    yy /= dist;
    
    // Check was the pad pressed close to the center
    if (dist > PAD_SENSITIVITY_LIMIT)
    {
        // Check if the distance from the center exceeds maximum
        if(dist>MAX_DIST)
        {
            dist = MAX_DIST;
            m_LimitReached = true;
        } else {
            m_LimitReached = false;
        }
        
        // Calculate new pad position
        QPoint newpos((xx*dist + 1) * m_Position.x(), (yy*dist + 1)*m_Position.y());
        setPadPosition(newpos);
        emitPadValue();
    } else {
        m_MouseClick = true;
    }
    update();
    emitValueChanged();
}
コード例 #28
0
ファイル: analogpad.cpp プロジェクト: zzilla/robocam
void AnalogPad::mouseMoveEvent(QMouseEvent *event)
{
    // Return if mouse was not pressed inside the pad area
    if(!m_MouseDown) return;

    if(m_MouseClick)
    {
        QPoint d = event->pos() - m_TouchPosition;
        if(d.manhattanLength()>4) m_MouseClick = false;
    }

    if (!m_MouseClick)
    {
        // Scale pad position to range [-1, 1]
        qreal xx = qreal(event->pos().x()) / m_Position.x() - 1;
        qreal yy = qreal(event->pos().y()) / m_Position.y() - 1;
        
        // Calculate the distance from the center
        qreal dist = sqrt(pow(xx, 2) + pow(yy, 2));
        
        // Calculate unit vectors
        xx/=dist;
        yy/=dist;

        // Check if the distance from the center exceeds maximum
        if(dist>MAX_DIST)
        {
            dist = MAX_DIST;
            m_LimitReached = true;
        } else {
            m_LimitReached = false;
        }

        // Calculate new pad position
        QPoint newpos((xx*dist + 1) * m_Position.x(), (yy*dist + 1)*m_Position.y());
        setPadPosition(newpos);
        update();
        emitValueChanged();
    }
}
コード例 #29
0
ファイル: window.cpp プロジェクト: beanhome/dev
void wxWindowDFB::DoMoveWindow(int x, int y, int width, int height)
{
    // NB: [x,y] arguments are in (parent's) window coordinates, while
    //     m_rect.{x,y} are in (parent's) client coordinates. That's why we
    //     offset by parentOrigin in some places below

    wxPoint parentOrigin(0, 0);
    AdjustForParentClientOrigin(parentOrigin.x, parentOrigin.y);

    wxRect oldpos(m_rect);
    oldpos.Offset(parentOrigin);

    wxRect newpos(x, y, width, height);

    // input [x,y] is in window coords, but we store client coords in m_rect:
    m_rect = newpos;
    m_rect.Offset(-parentOrigin);

    // window's position+size changed and so did the subsurface that covers it
    InvalidateDfbSurface();

    if ( IsShown() )
    {
        // queue both former and new position of the window for repainting:
        wxWindow *parent = GetParent();

        // only refresh the visible parts:
        if ( !CanBeOutsideClientArea() )
        {
            wxRect parentClient(parent->GetClientSize());
            oldpos.Intersect(parentClient);
            newpos.Intersect(parentClient);
        }

        parent->RefreshRect(oldpos);
        parent->RefreshRect(newpos);
    }
}
コード例 #30
0
ファイル: warp.cpp プロジェクト: aaronaskew/synfig
Color
Warp::get_color(Context context, const Point &p)const
{
	Point src_tl=param_src_tl.get(Point());
	Point src_br=param_src_br.get(Point());
	Real horizon=param_horizon.get(Real());
	bool clip=param_clip.get(bool());

	Point newpos(transform_forward(p));

	if(clip)
	{
		Rect rect(src_tl,src_br);
		if(!rect.is_inside(newpos))
			return Color::alpha();
	}

	const float z(transform_backward_z(newpos));
	if(z>0 && z<horizon)
		return context.get_color(newpos);
	else
		return Color::alpha();
}