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


C++ Direction类代码示例

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


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

示例1: toiDynTree

bool toiDynTree(const yarp::sig::Vector& yarpVector, Direction& direction)
{
    if( yarpVector.size() != 3 )
    {
        return false;
    }

    memcpy(direction.data(),yarpVector.data(),3*sizeof(double));

    // normalize
    direction.Normalize();

    return true;
}
开发者ID:mrkjankovic,项目名称:idyntree,代码行数:14,代码来源:YARPConversions.cpp

示例2: move

void Game::move(Direction d) {
    if (gameOver) {
        return UI::instance()->say("Game Over. Restart or quit.");
    }
    const int ny = player->getY() + d.dy(),
              nx = player->getX() + d.dx();

    LevelObject* obj = level->objectAt(ny, nx);

    if (obj) {
        // Walked into an object. What to do?
        MoveIntoVisitor visitor(*this, d);
        obj->accept(visitor);
        if (!visitor.keepMoving) {
            // Something happened, so don't do anything more.
            return;
        }
    }

    if (player->moveRelative(d)) {
        // A player action happened, so step.
        step();
    } else {
        UI::instance()->say("You can't pass that way.");
    }
}
开发者ID:goffrie,项目名称:gnarly,代码行数:26,代码来源:game.cpp

示例3: rotate_left

static Direction rotate_left( const Direction& dir )
{
  if( dir.index() > 0 )
    return _l_dir[dir.index()-1];
  else
    return _l_dir[_l_dir.size()-1];
}
开发者ID:snowgoon88,项目名称:radint,代码行数:7,代码来源:global.hpp

示例4: RecalcRoute

/// Gets the next direction the caravane has to take
unsigned char TradeRoute::GetNextDir()
{
    if(curPos == path.goal)
        return REACHED_GOAL;

    if(curRouteIdx >= path.route.size())
        return INVALID_DIR;

    Direction nextDir;
    // Check if the route is still valid
    if(gwg.CheckTradeRoute(curPos, path.route, curRouteIdx, player))
        nextDir = path.route[curRouteIdx];
    else
    {
        // If not, recalc it
        uint8_t calculatedNextDir = RecalcRoute();
        // Check if we found a valid direction
        if(calculatedNextDir >= 6)
            return calculatedNextDir; // If not, bail out
        nextDir = Direction::fromInt(calculatedNextDir);
    }

    RTTR_Assert(nextDir == path.route[curRouteIdx]);
    curRouteIdx++;
    curPos = gwg.GetNeighbour(curPos, nextDir);
    return nextDir.toUInt();
}
开发者ID:Return-To-The-Roots,项目名称:s25client,代码行数:28,代码来源:TradeRoute.cpp

示例5: GetPosition

Position Player::GetNextPosition(double dt) const {
  const double speed = 7;
  const Position pos = GetPosition();
  const Direction dir = GetDirection();
  return Position(pos.x + dir.x() * dt * speed,
		  pos.y + dir.y() * dt * speed);
}
开发者ID:mmilewski,项目名称:bynadlaster,代码行数:7,代码来源:Player.cpp

示例6: rotate_right

static Direction rotate_right( const Direction& dir )
{
  if( dir.index() < (_l_dir.size() - 1) )
    return _l_dir[dir.index()+1];
  else
    return _l_dir[0];
}
开发者ID:snowgoon88,项目名称:radint,代码行数:7,代码来源:global.hpp

示例7: TEST

/// Tests the Position Functions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCasePosition()
{
    //------Last Checked------//
    // - Jan 11, 2005
    Direction direction;
    
    // TEST CASE: IsValidPosition
    {
        wxUint32 i = 0;
        for (; i <= (Direction::MAX_POSITION + 1); i++)
        {
            TEST(wxString::Format(wxT("IsValidPosition - %d"), i),
                (Direction::IsValidPosition(i) == (i <= Direction::MAX_POSITION))
            );
        }
    }
    
    // TEST CASE: SetPosition
    {
        wxUint32 i = 0;
        for (; i <= (Direction::MAX_POSITION + 1); i++)
        {
            TEST(wxT("SetPosition - %d"), 
                (direction.SetPosition(i) == (i <= Direction::MAX_POSITION)) &&
                ((i > Direction::MAX_POSITION) ? 1 : (direction.GetPosition() == i))
            );
        }
    }
    return (true);
}
开发者ID:BackupTheBerlios,项目名称:ptparser-svn,代码行数:32,代码来源:directiontestsuite.cpp

示例8: streamOut

/// Tests the Serialization Fucntions
/// @return True if all tests were executed, false if not
bool DirectionTestSuite::TestCaseSerialize()
{
    //------Last Checked------//
    // - Jan 11, 2005
    bool ok = false;
    
    TestStream testStream;
    PowerTabOutputStream streamOut(testStream.GetOutputStream());
    
    // Write test data to stream
    Direction directionOut(12, Direction::toCoda, Direction::activeDaCapo, 4);
    directionOut.Serialize(streamOut);

    // Output must be OK before using input
    if (testStream.CheckOutputState())
    {
        PowerTabInputStream streamIn(testStream.GetInputStream());
    
        // Read test data back from stream
        Direction directionIn;
        directionIn.Deserialize(streamIn, PowerTabFileHeader::FILEVERSION_CURRENT);

        // Validate the data
        ok = ((directionIn == directionOut) 
            && (streamIn.CheckState()));
    }
    
    TEST(wxT("Serialize"), ok);
    
    return (true);
}
开发者ID:BackupTheBerlios,项目名称:ptparser-svn,代码行数:33,代码来源:directiontestsuite.cpp

示例9: signed_distance_on_direction

 static double signed_distance_on_direction(
     const Point &point0,
     const Point &point1,
     const Direction &direction) {
   return
     ((point1.x() - point0.x()) * direction.x()
      +
      (point1.y() - point0.y()) * direction.y());
 }
开发者ID:nsubiron,项目名称:intersect,代码行数:9,代码来源:Distance.cpp

示例10: Angle_Distance

// Angle between two vectors, useful for rotation
float Direction::Angle_Distance(const Direction& direction) const
{
	if (!(Get_X_Angle() == direction.Get_X_Angle() && Get_Y_Angle() == direction.Get_Y_Angle() && Get_Distance() == direction.Get_Distance()))
	{
		return (float)(acos(Dot(direction) / (Get_Distance() * direction.Get_Distance())) * DEGREES_PER_RADIAN);
	}
	else
	{
		return (0);
	}
}
开发者ID:CosineGaming,项目名称:CodeIndigo,代码行数:12,代码来源:Direction.cpp

示例11:

    void Resource<Dim, Type, Data>::move(Direction<Dim> _dir, double _time)
    { 
    	if(_time < 0.)
    	{
			logger(Logger::WARNING) << "Negative time, fix to 0";
			_time = 0.;
    	}
	    Coordonate<Dim, Type> tcoord = Object<Dim, Type>::coord;
	    // New position on the specified direction 
	    tcoord[_dir.getValue().first] += _dir.getValue().second*(velocity*_time); 
	    if(true) // TEST IN SPACE + NOT COLLIDING
	        Object<Dim, Type>::coord = tcoord;
    }
开发者ID:aquemy,项目名称:TaskAssignment,代码行数:13,代码来源:resource.cpp

示例12: switch

/**
  * Eine Figur verschieben. Dabei werden die Zellenrahmen beachtet.
  * @param figure Die zu verschiebende Figur.
  * @param direction Richtung, in die die Figur verschoben werden soll.
  */
void GameController::move(Figure* figure, Direction& direction) {
	unsigned int x = figure->getX();
	unsigned int y = figure->getY();
	if (field->allowsBorderMovement(x, y, direction)) {
		switch (direction.getValue()) {
			case Direction::UP:    y--; break;
			case Direction::LEFT:  x--; break;
			case Direction::DOWN:  y++; break;
			case Direction::RIGHT: x++; break;
		}
	}
	// Durch einen Tunnel verlassen -> auf dem anderen Ende wieder einsetzen
	x = (x + Field::FIELD_WIDTH)  % Field::FIELD_WIDTH;
	y = (y + Field::FIELD_HEIGHT) % Field::FIELD_HEIGHT;

	figure->setX(x);
	figure->setY(y);
	figure->setDirection(direction);

	// Wenn Pacman bewegt wurde: Nachsehen, ob sich auf dem neuen
	// Feld Essen befindet.
	if (figure == pacman) {
		if (field->getCell(pacman->getX(), pacman->getY())->isFood()) {
			points += DOT_POINTS;
			foodCount--;
		}
		field->getCell(pacman->getX(), pacman->getY())->setFood(false);
	}
}
开发者ID:psde,项目名称:Pacman,代码行数:34,代码来源:game_controller.cpp

示例13: SetDirection

bool Styx::Update(GameTime time)
{
    Playfield const &pf = *GetPlayfield();

    // create set of possibile directions to move in
    std::vector<Direction> choices;
    for (int n = 0; n < 4; ++n)
    {
        Direction dir = (Direction::Type)n;

        // can't reverse direction
        if (dir.Opposite() == direction)
            continue;

        Playfield::Element element = pf.At(location + dir.GetVector());
        if (element == Playfield::Line)
        {
            choices.push_back(Direction::Type(n));
        }
    }

    // if we have no where to go, reverse
    if (choices.empty())
    {
        direction = direction.Opposite();
    }
    else
    {
        // choose new random direction
        SetDirection(choices[rand() % choices.size()]);

        if (move_toward_player && choices.size() > 1)
        {
            Point pos_player = GetRoot()->GetWorld()->GetPlayer()->GetLocation();
            float min_dist = 0;
            bool first = true;
            foreach (Direction dir, choices)
            {
                float dist = (location + dir.GetVector() - pos_player).Length();
                if (first || dist < min_dist)
                {
                    first = false;
                    min_dist = dist;
                    SetDirection(dir);
                }
            }
        }
开发者ID:kotetsuy,项目名称:xiq,代码行数:47,代码来源:Styx.cpp

示例14: probabilityForDirection

double NetzerAccretionDiskGeometry::probabilityForDirection(Position /*bfr*/, Direction bfk) const
{
    double theta, phi;
    bfk.spherical(theta, phi);
    double ct = cos(theta);
    double sign = ct > 0 ? 1. : -1;
    return (6./7.) * ct * (2.*ct + sign);
}
开发者ID:DukhangLee,项目名称:SKIRT,代码行数:8,代码来源:NetzerAccretionDiskGeometry.cpp

示例15: screenPixelDirection

void screenPixelDirection(Direction &direction, float x, float y) {

    direction[0] = rangeX * (x - SCREEN_WIDTH / 2.0f) / SCREEN_WIDTH;
    direction[1] = rangeY * (y - SCREEN_HEIGH / 2.0f) / SCREEN_HEIGH;

    direction[2] = 1.f;
    direction.makeUnitVector();
}
开发者ID:Blizarre,项目名称:ray,代码行数:8,代码来源:main.cpp


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