本文整理汇总了C++中Vector2D类的典型用法代码示例。如果您正苦于以下问题:C++ Vector2D类的具体用法?C++ Vector2D怎么用?C++ Vector2D使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vector2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tausche
void tausche(Vector2D* a, Vector2D*b)
{
Vector2D help = *a;
b->kopiereIn(a);
help.kopiereIn(b);
}
示例2: ball_line
/*!
execute action
*/
bool
Bhv_GoalieChaseBall::execute( PlayerAgent * agent )
{
dlog.addText( Logger::TEAM,
__FILE__": Bhv_GoalieChaseBall" );
//////////////////////////////////////////////////////////////////
// tackle
if ( Bhv_BasicTackle( 0.8, 90.0 ).execute( agent ) )
{
dlog.addText( Logger::TEAM,
__FILE__": tackle" );
return true;
}
const ServerParam & SP = ServerParam::i();
const WorldModel & wm = agent->world();
////////////////////////////////////////////////////////////////////////
// get active interception catch point
Vector2D my_int_pos = wm.ball().inertiaPoint( wm.interceptTable()->selfReachCycle() );
dlog.addText( Logger::TEAM,
__FILE__": execute. intercept point=(%.2f %.2f)",
my_int_pos.x, my_int_pos.y );
double pen_thr = wm.ball().distFromSelf() * 0.1 + 1.0;
if ( pen_thr < 1.0 ) pen_thr = 1.0;
//----------------------------------------------------------
const Line2D ball_line( wm.ball().pos(), wm.ball().vel().th() );
const Line2D defend_line( Vector2D( wm.self().pos().x, -10.0 ),
Vector2D( wm.self().pos().x, 10.0 ) );
if ( my_int_pos.x > - SP.pitchHalfLength() - 1.0
&& my_int_pos.x < SP.ourPenaltyAreaLineX() - pen_thr
&& my_int_pos.absY() < SP.penaltyAreaHalfWidth() - pen_thr )
{
bool save_recovery = false;
if ( ball_line.dist( wm.self().pos() ) < SP.catchableArea() )
{
save_recovery = true;
}
dlog.addText( Logger::TEAM,
__FILE__": execute normal intercept" );
agent->debugClient().addMessage( "Intercept(0)" );
Body_Intercept( save_recovery ).execute( agent );
agent->setNeckAction( new Neck_TurnToBall() );
return true;
}
int self_goalie_min = wm.interceptTable()->selfReachCycle();
int opp_min_cyc = wm.interceptTable()->opponentReachCycle();
Vector2D intersection = ball_line.intersection( defend_line );
if ( ! intersection.isValid()
|| ball_line.dist( wm.self().pos() ) < SP.catchableArea() * 0.8
|| intersection.absY() > SP.goalHalfWidth() + 3.0
)
{
if ( ! wm.existKickableOpponent() )
{
if ( self_goalie_min <= opp_min_cyc + 2
&& my_int_pos.x > -SP.pitchHalfLength() - 2.0
&& my_int_pos.x < SP.ourPenaltyAreaLineX() - pen_thr
&& my_int_pos.absY() < SP.penaltyAreaHalfWidth() - pen_thr
)
{
if ( Body_Intercept( false ).execute( agent ) )
{
dlog.addText( Logger::TEAM,
__FILE__": execute normal interception" );
agent->debugClient().addMessage( "Intercept(1)" );
agent->setNeckAction( new Neck_TurnToBall() );
return true;
}
}
dlog.addText( Logger::TEAM,
__FILE__": execute. ball vel has same slope to my body??"
" myvel-ang=%f body=%f. go to ball direct",
wm.ball().vel().th().degree(),
wm.self().body().degree() );
// ball vel angle is same to my body angle
agent->debugClient().addMessage( "GoToCatch(1)" );
doGoToCatchPoint( agent, wm.ball().pos() );
return true;
}
}
//----------------------------------------------------------
// body is already face to intersection
// only dash to intersection
// check catch point
if ( intersection.absX() > SP.pitchHalfLength() + SP.catchableArea()
|| intersection.x > SP.ourPenaltyAreaLineX() - SP.catchableArea()
//.........这里部分代码省略.........
示例3: normalize
float Vector2D::normalizedDot(Vector2D v){
Vector2D normedV1 = normalize();
Vector2D normedV2 = v.normalize();
return ( normedV1.x*normedV2.x + normedV1.y*normedV2.y );
}
示例4: translate
void VideoManager::translate(const Vector2D &vector) const
{
glTranslatef(vector.getX(), vector.getY(), 0.0f);
}
示例5: if
/*!
*/
void
Bhv_GoalieChaseBall::doGoToCatchPoint( PlayerAgent * agent,
const Vector2D & target_point )
{
const ServerParam & SP = ServerParam::i();
const WorldModel & wm = agent->world();
double dash_power = 0.0;
Vector2D rel = target_point - wm.self().pos();
rel.rotate( - wm.self().body() );
AngleDeg rel_angle = rel.th();
const double angle_buf
= std::fabs( AngleDeg::atan2_deg( SP.catchableArea() * 0.9, rel.r() ) );
dlog.addText( Logger::TEAM,
__FILE__": GoToCatchPoint. (%.1f, %.1f). angle_diff=%.1f. angle_buf=%.1f",
target_point.x, target_point.y,
rel_angle.degree(), angle_buf );
agent->debugClient().setTarget( target_point );
// forward dash
if ( rel_angle.abs() < angle_buf )
{
dash_power = std::min( wm.self().stamina() + wm.self().playerType().extraStamina(),
SP.maxDashPower() );
dlog.addText( Logger::TEAM,
__FILE__": forward dash" );
agent->debugClient().addMessage( "GoToCatch:Forward" );
agent->doDash( dash_power );
}
// back dash
else if ( rel_angle.abs() > 180.0 - angle_buf )
{
dash_power = SP.minDashPower();
double required_stamina = ( SP.minDashPower() < 0.0
? SP.minDashPower() * -2.0
: SP.minDashPower() );
if ( wm.self().stamina() + wm.self().playerType().extraStamina()
< required_stamina )
{
dash_power = wm.self().stamina() + wm.self().playerType().extraStamina();
if ( SP.minDashPower() < 0.0 )
{
dash_power *= -0.5;
if ( dash_power < SP.minDashPower() )
{
dash_power = SP.minDashPower();
}
}
}
dlog.addText( Logger::TEAM,
__FILE__": back dash. power=%.1f",
dash_power );
agent->debugClient().addMessage( "GoToCatch:Back" );
agent->doDash( dash_power );
}
// forward dash turn
else if ( rel_angle.abs() < 90.0 )
{
dlog.addText( Logger::TEAM,
__FILE__": turn %.1f for forward dash",
rel_angle.degree() );
agent->debugClient().addMessage( "GoToCatch:F-Turn" );
agent->doTurn( rel_angle );
}
else
{
rel_angle -= 180.0;
dlog.addText( Logger::TEAM,
__FILE__": turn %.1f for back dash",
rel_angle.degree() );
agent->debugClient().addMessage( "GoToCatch:B-Turn" );
agent->doTurn( rel_angle );
}
agent->setNeckAction( new Neck_TurnToBall() );
}
示例6: Circle
Circle(const Point2D < T > &Point, const Vector2D < T > &Vector) {
this->Centre = Point;
this->R = Vector.Norm();
}
示例7: yp
Vector3D::Vector3D(const Vector2D &vector):xp(vector.x()), yp(vector.y()), zp(0.0){}
示例8: inertia_final_point
/*!
*/
double
TackleGenerator::evaluate( const WorldModel & wm,
const TackleResult & result )
{
const ServerParam & SP = ServerParam::i();
const Vector2D ball_end_point = inertia_final_point( wm.ball().pos(),
result.ball_vel_,
SP.ballDecay() );
const Segment2D ball_line( wm.ball().pos(), ball_end_point );
const double ball_speed = result.ball_speed_;
const AngleDeg ball_move_angle = result.ball_move_angle_;
#ifdef DEBUG_PRINT
dlog.addText( Logger::CLEAR,
"(evaluate) angle=%.1f speed=%.2f move_angle=%.1f end_point=(%.2f %.2f)",
result.tackle_angle_.degree(),
ball_speed,
ball_move_angle.degree(),
ball_end_point.x, ball_end_point.y );
#endif
//
// moving to their goal
//
if ( ball_end_point.x > SP.pitchHalfLength()
&& wm.ball().pos().dist2( SP.theirTeamGoalPos() ) < std::pow( 20.0, 2 ) )
{
const Line2D goal_line( Vector2D( SP.pitchHalfLength(), 10.0 ),
Vector2D( SP.pitchHalfLength(), -10.0 ) );
const Vector2D intersect = ball_line.intersection( goal_line );
if ( intersect.isValid()
&& intersect.absY() < SP.goalHalfWidth() )
{
double shoot_score = 1000000.0;
double speed_rate = 1.0 - std::exp( - std::pow( ball_speed, 2 )
/ ( 2.0 * std::pow( SP.ballSpeedMax()*0.5, 2 ) ) );
double y_rate = std::exp( - std::pow( intersect.absY(), 2 )
/ ( 2.0 * std::pow( SP.goalWidth(), 2 ) ) );
shoot_score *= speed_rate;
shoot_score *= y_rate;
#ifdef DEBUG_PRINT
dlog.addText( Logger::CLEAR,
"__ shoot %f (speed_rate=%f y_rate=%f)",
shoot_score, speed_rate, y_rate );
#endif
return shoot_score;
}
}
//
// moving to our goal
//
if ( ball_end_point.x < -SP.pitchHalfLength() )
{
const Line2D goal_line( Vector2D( -SP.pitchHalfLength(), 10.0 ),
Vector2D( -SP.pitchHalfLength(), -10.0 ) );
const Vector2D intersect = ball_line.intersection( goal_line );
if ( intersect.isValid()
&& intersect.absY() < SP.goalHalfWidth() + 1.0 )
{
double shoot_score = 0.0;
double y_penalty = ( -10000.0
* std::exp( - std::pow( intersect.absY() - SP.goalHalfWidth(), 2 )
/ ( 2.0 * std::pow( SP.goalHalfWidth(), 2 ) ) ) );
double speed_bonus = ( +10000.0
* std::exp( - std::pow( ball_speed, 2 )
/ ( 2.0 * std::pow( SP.ballSpeedMax()*0.5, 2 ) ) ) );
shoot_score = y_penalty + speed_bonus;
#ifdef DEBUG_PRINT
dlog.addText( Logger::CLEAR,
"__ in our goal %f (y_pealty=%f speed_bonus=%f)",
shoot_score, y_penalty, speed_bonus );
#endif
return shoot_score;
}
}
//
// normal evaluation
//
int opponent_reach_step = predictOpponentsReachStep( wm,
wm.ball().pos(),
result.ball_vel_,
ball_move_angle );
Vector2D final_point = inertia_n_step_point( wm.ball().pos(),
result.ball_vel_,
opponent_reach_step,
SP.ballDecay() );
{
Segment2D final_segment( wm.ball().pos(), final_point );
Rect2D pitch = Rect2D::from_center( 0.0, 0.0, SP.pitchLength(), SP.pitchWidth() );
Vector2D intersection;
int n = pitch.intersection( final_segment, &intersection, NULL );
if ( n > 0 )
{
//.........这里部分代码省略.........
示例9:
float Vector2D::distance(const Vector2D& rhs) const
{
Vector2D val = (*this);
val -= rhs;
return val.length();
}
示例10: tausche
void tausche(Vector2D &a, Vector2D &b){
Vector2D temp;
temp.kopiereIn(a);
a.kopiereIn(b);
b.kopiereIn(temp);
}
示例11: TackleResult
/*!
*/
void
TackleGenerator::calculate( const WorldModel & wm )
{
const ServerParam & SP = ServerParam::i();
const double min_angle = SP.minMoment();
const double max_angle = SP.maxMoment();
const double angle_step = std::fabs( max_angle - min_angle ) / ANGLE_DIVS;
#ifdef ASSUME_OPPONENT_KICK
const Vector2D goal_pos = SP.ourTeamGoalPos();
const bool shootable_area = ( wm.ball().pos().dist2( goal_pos ) < std::pow( 18.0, 2 ) );
const Vector2D shoot_accel = ( goal_pos - wm.ball().pos() ).setLengthVector( 2.0 );
#endif
const AngleDeg ball_rel_angle = wm.ball().angleFromSelf() - wm.self().body();
const double tackle_rate
= SP.tacklePowerRate()
* ( 1.0 - 0.5 * ball_rel_angle.abs() / 180.0 );
#ifdef DEBUG_PRINT
dlog.addText( Logger::CLEAR,
__FILE__": min_angle=%.1f max_angle=%.1f angle_step=%.1f",
min_angle, max_angle, angle_step );
dlog.addText( Logger::CLEAR,
__FILE__": ball_rel_angle=%.1f tackle_rate=%.1f",
ball_rel_angle.degree(), tackle_rate );
#endif
for ( int a = 0; a < ANGLE_DIVS; ++a )
{
const AngleDeg dir = min_angle + angle_step * a;
double eff_power= ( SP.maxBackTacklePower()
+ ( SP.maxTacklePower() - SP.maxBackTacklePower() )
* ( 1.0 - ( dir.abs() / 180.0 ) ) );
eff_power *= tackle_rate;
AngleDeg angle = wm.self().body() + dir;
Vector2D accel = Vector2D::from_polar( eff_power, angle );
#ifdef ASSUME_OPPONENT_KICK
if ( shootable_area
&& wm.existKickableOpponent() )
{
accel += shoot_accel;
double d = accel.r();
if ( d > SP.ballAccelMax() )
{
accel *= ( SP.ballAccelMax() / d );
}
}
#endif
Vector2D vel = wm.ball().vel() + accel;
double speed = vel.r();
if ( speed > SP.ballSpeedMax() )
{
vel *= ( SP.ballSpeedMax() / speed );
}
M_candidates.push_back( TackleResult( angle, vel ) );
#ifdef DEBUG_PRINT
const TackleResult & result = M_candidates.back();
dlog.addText( Logger::CLEAR,
"%d: angle=%.1f(dir=%.1f), result: vel(%.2f %.2f ) speed=%.2f move_angle=%.1f",
a,
result.tackle_angle_.degree(), dir.degree(),
result.ball_vel_.x, result.ball_vel_.y,
result.ball_speed_, result.ball_move_angle_.degree() );
#endif
}
M_best_result.clear();
const Container::iterator end = M_candidates.end();
for ( Container::iterator it = M_candidates.begin();
it != end;
++it )
{
it->score_ = evaluate( wm, *it );
#ifdef DEBUG_PRINT
Vector2D ball_end_point = inertia_final_point( wm.ball().pos(),
it->ball_vel_,
SP.ballDecay() );
dlog.addLine( Logger::CLEAR,
wm.ball().pos(),
ball_end_point,
"#0000ff" );
char buf[16];
snprintf( buf, 16, "%.3f", it->score_ );
dlog.addMessage( Logger::CLEAR,
ball_end_point, buf, "#ffffff" );
#endif
//.........这里部分代码省略.........
示例12: handleMovement
void Chaser::handleMovement(Vector2D velocity)
{
Vector2D newPos = m_position;
newPos.x(m_position.x() + velocity.x());
if (newPos.x() == m_playerPos->x())
{
m_velocity.x(0);
}
else
{
// check if the chaser is trying to go off the map
if (newPos.x() + getCollider().x < 0)
{
m_position.x(-getCollider().x);
}
else if (newPos.x() + getCollider().x + getCollider().w > TheGame::Instance().getMapWidth())
{
m_position.x(TheGame::Instance().getMapWidth() - getCollider().w - getCollider().x);
}
else
{
if (checkCollideTile(newPos) || checkCollideObject(newPos))
{
// collision, stop x movement
m_velocity.x(0);
if (checkCollideTile(newPos))
{
// Collision with the map, move to contact
if (m_position.x() < newPos.x()) // Collision with tile to the right
{
m_position.x(m_position.x() + (
abs(m_xSpeed) - (int(newPos.x() + getCollider().x + getCollider().w) % (*m_pCollisionLayers->begin())->getTileSize())));
}
else // Collision with tile to the left
{
m_position.x(m_position.x() -
(int(m_position.x() + getCollider().x) % (*m_pCollisionLayers->begin())->getTileSize()));
}
}
}
else
{
// no collision, add to the actual x position
m_position.x(newPos.x());
}
}
}
newPos.x(m_position.x());
newPos.y(m_position.y() + velocity.y());
// check if the chaser is going below map limits
if (newPos.y() + getCollider().y + getCollider().h > TheGame::Instance().getMapHeight())
{
m_position.y(TheGame::Instance().getMapHeight() - getCollider().h - getCollider().y);
m_velocity.y(0);
}
else
{
if (checkCollideTile(newPos) || checkCollideObject(newPos))
{
// Collision, stop y movement
m_velocity.y(0);
if (checkCollideTile(newPos))
{
// Collision with map, move to contact. Chaser doesn't jump so it's a lower tile
m_position.y(m_position.y() +
(m_ySpeed - (int(newPos.y() + getCollider().y + getCollider().h) % (*m_pCollisionLayers->begin())->getTileSize())));
}
}
else
{
// no collision, add to the actual y position
m_position.y(newPos.y());
}
}
}
示例13: bilinearInterpolate
double bilinearInterpolate(double xy, double x1y,double xy1, double x1y1, Vector2D p){
return (1-p.x())*(1-p.y())*xy + p.x()*(1-p.y())*x1y +
(1-p.x())*p.y()*xy1 + p.x()*p.y()*x1y1;
}
示例14: addData
RobotCommand TacticTransferObject::getCommand()
{
AllInMargin=true;
RobotCommand rc;
if(!wm->ourRobot[id].isValid) return rc;
rc.useNav=true;
rc.maxSpeed = 1;
rc.fin_pos.loc=wm->endPoint;//Vector2D(300,0);
int object;
addData();
mergeData();
sortData();
// if(wm->balls.size() > 0)
// {
// qDebug()<< " BALLL . X = " << wm->balls.at(0)->pos.loc.x << " BALLL . Y = " << wm->balls.at(0)->pos.loc.y;
// qDebug() << " MAX x : " << region[1].maxX() << " MIN X : " << region[1].minX() ;
// qDebug() << " MAX y : " << region[1].maxY() << " MIN y : " << region[1].minY() ;
// if(region[0].IsInside(wm->balls.at(0)->pos.loc)) qDebug() << " THE BALLLLL ISSS INNNNN SIDE !!!!!!!!!!!!!!!!!!!!!!1";
// }
index = -1;
for(int i=0;i<mergedList.size();i++)
{
// qDebug() << i << " AT : (" << mergedList.at(i).pos.x << "," << mergedList.at(i).pos.y << ")";
temp=0;
if(!region[mergedList.at(i).goalRegion].IsInside(mergedList.at(i).pos) && !IsInmargins(mergedList.at(i).pos,300))
{
//qDebug() <<" OBJECT : " << mergedList.at(i).pos.x << " ------ Y = " << mergedList.at(i).pos.y;// TOOOOOOOOOOOOOOOOOOOSHE !!!!!!!" << index ;
// AllInMargin=false;
index=i;
goalRegion=mergedList.at(i).goalRegion;
temp=1;
break;
}
}
for(int i=0; i<mergedList.size(); i++)
{
if(!IsInmargins(mergedList.at(i).pos,300))
{
AllInMargin=false;
}
}
if(AllInMargin)
{
for(int i=0;i<mergedList.size();i++)
{
if(!region[mergedList.at(i).goalRegion].IsInside(mergedList.at(i).pos))
{
index=i;
goalRegion=mergedList.at(i).goalRegion;
break;
}
}
}
// if(index ==-1)
// {
// for(int i=0;i<wm->Chasbideh.size(); i++)
// {
// if(!region[0].IsInside(wm->Chasbideh.at(i).position) && !region[1].IsInside(wm->Chasbideh.at(i).position))
// {
// //qDebug() <<" OBJECT : " << mergedList.at(i).pos.x << " ------ Y = " << mergedList.at(i).pos.y;// TOOOOOOOOOOOOOOOOOOOSHE !!!!!!!" << index ;
// index=i;
// goalRegion=0;//mergedList.at(i).goalRegion;
// temp=1;
// break;
// }
// }
// }
// qDebug() << mergedList.size() << " MERGED SIZE " ;
if(index != -1)
{
Vector2D point2 = mergedList.at(index).pos;
Vector2D diff2 = region[goalRegion].center() - point2;
bool reach=false;
if(temp!=0)
{
switch(state)
{
case 0:{ //Go Behind the Object
Vector2D space2=diff2;
space2.setLength(300);
rc.maxSpeed=1.4;
rc.useNav = true;
rc.fin_pos.loc=point2 - space2;
rc.fin_pos.dir=diff2.dir().radian();
object=findnearestObject(mergedShapeList,wm->ourRobot[id].pos.loc);
if(object!=-1) ObsC=Circle2D(mergedShapeList.at(object).position,(mergedShapeList.at(object).roundedRadios+ROBOT_RADIUS+150));
rc.fin_pos.loc=AvoidtoEnterCircle(ObsC,wm->ourRobot[id].pos.loc,rc.fin_pos.loc);
//.........这里部分代码省略.........
示例15:
float Vector2D::SqDistance(const Vector2D & v) const
{
Vector2D mag = v - *this;
return mag.GetLengthSq();
}