本文整理汇总了C++中b2Vec2::Length方法的典型用法代码示例。如果您正苦于以下问题:C++ b2Vec2::Length方法的具体用法?C++ b2Vec2::Length怎么用?C++ b2Vec2::Length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类b2Vec2
的用法示例。
在下文中一共展示了b2Vec2::Length方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Contact
void Bird::Contact(b2Vec2 impulse, GameItem *gameItem)
{
if(impulse.Length()>0)
{
remove=1;
travel=false;
isOut = 2;
setScore(impulse.Length());
}
else
{
isContact = false;
}
}
示例2: accumForce
bool Neural_SB::accumForce(b2Vec2 & totForce, b2Vec2 force) const
{
//std::cout << "\t\tTotalForce : " << totForce.x << " " << totForce.y << std::endl;
b2Vec2 tot = totForce + force;
if( tot.LengthSquared() <= m_fMaxForce*m_fMaxForce )
{
totForce += force;
return true;
}
force.Normalize();
force *= abs(m_fMaxForce - totForce.Length());
totForce += force;
return false;
}
示例3: ccTouchEnded
void LiquidFunScene::ccTouchEnded(cocos2d::CCTouch* touch,
cocos2d::CCEvent* event){
if (m_startSprite != NULL) {
const CCPoint& startSpritePosition = m_startSprite->getPosition();
const CCPoint& endSpritePosition = m_endSprite->getPosition();
// Calculate the start / end and length of the vector between them in
// world coordinates.
const b2Vec2 startPosition = ConvertScreenPositionToWorld(
b2Vec2(startSpritePosition.x, startSpritePosition.y));
const b2Vec2 endPosition = ConvertScreenPositionToWorld(
b2Vec2(endSpritePosition.x, endSpritePosition.y));
const b2Vec2 startEndVector = endPosition - startPosition;
const float32 startEndLength = startEndVector.Length();
// Calculate the middle point along the vector between startPosition and
// endPosition.
b2Vec2 midPoint;
midPoint = startEndVector;
midPoint *= 0.5f;
midPoint += startPosition;
b2PolygonShape box;
box.SetAsBox(startEndLength * 0.5f,
k_drawableBoxThickness * m_worldExtentMin);
b2BodyDef bodyDef;
bodyDef.type = b2_staticBody;
bodyDef.position = midPoint;
bodyDef.angle = atan2(startEndVector.y, startEndVector.x);
b2Body* body = m_world->CreateBody(&bodyDef);
body->CreateFixture(&box, 0);
removeChild(m_startSprite);
removeChild(m_endSprite);
// These will be cleaned up by the autorelease system since they were
// allocated by init()
m_startSprite = NULL;
m_endSprite = NULL;
}
}
示例4: RadiansOf
float RadiansOf(b2Vec2 vec) {
static b2Vec2 vertical(0, -1);
float dot = (vertical.x * vec.x) + (vertical.y * vec.y);
float angle_r = acos(dot / (vertical.Length() * vec.Length()));
return angle_r;
}
示例5: chaseFire
//Chase firing
bool Enemy::chaseFire(b2Vec2 & rFireV)
{
bool trigger = false;
//Did we fire?
if (fired_)
{
angry_ = fmaxf(angry_ - triggerSatisfaction_[brainStem_.weapon_training], 0);
fired_ = false;
}
//Fire at player?
if (play_)
{
b2Vec2 myPos = getPosition();
b2Vec2 pPos = player_->getPosition();
b2Vec2 between = (pPos - myPos);
float dist = between.Length();
//Fire if in visible range and
if (dist < visRange_[brainStem_.sensitivity] && chill_ > freezingPoint_)
{
rFireV = LJP(pPos, 100, 0, 2.0, 0); //*//Fire LJP const?
}
}
//DECIDE TO FIRE
float seePlayer = rFireV.Length();
float ammo = (float)getWeaponBar() / (float)getWeaponBarMAX();
//Otherwise, heat up, chill first
if (seePlayer != 0)
{
orient(rFireV);
if (chill_ != 0) chill_ = fminf(chill_ += seePlayer * 4 * moodMult_[brainStem_.aggression], 0);
else angry_ = fminf(angry_ + seePlayer * moodMult_[brainStem_.aggression], angryMAX_);
}
//If we're mad enough and we can see the player, fire
if (angry_ > boilingPoint_ && seePlayer != 0)
{
trigger = true;
}
//Reload if we're cool enough
if (angry_ - boilingPoint_ > (angryMAX_ - boilingPoint_) * accuracy_[brainStem_.weapon_training] * moodMult_[brainStem_.aggression]) //*//weapon training, aggression
{
if (ammo < accuracy_[brainStem_.weapon_training]) //*// weapon training causes later reloads
reup();
}
//Chill out when idle
if (angry_ == 0 && seePlayer == 0)
{
chill_ -= 1 * moodMult_[brainStem_.inner_peace];
if (chill_ <= freezingPoint_)
{
if (ammo < 1.f)
reup();
spin(-0.05f);
}
}
chill_ = fmax(chill_, chillMIN_);
return trigger;
}
示例6: sumMagnitude
float sumMagnitude(sf::Vector2f& V1, b2Vec2& V2)
{
return sqrtf(V1.x*V1.x + V1.y*V1.y) + V2.Length();
}