Ogre::Quaternion DetectedVehicle::getOrientation() const { Ogre::Vector3 speed = getSpeed() ; Ogre::Vector3 side(-speed.y,speed.x,-speed.z) ; side.normalise() ; Ogre::Vector3 forward = speed ; forward.normalise() ; Ogre::Vector3 up = forward.crossProduct(side) ; up.normalise() ; return Ogre::Quaternion(side,up,forward) ; }
float Vector3::angle2D(const Vector3 &v) { float dp, angPI ; dp = dot2D(v); //dot product if(dp >= 1.0) dp = 1.0f; if(dp <=-1.0) dp =-1.0f; angPI = (float)acos(dp); //determina a posicao relativa do vetor return angPI * side(v); }
bool BoardController::moveFigure(int from, int to) { if(!m_logic_controller.isMoveAllowed(from, to) || from == to) return false; auto victim = figureAt(to); auto victim_type = victim->type(); auto victim_color = victim->side(); Transition t(from, to, victim_color, victim_type); _moveFigure(from, to); emit figureMoved(t); return true; }
void WorksetContainer::allocateSideWorksets(const std::vector<BC> & bcs) { for(std::size_t i=0;i<bcs.size();i++) { // couldn't find workset, build it! const BC & bc = bcs[i]; SideId side(bc); const std::string & eBlock = bc.elementBlockID(); const PhysicsBlock & pb = lookupPhysicsBlock(eBlock); // store map for reuse in the future sideWorksets_[side] = wkstFactory_->getSideWorksets(bc,pb); } }
void UmlRelation::write_ends(FileOut & out) { // note : it is the first side out.indent(); out << "\t<memberEnd"; out.idref(this); out << "/>\n"; UmlRelation * other = side(FALSE); out.indent(); if (other != 0) { out << "\t<memberEnd"; out.idref(other); out << "/>\n"; } else { out << "\t<ownedEnd xmi:type=\"uml:Property\""; out.id_prefix(this, "REVERSE_"); if (_assoc_class != 0) out.ref(_assoc_class, "association"); else out.ref(this, "association", "ASSOC_"); out << " visibility=\"" << ((_vis_prefix) ? "vis_private\"" : "private\""); out.ref(parent(), "type"); out << " aggregation=\""; if (_gen_eclipse) out << "none"; else { switch (relationKind()) { case anAggregation: case aDirectionalAggregation: out << "shared"; break; case anAggregationByValue: case aDirectionalAggregationByValue: out << "composite"; break; default: out << "none"; } } out << "\" isNavigable=\"false\"/>\n"; out.indent(); out << "\t<memberEnd "; out.idref_prefix(this, "REVERSE_"); out << "/>\n"; } }
/* main loop */ int main(void) { input_line = (char *)malloc(6 * sizeof(char)); led_setperm(); set_time = 200000; while (strncmp(input_line, "quit", 4) != 0) { input_line = readline("Led Control> "); /* I know instruction parsing is really lame :/ */ if (!strncmp(input_line, "help", 4)) help(); if (!strncmp(input_line, "ledon", 5)) ledon(); if (!strncmp(input_line, "ledoff", 6)) ledoff(); if (!strncmp(input_line, "settime", 7)) settime(); if (!strncmp(input_line, "volume", 6)) volume(); if (!strncmp(input_line, "bin", 3)) bin(); if (!strncmp(input_line, "slide", 5)) slide(); if (!strncmp(input_line, "blink", 5)) blink(); if (!strncmp(input_line, "bislide", 7)) bislide(); if (!strncmp(input_line, "biblink", 7)) biblink(); if (!strncmp(input_line, "grow", 4)) grow(); if (!strncmp(input_line, "center", 6)) center(); if (!strncmp(input_line, "side", 4)) side(); if (!strncmp(input_line, "biside", 6)) biside(); if (!strncmp(input_line, "demo", 4)) demo(); } led_off_all(); exit(0); }
//----------------------------------------------------------------------------- // xxx perhaps this should be a call to a general purpose annotation for // xxx "local xxx axis aligned box in XZ plane" -- same code in in // xxx CaptureTheFlag.cpp void Pedestrian::annotateAvoidObstacle( const float minDistanceToCollision ) { const osVector3 boxSide = side() * radius(); const osVector3 boxFront = forward() * minDistanceToCollision; const osVector3 FR = position() + boxFront - boxSide; const osVector3 FL = position() + boxFront + boxSide; const osVector3 BR = position() - boxSide; const osVector3 BL = position() + boxSide; const Color white( 1,1,1 ); annotationLine( FR, FL, white ); annotationLine( FL, BL, white ); annotationLine( BL, BR, white ); annotationLine( BR, FR, white ); }
Material::Material(Material_t tag) : tag(tag), vertexShader(this), fragmentShader(this), index0AttributeName(this) { mId = Material::MaterialIdCount++; mUuid = Math::generateUUID(); mName = ""; side() = kFrontSide; opacity() = 1.0f; transparent() = false; blending() = kNormalBlending; blendSrc() = kSrcAlphaFactor; blendDst() = kOneMinusSrcAlphaFactor; blendEquation() = kAddEquation; depthTest() = true; depthWrite() = true; polygonOffset() = false; polygonOffsetFactor() = 0; polygonOffsetUnits() = 0; // mAlphaTest = 0; overdraw() = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer visible() = true; needsUpdate() = true; // By default, bind position to attribute index 0. In WebGL, attribute 0 // should always be used to avoid potentially expensive emulation. index0AttributeName("position"); linewidth() = 1.0f; metal() = false; perPixel() = true; shading() = kNoShading; vertexColors() = kNoColors; wireframe() = false; wireframeLinewidth() = 1.0f; }
inline static bool check(long long int &sx, long long int &sy) { printf("P: %lld %lld\n", sx, sy); unsigned int f = 0, size = verts - 2, mid; while(size > 2) { mid = (f + size / 2) % verts; if(side(std::make_pair(0, 0), fence[f], std::make_pair(sx, sy)) <= 0 && side(std::make_pair(0, 0), fence[(f + size) % verts], std::make_pair(sx, sy)) >= 0) { f = (f + size) % verts; size = verts - size; continue; } if(side(std::make_pair(0, 0), fence[mid], std::make_pair(sx, sy)) < 0) f = mid; size /= 2; } printf(">>%u %u\n", f, (f + size) % verts); return side(fence[f], fence[(f + size) % verts], std::make_pair(sx, sy)) >= 0; }
void Simplex::pivot(int row, int col) { float pivot = tab(row, col); if(pivot == 0) exit(-1); for(int i(0); i < tab.cols(); ++i) tab(row, i) /= pivot; for (int i = 0; i < tab.rows(); ++i) { float multip = tab(i, col); if(i == row) continue; for (int j = 0; j < tab.cols(); ++j) { tab(i, j) -= multip * tab(row, j); } } side(row-1) = col; }
Controller::Controller() { turnProportionalGain = 1.0f; //converts offset from camera to turn duty cycle throttleProportionalGain = 10.0f; // converts offset in the y direction to throttle sideProportionalGain = 1.0f; hover_throttle = 1.54; lower_altitude = 0; //initialize all controls to neutral turn(1.5); forward(1.48); side(1.59); throttle(1.09); isStarted = 0; time_lift = 0; }
void OpenSteer:: BoxObstacle:: findIntersectionWithVehiclePath (const AbstractVehicle& vehicle, PathIntersection& pi) const { // abbreviations const float w = width; // dimensions const float h = height; const float d = depth; const Vec3 s = side (); // local space const Vec3 u = up (); const Vec3 f = forward (); const Vec3 p = position (); const Vec3 hw = s * (0.5f * width); // offsets for face centers const Vec3 hh = u * (0.5f * height); const Vec3 hd = f * (0.5f * depth); const seenFromState sf = seenFrom (); // the box's six rectangular faces RectangleObstacle r1 (w, h, s, u, f, p + hd, sf); // front RectangleObstacle r2 (w, h, -s, u, -f, p - hd, sf); // back RectangleObstacle r3 (d, h, -f, u, s, p + hw, sf); // side RectangleObstacle r4 (d, h, f, u, -s, p - hw, sf); // other side RectangleObstacle r5 (w, d, s, -f, u, p + hh, sf); // top RectangleObstacle r6 (w, d, -s, -f, -u, p - hh, sf); // bottom // group the six RectangleObstacle faces together ObstacleGroup faces; faces.push_back (&r1); faces.push_back (&r2); faces.push_back (&r3); faces.push_back (&r4); faces.push_back (&r5); faces.push_back (&r6); // find first intersection of vehicle path with group of six faces PathIntersection next; firstPathIntersectionWithObstacleGroup (vehicle, faces, pi, next); // when intersection found, adjust PathIntersection for the box case if (pi.intersect) { pi.obstacle = this; pi.steerHint = ((pi.surfacePoint - position ()).normalize () * (pi.vehicleOutside ? 1.0f : -1.0f)); } }
int testCreateNewOrderSingle( int count ) { int start = GetTickCount(); for ( int i = 0; i <= count; ++i ) { FIX::ClOrdID clOrdID( "ORDERID" ); FIX::HandlInst handlInst( '1' ); FIX::Symbol symbol( "LNUX" ); FIX::Side side( FIX::Side_BUY ); FIX::TransactTime transactTime; FIX::OrdType ordType( FIX::OrdType_MARKET ); FIX42::NewOrderSingle( clOrdID, handlInst, symbol, side, transactTime, ordType ); } return GetTickCount() - start; }
int InsertionSort(int base[], int sz ){ int i,j; int temp; int count = 0; for(i=1;i<sz;++i){ temp = base[i]; for(j = i-1; j>=0 && temp < base[j] ; --j ){ base[j+1] = base[j]; move to right side(+1) element one by one ++count; } base[j+1] = temp; } printf("total count of loop : %d \n", count); return 0; }
void ChessGame::startTurn() { if (m_paused) return; Chess::Side side(m_board->sideToMove()); Q_ASSERT(!side.isNull()); emit humanEnabled(m_player[side]->isHuman()); Chess::Move move(bookMove(side)); if (move.isNull()) m_player[side]->go(); else m_player[side]->makeBookMove(move); }
bool polygon::contains(vec2d vertex) const { // check to see if we have points if(this->vertexes.size() > 0) { // see if we are more than a point if(this->vertexes.size() > 1) { // see if we are more than an edge if(this->vertexes.size() > 2) { int windCount = 0; edge ray(vertex, vertex + vec2d(1, 0)); for(unsigned int i = 0; i < this->vertexes.size(); i++) { edge side(this->vertexes[i], this->vertexes[(i + 1) % this->vertexes.size()]); if(side.contains(vertex)) return true; if(side.offset().y != 0) { auto intersect = ray.intersect(side); if(side.contains(intersect) && intersect.x >= ray.origin().x) { windCount += (int)(side.offset().y / abs(side.offset().y)); } } } return windCount != 0; } else { // we're an edge so compare along edginess edge thisEdge(this->vertexes[0], this->vertexes[1]); return thisEdge.contains(vertex); } } else { // we're a vertex so compare as vertices return vertex == this->vertexes[0]; } } else { return false; } }
void PieChart3D::paintExternal( QPainter& painter, bool top ) { for ( int i = 0; i < myAngles.count() - 2; i+=2 ) { QModelIndex index = this->model()->index( i/2, 0 ); bool isSelected = this->selectionModel()->selectedIndexes().contains( index ) || this->currentIndex() == index; QColor color( this->model()->data( index, Qt::DecorationRole ).toString() ); if ( !color.isValid() ) { color = Marb::predefinedColor( i/2 ); } painter.save(); qreal a1 = myAngles[i]; qreal delta = myAngles[i + 1]; qreal a2 = a1 + delta; if ( a1 < 180 && a2 > 180 ) { paintLeft( painter, color ); } if ( top == false ) { if ( a1 <= 180 && a2 > 180 ) { if ( myRender == Plain ) { configureColor( painter, color, 1 ); qreal delta = 180.0 - a1; QPointF offset = splittedOffset( myAngles[i], delta ); QPainterPath path = itemExternalPart( myAngles[i], delta, mySplitted ); painter.drawPath( path ); painter.setPen( Qt::NoPen ); path = side( 180, offset, isSelected ); painter.drawPath( path ); } painter.restore(); continue; } if ( a1 > 180 || a2 > 180 ) { painter.restore(); continue; } } else { if ( a1 < 180 && a2 < 180 ) { painter.restore(); continue; } } QPainterPath path = itemExternalPart( a1, delta, isSelected ); configureColor( painter, color, 3 ); painter.drawPath( path ); painter.restore(); } }
void OpenSteer::SimpleVehicle::measurePathCurvature (const float elapsedTime) { if (elapsedTime > 0) { const Vec3 dP = _lastPosition - position (); const Vec3 dF = (_lastForward - forward ()) / dP.length (); const Vec3 lateral = dF.perpendicularComponent (forward ()); const float sign = (lateral.dot (side ()) < 0) ? 1.0f : -1.0f; _curvature = lateral.length() * sign; blendIntoAccumulator (elapsedTime * 4.0f, _curvature, _smoothedCurvature); _lastForward = forward (); _lastPosition = position (); } }
void FancyLineEdit::updateMenuLabel() { m_d->m_menuLabel->setPixmap(m_d->m_pixmap); const Side s = side(); switch (s) { case Left: m_d->m_menuLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); m_d->m_menuLabel->setStyleSheet(m_d->m_leftLabelStyleSheet); break; case Right: m_d->m_menuLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight); m_d->m_menuLabel->setStyleSheet(m_d->m_rightLabelStyleSheet); break; } updateStyleSheet(s); positionMenuLabel(); }
long testSerializeToStringNewOrderSingle( int count ) { FIX::ClOrdID clOrdID( "ORDERID" ); FIX::HandlInst handlInst( '1' ); FIX::Symbol symbol( "LNUX" ); FIX::Side side( FIX::Side_BUY ); FIX::TransactTime transactTime; FIX::OrdType ordType( FIX::OrdType_MARKET ); FIX42::NewOrderSingle message ( clOrdID, handlInst, symbol, side, transactTime, ordType ); count = count - 1; long start = GetTickCount(); for ( int i = 0; i <= count; ++i ) { message.toString(); } return GetTickCount() - start; }
vector<Node> find(const string& query) const { vector<Node> result; lstring path = query.split("/"); string name = path.take(0), rule; unsigned lo = 0u, hi = ~0u; if(name.match("*[*]")) { lstring side = name.split<1>("["); name = side(0); side = side(1).rtrim<1>("]").split<1>("-"); lo = side(0).empty() ? 0u : numeral(side(0)); hi = side(1).empty() ? ~0u : numeral(side(1)); } if(name.match("*(*)")) { lstring side = name.split<1>("("); name = side(0); rule = side(1).rtrim<1>(")"); } unsigned position = 0; for(auto& node : children) { if(node.name.match(name) == false) continue; if(node.evaluate(rule) == false) continue; bool inrange = position >= lo && position <= hi; position++; if(inrange == false) continue; if(path.size() == 0) result.append(node); else { auto list = node.find(path.merge("/")); for(auto& item : list) result.append(item); } } return result; }
void PieChart3D::paintSides( QPainter& painter ) { QList<QPair<QPainterPath, QColor> > rightBottom; QList<QPair<QPainterPath, QColor> > rightTop; QList<QPair<QPainterPath, QColor> > leftBottom; QList<QPair<QPainterPath, QColor> > leftTop; for ( int i = 0; i < myAngles.count() - 2; i+=2 ) { QModelIndex index = this->model()->index( i/2, 0 ); bool isSelected = this->selectionModel()->selectedIndexes().contains( index ) || this->currentIndex() == index; QColor color( this->model()->data( index, Qt::DecorationRole ).toString() ); if ( !color.isValid() ) { color = Marb::predefinedColor( i/2 ); } QPointF offset = splittedOffset( myAngles[i], myAngles[i + 1] ); QPainterPath path = this->side( myAngles[i], offset, isSelected ); if ( myAngles[i] <= 90 ) { rightBottom << QPair<QPainterPath, QColor>(path, color); } else if ( myAngles[i] <= 180 ) { leftBottom.prepend( QPair<QPainterPath, QColor>(path, color) ); } else if ( myAngles[i] <= 270 ) { leftTop.prepend( QPair<QPainterPath, QColor>(path, color) ); } else { rightTop << QPair<QPainterPath, QColor>(path, color); } path = side( myAngles[i] + myAngles[i+1], offset, isSelected ); if ( myAngles[i] <= 90 ) { rightBottom << QPair<QPainterPath, QColor>(path, color); } else if ( myAngles[i] <= 180 ) { leftBottom.prepend( QPair<QPainterPath, QColor>(path, color) ); } else if ( myAngles[i] <= 270 ) { leftTop.prepend( QPair<QPainterPath, QColor>(path, color) ); } else { rightTop << QPair<QPainterPath, QColor>(path, color); } } QPair<QPainterPath, QColor> pair; leftTop << rightTop << leftBottom << rightBottom; foreach( pair, leftTop ) { configureColor( painter, pair.second, 2 ); painter.drawPath( pair.first ); }
void SurfaceDialog::addSurfaceEvent(){ gtk_widget_set_sensitive(GTK_WIDGET(m_rbBezier), false); gtk_widget_set_sensitive(GTK_WIDGET(m_rbBSpline), false); int num = 0; if(m_type == ObjType::BEZIER_SURFACE){ num = 3; }else if(m_type == ObjType::BSPLINE_SURFACE){ num = 1; } char *tmpSide = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(m_comboBox)); std::string side(tmpSide); delete tmpSide; if(side == "Ao lado"){ for(int col = 0; col < num; col++){ gtk_grid_insert_column(GTK_GRID(m_grid), m_max_j); for(int line = 0; line < m_max_i; line++){ gtk_grid_attach (GTK_GRID(m_grid), gtk_label_new(NULL), m_max_j, line, 1, 1); gtk_widget_show(gtk_grid_get_child_at(GTK_GRID(m_grid), m_max_j, line)); } ++m_max_j; } }else if(side == "Abaixo"){ for(int line = 0; line < num; line++){ gtk_grid_insert_row(GTK_GRID(m_grid), m_max_i); for(int col = 0; col < m_max_j; col++){ gtk_grid_attach (GTK_GRID(m_grid), gtk_label_new(NULL), col, m_max_i, 1, 1); gtk_widget_show(gtk_grid_get_child_at(GTK_GRID(m_grid), col, m_max_i)); } ++m_max_i; } } }
long testSerializeFromStringAndValidateNewOrderSingle( int count ) { FIX::ClOrdID clOrdID( "ORDERID" ); FIX::HandlInst handlInst( '1' ); FIX::Symbol symbol( "LNUX" ); FIX::Side side( FIX::Side_BUY ); FIX::TransactTime transactTime; FIX::OrdType ordType( FIX::OrdType_MARKET ); FIX42::NewOrderSingle message ( clOrdID, handlInst, symbol, side, transactTime, ordType ); std::string string = message.toString(); count = count - 1; long start = GetTickCount(); for ( int i = 0; i <= count; ++i ) { message.setString( string, VALIDATE, s_dataDictionary.get() ); } return GetTickCount() - start; }
//! Access, and construction of side worksets Teuchos::RCP<std::map<unsigned,Workset> > WorksetContainer::getSideWorksets(const BC & bc) { Teuchos::RCP<std::map<unsigned,Workset> > worksetMap; SideId side(bc); SideMap::iterator itr = sideWorksets_.find(side); if(itr==sideWorksets_.end()) { // couldn't find workset, build it! const std::string & eBlock = side.eblk_id; const PhysicsBlock & pb = lookupPhysicsBlock(eBlock); worksetMap = wkstFactory_->getSideWorksets(bc,pb); // store map for reuse in the future sideWorksets_[side] = worksetMap; } else { worksetMap = itr->second; } return worksetMap; }
void ChessGame::startTurn() { if (m_paused) return; Chess::Side side(m_board->sideToMove()); Q_ASSERT(!side.isNull()); emit humanEnabled(m_player[side]->isHuman()); Chess::Move move(bookMove(side)); if (move.isNull()) { m_player[side]->go(); m_player[side.opposite()]->startPondering(); } else { m_player[side.opposite()]->clearPonderState(); m_player[side]->makeBookMove(move); } }
//-------------------------------------------------------------------------------------------------- /// Classify where the points are located relative to the plane /// /// \param points Points to test for location relative the plane /// /// \return Plane::FRONT if points are either Plane::FRONT or Plane::ON\n /// Plane::BACK if points are either Plane::BACK or Plane::ON\n /// Plane::ON if all points are Plane::ON\n /// Plane::BOTH if points are located on both sides //-------------------------------------------------------------------------------------------------- Plane::Side Plane::side(const Vec3dArray& points) const { // Code taken from // http://code.google.com/p/papervision3d/source/browse/trunk/as3/trunk/src/org/papervision3d/core/math/util/ClassificationUtil.as cvf::uint frontCount = 0; cvf::uint backCount = 0; for (size_t i = 0; i < points.size(); i++) { Side s = side(points[i]); if (s == FRONT) { frontCount++; } else if (s == BACK) { backCount++; } } if (frontCount > 0 && backCount == 0) { return FRONT; } else if (frontCount == 0 && backCount > 0) { return BACK; } else if (frontCount > 0 && backCount > 0) { return BOTH; } else { return ON; } }
bool ConvexHull::PointInsideHull(const Vec2f &point) { int sgn = 0; for(unsigned int i = 0, numVertices = m_vertices.size(); i < numVertices; i++) { int wrappedIndex = Wrap(i + 1, numVertices); Vec2f currentVertex(GetWorldVertex(i)); Vec2f side(GetWorldVertex(wrappedIndex) - currentVertex); Vec2f toPoint(point - currentVertex); float cpd = side.Cross(toPoint); int cpdi = static_cast<int>(cpd / abs(cpd)); if(sgn == 0) sgn = cpdi; else if(cpdi != sgn) return false; } return true; }
long testValidateDictNewOrderSingle( int count ) { FIX::ClOrdID clOrdID( "ORDERID" ); FIX::HandlInst handlInst( '1' ); FIX::Symbol symbol( "LNUX" ); FIX::Side side( FIX::Side_BUY ); FIX::TransactTime transactTime; FIX::OrdType ordType( FIX::OrdType_MARKET ); FIX42::NewOrderSingle message ( clOrdID, handlInst, symbol, side, transactTime, ordType ); message.getHeader().set( FIX::SenderCompID( "SENDER" ) ); message.getHeader().set( FIX::TargetCompID( "TARGET" ) ); message.getHeader().set( FIX::MsgSeqNum( 1 ) ); count = count - 1; long start = GetTickCount(); for ( int i = 0; i <= count; ++i ) { s_dataDictionary->validate( message ); } return GetTickCount() - start; }
void ChessGame::onResultClaim(const Chess::Result& result) { if (m_finished) return; ChessPlayer* sender = qobject_cast<ChessPlayer*>(QObject::sender()); Q_ASSERT(sender != nullptr); if (result.type() == Chess::Result::Disconnection) { // The engine may not be properly started so we have to // figure out the player's side this way Chess::Side side(Chess::Side::White); if (m_player[side] != sender) side = Chess::Side::Black; m_result = Chess::Result(result.type(), side.opposite()); } else if (!m_gameInProgress && result.winner().isNull()) { qWarning("Unexpected result claim from %s: %s", qPrintable(sender->name()), qPrintable(result.toVerboseString())); } else if (sender->areClaimsValidated() && result.loser() != sender->side()) { qWarning("%s forfeits by invalid result claim: %s", qPrintable(sender->name()), qPrintable(result.toVerboseString())); m_result = Chess::Result(Chess::Result::Adjudication, sender->side().opposite(), "Invalid result claim"); } else m_result = result; stop(); }