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; }
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."); } }
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]; }
/// 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(); }
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); }
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]; }
/// 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); }
/// 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); }
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()); }
// 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); } }
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; }
/** * 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); } }
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); } } }
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); }
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(); }
/*! * \brief RectifyToVector::setUpResult * \param plane * \return */ bool RectifyToVector::setUpResult(Plane &plane){ //get and check point if(!this->inputElements.contains(0) || this->inputElements[0].size() != 1){ return false; } QPointer<Geometry> geometry = this->inputElements[0].at(0).geometry; if(geometry.isNull() || !geometry->getIsSolved() || !geometry->hasDirection()){ return false; } //get the sense (positive or negative) double sense = 1.0; if(this->scalarInputParams.stringParameter.contains("sense")){ if(this->scalarInputParams.stringParameter.value("sense").compare("negative") == 0){ sense = -1.0; } } //get the direction to compare OiVec r_reference = geometry->getDirection().getVector(); r_reference.normalize(); OiVec r_plane = plane.getDirection().getVector(); r_plane.normalize(); //calculate the angle between both directions double angle = 0.0; OiVec::dot(angle, r_reference, r_plane); angle = qAbs(qAcos(angle)); //invert the normal vector if the angle is greater than 90° if(angle > PI/2.0){ r_plane = -1.0 * r_plane; } //invert the normal vector if sense is negative r_plane = sense * r_plane; //set result Direction direction = plane.getDirection(); direction.setVector(r_plane); plane.setPlane(plane.getPosition(), direction); return true; }
void DebrisFountain::projectDebris(EntityList &entityList, Direction direction, Position from, double spread, int amount, RGB &colour, float size) { double startAngle = direction.Angle() - spread / 2.0; double angleStep = spread / (double) amount; for (int i = 0; i < amount; i++) { Direction debrisDirection{direction.Speed(), startAngle+angleStep*i, ((rand() % 10) / 10.f) - 0.5f}; Actor *actor = new Actor(colour, mover, renderer, std::unique_ptr<ElapsedTimeToLive>(new ElapsedTimeToLive(1000))); actor->position().set(from.X(), from.Y(), from.Rotation()); actor->direction().set(debrisDirection); actor->shape().Radius(size); entityList.add(actor); } }
unsigned int ConnectFour::Board::recursiveCheckMove(const CoordinateXY& coordinate, const Player& player, const Direction& direction) const { const CoordinateXY& newCoordinate = coordinate + direction.coordinate(); if(isInBounds(newCoordinate)) return recursiveCheckMove(newCoordinate, player, direction) + 1; return 0; }
void PowerTabOldImporter::convert( const PowerTabDocument::Direction &oldDirection, Direction &direction) { direction.setPosition(static_cast<int>(oldDirection.GetPosition())); for (size_t i = 0; i < oldDirection.GetSymbolCount(); ++i) { uint8_t type = 0; uint8_t active = 0; uint8_t repeat = 0; oldDirection.GetSymbol(i, type, active, repeat); direction.insertSymbol(DirectionSymbol( static_cast<DirectionSymbol::SymbolType>(type), static_cast<DirectionSymbol::ActiveSymbolType>(active), repeat)); } }
STEPEntity * Direction::Create(STEPWrapper *sw, SDAI_Application_instance *sse) { Factory::OBJECTS::iterator i; if ((i = Factory::FindObject(sse->STEPfile_id)) == Factory::objects.end()) { Direction *object = new Direction(sw,sse->STEPfile_id); Factory::AddObject(object); if (!object->Load(sw, sse)) { std::cerr << CLASSNAME << ":Error loading class in ::Create() method." << std::endl; delete object; return NULL; } return static_cast<STEPEntity *>(object); } else { return (*i).second; } }
Direction DumbDirectionSolver::whereICanGoFrom(Point pt) { Direction result; int count = 0; result = Direction(Direction::valueOf(dice->next(3))); while (count++ < 10 && ( (result.inverted() == direction && bomb.isNull()) || !board.isAt(result.changeX(pt.getX()), result.changeY(pt.getY()), Element(LL("SPACE"))) ) ) { result = Direction(Direction::valueOf(dice->next(3))); } if (count > 10) { result = Direction(LL("NULL")); } return result; }
Position Trust2Geometry::generatePosition() const { double X = _random->uniform(); if (X<_M0) { double dd0 = 0.0; double x, y, z; while (dd0<_R0*_R0) { x = (2.0*_random->uniform()-1.0) * _L0; y = (2.0*_random->uniform()-1.0) * _L0; z = (2.0*_random->uniform()-1.0) * _L0; dd0 = (x+_L0)*(x+_L0) + (y+_L0)*(y+_L0) + (z+_L0)*(z+_L0); } return Position(x,y,z); } else if (X<_M0+_M1) { Direction bfk = _random->direction(); double kx, ky, kz; bfk.cartesian(kx,ky,kz); double r = _R1*pow(_random->uniform(),1.0/3.0); double x1, y1, z1; _bfr1.cartesian(x1,y1,z1); double x = x1 + r*kx; double y = y1 + r*ky; double z = z1 + r*kz; return Position(x,y,z); } else { Direction bfk = _random->direction(); double kx, ky, kz; bfk.cartesian(kx,ky,kz); double r = _R2*pow(_random->uniform(),1.0/3.0); double x2, y2, z2; _bfr2.cartesian(x2,y2,z2); double x = x2 + r*kx; double y = y2 + r*ky; double z = z2 + r*kz; return Position(x,y,z); } }
void Game::attack(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(); if (level->free(ny, nx)) { UI::instance()->say("You swing at open space."); return; } // XXX ? Character* target = dynamic_cast<Character*>(level->objectAt(ny, nx)); if (target) { player->attack(target); step(); } else { UI::instance()->say("You can't attack that."); } }
void Attackers::create(const Position& pos, Move move) { if (black) { blackNum = 0; } else { whiteNum = 0; } DirectionFlags flags = pos.getEffect(move.getTo(), black).getExcludeKing(); while (flags.isNonZero()) { Direction rdir = flags.pop().toDirection(); Direction dir = rdir.reverse(); Square from = move.getTo(); while (true) { for (from += dir; pos.getBoard(from) == Piece::EMPTY; from += dir) ; if (from != move.getFrom()) { Piece piece = pos.getBoard(from); if (black) { blackAttackers[blackNum] = (piece != Piece::BKING ? (Value)param.getPieceExchangeAbs(piece) : (Value)Value::MAX); blackNum++; } else { whiteAttackers[whiteNum] = (piece != Piece::WKING ? (Value)param.getPieceExchangeAbs(piece) : (Value)Value::MAX); whiteNum++; } } DirectionFlags flags2 = pos.getEffect(from, black); if (!flags2.check(rdir, true)) { break; } } } if (black) { sort(blackAttackers, blackNum); } else { sort(whiteAttackers, whiteNum); } }
void Game::use(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(); // XXX these messages are wrong if (level->free(ny, nx)) { UI::instance()->say("You drink an imaginary potion."); return; } ItemAdapter* target = dynamic_cast<ItemAdapter*>(level->objectAt(ny, nx)); if (target) { if (player->addToInventory(target)) { step(); } } else { UI::instance()->say("That doesn't appear to be drinkable."); } }
/// Tests the Constructors /// @return True if all tests were executed, false if not bool DirectionTestSuite::TestCaseConstructor() { //------Last Checked------// // - Jan 11, 2005 // TEST CASE: Default constructor { Direction direction; TEST(wxT("Default Constructor"), (direction.GetPosition() == Direction::DEFAULT_POSITION) && (direction.GetSymbolCount() == 0) ); } // TEST CASE: Primary constructor { Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4); wxByte symbolType = 0; wxByte activeSymbol = 0; wxByte repeatNumber = 0; bool ok = direction.GetSymbol(0, symbolType, activeSymbol, repeatNumber); TEST(wxT("Primary Constructor"), (ok) && (direction.GetPosition() == 12) && (symbolType == Direction::toCoda) && (activeSymbol == Direction::activeDaCapo) && (repeatNumber == 4) ); } // TEST CASE: Copy constructor { Direction direction(12, Direction::toCoda, Direction::activeDaCapo, 4); Direction direction2(direction); TEST(wxT("Copy Constructor"), (direction2 == direction) ); } return (true); }
void SpriteObject::DoUnserializeFrom(gd::Project & project, const gd::SerializerElement & element) { const gd::SerializerElement & animationsElement = element.GetChild("animations", 0, "Animations"); animationsElement.ConsiderAsArrayOf("animation", "Animation"); for (std::size_t i = 0; i < animationsElement.GetChildrenCount(); ++i) { const gd::SerializerElement & animationElement = animationsElement.GetChild(i); Animation newAnimation; newAnimation.useMultipleDirections = animationElement.GetBoolAttribute("useMultipleDirections", false, "typeNormal"); //Compatibility with GD <= 3.3 if (animationElement.HasChild("Direction")) { for (std::size_t j = 0; j < animationElement.GetChildrenCount("Direction"); ++j) { Direction direction; direction.UnserializeFrom(animationElement.GetChild("Direction", j)); newAnimation.SetDirectionsCount(newAnimation.GetDirectionsCount()+1); newAnimation.SetDirection(direction, newAnimation.GetDirectionsCount()-1); } } //End of compatibility code else { const gd::SerializerElement & directionsElement = animationElement.GetChild("directions"); directionsElement.ConsiderAsArrayOf("direction"); for (std::size_t j = 0; j < directionsElement.GetChildrenCount(); ++j) { Direction direction; direction.UnserializeFrom(directionsElement.GetChild(j)); newAnimation.SetDirectionsCount(newAnimation.GetDirectionsCount()+1); newAnimation.SetDirection(direction, newAnimation.GetDirectionsCount()-1); } } AddAnimation( newAnimation ); } }
// Function to check if there are any of the oppositions counters in a given row. unsigned int BoardEvaluator::AllOneColour( Board &board, unsigned int colour, Direction &dir) { unsigned int lineValue = 0; for (unsigned int i = 0; i < CONNECT_LENGTH; i++) { if (board.Space(dir.Y(), dir.X()) != NULL) { if (board.Space(dir.Y(), dir.X())->GetColour() != colour) return 0; else lineValue++; } dir.Update(); } // TODO: take account of the weightings. unsigned int retVal = (unsigned int)pow(lineValue, GEN_WEIGHT); return retVal; }
void move() { headID += direction.nextID(); snake.push_back(headID); if(grow) { grow--; return; } queueID = snake.front(); snake.pop_front(); }
// Cross product. Finds perpendicular direction to plane defined by 2. Also useful for lighting and angles Direction Direction::Cross(const Direction& direction) const { return Direction::Coordinates( Get_Y() * direction.Get_Z() - Get_Z() * direction.Get_Y(), Get_Z() * direction.Get_X() - Get_X() * direction.Get_Z(), Get_X() * direction.Get_Y() - Get_Y() * direction.Get_X()); }