当前位置: 首页>>代码示例>>C++>>正文


C++ Grid函数代码示例

本文整理汇总了C++中Grid函数的典型用法代码示例。如果您正苦于以下问题:C++ Grid函数的具体用法?C++ Grid怎么用?C++ Grid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Grid函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: stepsVector

returnValue ModelData::setIntegrationGrid(	const Grid& _ocpGrid, const uint _numSteps
										)
{
	uint i;
	N = _ocpGrid.getNumIntervals();
	BooleanType equidistantControl = _ocpGrid.isEquidistant();
	double T = _ocpGrid.getLastTime() - _ocpGrid.getFirstTime();
	double h = T/((double)_numSteps);
	Vector stepsVector( N );

	if (integrationGrid.isEmpty() == BT_TRUE)
	{
		for( i = 0; i < stepsVector.getDim(); i++ )
		{
			stepsVector(i) = (int) acadoRound((_ocpGrid.getTime(i+1)-_ocpGrid.getTime(i))/h);
		}

		if( equidistantControl )
		{
			// Setup fixed integrator grid for equidistant control grid
			integrationGrid = Grid( 0.0, ((double) T)/((double) N), (int) ceil((double)_numSteps/((double) N) - 10.0*EPS) + 1 );
		}
		else
		{
			// Setup for non equidistant control grid
			// NOTE: This grid defines only one integration step because the control
			// grid is non equidistant.
			integrationGrid = Grid( 0.0, h, 2 );
			numSteps = stepsVector;
		}
	}
	return SUCCESSFUL_RETURN;
}
开发者ID:francesco-romano,项目名称:acado,代码行数:33,代码来源:model_data.cpp

示例2: Wall

Wall* Wall::create(Field* field, const Grid &pos)
{
    Wall* wall = new Wall();
    if (wall && wall->initWithGrid(field, "rWall_0003", pos))
    {
        wall->autorelease();
        wall->retain();
    }
    else
    {
        CC_SAFE_DELETE(wall);
        wall = nullptr;
    }
    
    wall->_is_top_wall_exist   = wall->_isWallExist(wall->m_grid_pos + Grid(0, -1));
    wall->_is_right_wall_exist = wall->_isWallExist(wall->m_grid_pos + Grid(1, 0));
    wall->_refreshWall();
    
    auto left_wall   = wall->_getWall(wall->m_grid_pos + Grid(-1, 0));

    if (left_wall)
    {
        left_wall->notifyRightWallExist();
    }
    
    auto bottom_wall = wall->_getWall(wall->m_grid_pos + Grid(0, 1));
    if (bottom_wall)
    {
        bottom_wall->notifyTopWallExist();
    }
    
    return wall;
}
开发者ID:wevet,项目名称:Cocos2dxResources,代码行数:33,代码来源:Wall.cpp

示例3: main

int main(){
  Grid g = Grid();

  Grid g2 = Grid();

  assert(g == g2);

  for (int i = 0; i < 9; i++) {
    for (int j = 0; j < 9; j++) {
      if ((i+j)%7 == 0) {
        g2.set(i,j,-1*(i+1)*(j+1));
      } else {
        g2.set(i,j,(i-1)*(j+1));
      }
    }
  }

  assert(g != g2);

  g = g2;

  assert (g == g2);

  g.set(8,8, -10);
  g.set(4,8, -10);
  g.set(3,8, -10);
  g.set(8,5, -10);
  g.set(1,3, -10);

  g.print();

  std::cout << "All tests passed!\n";

  return 0;
}
开发者ID:dhrupadb,项目名称:C-doku-,代码行数:35,代码来源:test_grid.cpp

示例4: int

Grid GameWorld::GetGridPos(float x, float y)
{
	if (x < rect.left || x >= rect.right || y > rect.top || y <= rect.bottom) return Grid(-1, -1);

	int tx = int((x - rect.left) / gridWidth);
	int ty = int((rect.top - y) / gridHeight);

	return Grid(tx, ty);
}
开发者ID:MagicBlocks,项目名称:Pac-man,代码行数:9,代码来源:GameWorld.cpp

示例5: getBrickAt

void Board::addDestroyedBricks(Brick* brick, std::vector<Brick*> &destroyedBricks)
{
    Grid location = brick->_currentLocation;
    Brick* north = getBrickAt(location + Grid(-1,0));
    Brick* south = getBrickAt(location + Grid(1,0));
    Brick* east = getBrickAt(location + Grid(0,1));
    Brick* west = getBrickAt(location + Grid(0,-1));
    
    if(north != 0 ) // not sure why some times short circuit works sometime it doesn't.
    {
        if(!north->tmp_moves)
        {
            if(brick->getType() == north->getType())
            {
                north->tmp_moves = true;    
                destroyedBricks.push_back(north);
            }
        }
    }
    if(south != 0 )
    {
        if(!south->tmp_moves)
        {
            if(brick->getType() == south->getType())
            {
                south->tmp_moves = true;    
                destroyedBricks.push_back(south);
            }
        }
    }
    if(east != 0)
    {
        if(!east->tmp_moves)
        {
            if(brick->getType() == east->getType() )
            {
                east->tmp_moves = true;    
                destroyedBricks.push_back(east);
            }
        }
    }
    if(west != 0 )
    {
        if(!west->tmp_moves)
        {
            if(brick->getType() == west->getType() )
            {
                west->tmp_moves = true;    
                destroyedBricks.push_back(west);
            }
        }
    }
}
开发者ID:ZwodahS,项目名称:DestroyTheBrick,代码行数:53,代码来源:Board.cpp

示例6: m_boundsManager

//#################### CONSTRUCTORS ####################
BroadPhaseCollisionDetector::BroadPhaseCollisionDetector(const BoundsManager_CPtr& boundsManager,
														 double minObjectSize, double maxObjectSize)
:	m_boundsManager(boundsManager)
{
	for(double gridSize=minObjectSize; gridSize<maxObjectSize*2; gridSize*=2)
	{
		m_hgrid.insert(std::make_pair(gridSize, Grid()));
	}

	m_hgrid.insert(std::make_pair(std::numeric_limits<double>::max(), Grid()));
}
开发者ID:longde123,项目名称:hesperus2,代码行数:12,代码来源:BroadPhaseCollisionDetector.cpp

示例7: Grid

bool Board::fireBrick(Grid location, Brick* nextBrick, zf::Direction direction)
{
    if(isMoving())
    {
        return false;
    }
    Grid directionGrid = Grid(0,0);
    switch(direction)
    {
        case zf::North:
            directionGrid = Grid(-1,0);
            break;
        case zf::South:
            directionGrid = Grid(1,0);
            break;
        case zf::East:
            directionGrid = Grid(0,1);
            break;
        case zf::West:
            directionGrid = Grid(0,-1);
            break;
    }
    Grid nextGrid = location + directionGrid;
    Brick* brick = getBrickAt(nextGrid.row , nextGrid.col);
    if(brick != 0)
    {
        return false; // if there is a brick blocking directly, don't allow it to shoot.
    }
    //find the first block that it will hit
    // move nextGrid back first
    nextGrid -= directionGrid;
    while(brick == 0)
    {
        nextGrid += directionGrid;
        Grid temp = nextGrid + directionGrid;
        if(!inShootableRange(temp.row,temp.col)) // if the next is not in shootable range , break
        {
            // prevent out of bound
            break;
        }
        brick = getBrickAt(temp.row, temp.col);
    }

    _knock = -1;
    putBrickInto(location.row,location.col,nextBrick);
    nextBrick->moveToLocation(nextGrid.row, nextGrid.col);
    _currentMovingDirection = directionGrid; 
    _movingBricks.push_back(nextBrick);
    return true;
}
开发者ID:ZwodahS,项目名称:DestroyTheBrick,代码行数:50,代码来源:Board.cpp

示例8: hasBot

bool World::hasBot(int row, int col)
{
    for(int i = 0 ; i < _enemyBots.size() ; i++)
    {
        if(_enemyBots[i]->getLocation() == Grid(row,col))
        {
            return true;
        }
    }
    if(_player->getLocation() == Grid(row, col))
    {
        return true;
    }
    return false;
}
开发者ID:ZwodahS,项目名称:LD26,代码行数:15,代码来源:World.cpp

示例9: GetSlot

void cSlotAreaCrafting::ClickedResult(cPlayer & a_Player)
{
	const cItem * ResultSlot = GetSlot(0, a_Player);
	cItem & DraggingItem = a_Player.GetDraggingItem();

	// Get the current recipe:
	cCraftingRecipe & Recipe = GetRecipeForPlayer(a_Player);

	cItem * PlayerSlots = GetPlayerSlots(a_Player) + 1;
	cCraftingGrid Grid(PlayerSlots, m_GridSize, m_GridSize);

	// If possible, craft:
	if (DraggingItem.IsEmpty())
	{
		DraggingItem = Recipe.GetResult();
		Recipe.ConsumeIngredients(Grid);
		Grid.CopyToItems(PlayerSlots);
	}
	else if (DraggingItem.IsEqual(Recipe.GetResult()))
	{
		cItemHandler * Handler = ItemHandler(Recipe.GetResult().m_ItemType);
		if (DraggingItem.m_ItemCount + Recipe.GetResult().m_ItemCount <= Handler->GetMaxStackSize())
		{
			DraggingItem.m_ItemCount += Recipe.GetResult().m_ItemCount;
			Recipe.ConsumeIngredients(Grid);
			Grid.CopyToItems(PlayerSlots);
		}
	}

	// Get the new recipe and update the result slot:
	UpdateRecipe(a_Player);
	
	// We're done. Send all changes to the client and bail out:
	m_ParentWindow.BroadcastWholeWindow();
}
开发者ID:l0ud,项目名称:MCServer,代码行数:35,代码来源:SlotArea.cpp

示例10: run_soft_sphere

double run_soft_sphere(double reduced_density, double temp) {
  Functional f = SoftFluid(sigma, 1, 0);
  const double mu = find_chemical_potential(OfEffectivePotential(f), temp, reduced_density*pow(2,-5.0/2.0));
  printf("mu is %g for reduced_density = %g at temperature %g\n", mu, reduced_density, temp);

  //printf("Filling fraction is %g with functional %s at temperature %g\n", reduced_density, teff);
  //fflush(stdout);
  temperature = temp;
  //if (kT == 0) kT = ;1

  Lattice lat(Cartesian(xmax,0,0), Cartesian(0,ymax,0), Cartesian(0,0,zmax));
  GridDescription gd(lat, dx);

  Grid softspherepotential(gd);
  softspherepotential.Set(soft_sphere_potential);

  f = SoftFluid(sigma, 1, mu); // compute approximate energy with chemical potential mu
  const double approx_energy = f(temperature, reduced_density*pow(2,-5.0/2.0))*xmax*ymax*zmax;
  const double precision = fabs(approx_energy*1e-9);

  f = OfEffectivePotential(SoftFluid(sigma, 1, mu) + ExternalPotential(softspherepotential));

  static Grid *potential = 0;
  potential = new Grid(gd);
  *potential = softspherepotential - temperature*log(reduced_density*pow(2,-5.0/2.0)/(1.0*radius*radius*radius))*VectorXd::Ones(gd.NxNyNz); // Bad starting guess
  printf("\tMinimizing to %g absolute precision from %g from %g...\n", precision, approx_energy, temperature);
  fflush(stdout);

  Minimizer min = Precision(precision,
                            PreconditionedConjugateGradient(f, gd, temperature,
                                potential,
                                QuadraticLineMinimizer));
  took("Setting up the variables");
  for (int i=0; min.improve_energy(true) && i<100; i++) {
  }

  took("Doing the minimization");
  min.print_info();

  Grid density(gd, EffectivePotentialToDensity()(temperature, gd, *potential));
  //printf("# per area is %g at filling fraction %g\n", density.sum()*gd.dvolume/dw/dw, reduced_density);

  char *plotname = (char *)malloc(1024);

  sprintf(plotname, "papers/fuzzy-fmt/figs/radial-wca-%06.4f-%04.2f.dat", temp, reduced_density);
  z_plot(plotname, Grid(gd, pow(2,5.0/2.0)*density));
  free(plotname);

  {
    //double peak = peak_memory()/1024.0/1024;
    //double current = current_memory()/1024.0/1024;
    //printf("Peak memory use is %g M (current is %g M)\n", peak, current);

  }

  took("Plotting stuff");
  printf("density %g gives ff %g for reduced_density = %g and T = %g\n", density(0,0,gd.Nz/2),
         density(0,0,gd.Nz/2)*4*M_PI/3, reduced_density, temp);
  return density(0, 0, gd.Nz/2)*4*M_PI/3; // return bulk filling fraction
}
开发者ID:droundy,项目名称:deft,代码行数:60,代码来源:radial-wca.cpp

示例11: PushCallStack

inline void
AbstractDistMatrix<T,Int>::Write
( const std::string filename, const std::string msg ) const
{
#ifndef RELEASE
    PushCallStack("AbstractDistMatrix::Write");
#endif
    const elem::Grid& g = Grid();
    const int commRank = mpi::CommRank( g.VCComm() ); 

    if( commRank == 0 )
    {
        std::ofstream file( filename.c_str() );
        file.setf( std::ios::scientific );
        PrintBase( file, msg );
        file.close();
    }
    else
    {
        NullStream nullStream;
        PrintBase( nullStream, msg );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
开发者ID:jimgoo,项目名称:Elemental,代码行数:26,代码来源:abstract_impl.hpp

示例12: logic_error

inline void
AbstractDistMatrix<T,Int>::AssertSameGrid
( const AbstractDistMatrix<U,Int>& A ) const
{
    if( Grid() != A.Grid() )
        throw std::logic_error("Assertion that grids match failed");
}
开发者ID:jimgoo,项目名称:Elemental,代码行数:7,代码来源:abstract_impl.hpp

示例13: Grid

FixPaintSelection::GridMap::iterator
FixPaintSelection::addGrid(const Point& pt)
{
    std::pair<GridMap::iterator, bool> inserted =
        mGrids.insert(GridMap::value_type(pt, Grid()));
    return inserted.first;
}
开发者ID:ueverything,项目名称:mmo-resourse,代码行数:7,代码来源:FixPaintAction.cpp

示例14: sol

Grid Grid::exact_solution(int time_steps) {
	std::vector<double> sol(size, 0);
	int shift = (int) (dt * xi / dh * time_steps / dh);
	for (int i = 0; i < size - shift; i++)
		sol[i + shift] = data[i];
	return Grid(sol, dh, dt, xi);
};
开发者ID:liviniuk,项目名称:MIPT_base,代码行数:7,代码来源:Grid.cpp

示例15: Game

		 : Game(rm, dbGraphics, screenBounds, gameFont, fontBrush, sound)
{
	// Create random instance
	rGen = gcnew Random();
	
	// Load background image
	//background = Image::FromFile("background.jpg");

	// Create gamegrid and preview
	grid = gcnew GameGrid(rm, Point(302,-30), graphics, sound, GAMEGRID_COLS, GAMEGRID_ROWS);
	preview = gcnew Grid(rm, Point(757,480), graphics, PREVIEW_COLS, PREVIEW_ROWS); 

	// Create arrays for tracking block stats
	tetriminoStats = gcnew array<int>(7);
	tetriminoTypes = gcnew array<ETetriminoType>
	{
		I_TETRIMINO,
		J_TETRIMINO, 
		L_TETRIMINO, 
		O_TETRIMINO, 
		S_TETRIMINO, 
		T_TETRIMINO,
		Z_TETRIMINO
	};

	// Create first two tetriminos
	tetriminoInPlay = generateTetrimino();
	nextTetrimino = generateTetrimino();

	// Initialize game update time
	waitTime = 50;
}
开发者ID:appsromch,项目名称:CPlusPlus,代码行数:32,代码来源:GamePlay.cpp


注:本文中的Grid函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。