本文整理汇总了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;
}
示例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.");
}
}
示例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];
}
示例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();
}
示例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);
}
示例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];
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
示例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();
}